SITL

Flight stack

PX4

Simulation environment

Gazebo

proccess communication

ROS

Setup environment for simulation using ROS2 with ePromisa fastrtps as middleware

requirements: mkdir uav cd uav setup px4 toolchain git clone https://github.com/PX4/PX4-Autopilot.git —recursive bash ./PX4-Autopilot/Tools/setup/ubuntu.sh also need ros2 gazebo

fastdds: install foonathan memory

git clone https://github.com/eProsima/foonathan_memory_vendor.git
cd foonathan_memory_vendor
mkdir build && cd build
cmake ..
cmake --build . --target install
git clone --recursive https://github.com/eProsima/Fast-DDS.git -b v2.0.2 ~/FastDDS-2.0.2
cd ~/FastDDS-2.0.2
mkdir build && cd build

for secure version

cmake -DTHIRDPARTY=ON -DSECURITY=ON ..
make -j$(nproc --all)
sudo make install

after dds install fastrtpsgen for code generation

git clone --recursive https://github.com/eProsima/Fast-DDS-Gen.git -b v1.0.4 ~/Fast-RTPS-Gen \
    && cd ~/Fast-RTPS-Gen \
    && gradle assemble \
    && sudo env "PATH=$PATH" gradle install
 
# colcon built tools
sudo apt install python3-colcon-common-extensions
# for transform library
sudo apt install ros-foxy-eigen3-cmake-modulehj
# for msg generation
sudo pip3 install -U empy pyros-genmsg setuptools

build ros2(colcon) workspace mkdir -p px4-colcon-ws/src populate src dir with code at bare minimum we need px4-ros-com and it’s dependacny px-msgs git clone https://github.com/PX4/px4_ros_com.git ~/px4_ros_com_ros2/src/px4_ros_com git clone https://github.com/PX4/px4_msgs.git ~/px4_ros_com_ros2/src/px4_msgs

we can also add support for ros1 bridge if needed git clone https://github.com/ros2/ros1_bridge.git -b dashing ~/px4_ros_com_ros2/src/ros1_bridge

Sanity check:

skip ros1_bridge —packages-skip ros1_bridge

verbose —event-handlers console_direct+

for rel —cmake-args -DCMAKE_BUILD_TYPE=RELWITHDEBINFO

generate code for clangd —cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

then we can build colcon build —cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=RELWITHDEBINFO —symlink-install —packages-skip ros1_bridge —event-handlers console_direct+

run the sim make px4_sitl_rtps gazebo