I’m trying to initialize the odrive as I do it in odrivetool but I can’t make it work with Arduino.
My initializing sequence in Odrivetool is:
-
odrv0.axis0.requested_state = AXIS_STATE_ENCODER_INDEX_SEARCH
odrv0.axis1.requested_state = AXIS_STATE_ENCODER_INDEX_SEARCH
…wait until it completes then do #2
-
odrv0.axis0.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
odrv0.axis1.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
Then I can run my machine’s commands.
Issue is I can’t make this simple sequence work in Arduino.
Example of the Arduino code I use triggered by a hardware button:
odrive.run_state(0, AXIS_STATE_ENCODER_INDEX_SEARCH, true);
odrive.run_state(1, AXIS_STATE_ENCODER_INDEX_SEARCH, true);
delay(7000);
odrive.run_state(0, AXIS_STATE_CLOSED_LOOP_CONTROL, true);
odrive.run_state(1, AXIS_STATE_CLOSED_LOOP_CONTROL, true);
It does all sort of whacky things, then motors start clacking. If do the initialization sequence via oDrivetool then i can run my arduino sketch perfect, sending velocity and torque commands work.
What am I not doing correctly?
Make sure you update to 0.5.4 (to remove ascii protocol problems) then try again.
I’m already on 0.5.4 , all I need is to send these commands via Arduino so I don’t have to go to odrivetool to run them before I can use my machine.
odrv0.axis0.requested_state = AXIS_STATE_ENCODER_INDEX_SEARCH
odrv0.axis1.requested_state = AXIS_STATE_ENCODER_INDEX_SEARCH
odrv0.axis0.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
odrv0.axis1.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
I tried these commands in Arduino to no avail:
odrive_serial << “w axis” << 0 << ".requested_state " << AXIS_STATE_ENCODER_INDEX_SEARCH << ‘\n’;
and this variation…
odrive.run_state(0, AXIS_STATE_ENCODER_INDEX_SEARCH,1);
You can open an odrivetool shell while sending from Arduino. Please check the errors with dump_errors(odrv0)
after sending from the Arduino…
It seems to work via the ASCII protocol on COM port for me, so I think it’s something UART specific. Do you have a ground connection between the Arduino and the ODrive?
Yes there is ground between ODrive and Arduino.
Let me check errors with odrivetool after sending commands.