You are on page 1of 4

INTRODUCTION

This report is on the trajectory tracking of the DaNI 2.0 nonholonomic differential drive robot from National
instruments. The control algorithm used was Sliding mode control in a cascade control strategy, whereby the sliding
mode controller loop is the outer loop which sends setpoints to an internal PI controller loop. The aim is to drive
the robot into following a time-parameterized state trajectory. The trajectories experimented with are: Line
trajectory, circle trajectory, S-trajectory and circle offset trajectory of 1.5m. The sliding mode controller was tuned
to yield satisfactory tracking of the desired trajectory, and the internal PID controller was tuned to control the
actuators (left and right DC motors), based on angular velocity setpoints from the outer loop.

IMPLEMENTATION
TASK 1: The sliding mode control using two switching functions S1 and S2 was implemented in LabVIEW according
to the block diagram in figure A1.1 in Appendix A1. This was implemented in the Task_SlidingMode.vi virtual
instruments using National Instruments LabVIEW software. A first formula node was used to estimate the pose of
the robot, by computing the real linear and angular velocities using the measured left and right DC motor angular
velocities read from a local variable, and then the states 𝒙(𝒌 + 𝟏), 𝒚(𝒌 + 𝟏), 𝜽(𝒌 + 𝟏) using equations (1),(2),(3),
(4) and (5) in appendix A2. In the second formula node, the previous values of the states, 𝒙(𝒌), 𝒚(𝒌), 𝜽(𝒌) were
then used with the desired trajectories, 𝒙𝒅, 𝒚𝒅, 𝜽𝒅 to compute the auxiliary errors using equation (6) in appendix
A2 in another formula node. A third formula node was then used to implement the sliding mode controller itself.
The time derivative of the errors was computed from the linear and angular velocities (desired and measured),
using equations (7), (8) and (9) in appendix A2. The sliding surfaces (switching functions) S1 and S2 which
incorporate al the three error variables was computed using equations (10) and (11) in appendix A2. The switching
functions indicate how the error exponentially decays. From equation (10), if 𝑠1 goes to 0, then 𝑥𝑒 exponentially
decays with a time constant determined by 𝒌𝟏 . The reference linear and angular accelerations 𝑽𝒄̇ and 𝝎̇𝒄 which
correspond to the control actions (𝒖𝟏 , 𝒖𝟐 ) from the sliding mode controller were then computed as a function of
the switching surfaces 𝑠1 and 𝑠2 , using the relationship in equation (12) and (13) in appendix A2. The reference
linear and angular velocities was then obtained by integrating 𝑉𝑐̇ and 𝜔̇ 𝑐 . The previous values of the linear and
angular velocities 𝑽𝒄 (𝒌 − 𝟏), 𝝎𝒄 (𝒌 − 𝟏) were obtained using shift registers as shown in the LabVIEW code, then
equations (15) and (16) in appendix A2 were used to compute the integral to obtain 𝑽𝒄 and 𝝎𝒄 . These reference
linear and angular velocities were then transformed to yield the reference angular velocities to be sent to the left
and right DC motors 𝝎𝒍 and 𝝎𝒓 respectively, using the relationship in equation (18) in appendix A2. The radius 𝒓 of
the wheels is given as 0.046m and the length 𝒍 is given as 0.365m. This reference angular velocities for the left and
right wheels were then stored in a local variable which was used to read these values into the inner PID loop as
shown in the Task_SlidingMode.vi virtual instrument. A sequence frame was used on the left hand side of the
labVIEW code to initialize all the local variables each time the VI is run so as to avoid data inconsistency. An error
cluster constant was wired from the sequence frame to the Open/Create File function. This was to ensure that the
sequence frame executes first before any other code executes. A tab control was used with a case structure to
specify the particular trajectory to be sent to the robot. This was used to eliminate the need to manually load the
trajectory files each time the VI is to be run. A condition was used with the no. of iterations terminal in the sliding
mode controller loop, such that when the no. of iterations is equal to a certain value (the value of the no. of lines
in the trajectory file), the loop stops. And this in turn stops the PID loop using a local variable. The PID controller
and PID.vi virtual instrument designed in the previous week was re-used in the inner loop. The PID controller
however was slightly retuned by setting the Derivative term to 0. The sampling time of the PID loop was faster at
50ms while the sampling time of the sliding mode controller loop was slower at 150ms.

