PID example code

Hello everyone,
I need to control a motor with a pid and I am not sure what is the best way to do it. I have a sensor that controls my motor. I don’t know if I need an arduino or I can connect the sensor to the odrive. Can someone show me a pid code to control a motor.

Thanks in advance

What kind of sensor is it?

It’s a EMG sensor.

Ok, so you want the position of the motor to be controlled by the EMG signal?

ODrive already has PID control loops build in for controlling position, velocity and torque of the motor. So you’d just set the ODrive up in closed loop position control as per the docs, but take the sensor as the position input.

The sensor seems to be designed to work with Arduino. So the easiest way would be to use an Arduino to read the sensor and convert your sensor measurement into a mechanical angle, and then send the angle as a position command to the ODrive over UART using the ASCII protocol.

If there is too much variation/noise in the signal, then setting the controller.config.input_mode to INPUT_MODE_FILTER_POS will apply a low-pass filter with controller.config.input_filter_bandwidth as the cutoff frequency.

thank you very much !!!