Escolar Documentos
Profissional Documentos
Cultura Documentos
ECE456 - Mechatronics
North Carolina State University
Shufarrel Bonaparte
David Plonski
Andr Ramos
1. Introduction
This document reports the final project developed as an assignment for the undergraduate
level course of Mechatronics on North Caroline State University, with the objective of designing
an Unmanned Vehicle (UV) for path tracking.
The robot should use Lego Mindstorms NXT as controller and shall be able to perform
the following tasks:
Shufarrel Bonaparte
David Plonski
Andr Ramos
2. Project Setup
In order to have a working robot, several steps had to be fulfilled on advance. From
assembling the robot with Lego parts until having a
Shufarrel Bonaparte
David Plonski
Andr Ramos
2.1.
Programming Platform
Lego Mindstorms NXT supports several programming languages and platforms. The
default one, developed and distributed by Lego, is NXT-G, a visual block based language. Even
though it is possible to develop complex algorithms in NXT-G, using user programmed blocks
and other resources, overall it is not the most flexible and appropriate language for complex
tasks.
From the several other supported languades and GUIs, such as Java on LeJOS, Matlab
and Simulink programming with extension modules for NXT communication, we choose to use
NXC with BricxCC.
NXC is based on standard C and provides several built-in functions, such as motor
regulation, sensor reading, file handling, etc. It also comprises a wider support community than
other languages. BricxCC provides all functionalities for coding, compiling and uploading
programs into NXT. It also provides debug tools for sensor reading, output testing and file
management.
Shufarrel Bonaparte
David Plonski
Andr Ramos
2.2.
Prior to robot assembling, it was important to determine where each part would be
positioned. It was decided that:
The two motors would be assembled side by side, with wheels on the front end of
the robot. This mounting aimed to provide enough stability for the robot, keeping
The following pictures show the final UV mounting and details of assembly.
PUT PICTURES HERE
Shufarrel Bonaparte
David Plonski
Andr Ramos
2.3.
The provided sensor for distance detection was the ultrasonic detector SRF04. This
sensor is capable of detecting
Shufarrel Bonaparte
David Plonski
Andr Ramos
2.3.1.
Sensor Powering
The first
Shufarrel Bonaparte
David Plonski
Andr Ramos
2.3.2.
Sensor Triggering
s
Figure 2 SRF04 Sensor Triggering and response signal (Source: http://www.robot-electronics.co.uk)
Shufarrel Bonaparte
David Plonski
Andr Ramos
2.3.3.
Shufarrel Bonaparte
David Plonski
Andr Ramos
3. Algorithm Design
The algorithm was designed to run two tasks in parallel. The main task is the control task,
responsible for initializing all variables, calling the PID control functions and setting motor
speed according to PID output. The task runs in parallel and is called in a 20 millisecond basis,
responsible for recording on file the reading of light sensors.
Shufarrel Bonaparte
David Plonski
Andr Ramos
3.1.
Main Task
10
Shufarrel Bonaparte
David Plonski
Andr Ramos
3.1.1.
For detecting if the red line was reached, Main Task calls the DetectRed() function. This
function is responsible for reading the light sensors and comparing the light sensor readings to
the reference values for red color, which is between 450 and 550 for Raw Sensor Value. In order
to avoid misreading, program is stopped only if the three sensors indicate red color
simultaneously.
11
Shufarrel Bonaparte
David Plonski
Andr Ramos
3.1.2.
For detecting if the block is too close and, therefore, stopping the stopping the UV, Main
Tasks calls detectBlock() function. This function reads the ultrasonic sensor signal plugged into
port 4 and stops the program when Raw Value indication for distance is below 220. This specific
distance value was setup during several trials until reaching a setpoint that allows the robot to
fully stop before hitting the block.
12
Shufarrel Bonaparte
David Plonski
Andr Ramos
3.1.3.
PID Algorithm
PID algorithm is processed by PID_control function. PID output is calculated using the
following equation:
PID output=K Perror + K I errordt +
K Dd ( error )
dt
13
Shufarrel Bonaparte
David Plonski
Andr Ramos
3.1.4.
Controlling the speed of the wheels depends on which task is being performed.
For task 1 and 2, the only running PID is the Line Following one. Therefore, the wheel
speed are calculated on the following equations:
Wheel A =( base speed )( Pathtracking PID control output)
WheelC = ( base speed )+( Pathtracking PID control output )
This set of equations works in a way that, when the PID controller requires an action, a
difference on wheel speed is caused. Since each wheel is positioned on one side of the robot,
setting difference speed makes the robot turn to the side of the wheel with the lowest speed.
Ideally, when the controller finishes the correction and theres no steady state error, the controller
output is zero and both wheels run on the set base speed.
For task 3, the equations are slightly modified to accommodate a base speed change
based on the reading distance:
Wheel A =( Platooning PID control output ) (Pathtracking PID control output)
WheelC = ( Platooning PID control output ) +( Pathtracking PID control output )
That way, when the robot is too close to the TAs UV, PID automatically lowers the
speed, increasing the distance between both UVs, and vice-versa.
14
Shufarrel Bonaparte
David Plonski
Andr Ramos
3.2.
Data Logging
For Data Logging, a parallel task was set, responsible for reading the sensors and current
timestamp and writing that information into a log file. After this function writes in the file the
string with the required information, it sleeps to allow the Main Task to be processed, being
awaken later in order to produce one entry on error log on, approximately 20 milliseconds.
15
Shufarrel Bonaparte
David Plonski
Andr Ramos
4. Algorithm Development
Once the basic functionalities of the code were set and coded, the Algorithm was refined
in order to find the ideal PID gains. For such, knowledge from Mechatronics classes were used,
determining which change on gains would be performed to achieve the desired behavior.
The following table was also used, resuming the usual effects that increasing each of the
PID gains might cause:
Table 1 - Impacts of gain increase over closed loop system performance
Gain
KP
Rise Time
Decrease
Overshoot
Increase
Settling Time
Small Change
KI
Decrease
Increase
Increase
Eliminate
KD
Small Change
Decrease
Decrease
Small Change
16
Shufarrel Bonaparte
David Plonski
Andr Ramos
4.1.
Considering that tasks 1, 2 and 3 are performed on different tracks, PID for Pathtracking
was set with different gains due to different requirements.
For task 1 and 2, track has turns, and for that reason base speed is set to a lower speed, of
60%, making line following easier, specially on tighter turns. Also, in order to perform well on
turns, it is acceptable to have a not so consistent performance on straight lines. Overall, this PID
have higher gains for Task 1 and 2, providing a more energetic response and, therefore, being
able to follow the line better on tight turns.
Task 3, on the other hand, is performed on a straight line. Also, TAs UV speed might be
set up between 0% and 75%. For that, PID is set with lower gains, avoiding shaking performance
that might have a negative impact on the Platooning Task.
17
Shufarrel Bonaparte
David Plonski
Andr Ramos
4.2.
For tuning the Platooning PID, the same methodology of changing gains following Table
1. Overall, this PID has a set of gains higher than the Path Tracking PID, since reference distance
signals is more sensitive, producing smaller signal changes over raw sensor values. Also, for
Pathtracking PID a small change of the controller output may cause a high turn, while the desired
change of the Platooning PID output is desired to be higher since it sets the base speed of the
robot.
18
Shufarrel Bonaparte
David Plonski
Andr Ramos
4.3.
One of the refinements performed during Algorithm Development were regarding file
handling. NXT can manage files with up to 1024 bytes, even when more space in memory is
available. This limitation required the development of auxiliary file handling functions.
Basically, the new functions analyses if the number of written bytes match the total number of
bytes in the string. If less bytes were written, the current file is closed and a new one is created.
By the end, NXT memory would have several number sequenced files, that may be joined
together in a PC for a complete error log.
19
Shufarrel Bonaparte
David Plonski
Andr Ramos
5. Results
20
Shufarrel Bonaparte
David Plonski
Andr Ramos
5.1.
Ultrasonic Sensor
21
Shufarrel Bonaparte
David Plonski
Andr Ramos
5.2.
PID Gains
The Tuning process for the PIDs resulted on the following gains:
22
Shufarrel Bonaparte
David Plonski
Andr Ramos
5.3.
Performance Results
23
Shufarrel Bonaparte
David Plonski
Andr Ramos
24
Shufarrel Bonaparte
David Plonski
Andr Ramos
7. References
25