Running ArduPilot Simulator and Gazebo: looking for a way to make them work together

Hello,

I have been working on for a passed few days to make SITL (simulator) and Gazebo (physical engine with visualization) work together. At this moment they work fine as standalone programs, but copter in gazebo doesn’t respond on commands from simulator.

At the beginning of the week I make SITL works with QGroundControl and handle python based programs, but migration to Gazebo for a more complex task faced with this issue.

$ /sim_vehicle.py -v ArduCopter -f gazebo-iris --console --out=udp:127.0.0.1:14551

BUILD SUMMARY
Build directory: /home/gelassen/Workspace/copter/ardupilot/build/sitl
Target Text (B) Data (B) BSS (B) Total Flash Used (B) Free Flash (B) External Flash Used (B)

bin/arducopter 4266024 200765 279264 4466789 Not Applicable Not Applicable

‘build’ finished successfully (3.151s)
SIM_VEHICLE: Using defaults from (default_params/copter.parm,default_params/gazebo-iris.parm)
SIM_VEHICLE: Run ArduCopter
SIM_VEHICLE: “/home/gelassen/Workspace/copter/ardupilot/Tools/autotest/run_in_terminal_window.sh” “ArduCopter” “/home/gelassen/Workspace/copter/ardupilot/build/sitl/bin/arducopter” “–model” “gazebo-iris” “–speedup” “1” “–slave” “0” “–defaults” “default_params/copter.parm,default_params/gazebo-iris.parm” “–sim-address=127.0.0.1” “-I0”
SIM_VEHICLE: Run MavProxy
SIM_VEHICLE: “mavproxy.py” “–retries” “5” “–out” “127.0.0.1:14550” “–master” “tcp:127.0.0.1:5760” “–sitl” “127.0.0.1:5501” “–out” “udp:127.0.0.1:9002” “–console”
RiTW: Starting ArduCopter : /home/gelassen/Workspace/copter/ardupilot/build/sitl/bin/arducopter --model gazebo-iris --speedup 1 --slave 0 --defaults default_params/copter.parm,default_params/gazebo-iris.parm --sim-address=127.0.0.1 -I0

Option “-e” is deprecated and might be removed in a later version of gnome-terminal.

Use “-- ” to terminate the options and put the command line to execute after it.

Connect tcp:127.0.0.1:5760 source_system=255
Failed to load module: No module named ‘console’. Use ‘set moddebug 3’ in the MAVProxy console to enable traceback
Log Directory:
Telemetry log: mav.tlog
Waiting for heartbeat from tcp:127.0.0.1:5760
MAV> link 1 down

Setting SIM_SPEEDUP=1.000000
Starting SITL Gazebo
Bind 127.0.0.1:9003 for SITL in
Setting Gazebo interface to 127.0.0.1:9002
Starting sketch ‘ArduCopter’
Starting SITL input
Using Irlock at port : 9005
bind port 5760 for SERIAL0
SERIAL0 on TCP port 5760
Waiting for connection …
Connection on serial port 5760
Loaded defaults from default_params/copter.parm,default_params/gazebo-iris.parm
bind port 5762 for SERIAL1
SERIAL1 on TCP port 5762
bind port 5763 for SERIAL2
SERIAL2 on TCP port 5763
Home: -35.363262 149.165237 alt=584.000000m hdg=353.000000

gz sim -v4 -r /usr/local/share/ardupilot_gazebo/worlds/iris_runway.sdf | grep ArduPilot

(2025-10-31 17:48:04.492) [info] [ArduPilotPlugin.cc:639] [iris_with_gimbal] Advertising on /gimbal/cmd_roll.
(2025-10-31 17:48:04.493) [info] [ArduPilotPlugin.cc:639] [iris_with_gimbal] Advertising on /gimbal/cmd_pitch.
(2025-10-31 17:48:04.493) [info] [ArduPilotPlugin.cc:639] [iris_with_gimbal] Advertising on /gimbal/cmd_yaw.
(2025-10-31 17:48:04.493) [debug] [SystemManager.cc:80] Loaded system [ArduPilotPlugin] for entity [15]
(2025-10-31 17:48:04.512) [info] [ArduPilotPlugin.cc:1147] Found IMU sensor with name [iris_with_standoffs::imu_link::imu_sensor]
(2025-10-31 17:48:04.512) [debug] [ArduPilotPlugin.cc:1161] Computed IMU topic to be: world/iris_runway/model/iris_with_gimbal/model/iris_with_standoffs/link/imu_link/sensor/imu_sensor/imu
(2025-10-31 17:48:04.761) [warning] [ArduPilotPlugin.cc:1445] [iris_with_gimbal] Drained n packets: 1
(2025-10-31 17:48:04.761) [warning] [ArduPilotPlugin.cc:1568] Incorrect protocol magic 0 should be 18458
(2025-10-31 17:48:06.788) [warning] [CameraZoomPlugin.cc:218] No scene or camera sensors available.
(2025-10-31 17:48:06.789) [warning] [Component.hh:144] Trying to serialize component with data type [St6vectorIdSaIdEE], which doesn’t have operator<<. Component will not be serialized.
(2025-10-31 17:48:06.826) [warning] [ArduPilotPlugin.cc:1445] [iris_with_gimbal] Drained n packets: 20
(2025-10-31 17:48:06.826) [warning] [ArduPilotPlugin.cc:1568] Incorrect protocol magic 0 should be 18458
(2025-10-31 17:48:06.826) [warning] [CameraZoomPlugin.cc:218] No scene or camera sensors available.
(2025-10-31 17:48:06.931) [warning] [Component.hh:189] [GUI] Trying to deserialize component with data type [St6vectorIdSaIdEE], which doesn’t have operator>>. Component will not be deserialized.
(2025-10-31 17:48:08.557) [warning] [Ogre2Camera.cc:423] Ogre2Camera::SetVisibilityMask: Mask bits c0000000 are set but will be ignored as they conflict with the reserved bits used internally by the ogre2 backend.
(2025-10-31 17:48:08.648) [warning] [ArduPilotPlugin.cc:1445] [iris_with_gimbal] Drained n packets: 17
(2025-10-31 17:48:08.648) [warning] [ArduPilotPlugin.cc:1568] Incorrect protocol magic 0 should be 18458
(2025-10-31 17:48:08.672) [warning] [ArduPilotPlugin.cc:1568] Incorrect protocol magic 0 should be 18458

It seems gazebo receives some packages, but on the different address.

However, ports seems are ok:

sudo ss -tulnp | grep 900
[sudo] password for gelassen: 
udp   UNCONN 0      0          127.0.0.1:9002       0.0.0.0:*    users:(("gz-sim-main",pid=471546,fd=37))    
udp   UNCONN 0      0            0.0.0.0:9003       0.0.0.0:*    users:(("arducopter",pid=466086,fd=9)

Hello @Gelassen, this is the wrong command. The version of Gazebo plugin you are using uses the SITL JSON backend, so the command line needs --model json added.

See the project README (GitHub - ArduPilot/ardupilot_gazebo: Plugins and models for vehicle simulation in Gazebo Sim with ArduPilot SITL controllers) and the wiki docs (Using SITL with Gazebo — Dev documentation).

Without this setting SITL will attempt to use the backend for the now EOL Gazebo Classic. That’s why the error is reporting an incorrect protocol marker:

(2025-10-31 17:48:06.826) [warning] [ArduPilotPlugin.cc:1568] Incorrect protocol magic 0 should be 18458
1 Like

Hello @rhys , thank you, that solves the issue!