Lab 9
Lab 9
LAB OBJECTIVE
The objective of this lab is to design and implement a motion control system for a mobile robot.
The developed controller has to ensure that the robot can follow a designed trajectory while
avoiding obstacles.
2.
BACKGROUND
The National Instruments (NI) Robotics Starter Kit 1.0 is a mobile robot platform that comes
equipped with sensors, motors, and a NI Single-Board RIO for embedded control. NI LabVIEW
graphical programming and the LabVIEW Robotics module can be used for programming the
mobile robot.
Robot Components
The NI Robotics Starter Kit uses a NI Single-Board RIO 9631 embedded control platform and an
ultrasonic range finder. The Single-Board RIO controller integrates a real-time processor,
reconfigurable field-programmable gate array (FPGA), and analog and digital input/output (I/O)
on a single board. It is powered by both NI LabVIEW Real-Time and FPGA technologies. The
built-in analog and digital I/O can be expanded using C Series modules.
The robot has two DC servomotors and 4 wheels. The DC motors are positioned between the
front and rear wheels on each side and connected via a 2-1 gear train to both wheels. Each motor
has a 400-tick encoder. Thus, the motor for each side (left or right) can be controlled
independently. The steering method for this wheel configuration is called skid-steer.
2.2
The NI sbRIO-9631 embedded control and acquisition device (see Figure 4) integrates a realtime processor, a user-reconfigurable field-programmable gate array (FPGA), and I/O on a single
printed circuit board (PCB). It features a 266 MHz industrial processor, a 1M gate Xilinx Spartan
FPGA, 110 3.3 V (5 V tolerant/TTL compatible) digital I/O lines, 32 single-ended/16 differential
16-bit analog input channels at 250 kS/s, and four 16-bit analog output channels at 100 kS/s. It
also has three connectors for expansion I/O using board-level NI C Series I/O modules. The
sbRIO-9631 offers a -20 to 55 C operating temperature range along with a 19 to 30 VDC power
supply input range. It provides 64 MB of DRAM for embedded operation and 128 MB of
nonvolatile memory for storing programs and data logging.
This device features a built-in 10/100 Mbits/s Ethernet port that can be used to conduct
programmatic communication over the network and host built-in Web (HTTP) and file (FTP)
servers. The RS232 serial port can be used to control peripheral devices.
Figure 4: sbRIO-9631
2.3
Robot Control
The NI sbRIO-9631, single board RIO, is programmed by using NI LabVIEW software. Using a
LabVIEW program developed for this lab, the robot can be programmed with high-level
programming. Using the program provided, the robot and the controller transmit control signals
and data at a frequency of 100 Hz.
Translate
Rotate
Description
Stop motors (irrespective of specified speed,
)
Rotate left and right wheels in same direction at specified speed,
, in rad/s
Forward:
Backward:
Rotate left and right wheels in different directions at specified speed,
, in rad/s
Counter Clockwise:
Clockwise:
Note: When the robot is in the translation or rotation mode, the robot should be stopped before
switching to another mode. If the robot is switched between these modes while the wheels are
still in motion, an error in robot motion can occur.
2.4
System Model
3.
ROBOT PROGRAMMING
3.1
In this lab, you will program the National Instrument, sbIO-9631, a microcomputer, to control
the robot. The sbRIO-9631 is programmed using LabVIEW 2012. LabVIEW uses block
diagrams to implement a real-time program. Two basic programs have been provided to manage
the transfer of both commands and data to and from the robot. The first program, Robot Manual Control allows the robot motion to be controlled manually via user inputs on the
keyboard. The second program, Robot - Formula Node Control, relies on a formula node block
to control what commands are sent to the robot. The formula node allows you to perform
complicated mathematical operations and control using the C programming language. You are
encouraged to scan the help section for this block (see Appendix 10.A.2) and carefully program
the controller. (Tip: If the C code has errors, the Run button used to start the program will change
from
to )
When you first open any LabVIEW program, you will see two windows, the front panel window
and a block diagram window. The front panel window allows you to monitor output variables
and set input parameters. The block diagram window displays the actual program written by
graphical programming and contains the code for controlling the robot.
Plots:
o
o
o
Data:
o
Sonar Plots: Time series sonar range measurements (filtered and unfiltered)
Position Plots: Time series , , and data
Trajectory Plot: Time series robot position and current heading
Position: , , and
o
o
o
o
3.2
The most important element in the block diagram for this lab is the formula node block. An
example formula node block used to program the robot to track a reference sine wave input can
be seen in Figure 10.
Data Type
Double
Description
Robot X Position (in)
Y
Th
In2Cnt
Deg2Cnt
Double
Double
Double
Double
FT
Double
FR
Double
sonar
count
delay
Ts
state
reset
Double
Int
Int
Double
Int
Int
cmd
sonarAngle
vel
error
previous_error
error_integral
Int
Double
Double
Double
Double
Double
error_derivative
iR
Double
Int
Error derivative
Rotation counter
All formula node output variables are fed back into the formula node as inputs using shift
registers,
. In LabVIEW, this directs the program to store the variable so that it can be
used during the next loop iteration. Any variable declared in the formula node that is not wired in
this way will be removed from memory after finishing each cycle of the loop. New shift
registers can be added by right-clicking on either the left or right wall of the while loop.
Similarly, new input or output variables can be added by right-clicking on the wall of the
formula node.
3.3
PRE-LAB REPORTS
Exercise 1:
The state machine provided in Figure 11 below makes the robot move to the target position
while avoiding any obstacles in its path. If an obstacle is encountered, the
robot will turn counter-clockwise and proceed to move around the edge of the obstacle. We have
made the assumption that each obstacle encountered is a fixed size and that they are spaced
sufficiently far apart to avoid simultaneiously encountering more than one obstacle. The
defintion for each state and the necessary variables are provided in Table 3 and Table 4. *NOTE:
This allows the robot to travel a shorter distance on the front/back of th obstacle than it does
along the side of the obstacle.
The value of the variable used to count rotations, , will need to be incremented/decremented as
directed after each rotation state is completed.
Definition
End Condition(s)
Translate until
Rotate robot
increment
Translate
| |
Rotate robot
and decrement
End
| |
or object detected
by 1
&&
&&
&&
&&
by 1
Definition
)
).
Using this state machine and the map provided below, determine the series of states the robot
will progress through as it moves from its initial position
to its final
position
. Additionally, note what the value of should be after each state is
completed. Assume the robot starts from
, the initial value of the rotation counter is
, and that the sonar sensor angle is fixed at zero. Draw the expected trajectory of the
robot.
Exercise 2:
Using proper LabVIEW formula node syntax, write a program to move the robot a specified
distance in inches. The robot should stop if the error between the current and desired position is
less than 0.04 inches or if the sonar detects an object closer than 10 inches. This scenario is
depicted by the following state machine diagram.
Similar to what was done in previous labs, the gains for our controller have been selected by
using the Ziegler-Nichols tuning method. After finding the critical gain,
, at which the output
oscillates with a constant amplitude, the critical gain,
, and the oscillation period,
, are
used with the type of controller desired to select the controller gains:
Exercise 3:
Using proper LabVIEW formula node syntax, write a program to rotate the robot by 90 degrees
counter-clockwise. The robot should stop if the error between the current and desired heading is
less than 0.25 degrees. This scenario is depicted by the following state machine diagram. Use the
same controller gains defined in Exercise 2.
5.
LAB PROCEDURE
Left Encoder
(counts)
Right Encoder
(counts)
Feedback Translation
(counts)
Feedback Rotation
(counts)
24.0
48.0
72.0
2. Use the keyboard to move the robot a series of specified robot headings (i.e. angles). Stop
the robot at each set heading and record the encoder measurement data in the table
provided. NOTE: Do not reset the encoders after each position.
Table 6: Feedback Rotation Calibration
Angle
(deg)
Left Encoder
(counts)
Right Encoder
(counts)
Feedback Translation
(counts)
Feedback Rotation
(counts)
90
180
270
Use the data in these two tables to find the calibration constants between FT and distance in
inches and between FR and angle in degrees.
Exercise 2: Translate Robot
Implement your program from Prelab Exercise 2 to move the robot forward 48 inches. Test the
program both with and without an obstacle placed 36 inches ahead of the robot.
The program automatically stores a graph of the x-axis trajectory, X Position.bmp, and places
it in your project directory. Make a copy of this graph for both conditions for your postlab.
6.
Exercise 1:
Using the left and right encoder data from Exercise 1, determine the relationship between
encoder counts and robot position.
a) Plot the feedback translation against the actual distances moved by the robot from the
first test (include the origin).
b) Using this graph, find the relationship between the encoder counts and robot distance (in
inches).
c) Plot the feedback rotation against the actual distances moved by the robot (include the
origin) from the second test.
d) Using this graph, find the relationship between the encoder counts and robot heading (in
degrees).
e) When calibrating the robots feedback translation, what was the expected feedback
rotation? Similarly, what was the expected feedback translation when testing feedback
rotation? Compare these expectations to your experimental results and explain any
discrepancies.
Exercise 2:
a) Provide a graph of the robots x-axis translation both with and without the robots path
obstructed by an obstacle.
b) Provide a printout of your working formula node code.
Exercise 3:
a) Provide a graph of the robots heading.
b) Provide a printout of your working formula node code.
Exercise 4:
a) Provide a graph of the robots trajectory.
b) On the graph, indicate which state corresponds to each segment of the robots trajectory
c) Provide a printout of your working formula node code.
APPENDIX
A.1 LABVIEW PROGRAM START-UP AND EXECUTION
1) Download the program archive (Lab 10.zip) from the course website
2) Using 7 zip, extract the entire archive to the computers hard drive
a) Double-click the zipped archive
b) Press 7 to open the file in 7-zip
c) Press Extract and select the folder D:\USERS\
d) Click OK and close 7-zip
3) Launch LabVIEW 2012
a) Start All Programs Local ni
National_Instruments_LabVIEW_2012_SP1_32-bit_
4) Open the top-level project file
a) Select Open Existing
b) Locate and select the file Lab 10.lvproj in the Lab 10 folder you just extracted
The top-level project file contains a directory of all the hardware and programs associated
with a given project. A view of the project directory we are working with for this lab can be
seen in Figure A1 below.
As shown, the project can be broken up into two main sections: (1) code that is compiled
and executed on the computer and (2) code that is compiled and executed directly on the
robot. The FPGA code on the robot has been pre-compiled and will not need to be
modified. Accordingly, we will only be working with programs compiled and executed
on the computer.
5) Open the main program to control the robot
a) Choose Robot - Formula Node Control to control the robot using logic defined in a
formula node or Robot - Manual Control to control the robot manually.
i) Exercise 1: Robot - Manual Control
ii) Exercise 2, 3, and 4: Robot - Formula Node Control
b) Run the program by clicking the Run button.
The program top level commands in LabVIEW are provided in the top left corner of
every program window. These can be seen in Figure A2 below.
With the MASTER switch off, the computer cannot connect to the robot. This switch
removes power from the entire robot. The MOTORS switch only removes power from
the robots motors. If due to an error in programming the robot moves uncontrollable or
is about to crash, the MOTORS switch can be turned off as a failsafe to stop motion.
c) Use the drop down menu provided to select the robot number
d) To confirm you selected the correct robot, type the 5-digit serial number found on the
bottom of your robot and hit <ENTER> on your keyboard
NOTE: The robot takes a minute to establish a proper connection through the buildings
network. If you try to connect through LabVIEW before this start-up time, your
connection attempt may fail.
7) Control the robot
a) If running the program Robot - Manual Control, use the keys defined in Figure A4
below to command the desired robot motion.
Control
Indicator
Data Type
Single, Double, or Extended floating-point
Fixed Point
8, 16, 32, 64 bit signed integer
8, 16, 32, 64 bit unsigned integer
Boolean
String
Reference
Error
Definition
While-loop
Loop period
Loop iteration
Conditional terminal: Stop loop if True
Shift Register: Feedback variables for next loop iteration
Inputs
Robot Number
Confirmation Code
Initialize
Robot
Purpose
Select the desired robot and
enter its unique 5 digit
confirmation code (serial
number)
Establish a connection to the
robot with LabVIEW
Stop
Robot
FPGA VI Reference
Error
Read
Encoders
FPGA VI Reference
Error
Initial Left Encoder (counts)
Initial Right Encoder (counts)
Reset Encoders
Robot Number
Outputs
Robot Number
Status
Robot Selected?
Robot Selection Confirmed?
FPGA VI Reference
Error
Initial Left Encoder (counts)
Initial Right Encoder (counts)
FPGA VI Reference
Error
Initial Left Encoder (counts)
Initial Right Encoder (counts)
Left Encoder (counts)
Right Encoder (counts)
Feedback Translation (counts)
Read
Sonar
FPGA VI Reference
Error
Filter
Sonar
Filter
Velocity
Robot
Motor
Command
Generate commands to
control the robot motors
FPGA VI Reference
Error
Sonar
Motor
Command
Generate a command to
control the sonar motor
FPGA VI Reference
Error
Command
Velocity (rad/s)
FPGA VI Reference
Error
Sonar Angle (deg)
Update
Robot
Position
X Position (in)
Y Position (in)
Th Position (deg)
Create
Map
Plot
Robot
Position
Plot
Sonar
FPGA VI Reference
Error
Map
X Position (in)
Y Position (in)
Th Position (deg)
Sonar Distance (in)
Sonar Angle (deg)
Map
Iteration
Maximum Plot Size
Reset Position
Sonar Distance (in)
Sonar Distance Filtered (in)
Iteration
Maximum Plot Size
Reset Position