Hi everyone! I’m trying to use odrive for torque control when speed is zero. I need constant resistance.
I’m using herlea x8311s kv140 motor, as5048a encoder and odrive3.6 56V board. Firmware I’m running is latest 0.5.1 version. My power supply is laboratory power supply able to give voltage and current up to 30V and 30A.
In torque control mode i set input_torque to some value and torque_setpoint follows that value but the current doesn’t match the desired torque. I measure current from odrv0.axis0.motor.current_control.Iq_measured and it is completely different from the torque reference. Also odrv0.axis0.motor.current_control.Iq_setpoint matches the measured current but not desired torque and it is dropping. Current into Odrive is also dropping. My vel_limit= 20 and enable_current_mode_vel_limit = True and motor is barely moving. Cranck is connected to motor shaft and it is driven into a board as shown on the picture.
I also wrote a script to measure input torque and torque given by current. On next graphs estimated torque = 8.27 * odrv0.axis0.motor.current_control.Iq_measured / 140 reference torque = 8.27 * odrv0.axis0.motor.current_control.Iq_setpoint / 140 and input_torque and torque_setpoint are self explanatory.
Can anybody tell me if this can be done and if I’m doing something wrong or expecting it to work in a way it doesn’t work. And why…
That’s some strange behaviour I must say. Where did you get your constant 8.27/140 ~= 0.06 from? Was that trial and error to try to get the plots to line up? Or is that the motor’s torque constant?
Check motor.config.phase_resistance and see if it matches the phase-to-phase resistance (or half or it) as measured by a multimeter. (if you don’t have a meter handy that can measure low resistances, you can use your bench power supply in constant current mode and record the voltage)
Did the calibration run properly? i.e. the motor turns both ways and there are no errors?
What input_mode are you running? It should be INPUT_MODE_PASSTHROUGH.
Obviously controller.config.control_mode should be CONTROL_MODE_TORQUE_CONTROL
Can you post the output of odrv0.axis0.motor.config and odrv0.axis0.controller.config?
What current does your power supply show? (I’d expect this to be very low, less than 500mA if set to 30V)
Hey man, thanks! I feel stupid. I was convinced I was in CONTROL_MODE_TORQUE_CONTROL but I was in CONTROL_MODE_POSITION_CONTROL. Very stupid of me but still interesting behaviour. Would still be interested in explaination.
That’s some strange behaviour I must say. Where did you get your constant 8.27/140 ~= 0.06 from? Was that trial and error to try to get the plots to line up? Or is that the motor’s torque constant?
That is the formula from this page: https://docs.odriverobotics.com/commands under Motor current and torque estimation. Explaination of the formula is given here: Where does the formula for calculating torque come from? . But still after I reversed before mentioned mistake I got that torque from current is larger than setpoint value and always with the ratio 1.4767858081772214. So i guess formula still needs to be calibratated for given motor.
No, for largest torques (around 2Nm) my current is 5-6A.
Yes, 5-6A when pushing 30A through the motor is about right, but I’d have expected something in the hundreds of milliamps range for your earlier post when the motor wasn’t producing any actual torque.
I asked just in case something might have been about to let out the magic smoke.
By setting a current input when you are in position control, maybe it applies a non-zero current demand for an instant (due to feedforward terms?), and then immediately returns to the zero demand from the position controller.
The current controller is a PI controller, so having an ‘impulse’ demand like that might produce a very small ‘saw tooth’ like in your earlier plots.
That’s just my guess anyway
For the ODrive firmware that supports torque control, you must set odrvX.axisX.motor.config.torque_constant to your 8.27/KV value for the torque output to be correct. The stock value is 0.04, which explains the roughly 1.5x error between your calculated torque and current. Sorry for any confusion, we’re in the process of updating the documentation pages and that will be included.
This is normal behavior based on the way the control loop works. It’s trying to drive it to the position, velocity, and torque commanded. But the velocity has “priority” over the torque feedforward term, and the position has priority over the velocity feedforward (roughly speaking).
So when you’re in position mode and you pass in a torque command, it will apply that torque, but the feedback loops of the velocity & position are still running, so they detect movement and reduce the torque to try to bring it back to 0 speed and the desired position.