AirSim icon indicating copy to clipboard operation
AirSim copied to clipboard

Multiple quadrotors using API acts as a group of 4 instead of all together

Open yashkaushal opened this issue 8 years ago • 5 comments

Hi, I tried to make a swarm of drones take off and land together.

I configured settings.json to have 12 drones in Unreal and used python API to make them takeoff together, but instead of all taking off together random 4 take off first, then next 4 and so forth.

See screenshot for reference: swarm takeoff 4 at a time All were expected to take off together but only the first 4 took off, after a few seconds the next 4 took off.

My OS is windows 10 pro version 1803, AirSim version 1.2(today's build), python 2.7.15, unreal version 4.20

Below is the settings.json I used:

{
    "SimMode": "Multirotor",
    "SeeDocsAt": "https://github.com/Microsoft/AirSim/blob/master/docs/settings.md",
    "SettingsVersion": 1.2,
    "Vehicles": {
        "SimpleFlight1": {
            "VehicleType": "SimpleFlight",
            "X": 4,
            "Y": -15,
            "Z": -2,
            "DefaultVehicleState": "Disarmed",
            "EnableCollisionPassthrogh": false,
            "EnableCollisions": true,
            "AllowAPIAlways": true,
            "RC": {
                "RemoteControlID": 0,
                "AllowAPIWhenDisconnected": false
            }
        },
        "SimpleFlight2": {
            "VehicleType": "SimpleFlight",
            "X": -4,
            "Y": -15,
            "Z": -2,
            "DefaultVehicleState": "Disarmed",
            "EnableCollisionPassthrogh": false,
            "EnableCollisions": true,
            "AllowAPIAlways": true,
            "RC": {
                "RemoteControlID": 0,
                "AllowAPIWhenDisconnected": false
            }
        },
        "SimpleFlight3": {
            "VehicleType": "SimpleFlight",
            "X": 0,
            "Y": -15,
            "Z": -2,
            "DefaultVehicleState": "Disarmed",
            "EnableCollisionPassthrogh": false,
            "EnableCollisions": true,
            "AllowAPIAlways": true,
            "RC": {
                "RemoteControlID": 0,
                "AllowAPIWhenDisconnected": false
            }
        },
        "SimpleFlight4": {
            "VehicleType": "SimpleFlight",
            "X": 4,
            "Y": -10,
            "Z": -2,
            "DefaultVehicleState": "Disarmed",
            "EnableCollisionPassthrogh": false,
            "EnableCollisions": true,
            "AllowAPIAlways": true,
            "RC": {
                "RemoteControlID": 0,
                "AllowAPIWhenDisconnected": false
            }
        },
        "SimpleFlight5": {
            "VehicleType": "SimpleFlight",
            "X": -4,
            "Y": -10,
            "Z": -2,
            "DefaultVehicleState": "Disarmed",
            "EnableCollisionPassthrogh": false,
            "EnableCollisions": true,
            "AllowAPIAlways": true,
            "RC": {
                "RemoteControlID": 0,
                "AllowAPIWhenDisconnected": false
            }
        },
        "SimpleFlight6": {
            "VehicleType": "SimpleFlight",
            "X": 0,
            "Y": -10,
            "Z": -2,
            "DefaultVehicleState": "Disarmed",
            "EnableCollisionPassthrogh": false,
            "EnableCollisions": true,
            "AllowAPIAlways": true,
            "RC": {
                "RemoteControlID": 0,
                "AllowAPIWhenDisconnected": false
            }
        },
        "SimpleFlight7": {
            "VehicleType": "SimpleFlight",
            "X": 4,
            "Y": -5,
            "Z": -2,
            "DefaultVehicleState": "Disarmed",
            "EnableCollisionPassthrogh": false,
            "EnableCollisions": true,
            "AllowAPIAlways": true,
            "RC": {
                "RemoteControlID": 0,
                "AllowAPIWhenDisconnected": false
            }
        },
        "SimpleFlight8": {
            "VehicleType": "SimpleFlight",
            "X": -4,
            "Y": -5,
            "Z": -2,
            "DefaultVehicleState": "Disarmed",
            "EnableCollisionPassthrogh": false,
            "EnableCollisions": true,
            "AllowAPIAlways": true,
            "RC": {
                "RemoteControlID": 0,
                "AllowAPIWhenDisconnected": false
            }
        },
        "SimpleFlight9": {
            "VehicleType": "SimpleFlight",
            "X": 0,
            "Y": -5,
            "Z": -2,
            "DefaultVehicleState": "Disarmed",
            "EnableCollisionPassthrogh": false,
            "EnableCollisions": true,
            "AllowAPIAlways": true,
            "RC": {
                "RemoteControlID": 0,
                "AllowAPIWhenDisconnected": false
            }
        },
        "SimpleFlight10": {
            "VehicleType": "SimpleFlight",
            "X": 4,
            "Y": 0,
            "Z": -2,
            "DefaultVehicleState": "Disarmed",
            "EnableCollisionPassthrogh": false,
            "EnableCollisions": true,
            "AllowAPIAlways": true,
            "RC": {
                "RemoteControlID": 0,
                "AllowAPIWhenDisconnected": false
            }
        },
        "SimpleFlight11": {
            "VehicleType": "SimpleFlight",
            "X": -4,
            "Y": 0,
            "Z": -2,
            "DefaultVehicleState": "Disarmed",
            "EnableCollisionPassthrogh": false,
            "EnableCollisions": true,
            "AllowAPIAlways": true,
            "RC": {
                "RemoteControlID": 0,
                "AllowAPIWhenDisconnected": false
            }
        },
        "SimpleFlight12": {
            "VehicleType": "SimpleFlight",
            "X": 0,
            "Y": 0,
            "Z": -2,
            "DefaultVehicleState": "Disarmed",
            "EnableCollisionPassthrogh": false,
            "EnableCollisions": true,
            "AllowAPIAlways": true,
            "RC": {
                "RemoteControlID": 0,
                "AllowAPIWhenDisconnected": false
            }
        }
    }
}

Below is the python code i used to call API commands, It is modified from multi_agent_drone.py demo.


import setup_path 
import airsim

import numpy as np
import os
import tempfile
import pprint

# connect to the AirSim simulator
client = airsim.MultirotorClient()
client.confirmConnection()
client.enableApiControl(True, "SimpleFlight1")
client.enableApiControl(True, "SimpleFlight2")
client.enableApiControl(True, "SimpleFlight3")

client.enableApiControl(True, "SimpleFlight4")
client.enableApiControl(True, "SimpleFlight5")
client.enableApiControl(True, "SimpleFlight6")

client.enableApiControl(True, "SimpleFlight7")
client.enableApiControl(True, "SimpleFlight8")
client.enableApiControl(True, "SimpleFlight9")

client.enableApiControl(True, "SimpleFlight10")
client.enableApiControl(True, "SimpleFlight11")
client.enableApiControl(True, "SimpleFlight12")

client.armDisarm(True, "SimpleFlight1")
client.armDisarm(True, "SimpleFlight2")
client.armDisarm(True, "SimpleFlight3")

client.armDisarm(True, "SimpleFlight4")
client.armDisarm(True, "SimpleFlight5")
client.armDisarm(True, "SimpleFlight6")

client.armDisarm(True, "SimpleFlight7")
client.armDisarm(True, "SimpleFlight8")
client.armDisarm(True, "SimpleFlight9")

client.armDisarm(True, "SimpleFlight10")
client.armDisarm(True, "SimpleFlight11")
client.armDisarm(True, "SimpleFlight10")

airsim.wait_key('Press any key to takeoff')
f1 = client.takeoffAsync(vehicle_name="SimpleFlight1")
f2 = client.takeoffAsync(vehicle_name="SimpleFlight2")
f3 = client.takeoffAsync(vehicle_name="SimpleFlight3")

f4 = client.takeoffAsync(vehicle_name="SimpleFlight4")
f5 = client.takeoffAsync(vehicle_name="SimpleFlight5")
f6 = client.takeoffAsync(vehicle_name="SimpleFlight6")

f7 = client.takeoffAsync(vehicle_name="SimpleFlight7")
f8 = client.takeoffAsync(vehicle_name="SimpleFlight8")
f9 = client.takeoffAsync(vehicle_name="SimpleFlight9")

f10 = client.takeoffAsync(vehicle_name="SimpleFlight10")
f11 = client.takeoffAsync(vehicle_name="SimpleFlight11")
f12 = client.takeoffAsync(vehicle_name="SimpleFlight12")

f1.join()
f2.join()
f3.join()

f4.join()
f5.join()
f6.join()

f7.join()
f8.join()
f9.join()

f10.join()
f11.join()
f12.join()

airsim.wait_key('Press any key to hover vehicles')

f1 = client.hoverAsync(vehicle_name="SimpleFlight1")
f2 = client.hoverAsync(vehicle_name="SimpleFlight2")
f3 = client.hoverAsync(vehicle_name="SimpleFlight3")

f4 = client.hoverAsync(vehicle_name="SimpleFlight4")
f5 = client.hoverAsync(vehicle_name="SimpleFlight5")
f6 = client.hoverAsync(vehicle_name="SimpleFlight6")

f7 = client.hoverAsync(vehicle_name="SimpleFlight7")
f8 = client.hoverAsync(vehicle_name="SimpleFlight8")
f9 = client.hoverAsync(vehicle_name="SimpleFlight9")

f10 = client.hoverAsync(vehicle_name="SimpleFlight10")
f11 = client.hoverAsync(vehicle_name="SimpleFlight11")
f12 = client.hoverAsync(vehicle_name="SimpleFlight12")

f1.join()
f2.join()
f3.join()

f4.join()
f5.join()
f6.join()

f7.join()
f8.join()
f9.join()

f10.join()
f11.join()
f12.join()

airsim.wait_key('Press any key to land vehicles')

f1 = client.landAsync(vehicle_name="SimpleFlight1")
f2 = client.landAsync(vehicle_name="SimpleFlight2")
f3 = client.landAsync(vehicle_name="SimpleFlight3")

f4 = client.landAsync(vehicle_name="SimpleFlight4")
f5 = client.landAsync(vehicle_name="SimpleFlight5")
f6 = client.landAsync(vehicle_name="SimpleFlight6")

f7 = client.landAsync(vehicle_name="SimpleFlight7")
f8 = client.landAsync(vehicle_name="SimpleFlight8")
f9 = client.landAsync(vehicle_name="SimpleFlight9")

f10 = client.landAsync(vehicle_name="SimpleFlight10")
f11 = client.landAsync(vehicle_name="SimpleFlight11")
f12 = client.landAsync(vehicle_name="SimpleFlight12")

f1.join()
f2.join()
f3.join()

f4.join()
f5.join()
f6.join()

f7.join()
f8.join()
f9.join()

f10.join()
f11.join()
f12.join()

client.armDisarm(False, "SimpleFlight1")
client.armDisarm(False, "SimpleFlight2")
client.armDisarm(False, "SimpleFlight3")

client.armDisarm(False, "SimpleFlight4")
client.armDisarm(False, "SimpleFlight5")
client.armDisarm(False, "SimpleFlight6")

client.armDisarm(False, "SimpleFlight7")
client.armDisarm(False, "SimpleFlight8")
client.armDisarm(False, "SimpleFlight9")

client.armDisarm(False, "SimpleFlight10")
client.armDisarm(False, "SimpleFlight11")
client.armDisarm(False, "SimpleFlight12")

# that's enough fun for now. let's quit cleanly
client.enableApiControl(False, "SimpleFlight1")
client.enableApiControl(False, "SimpleFlight2")
client.enableApiControl(False, "SimpleFlight3")

client.enableApiControl(False, "SimpleFlight4")
client.enableApiControl(False, "SimpleFlight5")
client.enableApiControl(False, "SimpleFlight6")

client.enableApiControl(False, "SimpleFlight7")
client.enableApiControl(False, "SimpleFlight8")
client.enableApiControl(False, "SimpleFlight9")

client.enableApiControl(False, "SimpleFlight10")
client.enableApiControl(False, "SimpleFlight11")
client.enableApiControl(False, "SimpleFlight12")

I tried using single client for each quad instead of a single client being shared among them but that also yielded the same result.

Please suggest me what steps to take to make them take off together.

Thanks, Yash Kaushal

yashkaushal avatar Nov 14 '18 11:11 yashkaushal

Not that this is the actual cause, but did you catch that you do a typo in the first set of client.disarm:
client.armDisarm(True, "SimpleFlight10") client.armDisarm(True, "SimpleFlight11") client.armDisarm(True, "SimpleFlight10")

RVBldr avatar Nov 15 '18 14:11 RVBldr

Hi @RVBldr Thanks for pointing the typo, I did some searching around and found that it has been reported earlier as well in the last comment of #1137 by KavehFathian.

yashkaushal avatar Nov 18 '18 11:11 yashkaushal

in the video referenced in #1137, it's interesting that they are able to work 9 apparently without the 4 ship bug. Internally we're taking at look at that and initial thoughts are that it's a threading issue.

RVBldr avatar Nov 18 '18 19:11 RVBldr

I think the issue is in this line.

pimpl_->server.async_run(4); //4 threads

Try changing it to number of vehicles and see if it works.

We need to set the number of threads from AirSimSettings. Ideal would to do max of count of vehicles in AirSimSettings or user specified value.

sytelus avatar Nov 21 '18 03:11 sytelus

Fixed: https://github.com/Microsoft/AirSim/commit/262cb28e0845c9879078ce453169acbea7630c8b

sytelus avatar Nov 29 '18 08:11 sytelus