mavlink / MAVSDK-Python

MAVSDK client for Python.
https://mavsdk.mavlink.io
BSD 3-Clause "New" or "Revised" License
320 stars 219 forks source link

Waiting for drone to connect... #358

Closed offjangir closed 3 years ago

offjangir commented 3 years ago

I was trying to run some simple examples with gazebo. I launch iris in gazebo with px4 autopilot it works perfectly but when I run any example / my code following is seen: Waiting for mavsdk_server to be ready... Connected to mavsdk_server! Waiting for drone to connect...

I wanted to use mavsdk for multi drone simulation but for some reason My connection is not being set up. Help please!

JonasVautherin commented 3 years ago

By default, the examples listens on udp://:14540. I think that SITL broadcasts on 14540 by default, so if both run on the same machine, it should work.

Does QGC connect to your SITL instance? QGC uses udp://:14550 by default.

offjangir commented 3 years ago

I am not using QGC . when I run SITL instance directly -- make px4_sitl_default gazebo_iris everything works fine and I am able to control things..

what I want to do is to launch multiple bots .. when I do that with roslaunch px4 multi_uav_mavros_sitl.launch

mavsdk server connects but Drones dont get connected. For ex. I launched multiple drones but tried to connect to udp 14540 with drone id 0 and mavsdk isnt able to find drone.

I am new at this so maybe doing some trivial mistake.

JonasVautherin commented 3 years ago

When you run make px4_sitl_default gazebo_iris, it will broadcast mavlink messages to udp 14540 (that's the default for MAVSDK) and udp 14550 (that's the default for QGC).

Now when you run multiple drones with that ROS command, I don't know what it does. Did you read what multi_uav_mavros_sitl.launch does? Where is that file?

offjangir commented 3 years ago

Yeah I took a look at it but didn't think of a reason it should not work. udp is clearly defined for each drone.

Launch file for your Reference : https://github.com/PX4/PX4-Autopilot/blob/8c4b900f9ac6aa48c60def3d1cda04ee22e59777/launch/multi_uav_mavros_sitl.launch#L1

JonasVautherin commented 3 years ago

But do you run mavsdk to listen on 14560, 14561 and 14562? Isn't that where your launch file says that mavlink will be broadcasted?

offjangir commented 3 years ago
drone = System()
await drone.connect(system_address="udp://:14560")

yes I am , for starters I just want to connect to one drone in the whole swarm. but when I run

Waiting for mavsdk_server to be ready... Connected to mavsdk_server! Waiting for drone to connect...

I am stuck here as drone is not being discovered.

offjangir commented 3 years ago

The example that I am running is like this :

async def run(): drone = System() await drone.connect(system_address="udp://:14560")

print("Waiting for drone to connect...")
async for state in drone.core.connection_state():
    if state.is_connected:
        print(f"Drone discovered!")
        break

print("Waiting for drone to have a global position estimate...")
async for health in drone.telemetry.health():
    if health.is_global_position_ok:
        print("Global position estimate ok")
        break

print("-- Arming")
await drone.action.arm()

print("-- Taking off")
await drone.action.takeoff()

await asyncio.sleep(5)

print("-- Landing")
await drone.action.land()

if __name__ == "__main__":
     loop = asyncio.get_event_loop()
     loop.run_until_complete(run())
JonasVautherin commented 3 years ago

You need to make sure that your drone (SITL or not) sends mavlink packets that reach MAVSDK. If it is your first time using MAVSDK, a quick way to try with a headless gazebo is documented here:

docker run --rm -it jonasvautherin/px4-gazebo-headless:1.11.0

And if the docker container does not run on the same host as mavsdk, you can specify the IP where mavsdk runs, for instance:

docker run --rm -it jonasvautherin/px4-gazebo-headless:1.11.0 192.168.1.12

If this works, then it means that you need to look into what your SITL does, and make sure it can reach mavsdk.

offjangir commented 3 years ago

@JonasVautherin Thanks for your help. Actually I found out the problems through one of your answer in #931 The PX4 launch files launch Mavros in the file itself and hence Mavsdk is not able to connect to the ports. For Connecting multiple vehicles I did was this : 1) Run multiple vehicles with no ROS in Gazebo (follow this ) 2) Launch mavsdk_severs : cd /Path_to_mavsdk/bin ./mavsdk_server -p 50040 udp://:14540 ./mavsdk_server -p 50041 udp://:14541 ./mavsdk_server -p 50042 udp://:14542

Everything works fine after that.