Obtaining the Angular speed of the wheels


The sub-VI which is used to calculate the angular speed of the wheels is the radsleft.vi and radsright.vi for the left
and right wheels respectively. This sub-VI is a sub-VI inside the DaNIsim.vi virtual instrument. It makes use of the
counts as one of the inputs. The counts represent the number of pulses at time instant k. It also measures the CPR
and uses it as input too. The CPR is the counts per revolution and depends on the encoder type used. This is used
to compute the distance travelled by the wheels ∆s for the left and right wheels respectively. The distance travelled
is then used to compute the angular speed, ω using the following relationship, ∆t . ω. d = ∆s.

1
RESULTS
N/B: All figures for this task are in Appendix A1.2
Line Trajectory: The implemented sliding mode controller was tested with the line trajectory. The responses
obtained were poor initially and the parameters, 𝑄1 , 𝑄2 , 𝑃1 , 𝑃2 , 𝑘0 , 𝑘1 , 𝑘2 were very difficult to tune. However,
tuning was carried out on these parameters taking into account the Lyapunov stability for the control law and that
the surfaces, 𝑠1 and 𝑠2 , should converge to 0 to provide a reaching condition. A set of parameters which yielded
reasonable tracking responses was then obtained. The final parameters chosen are as follows: 𝑸𝟏 = 𝟎. 𝟏𝟏, 𝑸𝟐 =
𝟎. 𝟏𝟒, 𝑷𝟏 = 𝟎. 𝟎𝟗𝟗, 𝑷𝟐 = 𝟎. 𝟎𝟎𝟗, 𝒌𝟎 = 𝟎. 𝟗𝟒, 𝒌𝟏 = 𝟎. 𝟗𝟓, 𝒌𝟐 = 𝟎. 𝟗𝟓. The responses obtained for the line
trajectory are given in appendix A1.2. From figure A1.2(a), it is observed that the real robot x trajectory tracked the
desired x trajectory almost perfectly. The desired y and θ trajectories is 0 because it is a straight line. There is
however slight differences to a magnitude of about 0.03 in the real robot’s y and θ trajectories as seen from figures
A1.2(b) and A1.2(c). This slight difference is due to some tuning errors. From figure A1.2(d), the tracking error
between the real and desired robot trajectory showed that the error was largest in the beginning but then became
bounded between 0.05 and -0.02. It can also be concluded that for the line trajectory, the x position had the least
error being closest to 0 than the other states. The linear velocity of the robot from figure A1.2(e) is seen to track
the desired linear velocity by rising steadily initially, and after about 4.5 seconds (30x150ms), it starts varying
constantly between 0.25m/s and 0.35m/s, and then later reduced steadily until it reached 0 m/s to bring the robot
to a stop. The constant variation at the mid-phase (between 0.25 and 0.35m/s) is due to the noise from the sensors
(encoders) in the DC motors. Similar response was obtained for the angular velocity which varied between -0.2 and
0.2 m/s2 as seen in figure A1.2(f). The angular velocity is 0 as it is a straight line trajectory. These linear and angular
velocities represent the control signals from the sliding mode controller which is transformed into left and right
motor angular velocity reference fed into the PID loop. Figures A1.2(g) and A1.2(h) show the linear and angular
accelerations respectively, which are integrated to yield the linear and angular velocities. It can be seen that the
real linear and angular acceleration track the desired linear and angular accelerations, although they are
discontinuous and hence appear as if they are oscillating. The switching functions s1 and s2 are given in figure
A1.2(i). It can be observed that both s1 and s2 converge to 0, starting with large magnitude and then tending
towards 0 as time goes on. It can also be seen that S2 had more chattering compared with S1 varying between -0.4
and 0.3 while S1 varied between -0.1 and 0.1. The response of the surfaces can be improved by retuning the sliding
mode gains especially P1 and P2. Figure A1.2(j) shows the control action (voltages) from the PID controller to the
left and right DC motors. The control voltages are slightly different due to differences in dynamics of the DC motors.
Figures A1.2(k) and A1.2(l) gives the errors of the linear and angular velocities. It is observed that the errors are
quiet low at values between -0.1 and 0.1m/s for the linear velocity and between -0.4 and 0.3rad/s for the angular
velocity. This implies reasonable tracking between the desired and actual linear and angular velocities. Similarly,
the error in the linear and angular accelerations for the line trajectory was observed to be reasonably low, bounded
between -0.2 and 0.2m/s2 for the linear acceleration and between -0.2 and 0.3 rad/s2 for the angular acceleration,
as confirmed from figures A1.2(m) and A1.2(n). Figures A1.2(o) and A1.2(p) shows the reference angular velocities
sent to the PID loop from the sliding mode controller, and the corresponding measured left and right angular
velocities for the PID output. It can be observed that the PID controller worked well in ensuring reference tracking.
There is however some noise in the response due to the sensor noise from the encoders of the DC motors.

