Control 2 VESCs with external CAN

Support for creating custom user applications on the VESC.
Dimitri.d
Posts: 4
Joined: 03 Feb 2017, 09:55
Location: Paris

Control 2 VESCs with external CAN

Postby Dimitri.d » 03 Feb 2017, 10:26

Hello,

I'm working on a project, and I would like to control 2 VESC with external CAN.

I'd like to be able to :

- Control each VESC speed independently
- Control each VESC direction of rotation independently
- Control each VESC braking current independently

I'm aware that I can give each VESC a different ID, but I would like to know what kind of CAN frame should I send to it.

I studied the source code and I guess I should send something like : |Controller ID|Command|Parameter|
where Controller ID is the ID i setted on BLDC tool, Command is (Duty cycle, braking current, etc.)

So I would like to know the bytes (corresponding to each command) that I have to send.

I would also like to know if I can get each VESC current informations on the CAN bus.

Thanks in advance for your replies.

Dimitri

pf26
Posts: 278
Joined: 28 Mar 2016, 14:37
Location: FR Valence

Re: Control 2 VESCs with external CAN

Postby pf26 » 03 Feb 2017, 17:11

you need to program your CAN engine (500kbds, receive filters..) to be able to send or receive the CAN messages from VESC.
You can get inspiration on frames by the file from VESC code named "comm_can.c".
To sen a position request using a PIC18 with can bus, it goes like:

Code: Select all

   TXB0SIDH = 0;
   TXB0SIDL = 0x18;   // Extd message filter : 0x00
   TXB0EIDL = ID;      // VESC destination ID
   TXB0EIDH = CAN_PACKET_SET_POS;   // Command to send to VESC - for example  CAN_PACKET_SET_POS=4
      TXB0DLC = 8;  // 8 bytes to transmit
   TXB0D0 = position >> 24;
   TXB0D1 = position >> 16;
   ...
   TXB0CONbits.TXREQ=1;    // Mark this buffer as ready to start transmit.

Dimitri.d
Posts: 4
Joined: 03 Feb 2017, 09:55
Location: Paris

Re: Control 2 VESCs with external CAN

Postby Dimitri.d » 06 Feb 2017, 08:19

Thanks for your reply.

My problem is that I can't find the decimal values of the different commands to send.
Where did you get "CAN_PACKET_SET_POS = 4". I'm not seeing this in the "comm_can.c"

Dimitri.d
Posts: 4
Joined: 03 Feb 2017, 09:55
Location: Paris

Re: Control 2 VESCs with external CAN

Postby Dimitri.d » 06 Feb 2017, 08:25

My bad,
I just saw that the different commands ID have been declared in the file "datatypes.h"

Thanks again for your help

I also wanted to know if I can get VESC information like Current over the CAN bus ?

Dimitri.d
Posts: 4
Joined: 03 Feb 2017, 09:55
Location: Paris

Re: Control 2 VESCs with external CAN

Postby Dimitri.d » 07 Feb 2017, 16:04

Thanks a lot, this is exactly what I needed

s28500
Posts: 12
Joined: 13 Sep 2016, 18:33
Location: Florida
Contact:

Re: Control 2 VESCs with external CAN

Postby s28500 » 06 Apr 2017, 19:21

Did you figure out how to pull info from the VESC units over CAN? Also, are you using the TI SN65HVD232 Transceiver as your external can IC?
Thanks!

benjamin
Site Admin
Posts: 280
Joined: 15 Dec 2015, 08:38
Location: Sweden
Contact:

Re: Control 2 VESCs with external CAN

Postby benjamin » 07 Apr 2017, 07:23

A tutorial would probably be helpful, but here is the CAN interface I'm using for a self driving RC car:
https://github.com/vedderb/rise_sdvp/bl ... comm_can.c

and here is the bldc interface code
https://github.com/vedderb/rise_sdvp/bl ... nterface.c
https://github.com/vedderb/rise_sdvp/bl ... nterface.h

here is an older version of the interface that should work for FW 2.16
https://github.com/vedderb/bldc_uart_co ... nterface.c
https://github.com/vedderb/bldc_uart_co ... nterface.h

There are also a few much simpler CAN commands with limited functionality, but by implementing the things above you will be able to access everything on the VESC over CAN, including changing the configuration.

s28500
Posts: 12
Joined: 13 Sep 2016, 18:33
Location: Florida
Contact:

Re: Control 2 VESCs with external CAN

Postby s28500 » 07 Apr 2017, 17:53

Thank you for the reply, Ben! I will read through the code and play with it. I can make a lite tutorial with examples once I get it working.
Cheers!

kitewinder
Posts: 16
Joined: 29 May 2017, 20:47
Location: Bordeaux

Re: Control 2 VESCs with external CAN

Postby kitewinder » 01 Jun 2017, 10:20

hello all!
I'm really interested by this topics.
for info we do that : www.kitewinder.fr
My which is to control a Vesc trough a can bus delivered by an arduino with can shield bus.

I try to figure out infos but with no great success at that point.
My first step would be just to send data from vesc ( voltage, current for example) and try to get them on the arduino can bus port. but even the conf that shall be given in bldc tool, I'm not sure about it...

Is there some update available, tutorials, anything. Any help would be greatly appreciated !

ondyll
Posts: 1
Joined: 08 Jun 2017, 12:22
Location: Prague

Re: Control 2 VESCs with external CAN

Postby ondyll » 08 Jun 2017, 12:38

benjamin wrote:A tutorial would probably be helpful, but here is the CAN interface I'm using for a self driving RC car:
https://github.com/vedderb/rise_sdvp/bl ... comm_can.c

and here is the bldc interface code
https://github.com/vedderb/rise_sdvp/bl ... nterface.c
https://github.com/vedderb/rise_sdvp/bl ... nterface.h

here is an older version of the interface that should work for FW 2.16
https://github.com/vedderb/bldc_uart_co ... nterface.c
https://github.com/vedderb/bldc_uart_co ... nterface.h

There are also a few much simpler CAN commands with limited functionality, but by implementing the things above you will be able to access everything on the VESC over CAN, including changing the configuration.


Hi Ben,

I would like first to thank you for the VESC controller which is a really great solution!

And I would like to ask about the CAN bus protocol. Are there any news? It would be great to control several VESC controllers over the CAN. I know how to configure and use a CAN bus in the microprocessor but decoding a CAN bus messages' format from the code is so time consuming. Do u have maybe a table (draft, whatever) that would contain the messages format (a name of the message, its description and meaning of its data bytes)?

I would like also to ask how is the communication from the VESC solved? Does it send its status periodically over the CAN or do I need to pull it?

Thank you very much.
Regards
Ondrej


Return to “Custom Applications”

Who is online

Users browsing this forum: No registered users and 1 guest