The goals of this lab are to gain experience working with PID controllers, launch files, and the ROS parameter server.
pid_chase
on stu. Check the repository out to your local machine. Don't create a package at this point.
pid_chase
repository. If you've done this correctly, your pid_chase
package should now be configured as follows:
$ cd ~/cs354_ws/src/pid_chase/ $ ls CMakeLists.txt launch package.xml scripts src
pid_chase.py
in the
scripts directory, and the file pid_chase.launch
in the
launch directory. Make sure you understand the contents of those
files.
source devel/setup.bash
.
pid_chase.launch
. Point the robot toward
a wall and run pid_chase.py
. You should see an error like the following:
[ERROR] [WallTime: 1422370481.748347] PID Parameters not set. Exiting
rosparam
command to set the three parameters expected by pid_chase.py
to some initial values and re-execute pid_chase.py
.
Experiment with different values for your gain parameters until you
find settings that work well. You want the Turtlebot to smoothly
approach the target distance then stop at the appropriate point
without excessive oscillations. The p_error
term
should be driven to a value that is very close to 0.
The pid_chase.py
node publishes all three error terms. You
can echo them to a terminal:
rostopic echo /p_erroror you can visualize them using rqt_plot:
rosrun rqt_plot rqt_plot /p_error/data /i_error/data
pid_chase.launch
to set the parameters
appropriately. The launch file XML format is described
on this wiki
page. Test the new launch file. Once everything is working,
commit your changes and push your work to stu. One weakness of the current version of this code is that the robot makes fast velocity changes when the distance changes: for example, when someone steps in front of the depth sensor. This results in jerky motions that are hard on the robot's motors.
We can force the velocity to change smoothly by taking a weighted average between the previous velocity and the desired velocity:
new_velocity = α × desired_velocity + (1 - α) × previous_velocityValues of α near 1 will lead to fast velocity changes, while values of α near 0 will lead to slow changes in velocity.
pid_chase.py
to implement velocity smoothing.
(You may need to re-tune your PID gain terms. In effect, smoothing
the velocity changes the dynamics of the system that the PID
controller is trying to control.)