TASK 2 (All figures for this task are in Appendix A1.3)


Circle Trajectory: The implemented sliding mode controller using the cascade control strategy was also tested with
the provided circle trajectory. The gains were slightly retuned to ensure a stable response. The final chosen gains
are as follows: 𝑸𝟏 = 𝟎. 𝟎𝟔, 𝑸𝟐 = 𝟎. 𝟎𝟕, 𝑷𝟏 = 𝟎. 𝟎𝟗𝟗, 𝑷𝟐 = 𝟎. 𝟖𝟑, 𝒌𝟎 = 𝟎. 𝟗𝟒, 𝒌𝟏 = 𝟎. 𝟗𝟓, 𝒌𝟐 = 𝟎. 𝟗𝟕. The x and y
positions for the circle trajectory are given in figures A1.3(a) and (b) respectively and the orientation θ is given in
figure A1.3(c). It is observed that the x and y positions and the θ orientation trajectories tracked the desired
reference trajectories. However, it can be observed from these figures that the x and y positions had relatively large
errors at the peaks of the trajectory, while the orientation θ had very little error, and tracked the desired trajectory
well. The large errors in the x and y positions is due to improper tuning of the sliding mode gains. The tracking errors
are shown in figure A1.3(d), where it can be confirmed that the errors are largest at the peaks for the x and y
position, and largest θ towards the end of the trajectory. However, the errors are generally small and bounded
between -0.15 and 0.2 for all the states as seen from the figure. The linear and angular velocities are given in figures
A1.3(e) and A1.3(f), where it can be observed that the linear velocity was rising steadily and tracking the desired

2
linear velocity, until about 30 samples (4500ms at 150ms sampling time) where it stops rising steadily and is
somehow constant. However, it is above the desired linear velocity. The angular velocity on the other hand tracks
the desired angular velocity as required varying with a peak value of 0.6. The angular velocity rises constantly up to
about 30 samples where it becomes steady and tracks the desired. This linear and angular velocities correspond to
the control action obtained from integrating the linear and angular accelerations. Both the linear and angular
velocity responses contains some noise which is from the sensor of the DC motors. Figure A1.3(g) and A1.3(h) shows
the linear and angular accelerations for the circle trajectory. It is observed that the responses contain a high level
of noise. However, the real trajectory tracks the desired trajectory for both the linear and angular accelerations.
The noise is probably due to the encoder sensor noise. This also indicates inadequate tuning gains for the sliding
mode controller. The response of the switching surfaces s1 and s2 are given in figure A1.3(i). It can be observed
that the second surface, S2 shows high level of chattering. This chattering is due to the nonholonomic constraints
such that we are trying to control 3 degrees of freedom (x, y, θ) using only 2 actuators (2 DC motors). However,
both s1 and s2 tend towards zero and hence the movement of the robot is stable. The control action (voltages)
from the PID controller to the DC motors is given in figure A1.3(j). It is observed that the control voltage for the
right motor is significantly higher than that for the left DC motor. This because the robot is to turn in a circle towards
the anti-clockwise direction and hence more angular velocity is needed to the right wheels (right DC motor) to
ensure that this happens, as specified in the desired trajectory. The actual robot was seen to move in an
anticlockwise path when the Task_SlidingMode.vi virtual instrument was run. The errors in the linear and angular
velocity for the circle trajectory are given in figures A1.3(k) and A1.3(l), where it can be observed that the errors are
very small and bounded between -0.15 and 0.15 m/s for the linear velocity and between -0.3 and 0.3rad/s for the
angular velocity. This low error values implies reasonable tracking between the desired and real linear and angular
velocities. Similarly, figures A1.3(m) and A1.3(n) give the errors in the linear and angular acceleration. The error in
the linear acceleration is bounded between -0.1 and 0.25 m/s2 while that of the angular acceleration is between
-0.4 and 0.4 rad/s2, and hence the error between the desired angular acceleration and real angular acceleration is
greater than that between the desired linear acceleration and the real linear acceleration. Figures A1.3(o) and
A1.3(p) show the reference angular velocities for the left and right DC motors, obtained from the sliding mode
controller by transforming the linear and angular velocities, and the corresponding real angular velocities obtained
from the left and right DC motors. It can be seen from the figures that the real angular velocity from the DC motor
tracked the reference angular velocity sent in from the sliding mode controller to the PID loop. Similarly, the real
angular velocity from the right DC motor also tracks the reference angular velocity from the sliding mode controller.
In both cases however, it is observed that there is noise in the responses and this is due to measurement noise form
the encoder in the DC motors. There was also some slight delay in the responses as observed from the figures.

TASK 3 (All figures for Task 3 are in Appendix A1.4)


S-shape Trajectory: The sliding mode controller with the cascade control strategy was further tested with the S-
shape trajectory. The sliding mode controller gains were slightly retuned in an attempt to improve the responses.
This trajectory was however quite difficult to tune. During tuning, good trajectory tracking resulted in divergent
surfaces hence a compromise was reached which gave acceptable trajectory tracking and stable convergent
surfaces. The final gains which were chosen are as follows: 𝑸𝟏 = 𝟎. 𝟎𝟖, 𝑸𝟐 = 𝟎. 𝟎𝟖, 𝑷𝟏 = 𝟎. 𝟎𝟏, 𝑷𝟐 = 𝟎. 𝟗𝟎, 𝒌𝟎 =
𝟎. 𝟗𝟎, 𝒌𝟏 = 𝟎. 𝟗𝟓, 𝒌𝟐 = 𝟎. 𝟗𝟓. Figures A1.4(a), A1.4(b) and A1.4(c) shows the x position, y position and the
orientation θ obtained for the S-shape trajectory. It can be observed that the real x position follows the desired x
position but does not track it satisfactorily. The real y position and orientation θ tracked their desired trajectories
better than the x position as can be observed from the plots. The poor tracking of the x is due to the gain selection
for the sliding mode controller. This poor tracking of the x trajectory is confirmed in figure A1.4(d) where the error
for the x trajectory is seen to be the largest in magnitude above 0.2, and the error of the y trajectory is less at about
0.15. Figures A1.4(e) and A1.4(f) shows the linear and angular velocities for the S-shape trajectory. This corresponds
to the control actions from the sliding mode controller which are transformed to left and right reference velocities
sent to the PID loop. It can be observed from the figures that the linear velocity rises steadily initially, and then
starts to vary constantly in the mid-phase of the robots movement, and then starts to reduce steadily after about
18 seconds (120samples x 150ms), until it gets to 0 m/s to bring the robot to a stop. The real linear velocity was
seen to reasonably track the desired trajectory. The real angular velocity was also seen to track the desired angular
velocity very well. As usual, there was some measurement noise from the encoder of the DC motors. Similar

