You are here

VESC CAN_STATUS_1_2_3_4 explained (RPi)

4 posts / 0 new
Last post
kimpet
Offline
Last seen: 5 years 6 months ago
Joined: 2019-04-01 11:39
Posts: 7
VESC CAN_STATUS_1_2_3_4 explained (RPi)

After using way too much time figuring out how the VESC can status messages function, I decided to share it :)

can explained.png

Found it in the can.c code https://github.com/vedderb/bldc/blob/master/comm_can.

CAN_STATUS_1

for (int i = 0;i < CAN_STATUS_MSGS_TO_STORE;i++) {

                                            can_status_msg *stat_tmp = &stat_msgs[i];

                                            if (stat_tmp->id == id || stat_tmp->id == -1) {

                                                    ind = 0;

                                                    stat_tmp->id = id;

                                                    stat_tmp->rx_time = chVTGetSystemTime();

                                                    stat_tmp->rpm = (float)buffer_get_int32(rxmsg.data8, &ind);

                                                    stat_tmp->current = (float)buffer_get_int16(rxmsg.data8, &ind) / 10.0;

                                                    stat_tmp->duty = (float)buffer_get_int16(rxmsg.data8, &ind) / 1000.0;

                                                    break;

 

CAN_STATUS_2

 

for (int i = 0;i < CAN_STATUS_MSGS_TO_STORE;i++) {

                                            can_status_msg_2 *stat_tmp_2 = &stat_msgs_2[i];

                                            if (stat_tmp_2->id == id || stat_tmp_2->id == -1) {

                                                    ind = 0;

                                                    stat_tmp_2->id = id;

                                                    stat_tmp_2->rx_time = chVTGetSystemTime();

                                                    stat_tmp_2->amp_hours = (float)buffer_get_int32(rxmsg.data8, &ind) / 1e4;

                                                    stat_tmp_2->amp_hours_charged = (float)buffer_get_int32(rxmsg.data8, &ind) / 1e4;

                                                    break;

CAN_STATUS_3

 

 

 

 

for (int i = 0;i < CAN_STATUS_MSGS_TO_STORE;i++) {

 

can_status_msg_3 *stat_tmp_3 = &stat_msgs_3[i];

                                            if (stat_tmp_3->id == id || stat_tmp_3->id == -1) {

                                                    ind = 0;

                                                    stat_tmp_3->id = id;

                                                    stat_tmp_3->rx_time = chVTGetSystemTime();

                                                    stat_tmp_3->watt_hours = (float)buffer_get_int32(rxmsg.data8, &ind) / 1e4;

                                                    stat_tmp_3->watt_hours_charged = (float)buffer_get_int32(rxmsg.data8, &ind) / 1e4;

                                                    break;

CAN_STATUS_4

for (int i = 0;i < CAN_STATUS_MSGS_TO_STORE;i++) {

                                            can_status_msg_4 *stat_tmp_4 = &stat_msgs_4[i];

                                            if (stat_tmp_4->id == id || stat_tmp_4->id == -1) {

                                                    ind = 0;

                                                    stat_tmp_4->id = id;

                                                    stat_tmp_4->rx_time = chVTGetSystemTime();

                                                    stat_tmp_4->temp_fet = (float)buffer_get_int16(rxmsg.data8, &ind) / 10.0;

                                                    stat_tmp_4->temp_motor = (float)buffer_get_int16(rxmsg.data8, &ind) / 10.0;

                                                    stat_tmp_4->current_in = (float)buffer_get_int16(rxmsg.data8, &ind) / 10.0;

                                                    stat_tmp_4->pid_pos_now = (float)buffer_get_int16(rxmsg.data8, &ind) / 50.0;

                                                    break;

 

Pimousse
Offline
Last seen: 10 months 4 days ago
VESC Original
Joined: 2017-05-24 12:15
Posts: 101

Thanks for sharing !

If you need, I built some tools you may find useful (like like what you've done) here :

https://drive.google.com/folderview?id=1cz4vvPLa9w7otzsrnxXuGm6yhv0MWV9E

Have a look at VESC_COMMUNICATION.xlsx

Regards

Jobe_devian
Offline
Last seen: 8 months 3 weeks ago
Joined: 2018-05-19 14:18
Posts: 5

this may be a good place to ask: 

If I send a CAN command via the UART (usb) will the vesc pass that on to the canbus?

specifically this:

comm_can_set_rpm(uint8_t controller_id, float rpm) 

my goal is to have controller_0 connected to usb on the rpi, controller_1 connected to controller_0 via can, and be able to set motor speed of controller_1 by the usb cable between controller_0 and rpi

Jack_Li
Offline
Last seen: 4 years 11 months ago
Joined: 2019-07-01 05:03
Posts: 12

good job,i already finished my work on STM32F407VET6 boards.

jack li