by el-jausyan
first think first before you do drone simulation in gazebo you need to donwload all dependencies need in ubuntu, first things fisrt you need to download this
- ROS 2 Foxy
- Mavros
- Ardupilot
- Ardupilot_gazebo
- Mavlink / stlink
- geographicslib
- gazebo classic
How to simulate your drone in Gazebo classic
Go to the terminal (Ctrl + Alt + T)
Run MAVProxy
cd ardupilot/ArduCopter
sim_vehicle.py -v ArduCopter -f gazebo-iris --consoleRun Gazebo and load Iris Drone model
gazebo --verbose ~/ardupilot_gazebo/worlds/iris_arducopter_runway.worldDont forget to check Connection status at console

run MAVROS Console
ros2 run mavros mavros_nodeor
ros2 run mavros mavros_node --ros-args -p fcu_url:=udp://127.0.0.1:14550@14550real drone
ros2 run mavros mavros_node --ros-args -p fcu_url:=serial:///dev/ttyACM0:57600or
ros2 run mavros mavros_node --ros-args -p fcu_url:=serial:///dev/ttyUSB0:115200ros2 topic listto simulate drone goto MAVProxy console and type the following command
mode guided
arm throttle
takeoff <altitude_in_meters>
rtl
landGuided Mode (auto/rtl/land)
ros2 service call /mavros/set_mode mavros_msgs/srv/SetMode "{custom_mode: 'guided'}"Arming
ros2 service call /mavros/cmd/arming mavros_msgs/srv/CommandBool "{value: true}"takeoff
ros2 service call /mavros/cmd/takeoff mavros_msgs/srv/CommandTOL "{altitude: 1}"Forward
ros2 topic pub --once /mavros/setpoint_velocity/cmd_vel_unstamped geometry_msgs/msg/Twist "{linear: {x: 1.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}"Back
ros2 topic pub --once /mavros/setpoint_velocity/cmd_vel_unstamped geometry_msgs/msg/Twist "{linear: {x: -1.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}"Right
ros2 topic pub --once /mavros/setpoint_velocity/cmd_vel_unstamped geometry_msgs/msg/Twist "{linear: {x: 0.0, y: -1.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}"Left
ros2 topic pub --once /mavros/setpoint_velocity/cmd_vel_unstamped geometry_msgs/msg/Twist "{linear: {x: 0.0, y: 1.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}"Up
ros2 topic pub --once /mavros/setpoint_velocity/cmd_vel_unstamped geometry_msgs/msg/Twist "{linear: {x: 0.0, y: 0.0, z: 1.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}"Down
ros2 topic pub --once /mavros/setpoint_velocity/cmd_vel_unstamped geometry_msgs/msg/Twist "{linear: {x: 0.0, y: 0.0, z: -1.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}"Yaw Left
ros2 topic pub --once /mavros/setpoint_velocity/cmd_vel_unstamped geometry_msgs/msg/Twist "{linear: {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.0}}"Yaw Right
ros2 topic pub --once /mavros/setpoint_velocity/cmd_vel_unstamped geometry_msgs/msg/Twist "{linear: {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: -1.0}}"Landing
ros2 service call /mavros/cmd/land mavros_msgs/srv/CommandTOL "{min_pitch: 0.0, yaw: 0.0, latitude: 0.0, longitude: 0.0, altitude: 0.0}"Stop movement
ros2 topic pub /mavros/setpoint_velocity/cmd_vel_unstamped geometry_msgs/msg/Twist "{linear: {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}"Send 10 Hz command
ros2 topic pub -r 10 /mavros/setpoint_velocity/cmd_vel_unstamped geometry_msgs/msg/Twist "{linear: {x: 1.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}"move to
ros2 topic pub /mavros/setpoint_position/local geometry_msgs/msg/PoseStamped "{
header: {
stamp: {sec: 0, nanosec: 0},
frame_id: 'map'
},
pose: {
position: {x: 1.0, y: 1.0, z: 1.0},
orientation: {x: 0.0, y: 0.0, z: 0.0, w: 1.0}
}
}" --onceThis im gonna show you how to build Ros2 workspcae to build script and drone task
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws
colcon build
source install/setup.bashbased own your package script usage
cd ~/ros2_ws/src
ros2 pkg create --build-type ament_cmake drone_teleop --dependencies rclcpp geometry_msgs mavros_msgs std_msgsgo to folder
cd drone_teleopmkdir src
cd src
touch teleop_keyboard.cpp
