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.

Sunday 30 June 2024

Set up a VM to run Gazebo and ROS2

More than a tutorial, this is going to be a summary of the links I used and the hiccups I found in the process of learning Gazebo and ROS 2.

I installed an Ubuntu 22.04 VM. One important thing to consider is that Gazebo requires significant CPU power, so at least 3-4 cores are needed for the simulations to run smoothly.

These are the steps that I followed for the VM:


Step 1: Download and Install VirtualBox

  1. Go to the VirtualBox website.
  2. Click on "Download VirtualBox."
  3. Choose the appropriate version for your operating system (Windows, macOS, Linux).
  4. Download and install VirtualBox by following the on-screen instructions.

Step 2: Download Ubuntu 22.04 ISO

  1. Go to the Ubuntu website.
  2. Click on "Download" for Ubuntu 22.04 LTS.
  3. Save the ISO file to your computer.

Step 3: Create a New Virtual Machine

  1. Open VirtualBox.
  2. Click on "New" to create a new virtual machine.
  3. Enter a name for your VM (e.g., "Ubuntu 22.04").
  4. Choose the type as "Linux" and the version as "Ubuntu (64-bit)."
  5. Click "Next."

Step 4: Allocate Memory (RAM)

  1. Allocate the desired amount of RAM for the VM. A minimum of 2 GB (2048 MB) is recommended, but 4 GB or more is preferred for better performance.
  2. Click "Next."

Step 5: Create a Virtual Hard Disk

  1. Choose "Create a virtual hard disk now" and click "Create."
  2. Select "VDI (VirtualBox Disk Image)" and click "Next."
  3. Choose "Dynamically allocated" and click "Next."
  4. Set the size of the virtual hard disk. A minimum of 25 GB is recommended.
  5. Click "Create."

Step 6: Configure the VM Settings

  1. Select your newly created VM and click on "Settings."
  2. Go to the "System" tab, then the "Processor" tab, and allocate at least 2 CPU cores.
  3. Go to the "Storage" tab, click on the empty optical drive, and choose "Choose a disk file."
  4. Select the Ubuntu 22.04 ISO file you downloaded earlier and click "Open."
  5. Go to the "Network" tab and ensure that "Attached to" is set to "NAT."

Step 7: Start the VM and Install Ubuntu

  1. Click "Start" to boot the VM.
  2. The VM will boot from the Ubuntu ISO. Select "Install Ubuntu" from the menu.
  3. Follow the on-screen instructions to install Ubuntu. This will include selecting your language, keyboard layout, and installation type (usually "Erase disk and install Ubuntu" for a clean installation).
  4. Set your timezone, create a user account, and set a password.
  5. Continue with the installation process. This may take some time.

Step 8: Complete Installation and Reboot

  1. Once the installation is complete, you will be prompted to restart the VM.
  2. After restarting, you may need to remove the ISO from the virtual drive. Go to "Devices" > "Optical Drives" > "Remove disk from virtual drive."
  3. Restart the VM again if necessary.

Step 9: Install VirtualBox Guest Additions (Optional but Recommended)

  1. With the VM running, go to "Devices" > "Insert Guest Additions CD image."

  2. Open a terminal in Ubuntu and run the following commands to install the necessary packages:

    sudo apt update sudo apt install build-essential dkms linux-headers-$(uname -r)
  3. Mount the Guest Additions CD if not already mounted, and run the installer:

    sudo /media/$USER/VBox_GAs_*/VBoxLinuxAdditions.run
  4. Reboot the VM after the installation is complete.

Now you have Ubuntu 22.04 installed and running in a VirtualBox VM!


Gazebo Installation

As I have ubuntu 22.04 the guide recommends gazebo fortress

The following are the instruction from Gazebo ignition fortress.....

https://gazebosim.org/docs/fortress/install_ubuntu

Binary Installation on Ubuntu

Fortress binaries are provided for Ubuntu Bionic, Focal and Jammy. All of the Fortress binaries are hosted in the osrfoundation repository. To install all of them, the metapackage ignition-fortress can be installed.

First install some necessary tools:

sudo apt-get update
sudo apt-get install lsb-release wget gnupg

Then install Ignition Fortress:

sudo wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null
sudo apt-get update
sudo apt-get install ignition-fortress

All libraries should be ready to use and the ign gazebo app ready to be executed.