Sitl gazebo and mavlink

Hi,
I’m trying to control a SITL (Software In The Loop) drone using my own Python code based on MAVLink. Here’s what I’ve done so far:

  1. I initialize the virtual drone using the following command:

    sim_vehicle.py -v ArduCopter -f gazebo-iris --console --map

  2. I open Gazebo with the following command:

    gazebo --verbose ardupilot_gazebo/worlds/iris_arducopter_runway.world

When I open QGroundControl (QGC), I can see and fly the drone successfully, so I know the SITL and Gazebo setup are working.

Now, I’m trying to connect to the virtual drone with my own Python code. Here is the relevant part of my code:

master = mavutil.mavlink_connection(‘tcp:127.0.0.1:9003’)

Unfortunately, the code doesn’t seem to connect to the drone. I’m new to Ubuntu, and getting this far has been a big achievement for me. However, I’m stuck at this point and need some guidance.

What I need help with:

  • Am I using the correct connection string (tcp:127.0.0.1:9003) for connecting to the SITL drone?
  • Are there any additional steps I need to take to make the virtual drone accessible to my Python code?

Any advice or suggestions would be greatly appreciated!

hello,

by defaul, SITL open TCP port 5760, 5761, 5762 ,5763. Mavproxy is using 5760. So you can use any other.
9003 is gazebo communication port and isn’t mavlink so you shouldn’t use it.

thank you for answer.

I try given below yet any of them did not work.

    master = mavutil.mavlink_connection('tcp:0.0.0.0:9054')
    master = mavutil.mavlink_connection('tcp:0.0.0.0:15144')
    master = mavutil.mavlink_connection('tcp:127.0.0.1:5761')
    master = mavutil.mavlink_connection('tcp:127.0.0.1:15144')
    master = mavutil.mavlink_connection('udp:127.0.0.1:15144')

This is the error I get.
Connecting to the drone…
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping

I want to be sure I am doing the right thing so; I am starting sim_vehicle, gazebo than my own code right?

an update;
this worked;
master = mavutil.mavlink_connection(‘udp:127.0.0.1:14550’)