ODrive Motor cuting off when executing test move

Hi,

I have a ODrive v3.6 controller, AM102 encoder, and D5065 motor running with the Arduino Test code posted on github. The motor currently runs the calibration phase but cuts off after a second when executing the test phase and goes out of closed loop. I tried messing with the current and velocity limits but it would still cut-off. I don’t think the power supply isn’t the one malfunctioning since there is a green LED indicator on it whenever the circuit is overloaded and it hasn’t indicated that when executing the code.

Everything is set up correctly and I am still having a hard time figuring this out.

Any help would be appreciated.

Here’s the current code:

#include <SoftwareSerial.h>
#include <ODriveArduino.h>

// Printing with stream operator
template inline Print& operator <<(Print &obj, T arg) { obj.print(arg); return obj; }
template<> inline Print& operator <<(Print &obj, float arg) { obj.print(arg, 4); return obj; }

// Serial to the ODrive
SoftwareSerial odrive_serial(8, 9); //RX (ODrive TX), TX (ODrive RX)

// ODrive object
ODriveArduino odrive(odrive_serial);

void setup() {
// ODrive uses 115200 baud
odrive_serial.begin(115200);

// Serial to PC
Serial.begin(115200);
while (!Serial) ; // wait for Arduino Serial Monitor to open

Serial.println(“ODriveArduino”);
Serial.println(“Setting parameters…”);

// In this example we set the same parameters to both motors.
// You can of course set them different if you want.
// See the documentation or play around in odrivetool to see the available parameters
for (int axis = 0; axis < 2; ++axis) {
odrive_serial << “w axis” << axis << ".controller.config.vel_limit " << 22000.0f << ‘\n’;
odrive_serial << “w axis” << axis << ".motor.config.current_lim " << 10.0f << ‘\n’;
// This ends up writing something like “w axis0.motor.config.current_lim 10.0\n”
}

Serial.println(“Ready!”);
Serial.println(“Send the character ‘0’ or ‘1’ to calibrate respective motor (you must do this before you can command movement)”);
Serial.println(“Send the character ‘s’ to exectue test move”);
Serial.println(“Send the character ‘b’ to read bus voltage”);
Serial.println(“Send the character ‘p’ to read motor positions in a 10s loop”);
}

void loop() {

if (Serial.available()) {
char c = Serial.read();

// Run calibration sequence
if (c == '0' || c == '1') {
  int requested_state;

  requested_state = AXIS_STATE_MOTOR_CALIBRATION;
  Serial << "Axis" << c << ": Requesting state " << requested_state << '\n';
  odrive.run_state(atoi(c), requested_state, true);

  requested_state = AXIS_STATE_ENCODER_OFFSET_CALIBRATION;
  Serial << "Axis" << c << ": Requesting state " << requested_state << '\n';
  odrive.run_state(atoi(c), requested_state, true);

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

// Sinusoidal test move
if (c == 's') {
  Serial.println("Executing test move");
  for (float ph = 0.0f; ph < 6.28318530718f; ph += 0.01f) {
    float pos_m0 = 20000.0f * cos(ph);
    odrive.SetPosition(0, pos_m0);
    delay(5);
  }
}

// Read bus voltage
if (c == 'b') {
  odrive_serial << "r vbus_voltage\n";
  Serial << "Vbus voltage: " << odrive.readFloat() << '\n';
}

// print motor positions in a 10s loop
if (c == 'p') {
  static const unsigned long duration = 10000;
  unsigned long start = millis();
  while(millis() - start < duration) {
    for (int motor = 0; motor < 2; ++motor) {
      odrive_serial << "r axis" << motor << ".encoder.pos_estimate\n";
      Serial << odrive.readFloat() << '\t';
    }
    Serial << '\n';
  }
}

}
}

Please check that you can run the motor via USB first, for testing purposes. That will give you a richer debugging experience. (see dump_errors(odrv0))

Thank you for your advice. I downloaded python and was able to find out there were no software problems with the ODrive so I figured it was hardware. So I took apart my setup and found out that the motor cuts off because of the friction between the motor housing and the enclosure. Is this a problem that you’ve seen that others have faced? The only way I could think of to fix this problem is to place bearings between the motor shaft and the enclosure. Is there something I could do software/hardware wise to alleviate this problem.

Thank you so much

Does encoder calibration succeed? Its possible that the friction is too high for it to calibrate correctly. For high friction loads you could try increasing <axis>.config.calibration_lockin.current in steps of around 50%. Make sure you don’t go higher than half of the maximum continuous current rating of your motor.