You are here

COMM_GET_VALUES on top of COMM_FORWARD_CAN not working

1 post / 0 new
yes_wecangogreen
Offline
Last seen: 1 day 4 hours ago
VESC Free
Joined: 2020-05-28 18:15
Posts: 7
COMM_GET_VALUES on top of COMM_FORWARD_CAN not working

Hi.

I am using VESC firmware 6.05 and 2 VESC for control 2 motors. I am using an ESP32-S3 board to communicate using UART with one VESC (main/master with CAN ID = 0) and connecting both VESCs using CAN. The secondary/slave VESC has CAN ID = 1.

I can control both motors, like setting their speed, using this Python code on ESP32-S3. I use COMM_FORWARD_CAN for controlling the secondary VESC:

    def set_motor_speed_rpm(self, value):
        """Set motor speed in RPM"""
        tx_command_buffer = bytearray(5)
        tx_command_buffer[0] = 8 # COMM_SET_RPM = 8; no response
        struct.pack_into('>l', tx_command_buffer, 1, int(value))
        self._pack_and_send(tx_command_buffer, 0)
        
    def set_can_motor_speed_rpm(self, value):
        tx_command_buffer = bytearray(7)
        
        tx_command_buffer[0] = 34 # COMM_FORWARD_CAN
        tx_command_buffer[1] = self._front_motor_data.cfg.can_id
        
        # VESC custom tx_command_buffer on custom firmware
        tx_command_buffer[2] = 8 # COMM_SET_RPM = 8; no response
        
        struct.pack_into('>l', tx_command_buffer, 3, int(value))
        self._pack_and_send(tx_command_buffer, 0)

I send the COMM_GET_VALUES over UART  to the main VESC and I successfully get the values, using this code:

    def update_motor_data(self):
        
        tx_command_buffer = bytearray(1)
        tx_command_buffer[0] = 4 # COMM_GET_VALUES = 4; 79 bytes response (firmware bldc main branch, April 2024, commit: c8be115bb5be5a5558e3a50ba82e55931e3a45c4)
        response = self._pack_and_send(tx_command_buffer, 79)

        if response is not None:
            # store the motor controller data
            self._rear_motor_data.vesc_temperature_x10 = struct.unpack_from('>h', response, 3)[0]
            self._rear_motor_data.motor_temperature_x10 = struct.unpack_from('>h', response, 5)[0]
            self._rear_motor_data.motor_current_x100 = struct.unpack_from('>l', response, 7)[0]
            self._rear_motor_data.battery_current_x100 = struct.unpack_from('>l', response, 11)[0]
            self._rear_motor_data.speed_erpm = struct.unpack_from('>l', response, 25)[0]
            self._rear_motor_data.battery_voltage_x10 = struct.unpack_from('>h', response, 29)[0]
            self._rear_motor_data.vesc_fault_code = response[55]

But when I send the same COMM_GET_VALUES but on top of COMM_FORWARD_CAN, to get the data from the secondary VESC, I receive nothing!! even if the COMM_SET_RPM on top of COMM_FORWARD_CAN works!! so I am sure the CAN configuration is ok. I set the CAN STATUS messages as expected, on VESC Tool.

And interestingly, is COMM_GET_VALUES is sent both to main and secondary VESCs, it stops to work on both, while if I send only to main VESC, it works.

Seems to me there is some issue with receiving data from CAN... can anyone please give me any clues? Thanks.

Code to send COMM_GET_VALUES on top of COMM_FORWARD_CAN. Am I doing something wrong??
The full code vesc.py is here: https://github.com/OpenSourceEBike/EBike_EScooter_modular_DIY/blob/dual_motor_read_data/diy_main_board/firmware/vesc.py

    def update_can_motor_data(self):
        
        tx_command_buffer = bytearray(3)
        tx_command_buffer[0] = 34 # COMM_FORWARD_CAN
        tx_command_buffer[1] = self._front_motor_data.cfg.can_id
        tx_command_buffer[2] = 4 # COMM_GET_VALUES = 4; 79 bytes response (firmware bldc main branch, April 2024, commit: c8be115bb5be5a5558e3a50ba82e55931e3a45c4)
        response = self._pack_and_send(tx_command_buffer, 79)

        if response is not None:
            # store the motor controller data
            self._front_motor_data.vesc_temperature_x10 = struct.unpack_from('>h', response, 3)[0]
            self._front_motor_data.motor_temperature_x10 = struct.unpack_from('>h', response, 5)[0]
            self._front_motor_data.motor_current_x100 = struct.unpack_from('>l', response, 7)[0]
            self._front_motor_data.battery_current_x100 = struct.unpack_from('>l', response, 11)[0]
            self._front_motor_data.motor_speed_erpm = struct.unpack_from('>l', response, 25)[0]
            self._front_motor_data.battery_voltage_x10 = struct.unpack_from('>h', response, 29)[0]
            self._front_motor_data.vesc_fault_code = response[55]  

 

I am using this setup on my Fiido Q1S, dual motor (on the right). Both motors works well, I only can't get the status data from the front motor / secondary CAN VESC, so on display I see only the rear motor power and not the total power sad

20241208_102252_preview.jpg