Skip to content

Commit

Permalink
fix segmentation API threading issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sytelus committed Nov 8, 2017
1 parent ade76f3 commit 8822f28
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion PythonClient/PythonClient.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>e2049e20-b6dd-474e-8bca-1c8dc54725aa</ProjectGuid>
<ProjectHome>.</ProjectHome>
<StartupFile>car_collision.py</StartupFile>
<StartupFile>segmentation.py</StartupFile>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
Expand Down
16 changes: 16 additions & 0 deletions PythonClient/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
client = CarClient()
client.confirmConnection()

AirSimClientBase.wait_key('Press any key to set all object IDs to 0')
found = client.simSetSegmentationObjectID("[\w]*", 0, True);
print("Done: %r" % (found))

AirSimClientBase.wait_key('Press any key to set all object IDs to 0 hard way')
alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
for letter in alphabet:
found = client.simSetSegmentationObjectID(letter+"[\w]*", 0, True);
print("Done: %r" % (found))

AirSimClientBase.wait_key('Press any key to change one ground object ID')
found = client.simSetSegmentationObjectID("Ground", 20);
print("Done: %r" % (found))
Expand All @@ -14,5 +24,11 @@
found = client.simSetSegmentationObjectID("ground[\w]*", 22, True);
print("Done: %r" % (found))

found = client.simSetSegmentationObjectID("tree[\w]*", 2, True);
found = client.simSetSegmentationObjectID("landscape[\w]*", 200, True);
print("Done: %r" % (found))





6 changes: 5 additions & 1 deletion Unreal/Plugins/AirSim/Source/Car/CarPawn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ class ACarPawn::CarApi : public msr::airlib::CarApiBase {
virtual bool simSetSegmentationObjectID(const std::string& mesh_name, int object_id,
bool is_name_regex = false) override
{
return UAirBlueprintLib::SetMeshStencilID(mesh_name, object_id, is_name_regex);
bool success;
UAirBlueprintLib::RunCommandOnGameThread([mesh_name, object_id, is_name_regex, &success]() {
success = UAirBlueprintLib::SetMeshStencilID(mesh_name, object_id, is_name_regex);
}, true);
return success;
}

virtual int simGetSegmentationObjectID(const std::string& mesh_name) override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,11 @@ Pose MultiRotorConnector::getPose()
bool MultiRotorConnector::setSegmentationObjectID(const std::string& mesh_name, int object_id,
bool is_name_regex)
{
return UAirBlueprintLib::SetMeshStencilID(mesh_name, object_id, is_name_regex);
bool success;
UAirBlueprintLib::RunCommandOnGameThread([mesh_name, object_id, is_name_regex, &success]() {
success = UAirBlueprintLib::SetMeshStencilID(mesh_name, object_id, is_name_regex);
}, true);
return success;
}

int MultiRotorConnector::getSegmentationObjectID(const std::string& mesh_name)
Expand Down

0 comments on commit 8822f28

Please sign in to comment.