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

Spawning a vehicle in Unreal via AirSim #1008

Closed
stephen-jang opened this issue Apr 24, 2018 · 12 comments
Closed

Spawning a vehicle in Unreal via AirSim #1008

stephen-jang opened this issue Apr 24, 2018 · 12 comments

Comments

@stephen-jang
Copy link

stephen-jang commented Apr 24, 2018

We have a need for spawning multiple vehicles. Please let me know if you have a proper way to implement spawning.

I made a change to MultiRotorAPI to accept "Spawn" call from a MultiRotorConnector.
I actually was able to call the spawn function, but UE4 errors and crashes as soon as I spawn a multirotor with this->GetWorld()->SpawnActor.

I am calling the spawn function inside SimModeWorldMultiRotor.cpp.

void ASimModeWorldMultiRotor::spawnVehicle(UWorld* world)
{
	FVector loc(300, 250, 300);
	FRotator rot(0, 0, 0);

	auto bp_class = UAirBlueprintLib::LoadClass("Class'/AirSim/Blueprints/BP_FlyingPawn.BP_FlyingPawn_C'");

	FActorSpawnParameters pawn_spawn_params;
	pawn_spawn_params.SpawnCollisionHandlingOverride =
		ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
	TMultiRotorPawn* spawned_pawn = world->SpawnActor<TMultiRotorPawn>(
		bp_class, loc, rot, pawn_spawn_params); **<<-- EXCEPTION THIS LINE**

ERROR INFO

  • UE4Editor.exe has triggered a breakpoint
  • EngineUtils.h line 190, check(IsInGameThread()); throws the exception.
@sytelus
Copy link
Contributor

sytelus commented Apr 25, 2018

We are currently working on this. There are bunch of design changes coming along with this feature in couple of weeks...

@stephen-jang
Copy link
Author

Thank you for the answer. I ended up hooking blueprint function called via c++. So now it spawns well. Looking forward to seeing the feature release.

@Isaac45
Copy link

Isaac45 commented May 8, 2018

@stephen-jang, please are you able to control two rotors in one environment.

{
"SettingsVersion": 1.0,
"SimMode": "Multirotor",
"DefaultVehicleConfig": "PX4"
"PX4_1": {
"FirmwareName": "PX4",
"SitlIp": "127.0.0.1",
"SitlPort": 14556,
"UdpIp": "127.0.0.1",
"UdpPort": 14560,
"UseSerial": true,
"SerialPort":"COM3",
"ApiServerPort": 41451
},
"PX4_2": {
"FirmwareName": "PX4",
"SitlIp": "127.0.0.1",
"SitlPort": 14557,
"UdpIp": "127.0.0.1",
"UdpPort": 14561,
"UseSerial": true,
"SerialPort":"COM5",
"ApiServerPort": 41452
}
}

it always only connect one

@stephen-jang
Copy link
Author

stephen-jang commented May 8, 2018

@Isaac45 As far as I know, their multi-agent doc is old. Basically you don't have to set VehicleConfigName inside Airsim/settings.

If you've pulled their latest branch, by just creating two vehicles on unreal environment will create 2 multirotor connectors which you can access with 2 different ports. Port numbers get incremented automatically. So just drag and drop 2 or more vehicles inside unreal editor.

https://github.com/Microsoft/AirSim/blob/master/Unreal/Plugins/AirSim/Source/Multirotor/SimModeWorldMultiRotor.cpp

Look at line from line111 carefully inside setupVehiclesAndCamera. You will notice that Airsim finds currently available pawns in unreal and connecting each of them with for loop.

@Isaac45
Copy link

Isaac45 commented May 9, 2018 via email

@Isaac45
Copy link

Isaac45 commented May 9, 2018

@stephen-jang, this is the challenge #978

@galgyeony
Copy link

galgyeony commented May 15, 2018

@stephen-jang
I followed your instructions but failed to control multi UAVs. (only one is able to be controlled)
It seems that setting up the "settings.json" to give different ApiServerPort numbers to multi UAVs is ineffective.
Even though I give another port number (e.g., 41452) through settings.json, the server is only listening to 41451, which is the default one.
The server port number "41451" is hard coded and the current source code supports only one port number. There is no automatic increase for it. Thus, for me, the only way to use another port number was to modify the source code directly to another one (e.g., 41452). But it is neither fancy nor supporting multi UAVs.

Please correct me if I am wrong.

@stephen-jang
Copy link
Author

stephen-jang commented May 15, 2018

@Isaac45 @galgyeony As I mentioned before, their doc for (settings.json) is outdated. Thus, ineffective.

Currently, You should have 2 or more pawns inside unreal before running anything. Port # was automatically incremented before. I believe they are in the process of getting their new multi-agent system.

Your createVehicle inside SimModeWorldMultiRotor should have this line:

std::shared_ptr<MultiRotorConnector> vehicle = std::make_shared<MultiRotorConnector>(
        wrapper, vehicle_params_.back().get(), getSettings().enable_rpc, getSettings().api_server_address,
            vehicle_params_.back()->getParams().api_server_port + vehicle_params_.size() - 1, manual_pose_controller
    );

@galgyeony
Copy link

galgyeony commented May 16, 2018

@stephen-jang
Based on your code and the sample python API script (i.e., swarmControl.py), now I am able to control 2 drones simultaneously.
However, an error message "API call timed out, entering hover mode" is frequently displayed on screen and I lose control for that drone.

For instance, if I execute a command "0 takeoff", then the drone with index 0 takes off. However, just after the takeoff, the error message is displayed and no more control for the drone 0, (e.g., "0 land" does not work).
Interestingly, if I execute another command "1 takeoff", the drone 1 takes off well. Then, if I execute "0 land" again, the drone 0 now lands well. In short, the drone 0 and drone 1 cannot be in the "land" state simultaneously.

Thank you very much for your help and comments.

@stephen-jang
Copy link
Author

@galgyeony swarmControl.py was written with not much testings. I grabbed that code from "https://github.com/saihv" But I know that communicating through port 41451, 41452, or more works. That I've tested with different setups. Try testing them a little to make sure they communicate in different ports.

@galgyeony
Copy link

@stephen-jang Yes, you're right. It mostly works using different ports like 41451, 41452 or more. But there are some problems. One example is that if there are two vehicles (0 and 1) and both already have taken off, then both ones cannot land. Only one is allowed to land.

@KerryMoffittRtn
Copy link
Contributor

@galgyeony I believe PR #1374 addresses the takeoff / landing issue.

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

No branches or pull requests

8 participants