Pages

Sunday 21 July 2024

First Plugin Changing the Buoyancy Model

I read the implementation of the buoyancy model in Gazebo. I understand the authors' motivation for implementing it in a generic way, which includes simulating two environments and allowing motion above what would be considered the surface line. In my case, I want to define any height above a certain Z value as the surface of the water.

To achieve this, I will modify the buoyancy to be equal to the weight of the vehicle when its position is at or above Z. The reason for this modification is that my vehicle is designed to have a ballast system that initially provides positive buoyancy. During the setup, the ballast system transitions to negative buoyancy, allowing the vehicle to perform an initial dive to a launch depth. This approach minimizes the distance required to test control algorithms, thereby optimizing the testing process.


My code modification is below



///////////////////////////////////////////////
// Compute Buoyancy at level Z=0
//////////////////////////////////////////////////
math::Vector3d BuoyancyPrivate::ComputeBuoyancyForce(
  const math::Pose3d &linkWorldPose, const math::Vector3d &gravity, double volume, double mass) const
{
  double fluidDensityAtPose = this->fluidDensity;
  math::Vector3d buoyancyForce;

  if (linkWorldPose.Pos().Z() >= 0)
  {
    // Buoyancy force equals vehicle weight at Z = 0
    buoyancyForce = mass * gravity;
  }
  else
  {
    // Standard buoyancy calculation
    buoyancyForce = -fluidDensityAtPose * volume * gravity;
  }

  return buoyancyForce;
} tag

I tested my plugin by placing the vehicle at Z=1


After Starting the simulation I can see the vehicle dropping but not sinking

The vehicle at this point has neutral buoyancy so stays in the location where it lands.


ChatGPT+Gazebo=Problems......

 


Background

Ten years ago, I attempted to learn Gazebo for my PhD but found the online guides and resources highly fragmented and inconsistent. The constant updates and structural changes made the learning curve steep, especially for a hobbyist approach. Consequently, I abandoned the platform in favor of Matlab, where I was already running simulations.

Initial Attempts with ChatGPT

Installation Guide

My first approach was to ask ChatGPT for a guide to install Gazebo and ROS2. As anticipated, this was not successful because ChatGPT lacked access to the latest versions and accurate literature.

Understanding IMU Units

Next, I provided specific Fortress literature to ChatGPT, requesting a detailed explanation and guidance on modifying the blue vehicle to include two IMUs. This approach was successful, and I managed to add two IMUs to a vehicle and run it.

Challenges with AUV Example

When attempting to run the AUV example, ChatGPT struggled, primarily due to the vast amount of outdated or irrelevant information it was trained on. The complexity and collaborative nature of the Gazebo and ROS2 repositories posed additional challenges, as did the difficulty in distinguishing between different software versions in forum content.

Effective Strategies for Learning with AI

To effectively use AI tools like ChatGPT for learning Gazebo and ROS2, I adopted the following strategies:

  1. Provide Specific Codes and Context: By supplying the exact codes from my installed version, I helped ChatGPT offer more relevant and accurate assistance.
  2. Ask Pinpointed Questions: Narrowing the scope of my questions and setting clear limits ensured that the suggestions remained within the relevant context.
  3. Utilize Official Documentation: Supplementing AI assistance with official documentation and specific version details enhanced the overall learning experience.

Conclusion

While AI can be a valuable tool in learning complex software, it is essential to provide precise context and limit the scope of inquiries to get the most relevant and accurate assistance. Combining AI support with official resources and community engagement creates a more effective and manageable learning pathway for Gazebo and ROS2.