Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple drones in Unity #3128

Merged
merged 15 commits into from
Sep 9, 2021
Merged

Conversation

ykeuter
Copy link
Contributor

@ykeuter ykeuter commented Nov 4, 2020

Using multiple vehicles is not yet supported in Unity ( #1540 ). This PR attempts to add this functionality.

A few things to note:

  • This PR mainly focusses on drones, but the changes should cover most part for car simulations too.
  • There is a test scene MultiDroneDemo which can be used with multi_agent_drone.py.
  • The vehicles in the scene should be named according to the names in settings.json.
  • Vehicle coordinates in settings.json are ignored (as is already the case with a single vehicle).
  • The new scripts AirSimServer and AirSimTick depend on a correct setting of the script execution order.
  • Issues Execution order of simulation loop for drone in Unity #3126 and Update render functions called twice per tick #3127 are related to parts of the code changes.
  • Code changes were made with minimal overall impact in mind (this is not a refactoring).

@ghost
Copy link

ghost commented Nov 4, 2020

CLA assistant check
All CLA requirements met.

@zimmy87
Copy link
Contributor

zimmy87 commented Jun 4, 2021

It seems that you have a lot of conflicts. This is most likely due to conflicts with autoformatted code in master. Please follow these steps to resolve this:

  1. check out your pull request
  2. run git checkout master .clang-format in your repo's root folder
  3. if you don't have npm installed, download it from https://www.npmjs.com/get-npm
  4. run npm install -g clang-format
  5. run clang-format -i path/to/file for each conflicting file
  6. run git add -u to track all style changes
  7. run git commit -am "apply style from clang-format"
  8. run git merge master
  9. resolve other non-style conflicts if you have any
  10. push changes

Thanks for helping us with these style changes!

@jonyMarino
Copy link
Collaborator

Hi @ykeuter! Thank you for applying the clang-format. It seems that there are more conflicts in your PR. If you can solve them, we are ready to test this and merge it. Thanks!

@ykeuter
Copy link
Contributor Author

ykeuter commented Jul 22, 2021

Hi @jonyMarino ! Thanks for your message. It's been a long time since I worked on this code. I just tried to apply the clang format, but indeed saw there are still conflicts. I will need time to get back into the project. No guarantee on my schedule, but I will keep you posted.

@ykeuter
Copy link
Contributor Author

ykeuter commented Jul 28, 2021

Hi @jonyMarino ! The merge conflicts are resolved now. I was able to run the MultiDroneDemo scene and everything seems to be working. Please have a look and let me know if there are any more issues / questions. Cheers. Yvo

@jonyMarino
Copy link
Collaborator

Thanks, Yvo! We will start testing this!

Copy link
Contributor

@zimmy87 zimmy87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with hello_drone.py and multi_agent_drone.py scripts, which both worked as expected. Looks good apart from minor style comments.

@zimmy87 zimmy87 merged commit afb0e8b into microsoft:master Sep 9, 2021
@ykeuter
Copy link
Contributor Author

ykeuter commented Sep 9, 2021

Hi @zimmy87! Thanks for the review and merging this PR. Much appreciated!

@SworterW
Copy link

Using multiple vehicles is not yet supported in Unity ( #1540 ). This PR attempts to add this functionality.

A few things to note:

  • This PR mainly focusses on drones, but the changes should cover most part for car simulations too.
  • There is a test scene MultiDroneDemo which can be used with multi_agent_drone.py.
  • The vehicles in the scene should be named according to the names in settings.json.
  • Vehicle coordinates in settings.json are ignored (as is already the case with a single vehicle).
  • The new scripts AirSimServer and AirSimTick depend on a correct setting of the script execution order.
  • Issues Execution order of simulation loop for drone in Unity #3126 and Update render functions called twice per tick #3127 are related to parts of the code changes.
  • Code changes were made with minimal overall impact in mind (this is not a refactoring).

Hi @ykeuter I try to play MultiDroneDemo, but it always make my unity crashed like #4764. whatever the latest airsim version, or this merge version. I also alter my settings.json like https://github.com/microsoft/AirSim/blob/main/PythonClient/multirotor/multi_agent_drone.py .Could you please tell me how can you play the MultiDroneDemo as normal, what the steps. Thanks so much !

@ykeuter
Copy link
Contributor Author

ykeuter commented Dec 15, 2022

Hi @ykeuter I try to play MultiDroneDemo, but it always make my unity crashed like #4764. whatever the latest airsim version, or this merge version. I also alter my settings.json like https://github.com/microsoft/AirSim/blob/main/PythonClient/multirotor/multi_agent_drone.py .Could you please tell me how can you play the MultiDroneDemo as normal, what the steps. Thanks so much !

Hi @SworterW ! Thanks for your message. It has been an awful long time since I looked at this. I do remember that the following point is really important:

  • The vehicles in the scene should be named according to the names in settings.json.

Apart from that I do not know if subsequent commits / changes to the code base have broken the multi-drone version. At a later stage I might look back into this.

@SworterW
Copy link

Hi @ykeuter I try to play MultiDroneDemo, but it always make my unity crashed like #4764. whatever the latest airsim version, or this merge version. I also alter my settings.json like https://github.com/microsoft/AirSim/blob/main/PythonClient/multirotor/multi_agent_drone.py .Could you please tell me how can you play the MultiDroneDemo as normal, what the steps. Thanks so much !

Hi @SworterW ! Thanks for your message. It has been an awful long time since I looked at this. I do remember that the following point is really important:

  • The vehicles in the scene should be named according to the names in settings.json.

Apart from that I do not know if subsequent commits / changes to the code base have broken the multi-drone version. At a later stage I might look back into this.

Hi @ykeuter ! Thank you for your reply. I find my defalt setting in names of vehicles in the scene is the same as my settings.json.
image
I even chang the gameobject's name to be the same like
image
My unity was crashed too.
I try to review the changes one by one, and i find it's not different with my version.
image

Honestly, i have no clue now. If it's convenient for you, could you please send a version that you play multidrone successfully. Then i will have a new test. Thanks so much!!

@ykeuter
Copy link
Contributor Author

ykeuter commented Dec 16, 2022

Hi @SworterW ! That is really strange. I was able to install everything from scratch and run MultiDroneDemo. The only thing I needed to change was the settings.json, but yours seems to be correct. Could you check if you have a stale (single drone) settings.json hanging around somewhere? I remember AirSim checks at multiple locations for this file and could pick up the wrong one. I put mine in My Documents\AirSim\settings.json.

@SworterW
Copy link

Hi @SworterW ! That is really strange. I was able to install everything from scratch and run MultiDroneDemo. The only thing I needed to change was the settings.json, but yours seems to be correct. Could you check if you have a stale (single drone) settings.json hanging around somewhere? I remember AirSim checks at multiple locations for this file and could pick up the wrong one. I put mine in My Documents\AirSim\settings.json.

Hi @ykeuter ! Your reply inspired me a lot. When i built airsim at the beginning, it would spawn setting.json at Document\AirSim\settings.json

image
I try a test. When i alter the vehicle name 'SimpleFlight' to 'Drone1' in DroneDemo, and alter the Document\AirSim\settings.json like
{
"SeeDocsAt": "https://github.com/Microsoft/AirSim/blob/master/docs/settings_json.md",
"SettingsVersion": 1.2,
"SimMode": "Multirotor",
"ClockSpeed": 1.0,
"Vehicles": {
"Drone1": {
"VehicleType": "SimpleFlight",
"DefaultVehicleState": "Armed",
"EnableCollisionPassthrogh": false,
"EnableCollisions": true,
"AllowAPIAlways": true,
"RC": {
"RemoteControlID": 0,
"AllowAPIWhenDisconnected": false
}
}
}
}
my unity crashed as i play MultidroneDemo. I realize that the Document\AirSim\settings.json is not work. So i search my computer.
840ca36d85d64fc78573a210a2ec68a
I find two other settings.json in my computer.When i alter the vehicle name to 'Drone1' at all the settings.json, my unity crashes too. But when i alter the vehicle name back to 'SimpleFlight' in DroneDemo, it play as normal.
From the test, i find the three setting.json are not work. I don't know where is the correct file would AirSim pick up.Thank you for your patience!

@ykeuter
Copy link
Contributor Author

ykeuter commented Dec 16, 2022

@SworterW, you probably still have yet another settings file lying around somewhere. The issue is that the dll plugin looks at different locations than the Unity code itself does. I once made a PR to deal with this confusion by using an environment variable:
main...ykeuter:AirSim:settings-env-var
Maybe this points you into the right direction.

@SworterW
Copy link

@SworterW, you probably still have yet another settings file lying around somewhere. The issue is that the dll plugin looks at different locations than the Unity code itself does. I once made a PR to deal with this confusion by using an environment variable: main...ykeuter:AirSim:settings-env-var Maybe this points you into the right direction.

Hi @ykeuter ! I'm so sorry to bother you again. I tried this method main...ykeuter:AirSim:settings-env-var
In fact, I found that unity was reading my json files correctly, whether or not this environment variable was set.
I did another test, if my json(at Documents\AirSim\settings.json) is set like this, and the Vehicle Name in DroneDemo is SimpleFlight:
image
then when I play the scene named SimModeSelector, he will jump to DroneDemo correctly.It played as normal and my unity did not crash.
When my json(at Documents\AirSim\settings.json) set null like this:
image
it will not jump to DroneDemo, and output thelog:
image
So I guess airsim should read the correct json path, but there is an exception in the process of parsing. Thank you very much for your patient reply each time. Being able to run MultiDroneDemo in unity is very important to me. If possible, could you send me a project file that can successfully run MultiDroneDemo. My email is 2019020800217@jlxy.nju.edu.cn

@pankan2
Copy link

pankan2 commented Aug 24, 2023

I also encountered the problem of modifying the json. I added the drone to the drone scene and modified the json file. Adding an additional drone directly at the point (0, 0, 0) is out of control. Did you solve this problem?

@sandilyasg
Copy link

@ykeuter @SworterW @zimmy87 Can you please give the steps you took to run the multi_agent_drone.py? I have my settings.json correctly set up, and in Unity I am running the "SimModeSelector" scene, after which I select "Drone" mode, but it crashes. What are the correct steps to setting this up?

@ykeuter
Copy link
Contributor Author

ykeuter commented Oct 12, 2023

Most of these issues still boil down to stale (auto-generated) settings.json files... Please check for any of those on your machine and take a look at main...ykeuter:AirSim:settings-env-var for some ways to get around this.

@SworterW
Copy link

SworterW commented Oct 12, 2023

@sandilyasg @pankan2
You can check out the additional settings.json generated on your system and change it to also support multiple drone configurations in your scenario

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants