This ROS 2 Python node controls a turtle in the turtlesim
simulator to drive it to a desired position using a PID controller. Currently, only the proportional constants (P) are utilized for both distance and heading error.
- Retrieves the current pose of the turtle.
- Computes the error in distance and heading to the desired position.
- Uses a simple proportional controller to compute the required linear and angular velocities.
- Publishes these velocities to command the turtle.
- ROS 2 (Humble,Foxy, Galactic, or later versions recommended).
turtlesim
package.
-
Ensure you have ROS 2 and
turtlesim
installed. -
Clone this repository:
git clone https://github.com/roboticvedant/ROS2_turtlesim_PID_demo.git
cd ROS2_turtlesim_PID_demo
- Source your ROS 2 installation:
source /opt/ros/[YOUR_ROS2_DISTRO]/setup.bash
- Build the package:
colcon build --symlink-install
- Source the built package:
source install/setup.bash
- Run the
turtlesim
node:
ros2 run turtlesim turtlesim_node
- In a new terminal, run the controller:
ros2 run turtle_demo_controller turt_controller
You can adjust the desired x
and y
positions by modifying the desired_x
and desired_y
variables respectively in the script.
PID control is one of the most widely used feedback controllers in the industry. It combines three components:
-
Proportional (P): The proportional term produces an output value that is proportional to the current error value. It determines the reaction based on the present error.
-
Integral (I): The integral term concerns past values of error. If the error has been present for an extended period, it will accumulate (integral of the error), and the controller will respond by increasing (or decreasing) the control action in relation to a sustained error.
-
Derivative (D): The derivative term is a prediction of future error. It provides a control action to counteract the rate of error change.
The weighted sum of these three actions is used to adjust the process via a control element, such as the position of a control valve or the power supply of a heating element.
In the current implementation, only the Proportional (P) control strategy is applied. This means the turtle's motion is directly influenced by the error in its position.
Given the predictable nature of the turtlesim
environment, a P-controller suffices for stable and effective control. However, in complex, unpredictable environments, PI
or PID control might be necessary.
- Incorporate full PID control for both distance and heading error.
- Add dynamic reconfiguration to adjust PID constants on-the-fly.
Feel free to fork, open issues, and submit pull requests. Any contributions are welcome!