Teensy 4 + 6 odrives - optimal communication protocol for high frequency control

@mike
I got more questions sorry :stuck_out_tongue:
when I want to calibrate an axis in native USB, I type: axis0.requested_state = 3
Now I need to implement this in ascii with one character command. So:

else if (cmd[0] == 'q') { // encoder count, format: e axis# count
    unsigned motor_number;
    int numscan = sscanf(cmd, "e %u", &motor_number);
    if (numscan < 1) {
        respond(response_channel, use_checksum, "invalid command format");
    } else if (motor_number >= AXIS_COUNT) {
        respond(response_channel, use_checksum, "invalid motor %u", motor_number);
    } else {
        axes[motor_number]->requested_state = 3;
    }

} 

Well, it does not work. I am suspecting the last instruction is wrong. Also I am not sure that numscan < 1 is correct either. Any suggestions?

OR

If I want to change position for a trap trajectory by using: axis0.controller.input_pos = 10000

else if (cmd[0] == 'n') { // encoder count, format: e axis# count
    unsigned motor_number;
    int32_t value;
    int numscan = sscanf(cmd, "e %u %i", &motor_number, &value);
    if (numscan < 1) {
        respond(response_channel, use_checksum, "invalid command format");
    } else if (motor_number >= AXIS_COUNT) {
        respond(response_channel, use_checksum, "invalid motor %u", motor_number);
    } else {
        //respond(response_channel, use_checksum, "%u %f", motor_number, value);
        axes[motor_number]->controller_.input_pos_ = value;
    }

} 

This also does not work. It does not give errors, it just does not move the motor. It is receiving the correct motor# and value. (yes i did check to see if the motor work using USB)

Jamil

Make sure input_mode is trapezoidal control and control_mode is position control, set your position, then call controller.input_pos_updated()

1 Like

@mike
Is it possible for you to share the teensy code and and the python script (assuming your using pythong) your using to read and write data at that frequency with me please?

Hi Mike,

Thank you so much for this great resource. Iā€™m currently working on a quadruped with a similar setup as yours (Teensy 4.1 + 6 ODrives). Would you be able to share your repo/code for the Teensy? That is, the Arduino code.