DC motor with encoders control


#1

Hello everyone,

We try to control two DC motors equiped with encoders and moto reductors using the controlled_motor_module (https://www.luos-robotics.com/en/documentation/controlled-motor/). It is not clear to us how we are supposed to work with this module (using pyluos) and we then have several questions :

r.controlled_mot0.positionPid = [3,0.002,100]
r.controlled_mot0.speedPid = [0.4,0.02,0]

how are we supposed to use the PID setup method ? what are supposed to mean P, I and D ?

what r.controlled_mot0. compliant() used for ?

When we launch

print (r.controlled_mot0.control())
before setting anything, power_mode is set as True

but, as soon as we do

r.controlled_mot0.trans_position_mode(True)
r.controlled_mot0.target_trans_position = 100.0
print (r.controlled_mot0.control())

power_mode seems to be set at False, even if we add

r.controlled_mot0.power_mode(True)

how is that possible ? Where do we get wrong ? is there any example of simple use of theses modules ?

Thank you for you help !
O.


#2

Hello,

PID?

The PID is for Proportional, Integral, Derivative. This is the coefficients used for the motor loopback.
Those coefs depend of your motors and your setup. You have to tune those values to have a stable position and speed on your setup.
Here is an article writen by @Simon with more complete explanations about it : https://medium.com/luosrobotics/an-introduction-to-pid-control-with-dc-motor-1fa3b26ec661

Compliant ?

This is used to enable or not the motor. At startup the motor is disable so you can move it by hand freely so it comply to your hand => it is compliant. I think you have the same kind of thing on MisBkit but you don’t call it the same.
To resume :

  • compliant = True => motor disable
  • compliant = False => motor enable
    So to make your motor move you have to disable compliant :
r.controlled_mot0.compliant = False

control mode ?

There is 3 way to control the movement of your motor :

  • power mode: This mode don’t use any feedback loop so no PID for this one you just control the power sent to the motor between -100.0% and 100.0%.
  • speed mode : This mode use feedback loop to maintain the motor speed as we target it regardless of disturbance. For this one you need to setup the speedPid. You control the speed of your motor in °/s. This mode is contradictory with the power mode, so when you enable it the module disable the power mode.
  • position mode : This mode use feedback loop to maintain the motor position as we target it regardless of disturbance. For this one you need to setup the positionPid. You control the position of your motor in °. This mode is contradictory with the power mode, so when you enable it the module disable the power mode.

Speed and position mode are not contradictory, you can enable both at the same time. When positionMode and speedMode are both enabled the motor module only use positionPid and control the speed of the motor using a motion planner algorithm.

Here is a small basic code allowing you to move (not perfectly because of not optimized PID) your motor :

# after connection
# ControlledMotor type settings
r.controlled_mot0.positionPid = [3,0.002,100] # position PID [P, I, D]
r.controlled_mot0.speedPid = [0.4,0.02,0] # speed PID [P, I, D]
r.controlled_mot0.encoder_res = 16 # Encoder resolution before reduction
r.controlled_mot0.reduction = 47 # gear reduction ratio of your motor
r.controlled_mot0.wheel_size = 100 # Wheel Diameter mm

# Motor control mode 
r.controlled_mot0.compliant = False # enable the motor
r.controlled_moto.rot_position_mode(True) # enable position mode so disable power mode
r.controlled_moto.rot_speed_mode(True) # enable speed mode
r.controlled_moto.target_rot_speed = 100.0 # set speed at 100°/s
r.controlled_moto.target_rot_position = 100.0 # set position in °

After execution of the # ControlledMotor type settings section, you should be able to do the other part of the code using the r.controlled_mot0.control() interface.


#3

Thanks for the answer !
We tried following your advices and it worked well.

:^)