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

🌊 Depth controller node

Overview

The depth_controller Node is designed for controlling the depth of a BlueRov2 underwater vehicle. This node uses a PID controller to adjust the throttle and maintain the desired depth.

✅ Prerequisites

Before using the Depth Controller Node, make sure you have the following:

👨🏼‍💻 Node Parameters

The Depth Controller Node accepts the following parameters:

  • depth_desired: Desired depth setpoint (default: 0 meter)
  • pwm_max: Maximum PWM value (default: 1900 pwm)
  • pwm_neutral: Neutral PWM value (default: 1500 pwm)
  • ki: Integral gain constant (default: 100)
  • kp: Proportional gain constant (default: 600)
  • kd: Derivative gain constant (default: 50)
  • enable: Enable/disable the depth controller (default: True)

These parameters can be adjusted by updating the corresponding values in the launch file or using dynamic reconfigure.

📜 Input Topics

The Depth Controller Node subscribes to the following topics:

  • /bluerov2/bar30: Bar30 sensor data - bluerov2_interfaces/Bar30
  • /settings/depth/set_depth: Set the desired depth - std_msgs/Float64
  • /settings/depth/set_pid: Set PID parameters - bluerov2_interfaces/PID
  • /settings/depth/set_enable: Enable/disable the depth controller - std_msgs/Bool

📜 Output Topics

The Depth Controller Node publishes the following topics:

  • /bluerov2/rc/throttle: Throttle control - std_msgs/UInt16
  • /settings/depth/status: Depth controller status - std_msgs/String

Understanding the /settings/depth/status Topic

The /settings/depth/status topic provides real-time status information about the Depth Controller Node. This information is published as a JSON-formatted string and includes key details about the current state of the depth controller. Here's an example of the JSON structure:

{
  "type": "depth_controller",
  "enable": true,
  "kp": 600,
  "ki": 100,
  "kd": 50,
  "pwm_max": 1900,
  "pwm_neutral": 1500,
  "depth_desired": 0
}

[!WARNING]
This topic is read-only.

⚠️ Important Note

The Depth Controller Node requires the BlueRov2 Controller Node to be running. Make sure to start the BlueRov2 Controller Node before using the Depth Controller Node.

⚒️ Example Usage

  1. Set the desired depth:

    ros2 topic pub /settings/depth/set_depth std_msgs/Float64 "data: 5.0"
    
  2. Adjust PID parameters:

    ros2 topic pub /settings/depth/set_pid bluerov2_interfaces/PID "{kp: 700, ki: 120, kd: 60, pwm_max: 2000}"
    
  3. Enable/disable the depth controller:

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

Feel free to experiment with different parameters to achieve optimal depth control for your BlueRov2 underwater vehicle! 🌊🤖