Compare the actual position with the target position!

I want to compare the actual position with the target position with an arduino mega. So that I can send a command to my machine (3D printer, CoreXY) if the actual position does not match the target position. For example if a motor is blocked a wrong movement is carried out as a result. This can lead to defective components in 3D printing. I now want my machine to receive a command from the Arduino so that it correctly executes the previously incorrect movement.

My question now is which commands do I have to compare with each other?

I have already found the arduino code but only the current position is retrieved every 10 s.

// 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';

Many thanks

The target position that the ODrive is attempting to hit is controller.pos_setpoint. However, you command it via controller.input_pos. If ODrive is in INPUT_MODE_PASSTHROUGH, these are the same. See

1 Like

Hello @Wetmelon,

thank you for your answer.
I am currently still using the v3.4 version of Odrive. Are the commands the same?

My Odrive system runs via step / dir mode. How do I connect my Arduino mega? Or do I connect it normally and use the “ODriveArduinoTest” code?

Is there a value where I can see that the motor is blocked (current increases)?

best regards

Yes, the commands are the same.

See for step/dir mode instructions

No, sorry, you will have to monitor <odrv>.<axis>.motor.current_control.Iq_measured

1 Like