You are here

Dual motor setup over CAN with UART

6 posts / 0 new
Last post
Pawel
Offline
Last seen: 2 years 4 months ago
Joined: 2017-10-22 01:23
Posts: 3
Dual motor setup over CAN with UART

Hello,

I have problem wit sorting out how CAN Bus is working in VESC. I'm trying to controll current and brake current in both VESCs connected with CAN magistral. 
Master (device with connected receiver)  VESC Tool Setup looks like this:
Master.jpg

Slave VESC Tool Setup looks like this:

Slave.jpg

For example COMM_SET_CURRENT message for Master device looks like this:

MessageSlave.jpg

And for Slave device like this:MessageMaster.jpg

These messages are sended one after another. Unfortunately VESCs are not responding for this messages so I suppose that message payload is incorrect. Have you any suggestions what I'm doing wrong?

This is how the source code looks like, for both: COMM_SET_CURRENT, COMM_SET_CURRENT_BRAKE messages:

void VescUartSetCurrent(ble_nus_c_t* p_ble_nus_c, float current, short address) {
	int32_t index = 0;
	uint8_t payload[7];
	
	payload[index++] = COMM_FORWARD_CAN ;
	payload[index++] = address ;
	payload[index++] = COMM_SET_CURRENT ;
	buffer_append_int32(payload, (int32_t)(current * 1000), &index);
	PackSendPayload(p_ble_nus_c, payload, 7);
}
void VescUartSetCurrentBrake(ble_nus_c_t* p_ble_nus_c, float brakeCurrent, short address) {
	int32_t index = 0;
	uint8_t payload[7];
	
	payload[index++] = COMM_FORWARD_CAN ;
	payload[index++] = address ;
	payload[index++] = COMM_SET_CURRENT_BRAKE;
	buffer_append_int32(payload, (int32_t)(brakeCurrent * 1000), &index);
	PackSendPayload(p_ble_nus_c, payload, 7);
}

I'll be appreciate for any help...

Tilman Baumann
Offline
Last seen: 5 years 1 week ago
Joined: 2018-02-12 11:53
Posts: 49

I'm not quite sure what you mean with message for master and message for client.

Your topology is, VESC1 is commanded via UART protocol (try ADC perhaps for simplicity first) and both VESC are connected via CAN ID 1 passing commands on to ID 2?

You see the messages from VESC1 going on the bus but VESC2 doesn't react?

Tilman Baumann
Offline
Last seen: 5 years 1 week ago
Joined: 2018-02-12 11:53
Posts: 49

I can tell that the ADC, PPM and Nunchuck apps have the necessary settings to connect multiple VESC. UART does not.

I guess this is your problem. Can you test it with a different APP on VESC1? At least to demonstrate it works.

If the UART app can be extended to support multiple VESC is going to be the next question I guess.

 

BUT, if you are driving your VESC digitally anyway, why don't you just drive both of them via CAN commands?

Pawel
Offline
Last seen: 2 years 4 months ago
Joined: 2017-10-22 01:23
Posts: 3

Ok, I've made few tests with CAN using other App config - PPM. CAN works perfect using PPM and logic monitor shows messages which looks like this:

PPM2.PNG

When I turn on UART app using simple message format without COMM_FORWARD_CAN (code below) one motor spins perfectly but secondone stay in place. Message over CAN looks like this:

UART2.PNG

void VescUartSetCurrent(ble_nus_c_t* p_ble_nus_c, float current) {
	int32_t index = 0;
	uint8_t payload[5];
	
	payload[index++] = COMM_SET_CURRENT ;
	buffer_append_int32(payload, (int32_t)(current * 1000), &index);
	PackSendPayload(p_ble_nus_c, payload, 5);
}

 

In my firs post you can see that I was trying to use COMM_FORWARD_CAN command to specify in message to which VESC payload is forwarded to, but now I know that it was probably mistake because none of VESC was working in that moment :( 
Asctually I have no idea how to deal with that problem.

Tilman Baumann
Offline
Last seen: 5 years 1 week ago
Joined: 2018-02-12 11:53
Posts: 49

Ah nevermind my comment, I'm beginning to understand your question. I Didn't know about the COMM_FORWARD_CAN command.

alex63610
Offline
Last seen: 4 months 1 week ago
Joined: 2018-06-08 14:38
Posts: 2

Hello,

I had the exact same issue, trying to control a second VESC with UART.

In some libraries for UART communication with VESC, the COMM_FORWARD_CAN is in position 33 and some others 34.

Capture.PNG

So with the same function you had but with a 34 value (instead of 33), it fully works on my side.

Let me know if it help