Lidar's motor controller using PID control loop
Overview
- The Lidar needs to be spinning at a constant speed of 250 rpms.
- The voltage needed by the motor to rotate at constant speed changes depending on external factors such as temperature.
- A PID controller is therefore implemented in order to always supply the adequate voltage to obtain the desired rpms.
- The chosen PID controller is adapted from the pid ROS package
- Lidar's motor is controlled via i2c using pyA20 package
PID controller
The PID controller is used to maintain constant rpms by continuously calculating the error between the current state and the desired setpoint. See Wikipedia page for detailed explanation.
The pid_lidar node subscibes to the 'state' topic rpms
and publishes the control value in control_effort
topic. The main parameters to be set are Kp, Ki and Kd. These parameters can be set manually or using Ziegler-Nichols method.
In our case we have seen that a PI is sufficient to control the speed. Indeed, the speed variation will be gradual and no brutal change should occur. Also, the response to a change do not need to be immediate and so the response time do not need to be very short.
RPMS to PWM duty cycle conversion
The published value in control_effort
topic represents the rpms that should be applied to compensate for the error. In order to be sent to the lidar's motor this value must be converted into a corresponding PWM value (more precisely into a duty cycle value). The duty cycle value will fix the voltage given to the motor. This is done in rpms2volts node. The values are converted according to a linear model : duty_cycle = a*rpms + b, with a and b parameters that can be set.
According to empirical tests in normal conditions (@Hackurium, ~20°C), these parameters have been set to a = 0.16 and b = 48
The PWM duty cycle value is published into motor_input
topic and ranges from 0 to 255.
i2c communication
The i2c_lidar node sends the desired PWM duty cycle value to the motor via i2c.
Graph of nodes and topics
[PICTURE NEEDED]
Cabling
[PICTURE NEEDED]
- Lidar motor controller board is connected to Olimex' UEXT1 pin
- Name of device : “/dev/i2c-2”
- Adress of device : 0x0f
- Motor controller board needs to be powered with 11V
- Be careful with the direction of spining of the lidar (only one direction is the correct one)
- Make sure Olimex and lidar motor controller board share the same ground (otherwise i2c communication gets interrupted)
Misc
I2C Grove (This board is no longer used)
- I2C pins of I2C Motor Driver should not be connected to VCC (only to GND SDA and SCL)
- Power supply need to come from pin J6 (11V)
- Input to LiDAR's motor on pin J1
- Adress of device : 0x0f (default, can be changed see documentation I2C Grove Motor Driver)
- I2C Motor Driver is connected to Olimex' UEXT1 pin