MAVROS-Gazebo simulation(SITL) build and application + mavros setup (also applicable for real drones)
- Need Ubuntu with ROS installed
- Simple Joystick Controller code implemented
1. Installation - here
2. Joystick controller code - here
3. Fly without GPS - here
5. Making new PX4 model(airframe) for SITL - here
6. Making new Gazebo world and Gazebo model - here
7. Use mobile robots(Kobuki, Jackal) for Gazebo - here
- Mavros and requirements
$ sudo apt-get install ros-<distro>-mavros ros-<distro>-mavros-extras
$ wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh
$ chmod +x install_geographiclib_datasets.sh
$ sudo ./install_geographiclib_datasets.sh
$ cd ~/ && git clone https://github.com/PX4/PX4-Autopilot.git
$ cd PX4-Autopilot
$ git reset --hard 6823cbc
$ git submodule update --init --recursive
$ source PX4-Autopilot/Tools/setup/ubuntu.sh --no-sim-tools --no-nuttx
- To run, set up the path and environments
$ cd ~/PX4-Autopilot
# important!!
$ sudo apt install libgstreamer-plugins-base1.0-dev ros-<distro>-gazebo-plugins
$ export LANG=C.UTF-8
$ export LC_ALL=C.UTF-8
$ DONT_RUN=1 make px4_sitl_default gazebo
# when undefined iginition error (gazebo: symbol lookup error: /usr/lib/x86_64-linux-gnu/libgazebo_common.so.9: undefined symbol: ZN8ignition10fuel_tools12ClientConfi..........
# $ sudo apt upgrade libignition-math4
$ source Tools/setup_gazebo.bash $(pwd) $(pwd)/build/px4_sitl_default
$ export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$(pwd)
$ export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$(pwd)/Tools/sitl_gazebo
$ roslaunch px4 mavros_posix_sitl.launch
- To remember setup,
$ echo "export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:/home/$(whoami)/PX4-Autopilot/Tools/sitl_gazebo/models" >> ~/.bashrc
$ echo "export GAZEBO_PLUGIN_PATH=/home/$(whoami)/PX4-Autopilot/build/px4_sitl_default/build_gazebo" >> ~/.bashrc
$ echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/$(whoami)/PX4-Autopilot/build/px4_sitl_default/build_gazebo" >> ~/.bashrc
$ echo "export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/home/$(whoami)/PX4-Autopilot:/home/$(whoami)/PX4-Autopilot/Tools/sitl_gazebo" >> ~/.bashrc
$ . ~/.bashrc
- Install and run
QGroundControl
while running PX4-SITL - Vehicle parameter setup -> set
COM_RCL_EXCEPT
as 4 (only once)
- Referred this viedeo
$ export PX4_SIM_SPEED_FACTOR=<how many times faster you want>
- To run Gazebo with default setup, with ROS
$ roslaunch px4 mavros_posix_sitl.launch
- To control with simple square path,
$ git clone <this repository>
$ python <clone directory>/python_offb.py
Mission / Joystick Controller - supports Kobuki and Jackal
- To use the other model with sensors => edit "models" param in mavros_posix.sitl.launch file
- use Joystick to manually control -> it supports mode 1,2 and Position/Rate control
- Velocity/Attitude control are not supported anymore due to their error.
$ git clone <this repository>
$ python <clone directory>/scripts/mavors_joy_controller.py
Fly without GPS - result clip here
Visual Inertial Odometry (VIO) · PX4 User Guide - here
- Guide here
- tf is needed when attached with different direction
- edit launch file
<node pkg="tf" type="static_transform_publisher" name="tf_baseLink_cameraPose" args="0 0 0 0 1.5708 0 t265_pose_frame test 1000"/>
<!-- when T265 is attached upward -->
VINS-Fusion for PX4 with Masking here
- check here
- Publish vision data e.g. VIO as geometry_msgs/PoseStamped type message into topic /mavros/vision_pose/pose
- Change EKF2_AID_MASK parameter at QGroundControl
- Uncheck use GPS
- Check vision position fusion and vision yaw fusion, consider vision velocity fusion too.
- Change EKF2_HGT_MODE parameter at QGC
- Set to Vision or Range (1D LiDAR, Altitude laser sensor)
- Change EKF2_EV_POS_X, EKF2_EV_POS_Y, EKF2_EV_POS_Z at QGC
- tf body_T_cam
- If using 1D LiDAR altitude sensor, Check
- EKF2_HGT_MODE, EKF2_RNG_AID, and SENS_TFMINI_CFG
- Also check EKF2_RNG_A_HMAX and EKF2_RNG_NOISE
- To use /dev/ttyACM as root admission
# check the groups current user is engaged in
$ id -Gn
# add to dialout group
$ sudo adduser $USER dialout
- /fs/microsd/etc/extras.txt file from QGC's nutshell
- Or place etc/extras.txt file in the SD card of Pixhawk as below or as this file
- add HIGHRES_IMU for imu/data_raw and ATTITUDE for imu/data
#!nsh
mavlink start -b 921600 -d /dev/ttyACM0 -m onboard
mavlink stream -d /dev/ttyACM0 -s PARAM_VALUE -r 200
usleep 100000
mavlink stream -d /dev/ttyACM0 -s ATTITUDE -r 100
usleep 100000
mavlink stream -d /dev/ttyACM0 -s HIGHRES_IMU -r 100
usleep 100000
mavlink stream -d /dev/ttyACM0 -s ATTITUDE_TARGET -r 100
usleep 100000
mavlink stream -d /dev/ttyACM0 -s ATTITUDE_QUATERNION -r 100
usleep 100000
mavlink stream -d /dev/ttyACM0 -s LOCAL_POSITION_NED -r 50
usleep 100000
- edit mavros/px4.launch file to same baudrate
<arg name="fcu_url" default="/dev/ttyACM0:921600" />
-
for ROS Topics
- Edit the rates in Firmware/ROMFS/px4fmu_common/init.d-posix/rcS as here
- and then rebuild the Firmware with
$ DONT_RUN=1 make px4_sitl_default gazebo
- or simply edit the rates in Firmware/build/px4_sitl_default/etc/init.d-posix/rcS as here
# API/Offboard link mavlink start -x -u $udp_offboard_port_local -r 4000000 -m onboard -o $udp_offboard_port_remote mavlink stream -r 100 -s LOCAL_POSITION_NED -u $udp_offboard_port_local mavlink stream -r 100 -s HIGHRES_IMU -u $udp_offboard_port_local mavlink stream -r 100 -s ATTITUDE -u $udp_offboard_port_local mavlink stream -r 100 -s ATTITUDE_QUATERNION -u $udp_offboard_port_local
-
for QGC Mavlink Inspector
- Edit the same Firmware/ROMFS/px4fmu_common/init.d-posix/rcS as here
- and then rebuild the Firmware with
$ DONT_RUN=1 make px4_sitl_default gazebo
- or simply edit the rates in Firmware/build/px4_sitl_default/etc/init.d-posix/rcS as here
# GCS link #################### -> This block is for Mavlink in QGC mavlink start -x -u $udp_gcs_port_local -r 4000000 mavlink stream -r 50 -s POSITION_TARGET_LOCAL_NED -u $udp_gcs_port_local mavlink stream -r 100 -s LOCAL_POSITION_NED -u $udp_gcs_port_local mavlink stream -r 50 -s GLOBAL_POSITION_INT -u $udp_gcs_port_local mavlink stream -r 100 -s HIGHRES_IMU -u $udp_gcs_port_local mavlink stream -r 100 -s ATTITUDE -u $udp_gcs_port_local mavlink stream -r 100 -s ATTITUDE_QUATERNION -u $udp_gcs_port_local mavlink stream -r 100 -s ATTITUDE_TARGET -u $udp_gcs_port_local mavlink stream -r 50 -s SERVO_OUTPUT_RAW_0 -u $udp_gcs_port_local mavlink stream -r 20 -s RC_CHANNELS -u $udp_gcs_port_local mavlink stream -r 10 -s OPTICAL_FLOW_RAD -u $udp_gcs_port_local
- Or type below as here
$ mavlink stream -u 14557 -s ATTITUDE -r 200 $ mavlink stream -u 14557 -s HIGHRES_IMU -r 200 $ mavlink stream -u 14557 -s LOCAL_POSITION_NED -r 200