yaw_controller.py - Vincent1334/ROS-Humble-BlueRov2-Driver GitHub Wiki

🎛️ Yaw Controller Node

Overview

The yaw_controller Node is responsible for controlling the yaw angle (heading) of the BlueROV2 underwater vehicle. It leverages a PID controller to dynamically adjust the PWM signal to achieve and maintain the desired yaw angle.

✅ Prerequisites

Ensure that the BlueROV2 Controller Node is running and configured correctly.

👨🏼‍💻 Node Parameters

The Yaw Controller Node accepts the following parameters:

  • yaw_desired: Desired yaw setpoint (default: 0 degrees)
  • pwm_max: Maximum PWM value (default: 1750 pwm)
  • pwm_neutral: Neutral PWM value (default: 1500 pwm)
  • kp: Proportional gain constant (default: 200)
  • kd: Derivative gain constant (default: 50)
  • enable: Enable/disable the yaw controller (default: True)

These parameters can be adjusted in the launch file or modified dynamically at runtime.

📜 Input Topics

The Yaw Controller Node subscribes to the following topics:

  • /bluerov2/attitude: Attitude data (Roll, Pitch, Yaw) - bluerov2_interfaces/Attitude
  • /settings/yaw/set_yaw: Set the desired yaw angle - std_msgs/UInt16
  • /settings/yaw/set_pid: Set PID parameters - bluerov2_interfaces/PID
  • /settings/yaw/set_enable: Enable/disable the yaw controller - std_msgs/Bool

📜 Output Topics

The Yaw Controller Node publishes to the following topics:

  • /bluerov2/rc/yaw: PWM signal for yaw control - std_msgs/UInt16
  • /settings/yaw/status: Yaw controller status - std_msgs/String

Understanding the /settings/yaw/status Topic

The /settings/yaw/status topic provides real-time status information about the Yaw Controller Node. The data is published in JSON format and contains details about the current controller configuration, as shown below:

{
  "type": "yaw_controller",
  "enable": true,
  "kp": 200,
  "kd": 50,
  "pwm_max": 1750,
  "pwm_neutral": 1500,
  "yaw_desired": 0
}

[!WARNING]
This topic is read-only and provides status information only.

⚠️ Important Note

The Yaw Controller Node requires the BlueROV2 Controller Node to be operational for accurate control. Ensure that the Controller Node is running before using the Yaw Controller.

⚒️ Example Usage

  1. Set the desired yaw angle:

    ros2 topic pub /settings/yaw/set_yaw std_msgs/UInt16 "data: 90"
    
  2. Adjust PID parameters:

    ros2 topic pub /settings/yaw/set_pid bluerov2_interfaces/PID "{kp: 300, kd: 80, pwm_max: 1800}"
    
  3. Enable/disable the yaw controller:

    ros2 topic pub /settings/yaw/set_enable std_msgs/Bool "data: true"
    

Experiment with these settings to fine-tune yaw control for your BlueROV2 underwater vehicle! 🌊⚙️