Skip to content

Autonomous navigation for ROS2 Turtlesim implementing a waypoint-following system with PID control for smooth trajectory tracking and goal-seeking behaviors.

Notifications You must be signed in to change notification settings

CodeName-Detective/ROS2-TurtleSim-Goal-Seeking-with-PID-Control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

ROS2 TurtleSim Goal-Seeking with PID Control

An autonomous navigation implementation for the ROS2 turtlesim environment. This project demonstrates a decoupled control strategy where a robot first rotates toward a waypoint and then translates toward it using tuned PID (Proportional-Integral-Derivative) controllers.

Overview

This repository contains a ROS2 package that enables a robot to follow a series of waypoints defined in a configuration file. The project is split into two phases:

  1. Part 1: Basic Goal Seeker – Implements the core logic to parse waypoints and navigate using a simple proportional controller and state-based movement (rotate-then-translate).
  2. Part 2: Full PID Controller – Enhances the movement profile by implementing full PID logic for both linear and angular velocities, ensuring smooth acceleration and deceleration while minimizing overshoot.

Installation

Prerequisites

  • ROS2 Humble (or compatible version)
  • tf_transformations:
sudo apt install ros-humble-tf-transformations

Build

  1. Clone this repository into your colcon workspace src folder.
  2. Navigate to the workspace root and build:
colcon build --packages-select goal_seek
source install/setup.bash

Usage

Running the PID Controller (Part 2)

To launch the full PID-controlled navigation along with the simulator:

ros2 launch goal_seek goal_seek_part_2.launch.py

Configuration

Waypoints are managed via a text file located at goal_seek/config/goals.txt. The format is simple space-separated x y coordinates:

4.5 6.4
7.6 2.4
8.7 2.3

Control Logic

The robot follows a state-machine approach within the Odometry callback:

  1. Heading Correction: If the angular error exceeds the threshold, the robot stops linear movement and rotates.
  2. Translation: Once facing the goal, the robot moves forward, using the PID controller to ramp down velocity as it approaches the coordinate.
  3. Wait State: Upon reaching a goal (within a defined distance threshold), the robot pauses for 5 seconds before fetching the next waypoint.

PID Implementation

The control output is calculated as:

Where:

  • Proportional (): Corrects based on current error.
  • Integral (): Eliminates steady-state error.
  • Derivative (): Dampens oscillations and prevents overshoot.

Project Structure

  • goal_seek_part_2.py: The primary node featuring the PID controller.
  • publish_odom.py: A utility node that converts turtlesim/Pose data into standard nav_msgs/Odometry.
  • launch/: Contains Python launch files to bring up the simulation and controllers simultaneously.

Resources

About

Autonomous navigation for ROS2 Turtlesim implementing a waypoint-following system with PID control for smooth trajectory tracking and goal-seeking behaviors.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages