PID Controllers

The goals of this lab are to gain experience working with PID controllers, launch files, and ROS2 parameters.

Resources

Tutorials:

Source Dependencies:

Deliverables

  • Modified version of a rocket-control package that uses PID control to smoothly fly a rocket to a target location. PID gain values will be adjustable through ROS2 parameter settings.
  • Commits by at least two group members.

Coding

  1. Run ros2_jmu_setup.sh and log into Github

  2. Clone the two repositories listed in the dependency section above into your ~/dev_ws/src folder. Build and source the packages and confirm that rocketbot is running correctly:

    ros2 run rocketbot rocketbot_node
    
  3. Accept the PID lab assignment invitation posted. The respository page for this lab already contains the starter code that you will be using. Clone the respository into your workspace folder:

    cd ~/dev_ws/src
    git clone GIT_URL pid_practice
    
  4. Take a minute to read over the file guidance.py and the file rocket.launch.py in the launch directory. Make sure you understand the contents of those files. Build and source your workspace.

  5. Launch rocket.launch.py in a separate terminal:

    ros2 launch pid_practice rocket.launch.py
    

    You can change the target altitude by clicking in the RocketBot simulator window. Use the rqt Plot plugin to visualize /target/y and /location/y.

Using a PID Controller and Tuning Parameters

  1. Modify guidance.py so that it uses the pid module (provided by the jmu_ros2_util package) to control the y-component of the thrust. You’ll need to look over the documentation in pid.py for the details of the API. Here is an example if instantiating a PID object:

    from jmu_ros2_util import pid
    
    # (set up gain values)
    
    pid = pid.PID(p_gain, i_gain, d_gain, i_min, i_max)
    

    The i_min and i_max arguments place lower and upper bounds on the magnitude of the term $I$ in the controller. If these aren’t set the controller can potentially accumulate a large amount of integral error when it starts a long way from the target value.

  2. Experiment with different values for your gain parameters until you find settings that work well. The rocket should rise smoothly to the target altitude with minimal overshoot and oscillations. (I suggest resetting the PID controller when the target location changes. Otherwise the $D$ term will experience a large transient value that could cause significant overshoot.)

  3. Once you are satisfied with your gain values, modify guidance.py so that it reads the PID gain values as parameters, then modify rocket.launch.py to set the parameters appropriately. Test the new launch file. Once everything is working, commit and push your changes. Make sure all members have joined the GitHub group.

PID for Horizontal Control

  • Have SOMEONE ELSE in your group clone your updated repository

  • Update guidance.py to handle horizontal as well as vertical control. Your finished control node should reliably move the rocket to whatever point the user clicks in the simulator window. NOTE: you will need to re-factor your solution (both guidance.py and rocket.launch.py) to specify separate gain values for horizontal and vertical control.

  • Commit and push the completed version of your pacakge.

There is nothing to submit for today, your grade is based on attendance and completing the task. Get my attention after you complete each part and I will notate that your group completed the task.

Acknowledgements

This assignment was originally developed by Nathan Sprague.

Last modified August 22, 2024: Calendar update (1e4ee0f)