Why do I start this project? After I started my internship, I have realized that robotics contains a variety of fields. At that time, I was a little bit dispirited, because I have a dream of becoming a chief robotics engineer but there are so many things I even haven’t heard about after three years’ university education. I then realized it is time to study robotics-related knowledge by myself.
I believe the best method to get mastery of a new area is integrating theory with practice. Thus, I set up this project. At the beginning of this project, I was surrounded by many unknowns. Until this point, I have learned C language, how to use STM32F767, the mechanism of microcomputer, how to design a control system via Root-Locus, and how to tune PID via Ziegler-Nichols rule.
The target of this project is building up a model car which keep a constant distance from an obstacle, no matter where the initial position is. Since the components I can get doesn’t have high accuracy, I decided to build up a close-loop control system rather than an open-loop system. Here is the mechanism of this project: after the whole system is initialized, an ultrasonic meter starts to measure the distance between the model car and obstacle. PWM signal from microcontroller will be used to control the voltage on the DC motor to control its speed. The model car will be driven by DC motors and the new position will be feedbacked to microcontroller; thus, a close-loop control system is formed.
A controller planted in system is designed to optimize the performance of plant. There are some target system’s transient response requirements to satisfy: Delay time should be shorter than 0.5s; Maximum percent overshoot should be less than 10%; Settling time under 5% allowable tolerance should be shorter than 5s.
The original plan was:
However it becomes:
because I cannot find some specifications of DC motors -_-
the transfer function for this close-loop system is:
for an DC motor, the armature circuit can be represented as:
E(s) is the voltage applied on the armature circuit;
Vb(s) is the back emf
Since rotational speed of DC motor is proportional to back emf, the relation betweenback emf and location can be represented as:
Kb is the back emf constant;
X(s) is the location function of the model car
Torque is provided by four DC motors, which can be transformed into forward force todrive the model car, the relation between current of armature circuit andlocation can be represented as:
Tm(s) is torque generated by motors;
Kt is motor torque constant;
m is the weigh of the model car
Tf is torque generated by DC motor friction
Note that E’(s)has a deadband caused by frictional torque. The sum of a step function and aunit impulse function is the difference between E’(s) and E(s). In order to linearize E’(s), the duty ratio of PWM signal will start with a number.
Based on the control system build as above, I had planned to design controller function C(s) via Root-Locus. Unfortunately, I haven’t expected that I cannot find the specifications of DC motor, thus I have to use Ziegler-Nichols rule to tune PID controller instead.
HC-SR04 ultrasonic module
The module is triggered to emit ultrasonic wave after sending a 10 us high-level signal to Pin trig, then Pin echo sends high-level signal when it receives ultrasonic echo. The duration of the high-level signal is equal to the time interval between the module emitultrasonic wave and receive ultrasonic echo. A half of the distance ultrasonic wave traveling is equal to distance between the model car and obstacle. Timer 5 in STM32 F767 demoboard is used in interrupt mode to calculate time.
L298N dual motor controller module
Since the minimum voltage to drive DC motor is 3V, and the maximum voltage from IO in STM32 demoboard is 3.3V, the demoboard cannot control the speed of DC motor via PWM signal independently. This L298N dual motor controller module is used in this project to make sure the voltage applied on DC motor larger than 3V and varies with duty ratio of PWM signal. The output voltage is approximately equal to the product of input voltage and duty ratio. Pin in1 to in4 are used to control rotation direction of two DC motors separately via level signal. Pin ENA and ENB can control the speed of corresponding DC motor via PWM signal.
STM32 F767 demoboard
Connected to HC-SR04 ultrasonic module, PA 7 is used to send high-level signal to trigger the ultrasonic module, and PH10 serves as timer 5 channel 1 in interruption mode to calculate the duration from ultrasonic wave leave to ultrasonic echo received.
Connected to L298N dual motor controller module, PE 3, 4, 5, 6 and PI 4, 5, 6, 7 are used to control motors’ direction. PC 6, 7 (timer 3 channel 1) and PB 4, 5 (timer 3 channel 2) transmit PWM signal to control motor speed.
Through experiment, it is found that when duty ratio of PWM signal is increased to 0.56, the model car starts to move at a very low and constant speed. Thus, the deadband of DC motor under this circumstance is 0.56*5V=2.8V. This deadband will be offset by algorithm in controller.
Ziegler-Nichols rule contains two methods for tuning PID controller. Since the plant (model car) involves integrator, only Second Method applies under this circumstance.
Through experiment, the critical gain Kcr is found to be 5500, at which the location of the model car first exhibits sustained oscillation. The corresponding period Pcr at the critical gain is 0.95 second. According to Ziegler-Nichols tuning rule (second method), the PID controller is set as following:
The program in demoboard inputs distance from obstacle and outputs PWM signal’s duty ratio, the algorithm of controller becomes:
For discrete controller, algorithm above becomes:
The diagrams above show transient response of this control system. This control system exhibits damped oscillations before reaching steady state. Theoretically, steady-state error doesn’t exist in a control system whose controller has integrator. While the last part of the location plot appears to be flat, mean while the model car stopped at this period. I believe this phenomenon isn’t inconflict with theory. It was observed that the duty ratio was still increasing at a low speed, which should have caused the model oscillates around reference line with a decreasing amplitude. A possible explanation is some part of the plant, such as wheels, is assumed to be linear while they are actually not. On the other hand, the deadband determined via experiment is relatively rough, which is another reason for this phenomenon.
The transient response characteristics of this control system are shown as following:
For delay time, half the final value is equal to 0.253621/2=0.126811 m. While the plant reaches the location of 0.13138 at 0.45 s, which is shorter than target delay time, 0.5 s.
Maximum percent overshoot is equal to (0.277759-0.253621)/0.253621*100% =9.5%, which is less than target maximum percent overshoot, 10%.
For settling time, the 5% allowable tolerance is equal to 0.012681 m, which means the allowable location ranges from 0.240940 m to 0.266302 m. The plant reaches 0.265 m at 3.35 s, which is shorter than target settling time, 5 s.
Thus, the controller system designed satisfies all target specification set in the beginning of this project.