3
responses were obtained for the responses of the linear and angular accelerations as seen from figures A1.4(g) and
A1.4(h). The real linear and angular accelerations from the sliding mode controller were approximately equal to the
desired linear and angular accelerations. However, there was also measurement noise in the responses. Figure
A1.4(i) gives the switching surfaces s1 and s2 for the S-shape trajectory. The figure shows that the surfaces are
stable since both tend to 0 as the time increases. However, there is some chatter, and this is because of the
nonholonomic constraint since we are trying to control 3 degrees of freedom with only 2 actuators. The first surface
has a significantly better response and this is perhaps due to gain selections for the sliding mode controller. The left
and right motor control actions (voltages) from the PID controller is given in figure A1.4(j). It is observed that
initially, the right motor input voltage is higher than that of the left, to make the robot move in the counter-
clockwise direction, then at some point, the right DC motor input voltage becomes less than that of the left, to
make the robot to turn in the clockwise direction. This ensures that the robot moves in an S-shaped path as desired.
The errors in the linear and angular velocities are given in figure A1.4(k) and A1.4(l), where it is observed that the
error in the linear velocity is bounded between -0.15 and 0.15m/s, and that of the angular velocity is bounded
between -0.2 and 0.3 rad/s. Similar responses were obtained for the error in the linear and angular accelerations
for the S-shape trajectory, as observed from figures A1.4(m) and A1.4(n). The error in the linear acceleration is
bounded between -0.15 and 0.15 m/s2 and that of the angular acceleration is bounded between -0.3 and 0.3 rad/s2.
Generally, the errors in the linear and angular velocities and accelerations is reasonably low and this implies good
tracking of the desired velocity and acceleration trajectories. The left and right motor reference angular velocities
from the sliding mode controller are given together with the corresponding real output from the DC motor in figures
A1.4(o) and A1.4(p). It can be observed that the real left motor angular velocity is approximately equal to the
desired/reference angular velocity from the sliding mode controller. Similarly, the real right motor angular velocity
is approximately equal to the desired/reference angular velocity from the sliding mode controller. It is also observed
that in both cases, there is a small time delay in the response and this is usually the case for practical systems. There
is also measurement noise from the encoder (sensor) of the Dc motors as can be seen in the responses.

TASK 4 (optional task) – All the figures for this task are in Appendix A1.5.
The implemented sliding mode controller was tested with the circle offset 1.5m trajectory. The sliding mode
controller was again retuned in an attempt to yield good performance. The retuned gains are: 𝑸𝟏 = 𝟎. 𝟎𝟕, 𝑸𝟐 =
𝟎. 𝟎𝟗, 𝑷𝟏 = 𝟎. 𝟎𝟖, 𝑷𝟐 = 𝟎. 𝟗𝟎, 𝒌𝟎 = 𝟎. 𝟗𝟓, 𝒌𝟏 = 𝟎. 𝟗𝟓, 𝒌𝟐 = 𝟎. 𝟗𝟓. The responses obtained did not differ too much
from that of the circle trajectory. The x and y positions tracked the desired trajectories but with large errors at the
peaks. The orientation θ was seen to track the desired trajectory very well, with very small errors. This can be seen
from figures A1.5(a), A1.5(b), A1.5(c) and A1.5(d). The linear and angular velocities and accelerations also followed
the same patterns as the circle trajectory. The real linear and angular velocities were seen to track the desired linear
and angular velocity, as seen from figures A1.5(e) and A1.5(f). The real linear and angular accelerations also
followed the desired linear and angular acceleration paths. However, in both cases, there was noise in the signals.
This is observed from figures A1.5(g) and A1.5(h). The switching surfaces were seen to converge to 0 and hence
stable. The first surface s1 had better response and less chatter than the second surface s2, as observed from figure
A1.5(i). The left and right control actions also had similar responses to that of the circle trajectory, except that
initially both left and right control voltages were approximately equal, as seen from figure A1.5(j). The right control
action is significantly higher than that of the left during the mid-phase of the robot’s movement to make the robot
turn in the counter-clockwise to cover the circular path.

CONCLUSION
It can be inferred from the results obtained that is indeed difficult to control real world complex systems such as
robots. The real responses and movements obtained were not totally equal to the desired trajectories for some of
the desired trajectories. It is also not trivial to tune a sliding mode controller. The controller linear and angular
accelerations and velocities for this experiment were seen to track the desired values approximately. These linear
and angular accelerations were integrated to yield continuous linear and angular velocities which were transformed
to left and right reference angular velocities fed into the PID loop. The results also showed that the PID controller
was reasonably tuned as the responses showed fast rise time, little or no overshoot and overall generally good
tracking. It is also evident that sliding mode control with cascade control strategy can be used to control complex
systems such as differential drive mobile robots like the DaNI 2.0 robot.

You might also like