You are here

Dual VESC Controller - Internal CAN Forwarding Failure -NOW WITH CODE EXAMPLE ;)

1 post / 0 new
XAQ
Offline
Last seen: 1 day 21 hours ago
VESC Free
Joined: 2025-08-24 01:29
Posts: 3
Dual VESC Controller - Internal CAN Forwarding Failure -NOW WITH CODE EXAMPLE ;)

Hello,

I'm hoping someone can help diagnose a fault in my dual VESC controller. I have (pretty much) confirmed that the internal CAN bus forwarding is not working on my Flipsky FSESC6.7.

Here is what I have proven through extensive testing:

  1. My host computer (a Raspberry Pi) and its UART port are fully functional (verified with a successful loopback test).

  2. The VESC correctly receives and executes direct commands sent over UART to whichever side is physically connected.

  3. However, when I send a valid COMM_FORWARD_CAN packet from the Pi to the master, the master executes the command on itself instead of forwarding it to the slave. This happens no matter which side is the master.

  4. I have tried every combination of App to Use, CAN_STATUS, and CAN Mode (COMM_BRIDGE breaks the link entirely). The forwarding fails regardless of the configuration.

    Can anyone help with configuration for this case?

    Thanks!!

  5.  

    This is the code i'm using:

    import pyvesc
    from pyvesc.VESC.messages import SetRPM
    import serial
    import time

    # --- Configuration ---
    SERIAL_PORT = '/dev/serial0'
    # IMPORTANT: The physically connected VESC is the MASTER
    # In your case, you are plugged into the LEFT motor's side.
    LEFT_MOTOR_ID = 59  
    RIGHT_MOTOR_ID = 45
    MOTOR_SPEED = 4000
    RUN_TIME_SECONDS = 3
    # --------------------

    def send_rpm_command(ser, controller_id, rpm):
        """
        Sends an RPM command to the specified motor controller by setting the can_id.
        """
        # Create the SetRPM message object
        message = SetRPM(rpm)
        # Set the destination CAN ID on the message itself
        message.can_id = controller_id
        # The encode function should see the can_id and build the correct packet
        ser.write(pyvesc.encode(message))

    # --- Main Program ---
    if __name__ == "__main__":
        
        # We use the correct IDs for the left and right motors now
        left_motor_id = LEFT_MOTOR_ID
        right_motor_id = RIGHT_MOTOR_ID

        try:
            # Use the master VESC (the one physically connected to the Pi) as the serial port
            with serial.Serial(SERIAL_PORT, baudrate=115200, timeout=0.05) as ser:
                print("Successfully connected to VESC. Starting sequence...")
                
                # --- Left Motor Sequence ---
                print(f"Running LEFT motor ({left_motor_id}) FORWARD for {RUN_TIME_SECONDS} seconds...")
                send_rpm_command(ser, left_motor_id, MOTOR_SPEED)
                time.sleep(RUN_TIME_SECONDS)
                
                print(f"Running LEFT motor ({left_motor_id}) BACKWARD for {RUN_TIME_SECONDS} seconds...")
                send_rpm_command(ser, left_motor_id, -MOTOR_SPEED)
                time.sleep(RUN_TIME_SECONDS)
                
                # --- Right Motor Sequence ---
                print(f"Running RIGHT motor ({right_motor_id}) FORWARD for {RUN_TIME_SECONDS} seconds...")
                send_rpm_command(ser, right_motor_id, MOTOR_SPEED)
                time.sleep(RUN_TIME_SECONDS)

                print(f"Running RIGHT motor ({right_motor_id}) BACKWARD for {RUN_TIME_SECONDS} seconds...")
                send_rpm_command(ser, right_motor_id, -MOTOR_SPEED)
                time.sleep(RUN_TIME_SECONDS)

                print("\nSequence complete.")

        except KeyboardInterrupt:
            print("\nProgram stopped by user.")
            
        except serial.SerialException as e:
            print(f"\nSerial port error: {e}")

        finally:
            print("Stopping all motors.")
            with serial.Serial(SERIAL_PORT, baudrate=115200, timeout=0.05) as ser:
                send_rpm_command(ser, left_motor_id, 0)
                send_rpm_command(ser, right_motor_id, 0)
            print("Motors stopped. Program finished.")