Dynamic gain control using UART

I’m using the ODriveArduino library to communicate between a Teensy4.1 and an ODrive (HW ver: 3.6.24 and FW ver: 0.5.4) for a Direct Drive Telescope I have built. I designed and built both the Altitude and Azimuth DC motors (PMAF) and ODrive works great with them. Also, I have written the FW to integrate the OnStep base FW package with the scope and TFT hand controller.

The communication channel works great to set positions, read encoders, read motor current, etc. But, I can’t seem to set (write) the gains even though I can read them. I want to be able to dynamically change the gains based on varying load conditions (like wind).

Is the ability to set the gains using the UART native protocol implemented?

Here is the sample code:

HardwareSerial& odrive_serial = Serial3;

// ODrive object
ODriveArduino odrive(odrive_serial);

void setOdriveVelGain(int axis, float level) {
odrive_serial << “w axis”<<axis<<".controller.config.vel_gain="<<level<<"\n";
}

float getOdriveVelGain(int axis) {
odrive_serial << “r axis”<<axis<<".controller.config.vel_gain\n";
return odrive.readFloat();
}

setOdriveVelGain(ALT, 0.3);

1 Like

You need a space between property name and value, not a “=”; see the example in the ASCII protocol documentation.

edit: oh, wow, that’s an awesome telescope!

2 Likes

Thanks!!! After looking at the examples closer, I see that is the case…I assumed the format was similar to the odrivetool format.

I will be posting how to construct the motors, the 3D design files, and the electrical design in a public forum in the future. Not sure which one would be best. Also, the code will be on GitHub at some point.

2 Likes