This repository provides a streamlined platform to perform waypoint tracking in quadcopter in ROS2, Gazebo and PX4.
- ROS2 Humble
- Gazebo Harmonic
- PX4
- QGroundControl
First, clone the project using Git in your linux system(Ubuntu, Arch and etc):
git clone https://github.com/Srindot/assignment2_Introduction_To_UAV_Design.git
Ensure Docker is installed and configured on your device.
- Launch Visual Studio Code (VS Code) .
- Open the cloned project folder.
For arch:
sudo pacman -S xorg-xhost
For Ubuntu:
sudo apt update && sudo apt install x11-xserver-utils
If your host system doesn't have a Nvidia Card, remove the instance of gpus in devcontainer and you can ignore the below instruction to download Nvidia Container Toolkit. (Follow the comments in the devcontainer file)
For Arch:
sudo pacman -S nvidia-container-toolkit
and restart the docker daemon
sudo systemctl restart docker
For Ubuntu: Set up the Repository
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
Then install the nvidia-contianer-toolkit
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
After this restart the docker daemon:
sudo systemctl restart docker
-
Press
Ctrl + Shift + P
to open the Command Palette . -
Search for "Dev Conatiners: Reopen in Container" and select it to start building the container.
This will take a long time, it will pull the image from the github container registry and to open it.
- After this, make sure to choose the terminal profile in vscode to be
bash
. You can do this in the command pallete in github, search for terminal profile and selectbash
.
-
Once inside the container, press
Ctrl + Shift + P
again. -
Search for "Run Tasks" , then select and execute the following tasks :
- MicroXRCEAgent : Connection to ROS2 and PX4
- PX4 SITL : To start up PX4 with gazebo gui
- QGroundControl : To launch QGroundControl
- Sensor Combined Listener : To echo gyro readings and acceleration in all three axis
- Offboard Control : To arm the vehicle and publish waypoint for quadcopter to track
First pull the image: Open a terminal and run the following command
docker pull ghcr.io/srindot/rosgzpx4
This is going to take some time.
Create a container instance from the pulled image with the name as myros:
xhost +local:docker && docker run -it \
--name myros \
--privileged \
--user rosusr \
-e DISPLAY=$DISPLAY \
-e PULSE_SERVER=unix:/run/user/$(id -u)/pulse/native \
--volume=/run/user/$(id -u)/pulse/native:/run/user/$(id -u)/pulse/native \
--device /dev/snd \
--group-add audio \
--net=host \
--volume /tmp/.X11-unix:/tmp/.X11-unix \
--volume /home/$(whoami)/.Xauthority:/root/.Xauthority:ro \
ghcr.io/srindot/rosgzpx4:latest
After this command, the container opens up automatically in /bin/bash.
To exit the container :
exit
To stop the container :
docker stop myros
To start the contianer:
docker start myros
To re enter a container:
docker exec -it myros /bin/bash
To delete the container instance:
docker rm -f myros
- To launch MicroXRCEAgent: Navigate to a new terminal and run the below command to launch it
MicroXRCEAgent udp4 -p 8888
- To make PX4_sitl, open another terminal and navigate to PX4-Autopilot dir
cd ~/PX4-Autopilot
Make the PX4_sitl and launch the vehicle gz_x500
make px4_sitl gz_x500
- To launch QGroundControl, Open another terminal and run the following command
QGroudControl
- open a new terminal and source ros2 and local_setup.bash in sensor combined workspace
cd ~/ws_sensor_combined && source /opt/ros/humble/setup.bash && source install/local_setup.bash
and run the below command to run the sensor combined listener
ros2 launch px4_ros_com sensor_combined_listener.launch.py
- To arm the vehicle and switch it to offoard mode, open a new temrinal source ros2 and local setup by runnig below the command
cd ~/ws_offboard_control/src && cd .. && source /opt/ros/humble/setup.bash && source install/local_setup.bash
Now run the offboard_control.py file present in the dir
cd && python3 ~/workspace/offboard_control.py
To set the waypoint for the quadcopter to track, navigate to here and set the waypoints in the list.
If you encounter any problems or have questions, feel free to raise an issue.