Get the data from ODrive continuously


I am not very good at English, so I apologize in advance.

Now, I use Arduino to get the data from ODrive and output the data to Serial Monitor (Arduino IDE).
But, this way couses time delay. ( I need to send command from Arduino to ODrive at very short intervals(10Hz))

Is there any good way?


I’m surprised that you are having problems at 10Hz. This should be easily achievable by any of the ODrive’s many control interfaces.
The most common approach us to use serial, a more advanced approach is to use CAN. If you have a computer or Raspberry Pi, you can use USB and Python of course.

Below code is a part of my Arduino code

if (c == 't') {
    Serial.println("Executing test move");
    for (float ph = 0.0f; ph < 6.28318530718f * 50; ph += 0.63f) {
    time = millis();
    float pos_m0 = 1.0f * sin(ph);
    odrive.SetCurrent(0, pos_m0); 
    // diplay serial monitor 
    odrive_serial  << "r axis" << 0 << ".controller.input_torque"
    Serial << odrive.readFloat() << '\t';
    odrive_serial  << "r axis" << 0 << ".motor.current_control.Iq_measured"
    Serial << odrive.readFloat()  * k << '\n'; // k is torque constant

Because for loop takes 2 ms in one cycle I adjust ph value and achive 10Hz.
However, motor does not rotate smoothly. (If “odrive_serial << ~” statement is commented out, motor rotate smoothly.)

What’s wrong with my program?


A few suggestions:
1: Increase your serial port Baud rate as high as it will go without errors. If you are at 9600 baud, it could explain why it is going so slowly.
2: Use something to limit the loop rate. e.g. define a total time and a loop rate, and a number of steps = total_time * loop_rate, and then wait until time >= start_time + (step_n/total_steps) * total_time. That way you will not saturate the communications link.
3: If it is still too slow, consider using the native protocol over serial.

1 Like