2 Odrives 1 Arduino (Due)

I’m looking to control a total of 3 motors with 2 Odrives and 1 Arduino Due, my plan is to use 2 of the 3 hardware serial ports on the Due in order to communicate with the two ODrives. My question arises when figuring out how to talk to two individual ODrives through a single Arduino program. I’ve gone through the example ODrive Arduino sketch and attempted to modify it to work with 2 Odrives but I am stumped with it comes setting a position for the motor or velocity for the motor.

Establishing two odrives over two serial lines of communication:
ODriveArduino odrive(Serial1);
ODrive2Arduino odrive(Serial2);

Calibrate both odrive motors, go into closed loop control.
requested_state = ODriveArduino::AXIS_STATE_MOTOR_CALIBRATION;
Serial << “Axis” << c << ": Requesting state " << requested_state << ‘\n’;
odrive.run_state(motornum, requested_state, true);

requested_state = ODriveArduino::AXIS_STATE_ENCODER_OFFSET_CALIBRATION;
Serial << “Axis” << c << ": Requesting state " << requested_state << ‘\n’;
odrive.run_state(motornum, requested_state, true);

  requested_state = ODriveArduino::AXIS_STATE_CLOSED_LOOP_CONTROL;
  Serial << "Axis" << c << ": Requesting state " << requested_state << '\n';
  odrive.run_state(motornum, requested_state, false); // don't wait

requested_state = ODrive2Arduino::AXIS_STATE_MOTOR_CALIBRATION;
Serial << “Axis” << c << ": Requesting state " << requested_state << ‘\n’;
odrive.run_state(motornum, requested_state, true);
requested_state = ODrive2Arduino::AXIS_STATE_ENCODER_OFFSET_CALIBRATION;
Serial << “Axis” << c << ": Requesting state " << requested_state << ‘\n’;
odrive.run_state(motornum, requested_state, true);

  requested_state = ODrive2Arduino::AXIS_STATE_CLOSED_LOOP_CONTROL;
  Serial << "Axis" << c << ": Requesting state " << requested_state << '\n';
  odrive.run_state(motornum, requested_state, false); // don't wait

Giving commands:
odrive.SetPosition(1, pos_m1);??
odrive.SetVelocity(0, vel_m1);??

How do I differentiate between telling the first odrive vs. the second odrive?

Any insight would be greatly appreciated!

Upon further research it looks like James Bruton has figured it out

Yeah, Due has enough Serial ports to do it. Or you can try out the CAN interface :slight_smile: