Reading Motor Velocity and Measuring Time via USB


#1

Hi everyone,

I would like to run a series of motor control tests using a motor connected via a shaft to a rotary encoder. The motor CPR has been found to be 2400. In the commands below I have neglected feedforward values.

First, I would like to connect the ODrive controller to a PC via USB and run the test_bulk.py script. I would set the motor velocity to e.g. 2400 counts/second (v 0 2400 0, then get a measurement of velocity for M0.
I have looked through the exposed variable table in low_level.c, but I can’t identify an appropriate variable for instantaneous angular velocity. Would anyone know of a suitable variable?

Secondly, I would like to use position control on the motor. I would like to set the initial motor position to 0 (p 0 0 0 0), make it rotate 180 degrees (p 0 1200 0 0), and measure the time taken to rotate through that angle. What would be the simplest way to determine the time to rotate through a given angle?

Many thanks for your help!


#2

The velocity can be found on the variable motor.rotor.pll_vel in counts/s.

You can continuously poll the position variable (motor.rotor.pll_pos) at a high rate, and compute the time in python.

Otherwise, you would have to add code in the firmware: you can make something that counts the number of control cycles until your desired rotation was achieved. You would have to expose a new variable for reporting it, and one for specifying the trigger angle to stop counting. Note that the duration of one control cycle is available as CURRENT_MEAS_PERIOD.


#3

Thank you very much, this helps a lot.