Hi Everyone!
I’m trying to use Arduino to control the ODrive S1 with the MK8325S motor but everytime I initialize my variable “pos_val”, the motor move to position 0. Even if I include in the setup function that pos_val = getPosition(), the motor still moves to the encoder count 0. When the program starts up, I want to set the current position of the motor to be “0” and then move the motor in position control. So the motor will be start at “0” and then move by counts until it hits my limit switch and then that value will become the new “0”.
Hi! If you want to set the position, check out Controller — ODrive Documentation 0.6.11 documentation
In brief, you’ll want to set axis0.controller.config.absolute_setpoints
to True. On initialization/startup, you’ll want to set axis0.pos_estimate
to 0. Then, you can move the motor until you hit he limit switch, and then set axis0.pos_estimate
to 0 again.
Using the GUI setup, I can set axis0.controller.config.absolute_setpoints
to True and then in the Arduino code I use axis0.pos_estimate = 0
?
Correct! Note two things:
- Setting absolute_setpoints to True will require you to initialize pos_estimate to 0 before moving the motor (after each ODrive reboot). You can initialize it automatically by setting an absolute encoder reference frame, to set it based on the encoder reading.
- Make sure to call
save_configuration
in the inspector tab after setting absolute_setpoints to True (also in the inspector tab).
Are you using the Arduino over UART or CAN?
In that case you’d set the position via:
odrive.setParameter("axis0.pos_abs", position_to_set);
Where position_to_set
is the position you’d like to set the ODrive count to.
I tried using odrive.setParameter("axis0.pos_abs", 0);
to make the current position the motor is at 0 when initializing in Arduino but the motor doesn’t recognize its current position as 0. Currently in my code when I hit the limit switch it increases the count by 1. When I first uploaded it, It started going up to 5, then when I reuploaded the code the motor didn’t move until after I hit the limit switch 5 times meaning that its current position when I reuploaded the code was 5 but I want it to be 0 everytime I upload the code again.
Oops - sorry, I screwed up. It would be:
odrive.setParameter("axis0.pos_estimate", position_to_set);
pos_abs was from an older ODrive firmware release, I got confused, apologies 
Is there a way to change between velocity control and position control? Or is the only way to do it by changing it with the GUI? Cause I would like to use position control for the motor to slowly approach the limit switch, set that position to 0 and then use velocity control.
odrive.setParameter("axis0.controller.config.control_mode", CONTROL_MODE_POSITION_CONTROL)
(or CONTROL_MODE_VELOCITY_CONTROL
). Make sure to set axis0.controller.config.input_mode too Controller — ODrive Documentation 0.6.11 documentation
Do I have to set up the motor with the GUI setup everytime I turn on the motor again? I tried to run the same arduino code that I ran last time when it was working and the motor doesn’t move when I press the limit switch
Once you run all the calibration in the GUI, it’ll save the values to the ODrive, you don’t need to re-run setup again. Maybe you could share your Arduino code?