You are here

Dual VESC with UART communication (Arduino) - how to communicate with slave over can ?

22 posts / 0 new
Last post
GargiMan
Offline
Last seen: 11 months 2 weeks ago
Joined: 2018-09-01 01:34
Posts: 8
Dual VESC with UART communication (Arduino) - how to communicate with slave over can ?

Hey guys , if this post is in wrong topic , then i am really sorry for it , i am new here. Now what's going on ....

I have Dual VESC setup (with 2 motors) ... i am communicating with master over UART. It looks like its working.

But slave doesn't respond ... or im not even trying with second VESC i think ... because i am not using any ID selector for VESC or anything with CAN. 

I am using SolidGeek's libraries. (https://github.com/SolidGeek/VescUart)

Can someone please explain a give me example how to implement this CAN bus communication / selector maybe in example code in libraries ? 

I have search all over the browser ,but i couldnt find any example code for this. (Only found this https://vesc-project.com/node/482 but it looks like no one build a complete working example.)

 

VESC 4.12

Thanks a lot. Im in struglle with it. I need it for my high school project.

josh
josh's picture
Offline
Last seen: 6 months 2 days ago
VESC Original
Joined: 2017-05-24 12:15
Posts: 92

Sounds like it is not forwarding to the slave vesc, I would check and make sure you have the forwarding configuration setup correctly in the app settings. Make sure the slave vesc has "send status over can" option checked. I believe there is a wizard for it in the net VESC tool.

Cheers!

GargiMan
Offline
Last seen: 11 months 2 weeks ago
Joined: 2018-09-01 01:34
Posts: 8

Yes i have Status over can checked on Slave side. As i saw it doesn't need to be checked on master side.

But i need somehow enable COMM_FORWARD_CAN in Arduino. (it's in datatypes.h)

Master app settings:

Slave app settings:

Thanks a lot.

GargiMan
Offline
Last seen: 11 months 2 weeks ago
Joined: 2018-09-01 01:34
Posts: 8

Do you have any ideas that help me ? 

GargiMan
Offline
Last seen: 11 months 2 weeks ago
Joined: 2018-09-01 01:34
Posts: 8

I found this topic , probably on old forum... but there are missing link/images from comments , so i can't really get into it.

http://vedder.se/forums/viewtopic.php?t=119

josh
josh's picture
Offline
Last seen: 6 months 2 days ago
VESC Original
Joined: 2017-05-24 12:15
Posts: 92

Looks like you need to put the COMM_CAN_FOWARD value followed by the VESC ID to forward to in the first two bytes of the UART command that you wish to forward. Original quote by Ben: 

You can forward messages over CAN when using UART. To do that, make the first byte of the payload (the command) COMM_FORWARD_CAN and the second byte the ID of the controller on the bus to forward the message to. After that, the message can be the usual content. This way, you can communicate with any VESC on the CAN bus from the UART or USB port of any of them.

Another option is to use the COMM_SET_CHUCK_DATA command and configure the nunchuk app to forward over CAN.

Cheers!

GargiMan
Offline
Last seen: 11 months 2 weeks ago
Joined: 2018-09-01 01:34
Posts: 8
void VescUart::setDuty(float duty) {
  int32_t index = 0;
  uint8_t payload[5];

  payload[index++] = COMM_FORWARD_CAN;        //command for CAN comm, added by me
  payload[index++] = 1;                       //ID, added by me
  payload[index++] = COMM_SET_DUTY;
  buffer_append_int32(payload, (int32_t)(duty * 100000), &index);

  packSendPayload(payload, 5);

  //--------------------  added same bunch of commands and setting after can comm to comm with master vesc also 
  index = 0;

  payload[index++] = COMM_SET_DUTY;
  buffer_append_int32(payload, (int32_t)(duty * 100000), &index);

  packSendPayload(payload, 5);
}

yes i tried yesterday , after that i recognize that both motors tried to rotate , when i force them both on command , but both were irensponsible to my moves 

... maybe i decided to comunicate with both of them using Arduino Mega that have more serial ports ... so would be able to communicate with each separative after few code updates ... i will give you my feedback then 

repair my code if its bad also , ... i learned C++  little after few theese remakes

also if u have time to look for how to communicate with 2 vesc in same time using UART (with CANBUS) or I2C , it will also help me 

fourchette
Offline
Last seen: 2 years 11 months ago
Joined: 2018-11-07 19:29
Posts: 16

I'm really interested in the outcome. Did it work for you in the end?

GargiMan
Offline
Last seen: 11 months 2 weeks ago
Joined: 2018-09-01 01:34
Posts: 8

actually i havent tried it yet ... but soon ... in few days / weeks i will do it for sure ... then i will give my feedback here , but i am still interested in that ... how to do it with Arduino Nano / Uno using i2c or 1 UART (+CANBUS) , Arduino Mega is too big for me ... i dont need too much inputs / outputs for it 

GargiMan
Offline
Last seen: 11 months 2 weeks ago
Joined: 2018-09-01 01:34
Posts: 8

Little bit late but ... UPDATE is here :)

For now im running on single VESC with UART , because i was working on wireless communication.

Soon i will give u little feedback when i will use dual vesc drive.

GargiMan
Offline
Last seen: 11 months 2 weeks ago
Joined: 2018-09-01 01:34
Posts: 8

I've changed my mind , after few rides with 1 motor 6374 , i decided to run only at single VESC setup. From Arduino i have moved to a ESP32 , that i control with my phone. 

In close future i will also try to run dual VESC with ESP32. If anyone have questions about my work. U can ask in this thread or write me an email (mage26gg@gmail.com).

spork
spork's picture
Offline
Last seen: 2 years 5 months ago
Joined: 2018-11-26 06:55
Posts: 29

I think this is exactly what I'm looking for.  So if I understand correctly, I should  be able to send a COMM_GET_VALUES command to one VESC to get its values, and if I precede the COMM_GET VALUES with a COMM_FORWARD_CAN and the index of the second VESC I should actually receive the values from the second VESC through the UART port of the first VESC - right?

 

It looks like this thinks I'm replying to post #11, but I'm actually replying to Josh - post #6.  Sorry for any confusion.

 

benjamin
Offline
Last seen: 2 weeks 4 days ago
VESC FreeVESC OriginalVESC Platinum
Joined: 2016-12-26 15:20
Posts: 490

That is correct. I'm working on some documentation about this, hopefully it will be available soon.

spork
spork's picture
Offline
Last seen: 2 years 5 months ago
Joined: 2018-11-26 06:55
Posts: 29

Excellent!  Thanks very much.  And if I may ask one more question...

One of my VESC's is running FW-2.18 and the other is running FW-3.40.  Will that cause any trouble in passing messages through?  Is there a preferred direction?

 

 

benjamin
Offline
Last seen: 2 weeks 4 days ago
VESC FreeVESC OriginalVESC Platinum
Joined: 2016-12-26 15:20
Posts: 490

It is best to run the latest and same firmware on both. The protocol has changed a bit across versions, and 2.18 is very outdated in general. Most commands (except the configuration commands) will stay compatible in future firmwares, but that was not true for the earlier versions. I will also document that.

spork
spork's picture
Offline
Last seen: 2 years 5 months ago
Joined: 2018-11-26 06:55
Posts: 29

Thanks.  The reason I have two different firmware versions is because I had one VESC repaired and it came back with the newer firmware (3.40).  It seems like it may be having cut-out issues.  That's why I'm logging it for the moment (to look for faults).  Once I have that sorted out I'll probably get them on the same FW.  At the moment I'm inclined to put them both on 2.18 since that one seems to be behaving best, but I know that's a bad solution to what's probably a setup problem.

In the meantime, I may try and log them both simultaneously using the CANBUS.  If that doesn't work I can log independently.  The logs for the 2.18 version already look pretty good.

 

spork
spork's picture
Offline
Last seen: 2 years 5 months ago
Joined: 2018-11-26 06:55
Posts: 29

Quick update.  I am talking to both VESC's via UART (one at a time).  They have different firmware versions, and I use different logging software for them.  I did try talking to one via UART and getting data from the other over CANBUS.  And it does seem that fw 2.18 and fw 3.40 are not compatible in that regard (as you suggested).  So I'll do a little logging on the 3.40 VESC, and will then likely upgrade both to 3.40.

Would you say there's any particular fw version that's particularly stable, or is it simply the case that each has been an improvement over the previous version?

Thanks again!

 

Rc 44
Offline
Last seen: 2 weeks 12 hours ago
VESC Original
Joined: 2019-01-28 20:36
Posts: 11

Hi Spork! I managed to make it work, now I have access to all of the UART data from both Vescs using only one port. I only edited a slight bit fom GargiMan's code. 

 

(On the VescUart.cpp file)

 

void SetCanId(int CanId){  //Added by me, use "SetCanId();" on arduino sketch
 CANid = CanId;            //to set the CAN bus id of the Vesc you desire to communicate.
 }

bool VescUartGetValue(bldcMeasure& values, HardwareSerial* _vescserialPort) {

  int32_t index = 0;
  uint8_t command[3];

if(CANid == !0){  //When talking to a slave Vesc

          command[index++] = { COMM_FORWARD_CAN }; //Forwarding CAN 
          command[index++] = CANid;                //Sending CAN id
          command[index++] = { COMM_GET_VALUES };  //Requesting Values
 }

if(CANid == 0){  // When talking to the master Vesc

 command[index++] = { COMM_GET_VALUES }; //Just requesting values
 }

  uint8_t payload[256];
  _vescserialPort->flush(); // move to comm function directly?
  PackSendPayload(command, 3, _vescserialPort);

  int lenPayload = ReceiveUartMessage(payload, _vescserialPort);
  if (lenPayload > 1) {
    bool read = ProcessReadPacket(payload, values, lenPayload); //returns true if sucessful
    return read;
  }
  else
  {
    return false;
  }
}
bool VescUartGetValue(bldcMeasure& values) {
  return VescUartGetValue(values, vesc_io);
}

 

 

 

(On the VescUart.h file)

void SetCanId(int CanId);

 

By the way, I'm using a dual Vesc 6 Setup, not sure if it works on 4.xx versions.

 

v8-rt
Offline
Last seen: 1 year 7 months ago
Joined: 2020-03-13 21:14
Posts: 4

Dear Rc 44,

Thank you for posting these add-ons to VescUart.cpp and .h.

However, could you please explain, what line i would need to type in my .ino, to adress a specific motor (that is connected via CAN to the master VESC).

And. way more importantly: Is there a way, to automatically update the RPM of all VESCs (in my case 4) that are connected via CAN our themselves?

Or is in that case, the best to simply connect all RXs of the VESCS together, and disconnect CAN-Bus?

Thanks in advance,

Best Regards, Andi

jbrun87
Offline
Last seen: 4 years 1 month ago
Joined: 2020-02-29 17:51
Posts: 2

Hi Rc 44 and others!

I tried to integrate the code in both VescUart.cpp and VescUart.h files.

Would it be possible to access to your whole code?

I am not sure where you got those from:

- HardwareSerial* _vescserialPort

- vesc_io

Did you also modify the void PackSendPayload(); to add some more elements? If yes, what did you modify there?

I would like to modify the void VescUart::setRPM to be able to control 8 VESCs from the Arduino. For now, it works individually, both the VESC Master via UART and the VESC Slave via COMM_FORWARD_CAN, but it doesn't work together.

Any help would be very appreciated!

Thanks a lot.

jbrun87
Offline
Last seen: 4 years 1 month ago
Joined: 2020-02-29 17:51
Posts: 2

I found my answers here: https://github.com/astulnikov/ESk8Arduino/tree/405fe467cace6ee455dba3c70... !!!

Might help somebody later :)

Shubham07
Offline
Last seen: 1 year 1 month ago
VESC Free
Joined: 2022-05-02 05:59
Posts: 1

You can communicate one Vesc over uart and other on CAN-Forward, One vesc acts like master and others will act like slaves

Here you can find all the tutorial and configuration setup:

https://github.com/GTU-Robotics-Club-2023/VESC-UART-CAN-Forward

Shubham