Vision Control for QBot Mobile Robot
Vision Control for QBot Mobile Robot
Vision-guided control
for the differential drive QBot mobile robot
Hugues Garnier
Mayank Jha
January 2024
Contents
1 Vision guided control for a differential drive mobile robot 2
1.1 The Quanser QBot mobile platform . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1.1 Main Hardware Components . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.1.2 Software and Communication . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 Download of the files required for the lab . . . . . . . . . . . . . . . . . . . . . . 7
1.3 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.3.1 Matlab 2021a and supplied Simulink files . . . . . . . . . . . . . . . . . . 7
1.3.2 Setting up the QBot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.3.3 Setting up and Verifying the Network Connections . . . . . . . . . . . . . 7
1.3.4 Configuration of QUARC: How to Run a Simulink Model . . . . . . . . . 9
1.3.5 Basic Input/Output Tests . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.3.6 Explore the Actuators: DC Motors . . . . . . . . . . . . . . . . . . . . . 13
1.3.7 Explore the Sensors: Encoders . . . . . . . . . . . . . . . . . . . . . . . . 14
1.3.8 Explore the Sensors: Gyroscope . . . . . . . . . . . . . . . . . . . . . . . 14
1.4 Keyboard Manual Drive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.4.1 Basic Wheel Drive Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.4.2 Normal Drive Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.5 Kinematic Models and Locomotion . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.5.1 Differential Drive Kinematics . . . . . . . . . . . . . . . . . . . . . . . . 18
1.5.2 Forward and Inverse Kinematic Models . . . . . . . . . . . . . . . . . . . 21
1.6 Odometric Localization and Dead Reckoning . . . . . . . . . . . . . . . . . . . . 26
1.6.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
1.6.2 Equations of Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
1.6.3 Trajectory Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
1.7 Vision guided control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
1.7.1 Explore the Sensor: Microsoft Kinect . . . . . . . . . . . . . . . . . . . . 29
1.7.2 Computer Vision and Image Processing . . . . . . . . . . . . . . . . . . . 31
1.7.3 Reasoning and Motion Planning . . . . . . . . . . . . . . . . . . . . . . . 35
1.8 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
1.9 Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
i
CONTENTS
Acknowledgements
The contents of this lab has been adapted from an initial version provided by Quanser1 . This
is fully acknowledged.
Special thanks go to Sarah HELLY for having provided some nice contributions to the
contents.
1
[Link]
1
Lab 1
Vision guided control for a differential
drive mobile robot
Figure 1.1 depicts an overview scheme that summarizes the see-think-act cycle in mobile
robot systems1 .
Figure 1.1: The see-think-act cycle in mobile robot systems (adapted from Siegwart et al.,
Autonomous Mobile Robots, ETH 20211 )
This final goal of this Lab is to study and develop a vision-guided control strategy for the
Quanser two wheel differential drive QBot mobile robot.
1
[Link]/education/lectures/autonomous_mobile_robots/[Link]
2
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
Figure 1.2: Vision guided control for the QBot mobile robot
Equipped with built-in sensors and a vision system, the QBot is ideally suited for studying
standard and advanced control for mobile robots.
The purpose of this introductory section is to familiarize you with the basic concepts
related to the QBot platform including the hardware (actuators and sensors) and the software
components.
To start with, watch the first 10 mn of the video by two Quanser engineers presenting some
of the capabilities of the QBot mobile robot:
[Link]/watch?v=QwKh-45yQ9Y
Further information about the QBot platform can also be obtained from:
[Link]/products/QBot-2e/
2
We are actually using the Quanser QBot 2e but we will use its shorter name QBot in this Lab.
3
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
As shown in Figure 1.3, the QBot robot consists of two left and right drive wheels mounted on
a common axis. This drive configuration is known as differential drive. Two castor wheels at
the front and back of the robot stabilize the platform without compromising movement. The
two drive wheels are independently driven forward and backward in order to actuate the robot.
Figure 1.3: Bottom and top views of the QBot mobile robot
The motion of each wheel is measured using encoders, and the robot orientation, or yaw
angle, are estimated using the integrated gyro. More information on the Kinematics, and
how you can generate wheel commands to achieve specific motion trajectories will be given in
the upcoming sections. You will also learn how the measured sensory information is used for
odometric localization.
In addition to the encoders and gyro, the QBot comes with a Microsoft Kinect
([Link]/wiki/Kinect) for computer vision, that outputs color image frames
(RGB) as well as depth information. You can process RGB and depth data for various
purposes including visual inspection, 2D and 3D occupancy grid mapping, visual odome-
try, etc. More information on these concepts will be given in the Vision Guided Control Section.
As shown in Figure 1.3, the QBot robot also comes with integrated bump sensors (left, right
and central), and cliff sensors (left, right, and central). These sensors can be used in a control
algorithm to avoid obstacles or prevent damage to the robot. The battery fits underneath the
QBot, and can last continuously for about 3 hours after a full charge. The robot can charge
with a battery charger connected to the plug as shown in Figure 1.4.
4
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
Figure 1.4: Button on/off and plug for the battery charger
Figure 1.5: Raspberry Pi 3 Model B+ with integrated WiFi embedded on the QBot robot
During this Lab, we will make use of QUAnser Rapid Control (QUARC) Prototyping software
which seamlessly integrates with MATLAB/Simulink to provide real-time communication and
interfacing to hardware platforms.
QUARC is a very efficient way to design, develop, deploy and validate real-time applications
on a variety of hardware target systems using Simulink. QUARC will generate real-time code
directly from Simulink and runs it in real-time on the QBot robot, all without digital signal
processing or without writing a single line of code.
Further information and tutorial video introduction to QUARC can also be obtained from:
[Link]/support/tutorials/?fwp_tutorial_categories=quarc
Controllers will be developed in Simulink with QUARC on the host computer, and these
Simulink models will be cross-compiled and downloaded to the target (Raspberry Pi 3 Model
B+) seamlessly by using the wireless router. A diagram of this configuration is shown in Figure
1.6.
5
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
Figure 1.6: Communication between a computer with QUARC installed and the QBot
To communicate with the QBot, several QUARC blocks available in the Quanser Library
in Simulink will be used. The following blocks will be, in particular, most useful :
1. Hardware In the Loop (HIL) Initialize block: it configures the drivers and hardware
interface for the QBot.
4. Host Initialize: it can be used for external input devices such as a keyboard (Host
Keyboard) or joystick (Host Game Controller).
5. Kinect Initialize block: it is used to initialize the Kinect sensor. Maximum frame-rate
and resolution are set in this block.
6. Kinect Get Image block: it captures RGB data from the Kinect sensor.
7. Kinect Get Depth block: it captures depth data from the Kinect sensor.
All the aforementioned blocks will be seen in the Simulink files supplied for this lab. The
complete list of available QUARC blocks available in the Quanser Library is available on the
following site:
[Link]/quarc/documentation/quarc_block_categories.html
6
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
2. Start Matlab.
3. Important ! By clicking on the browse for folder icon , change the current folder of
Matlab so that it becomes your C:/temp/Qbot folder that contains the files needed
for this part.
From now on, this will be your "working-directory".
In the User_guide sub-folder, you will find the following two pdf files
- Quick Start [Link]
- User [Link]
Please refer to these documents any time.
Before launching any Simulink file, it is recommended to follow the steps below:
1. Make sure that the wireless antenna is connected to the "Qcars" Wifi as shown in Figure
1.7
7
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
Figure 1.7: Connection between the Wifi and the PC through the antenna
2. Ping then the robot address to verify the wifi connection between the robot and the
wireless network. The robot address (XX below) is indicated on the QBot robot near the
Raspberry Pi:
ping [Link].
If successful, you should get messages as shown in Figure 1.8
8
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
It is important to verify the network wifi connection anytime during the Lab. Repeat the
tests above in case your Simulink program does not work anymore. If the robot does not
communicate with the computer, see the Troubleshooting Section at the end of this document.
3. Select Preferences as shown in Figure 1.10 and click on the three dots ... at the end of
the line Default model URI.
9
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
4. As shown in Figure 1.11, setup the Default Model URI with the IP address of the de-
sired target robot: "Hostname:[Link] where your Qbot address (XX below) is
indicated on the robot near the Raspberry Pi.
Once the configuration of QUARC is complete, a Simulink model may be built, down-
loaded and then start/stop on the Qbot target by clicking on Monitor & Tune button as
10
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
shown below (do not use the button Build, deploy & start
Further information about the procedure to build a model is available on the Quanser
site:
[Link]/quarc/documentation/quarc_procedures.html#external_mode_
operation
11
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
The QBot is equipped with several binary digital sensors including impact bumpers,
wheel drop sensors, cliff sensors, and buttons. These sensors can be used for various
custom applications including obstacle avoidance and path following. The digital sensors
are measured using the QUARC HIL Read block, and are accessed on digital channels
28-38. The sensor mapping is outlined in the User Manual, and is shown in Figure 1.13.
The chassis also includes over-current sensors to ensure that the motors are not damaged
due to improper use. These sensors can be measured on channels 39 and 40.
To track the status of the QBot battery, and for possible closed-loop motor control several
power sensors are provided. The battery voltage can be measured using the QUARC HIL
Read on Analog channel 0. The two motor current measurements can also be measured
on Analog channels 4 and 5.
Task
Compile and run the QBot2e_Explore_Sensors.mdl file. Once the QBot beeps,
indicating that the initialization routine is complete, trigger several of the sensors to
familiarize yourself with their operation. Close the Simulink file.
12
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
As shown in Figure 1.15, there are two programmable LEDs on the top of the QBot,
that can be illuminated as either green or red. The LEDs are commanded on digital lines
28 through 31 as outlined in the QBot User Manual, and as demonstrated in the model
shown in Figure 1.14.
Task
Compile and run the QBot2e_Explore_Commands.mdl file. Once the QBot beeps, indi-
cating that the initialization routine is complete, toggle the switches that control the
commands sent to each LED to familiarize yourself with their operation. Do not mod-
ify the slider gains for the left and right drive wheels; this will be explored in the next
sub-section.
Task
Compile and run the QBot2e_Explore_Commands.mdl file. Once the QBot beeps, follow
the procedures outlined below to familiarize yourself with the motor operation.
13
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
For more information on mapping the rotational speed of the wheels to deterministic
motion of the chassis, please refer to the Kinematics models and locomotion Section.
Close the Simulink file.
The QBot is equipped with two high resolution wheel encoders to track the rotation of
each wheel. The wheel encoder values for the right and left wheels are read using the
QUARC HIL Read block on encoders channels 0 and 1 respectively, as shown in Figure
1.13.
Compile and run the QBot2e_Explore_Sensors.mdl file. Once the QBot beeps, follow
the procedures outlined below to familiarize yourself with the encoders.
i - Slowly move the robot forward and backward and track the direction of each encoder.
Then rotate the robot clockwise and counter-clockwise.
ii - The encoders on the QBot measure 52 counts per rotation at the motor, which
when translated through the gearbox yields 2578 counts per rotation at the wheel.
To convert the wheel rotation counts to wheel rotations in radian add a gain of
2×π
2578
= 0.0024 to each measurement.
iii - A multiplication by a gain of 0.035 that represents the wheel radius in m will translate
the rotation of the wheels to linear movement (in m/s) of each wheel. Try adding
these gains to check the rotation of each wheel against the movement of the robot
base.
The QBot is equipped with a three axis gyroscope that tracks the angular rate of the
roll, pitch, and yaw of the robot. For simplicity, the yaw angle of the robot is output
on channel 1002 using the QUARC HIL Read block, along with the roll, pitch, and yaw
rates on channels 3000-3002. The proper configuration of these measurements is shown
in Figure 1.13.
Compile and run the QBot2e_Explore_Sensors.mdl file. Once the QBot beeps, follow
the procedures outlined below to familiarize yourself with the gyroscope.
i - Slowly rotate the robot clockwise, and counterclockwise and observe the changing
gyroscopic values.
ii - Pitch and roll the robot and observe the measured angular rates. If needed, take
note of the conventions which all follow a conventional right-hand rule.
14
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
In this file, we use, as seen in the blue frame, the HIL Initialize block to configure the
interface options for the QBot, the 3D video Interface for the Kinect sensor, the Host
Keyboard for the keyboard interface.
If you double click on the QBot Basic Motor Commands and Sensor Measurement
subsystem block, and then QBot2e_IO_Basic, you will find HIL_Write and HIL_Read
blocks used to drive the motors and read from the sensors. Take time to explore the
model. You can right-click on the blocks and select help to find more useful information
regarding each block.
Figure 1.16: Snapshot of the Simulink QBot2eK eyboardB asicW heelD [Link] ile
The Kinect Get Depth and Kinect Get Image blocks are used to read the depth and
RGB data from the Kinect sensors. We then use the Video Compressed Display blocks
to display these images.
The keyboard controls for this experiment are as follows:
• Left wheel rotational speed command: H (-) and J (+)
• Right wheel rotational speed command: K (-) and L (+)
Tasks
15
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
ii - Double-click on the XY Figure block in blue on the right, as well as on the Video
Compressed Display (Depth) and Video Compressed Display (RGB) blocks.
iii - Use the keyboard to command the robot.
iv - Describe how the speed of the left/right wheels relate to the actual motion of the
robot (forward/backward motion, left/right turn, etc.).
v - Stop the file.
The QUARC blocks used in this file are similar to the ones described above.
Figure 1.17: Snapshot of the Simulink QBot2eK eyboardN ormalD [Link] ile
Two customized blocks are also used that apply the inverse kinematics and forward kine-
matics models of the device, the details of which are presented in the next Section.
Keyboard controls for this experiment are as follows:
• Linear velocity command: Up arrow (+) and Down arrow (-)
• Angular velocity command: Left arrow (+) and Right arrow (-)
Tasks
After turning on the robot and connecting to the Quanser_UVS-5G wifi network, follow
the steps below to run the Simulink file:
16
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
17
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
The purpose of this experiment is to study the basic motion behaviour of the Quanser
QBot mobile platform.
Kinematics is used to determine the appropriate actuator commands for the robot. You
can get a full and clear explanation about the derivation of the kinematic model for the
differential drive and car-like model by watching the following video:
[Link]/watch?v=LrsTBWf6Wsc
Differential drive kinematics is the mathematical relationship that maps the independent
motion of the wheels to the overall movement of the robot chassis. This fundamental
topic is the foundation of all mobile robot control, in that it is chiefly responsible for the
predictable mobility of the robot. In this experiment you will investigate the differential
drive kinematics of the Quanser QBot mobile platform.
The QBot is driven by a set of two coaxial wheels. These wheels are actuated
using high-performance DC motors with encoders and drop sensors. To determine
the relationship between the independent motion of the two wheels and the motion
of the overall robot, we begin by modeling the motion of the robot about a common point.
Let the radius of the wheels be denoted by r, and the wheel rotational speed be
denoted by wL and wR for the left and right wheel respectively. The linear speed of the
two wheels along the ground is then given by the following equations:
vL = wL r (1.1)
vR = wR r (1.2)
18
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
Assuming there is no wheel slippage, the QBot can move along the horizontal plane in
straight or curved trajectory, as well as spin on a spot, by varying the relative speed
between the left and right wheels.
Since we are assuming that the wheels are not subject to slip, the motion of the
wheels are constrained to move along their forward and backward directions. This,
together with the inherent constraint that is imposed by the robot chassis coupling the
two wheels together, means that all robot chassis rotations must be about a point that
lies along the common wheel axis. For example, if only one of the two wheels rotates,
the robot would rotate (pivot) about the non-moving wheel. On the other hand, if both
wheels rotate at the same speed, the robot rotates about a point infinitely far from the
robot. This center of rotation is known as the Instantaneous Center of Curvature (ICC)
as shown in Figure 1.18.
[Link] Background
Let ricc be the distance measured from the center of the robot chassis, which is halfway
between the left and right wheels, to the ICC. If d is the distance between the left and
right wheels, θ is the heading angle of the robot, and vC is the (forward/backward) speed
of the robot chassis center, the motion of the QBot chassis can be summarized by the
following equations:
vC = θ̇ricc (1.3)
d
vL = θ̇ ricc − (1.4)
2
d
vR = θ̇ ricc + (1.5)
2
19
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
Notice that vC , vL and vR are all defined along the same axis, which lies in the for-
ward/backward direction of the chassis. Given the wheel speed, vL and vR , the robot
speed, vC , the angular rate, wC = θ̇, and the distance from ICC, ricc ,we can relate the
motion of the wheels to the motion of the robot using the forward kinematic model for
the differential drive system, as shown in Figure 1.19.
vR + vL
vC = (1.6)
2
vR − vL
wC = θ̇ = (1.7)
d
d vR + vL
ricc = (1.8)
2 vR − vL
Given the robot speed, vC and the angular rate, wC = θ̇, we can compute the wheel
speed, vL and vR , of the robot using the inverse kinematic model for the differential drive
system, as shown in Figure 1.20.
1
vR = vC + d wC (1.9)
2
1
vL = vC − d wC (1.10)
2
Tasks
20
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
The QBot diff drive kinematics block, highlighted in yellow, receives the left and right
wheel velocities as input and computes the forward/backward speed and angular velocity
of the robot chassis center.
i - By using equations (1) to (5), derive (6), (7) and (8).
ii - Compile and run the Simulink file.
iii - Wait 5 seconds until the QBot has fully initialized, and then enable the movement
of the robot using the manual enable switch shown in blue in Figure 1.21.
iv - Set both left and right wheel velocity set points, highlighted in blue, to 0.1 m/s. Run
the file and observe the linear and angular velocities calculated by using (5) to (7).
What are the values of ricc and wC when the left and right wheels are moving at the
same speed (i.e. vL = vR )? What do your results indicate about the relationship
between ricc and wC ?
v - Change the right wheel velocity to - 0.1 m/s and keep the left wheel velocity com-
mand at 0.1 m/s. What is the value of ricc when the left and right wheels are moving
at the same speed but in the opposite direction (i.e. vL = - vR )? What do these
results indicate? Does the relationship identified earlier hold?
vi - What does it mean when ricc is negative?
vii - What does it mean when wC is negative?
A typical forward kinematic model that computes the robot chassis speeds, vC ,
and turning rate, wC , from the wheel speed, vR and vL , with wheel separation distance,
d, for a robot with differential drive system like the QBot is given by (6) and (7).
21
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
Figure 1.22: Robot chassis local and global reference frames for a robot with a heading θ
Implicit in the derivation of the above kinematic model is the use of a local frame of
reference. In other words, the chassis speed, vC , is expressed in the forward/backward
(heading) direction of the robot chassis and not the global frame that would be used in a
map of the environment. Since the robot chassis heading changes when the angular rate is
non-zero, wC = θ̇, we need to apply a transformation to the differential drive kinematics
model in order to compute the robot chassis motion with respect to the global reference
frame. For a robot with a heading, θ, the transformation required is the following rotation
matrix:
cos θ − sin θ 0
R = sin θ cos θ 0 (1.11)
0 0 1
This transformation maps motion expressed with respect to the robot chassis local frame
to the corresponding motion in the global frame.
cos θ sin θ 0
R−1 = − sin θ cos θ 0 (1.12)
0 0 1
22
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
We define a state vector, S, as the position, x and y, and the heading, θ, of the robot
chassis. Its definition and rate of change are given as follows:
x
S = y (1.13)
θ
ẋ
Ṡ = ẏ (1.14)
θ̇
The x and y axes lie in the "ground" plane that the robot primarily travels in. The
heading, θ, is measured about the vertical z axis, which is defined as positive pointing
upwards. The heading is zero, (θ = 0), when the robot chassis forward direction aligns
with the global x axis. The time-derivative of the states can be expressed in terms of the
robot chassis speed, vC , and angular rate, wC , as follows:
1
ẋ vC vC cos θ 2
(v R + vL ) cos θ
Ṡ = ẏ = R 0 = vC sin θ = 12 (vR + vL ) sin θ (1.15)
1
θ̇ wC wC (v − vL )
d R
Equation (1.15) represents the forward kinematic model for the QBot that computes the
linear speed, (ẋ and ẏ), and turning rate, (wC ), of the robot chassis given its heading
(θ), and wheel speed (vR and vL ).
x − d2 (v R +vL )
xICC x 0 x − rICC sin θ (vR −vL )
sin θ
d (vR +vL )
y = y + R r = y + r cos θ = y + cos θ (1.16)
ICC ICC ICC 2 (vR −vL )
0 0 0 0 0
Equation (1.15) can be useful for path planning or obstacle avoidance algorithms.
Tasks
23
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
If you want the robot to follow a certain path or drive at a given speed, you need to
send appropriate left and right wheel commands to the robot. The inverse kinematics
model computes the required wheel speed to obtain a desired robot chassis speed vC , and
angular rate θ. It is obtained by solving (6) and (7) together for the wheel speed vR and
vL and is given as follows: " # " #
vR vC + 12 d wC
= (1.17)
vL vC − 12 d wC
Tasks
24
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
25
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
1.6.1 Background
Given the robot chassis state vector, S(t), and its rate of change, Ṡ(t), expressed in the
global inertial frame, the robot pose at time, t, can be computed as follows:
x(t) Z t
S(t) = y(t) = Ṡ(t) dt (1.18)
0
θ(t)
For the QBot, given the wheel separation, d, the heading, θ, and the wheel speed, vR and
vL , the equations of motion for odometric localization are given by:
x(t) Z t 12 (vR (t) + vL (t)) cos θ(t)
1
S(t) = y(t) = 2 (vR (t) + vL (t)) sin θ(t) dt (1.19)
0 1
θ(t) (v (t) − vL (t))
d R
In MATLAB/Simulink, it is easy to use the built-in integration blocks to solve the odo-
metric calculations. However, for low-level languages, we need to employ other integration
methods. For example, for a small time step, δt, the above QBot equations of motion can
be approximated as a first-order Taylor series expansion:
1
x(t) (v (t) + vL (t)) cos θ(t)
2 R
S(t + δt) = S(t) + Ṡ(t)δt = y(t) + 21 (vR (t) + vL (t)) sin θ(t) δt (1.20)
1
θ(t) (v (t) − vL (t))
d R
26
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
The Simulink model implements an open-loop trajectory controller for the QBot. The
specified path consists of the following segments:
At the end of the specified path, the QBot is expected to have returned to approximately
the starting point.
Tasks
27
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
ii - Mark the starting location and heading, prior to running the Simulink model.
iii - Compile and run the Simulink model, then follow the procedure outlined below.
Make observations on the motion of the robot, and answer the associated questions.
iv - Once the QBot has fully initialized (upon hearing the QBot start-up chime), it will
begin to move.
v - Measure and record the final position and heading of the robot chassis with respect
to the starting position and heading. A MATLAB function called plotXY.m has
been provided to generate an appropriate plot for the path analysis.
• What is the error between the desired end-point of the robot, and the actual
final x-y position? Recall, the x axis is in the forward/backward direction of the
robot and the y axis is in the left/right direction.
• What is the heading error?
The XY plot should look similar to the figure below
The robot travels less than the ideal calculated distance due to the speed tracking
error mostly at the beginning of the motion when the robot is trying to overcome
the friction and has not yet reached the desired speed. This error depends highly on
the type of flooring that causes the friction. In Figure 1.27, the robot has traveled
almost 3/4 of the full circle, and therefore, would require more time to reach the
final destination.
vi - Determine the theoretical right wheel and left wheel commands, and time required,
for the QBot to travel in a straight line 2 meters in length. Enter your values into
the appropriate fields in the Simulink model, indicated in blue and shown in Figure
1.26.
vii - Repeat steps 1 and 2, and record your new results. Modify the wheel commands
and time values until the robot is able to reach the correct position.
viii - Identify and discuss the different factors that contribute to the path/trajectory track-
ing error. Specifically, note the error reported by the Simulink model and the error
based on direct physical measurements.
28
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
The objective of this experiment is to study computer vision for robotic applications
using the QBot mobile platform.
We will first explore the image-based sensor available with the Qbot.
To enable the QBot to easily perform classic mobile robotic algorithms and applications
including visual servoing, mapping and localization, obstacle avoidance, and path fol-
lowing, the QBot is equipped with a Microsoft Kinect which utilizes an infrared laser
projector and monochrome CMOS sensor for depth measurement, and an RGB camera
for image processing. The camera provides image and depth capture at a frame rate of
up to 30 fps and resolution of 640 x 480 pixels. The depth sensor has a range of 0.5 to
6 m. The sensor has a horizontal field of view (FOV) of 57 degrees, and vertical FOV
of 43 degrees. The sensor can also be pivoted vertically by up to 21.5 degrees to allow
the sensor to measure objects outside of the conventional horizontal field. The depth of
objects are measured as a monochrome value depending on their distance from the sensor
as illustrated in Figure 1.28.
29
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
Before running the Simulink model, there are several configuration settings that should
be observed to ensure proper deterministic operation of the sensor. Begin by making
sure that the trigger duration in the Signal and Triggering sub-menu of the Hardware
Control Panel is set to a Duration of 2, as shown in Figure 1.30.
30
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
To achieve a desired frame rate, use the Sample Time parameter in the Kinect Initialize,
Kinect Get Depth, and Kinect Get Image blocks. The parameter is specified in seconds.
By default, the Sample Time parameter is set to qc_get_step_size * ceil(0.033 /
qc_get_step_size), where it attempts to acquire images at the maximum rate of 30 fps.
As an example, assuming the sample time of the model is qc_get_step_size = 0.005 s, to
acquire images at a say 10 fps (100 milliseconds per frame), the Sample Time parameter
should be set to qc_get_step_size*20 = 100 milliseconds per frame.
For improved image playback it is recommended to use the Video Compressed Display as
shown in Figure 1.29. The Video Compressed Display block displays video in a window
on the host. However, it uses image compression internally to minimize the bandwidth
required to transmit the raw image from the target model to the host. It is designed for
typical video frame rates. The video can be paused and resumed, and the current frame
may be saved to disk as an image. This block has much higher performance than the
Display Image block because it does not use MATLAB figure windows. However, as a
result it cannot be used to drive axes in a MATLAB GUI.
Compile and run the QBot2e_Explore_Vision.mdl file. Once the QBot beeps, indicating
that the initialization routine is complete, make sure that the Depth Data and RGB Video
windows are visible. If they are not open, double click on each of the display blocks to
open the viewers. With the model running, move the robot and place objects in front of
the robot to familiarize yourself with the operation and capabilities of the vision sensor.
The objective of this experiment is to explore some useful image processing tech-
niques using the Quanser QBot Mobile Platform.
A digital image can be defined as a twodimensional function, f (x, y), where x and
y are spatial coordinates, and the amplitude of f at any pair of coordinates (x, y) may
be a scalar or a three element vector. When the scalar represents a value proportional to
the energy of the visual spectrum of the electro magnetic (EM) field at the coordinate (x,
y), the image is called a grayscale image. On the other hand, when the vector amplitude
represents the energy of red, green, and blue colours in the visible EM spectrum, the
image is called a colour image or RGB (RedGreenBlue).
In digital image acquisition, photo sensors are arranged in a 2D array where each
photo sensor indicates a point in the discrete spatial coordinate and is called a picture
element or pixel. The spatial coordinate and is called a picture element or pixel. The
electrical signals from photo sensors are digitized using a quantizer to produce a digital
image which can be stored in a memory chip.
31
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
Therefore, when working with images in this experiment, you will be dealing with
mxn (for grayscale images) or mxnx3 for colour images, where m is the numbers of pixels
in a row (number of columns) and n is the number of the pixels in a column (number of
rows).
Once an image has been acquired, it can be processed. Image processing funda-
mentally involves the manipulation of digital images using a computer. Image processing
techniques are widely used for visual based control of mobile vehicles. The following
subsections briefly describe selected image processing techniques covered in the QBot
experiments.
There are several types of image processing, we are going to explore three meth-
ods:
• Image thresholding
• Edge detection;
• Blob analysis.
32
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
The Image Thresholding block, in yellow, implements the thresholding algorithm using
the different methods described in the background section. This block receives the
frame, region of interest (roi), thresholds on all three color channels (th_red, th_green,
th_blue), the method (th_type) and the truncation values (thuncval) required for the
truncation approach. This block outputs the processed image through RGB channels as
well as the histograms.
Follow the procedure outlined below. Make observations about the effect of the
algorithms on the generated images, and answer the associated questions.
An edge is a set of similar, connected pixels that lie on the border between two regions.
This method allows you to detect the edge of different shapes.
33
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
The Edge Detection subsystem, shown in yellow, processes the image using the mask
convolution technique described in the Background section. Doubleclick on this block,
open the embedded mathscript and find the masks and convolution functions used in the
code.
Follow the procedure outlined below. Make observations about the effect of the
algorithms on the generated images, and answer the associated questions.
i - Make sure the manual switch (Enable switch) as well as all the sliding gains (shown
in blue) are set to zero.
ii - Double click on the Video Display (Edge) block to open up the figure window.
iii - Compile the file and run it once it is downloaded to the target.
iv - Look at the resulting image showing the edges. Toggle the enable switch, and slowly
change the slider gain related to Omega. Observe the effect on the generated image,
and record your observations.
v - Toggle the manual switch to disable the algorithm, and stop the file.
vi - Double click on the Edge Detection block to open the embedded mathscript. Com-
pile the updated code and go through the steps above to access the comparative
performance of your solution.
vii - What would need to be changed if you were asked to implement a different edge
detection technique?
viii - Describe how you would extract the edges out of the image.
Blob analysis makes it possible to detect the different regions that make up the image.
34
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
Follow the procedure outlined below. Make observations about the effect of the
algorithms and answer the associated questions.
i - Set the [min max] values of the three threshold parameters (highlighted with blue)
that you found in the first part of the lab.
ii - Make sure that the manual switch (Enable Switch) is set to zero.
iii - Double click on the Video Compressed Display blocks.
iv - Compile and run the model and look at the video display window.
v - Bring your colored piece in front of the robot and see if it is completely detected
by the robot. Move if back and force, up and down and look at the Blob Centroid
display (in blue). If the object is not fully detected as a blob, tune the [minmax]
threshold values until your object is fully detected as one blob.
vi - Explain how the blob centroids could be used to plan the motion of the robot.
35
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
Image features, such as blob centroids, edges, corners, etc. are utilized primarily in
robotics to make reasoned statements as to the environment around the robot, and an
appropriate course of action. In order to create an algorithm that can make appropriate
decisions, you will often need to remove much of the detail from the data that is provided
by the image capture device in order to create clear judgments about the state of
the robot and the environment. This act of using available data to create conditional
statements is the basis for much of artificial intelligence.
Figure 1.34: Goal and current location of the robot base in a line following scenario.
Motion planning generally involves the creation of motion commands for the robot based
on a series of goal positions, or waypoints. For this experiment experiment, the motion
planning algorithm uses the centre of the current blob as the next goal for the position
of the robot (command or setpoint), as well as the current location of the robot to create
the motion path. Given that the Kinect sensor is mounted on top of the robot, and
can see directly in front of the robot (when the Kinect is tilted down), we can always
assume that the current location of the robot is a fixed distance below the last row of
the image in the image coordinate frame. The goal (blob centroid) as well as the cur-
rent location of the robot (below the last row of the image) in the image coordinate frame.
36
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
Tasks
The file for this part of the lab is QBot2e_Image_Proc_Line_Following.mdl. This file
uses image processing algorithms, explicitly blob filtering, in order to find a line, locate
the goal, and controls the robot to reach the target.
1.8 Conclusion
Summarize and reflect on what you have seen and learned in this lab.
37
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
1.9 Troubleshooting
How to fix some issues that may appear:
i - If the router does not communicate with the computer: follow the instruc-
tions in "Quick Start Guide" (in the Folder User_guide).
ii - If the robot does not communicate with the computer:
i. Verify the robot is turned on.
ii. Open "invite de commandes" and ping network :"ping [Link]".
iii. Verify that there is not a second router in the room. If there is: verify that
the robot does not communicate with the second network: ping the robot from
the computer that could be connected to the second router.
If the robot communicates with the second router: turn off the second
router (switch at the rear), wait and ping the address of the robot on the first
computer.
After the connection is established: turn on the second router.
iii - For any error::
i. Verify that ”C : \P rogramF iles\Quanser” is added to the Matlab path.
ii. Verify that ”C : \GW ” is added to the Matlab path.
iii. Delete the files that do not ": ".mdl", ".m" or ".jpg"
iv. Delete the folder "slprj" and "name_of_program_quarc_linux_pi_3".
v. Quit and restart Matlab.
vi. Reboot the computer.
iv - If a Message Box pops up, saying the file is not added to the path, here
is the method to follow : Click Add To Path
38
39
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
40
Lab n◦ 2 – Vision guided control for a differential drive mobile robot
41