SIGN IN SIGN UP
microsoft / AirSim UNCLAIMED

Open source simulator for autonomous vehicles built on Unreal Engine / Unity, from Microsoft AI & Research

0 0 29 C++
2018-06-15 02:59:05 -07:00
# In settings.json first activate computer vision mode:
# https://github.com/Microsoft/AirSim/blob/master/docs/image_apis.md#computer-vision-mode
2017-12-07 01:54:59 -08:00
2018-06-15 02:59:05 -07:00
import setup_path
import airsim
2017-12-07 01:54:59 -08:00
2018-06-15 03:23:37 -07:00
import pprint
2018-06-15 02:59:05 -07:00
client = airsim.VehicleClient()
2017-12-07 01:54:59 -08:00
client.confirmConnection()
# objects can be named in two ways:
# 1. In UE Editor, select and object and change its name to something else. Note that you must *change* its name because
# default name is auto-generated and varies from run-to-run.
# 2. OR you can do this: In UE Editor select the object and then go to "Actor" section, click down arrow to see "Tags" property and add a tag there.
#
# The simGetObjectPose and simSetObjectPose uses first object that has specified name OR tag.
# more info: https://answers.unrealengine.com/questions/543807/whats-the-difference-between-tag-and-tag.html
# https://answers.unrealengine.com/revisions/790629.html
# below works in Blocks environment
#------------------------------------ Get current pose ------------------------------------------------
# search object by name:
pose1 = client.simGetObjectPose("OrangeBall");
print("OrangeBall - Position: %s, Orientation: %s" % (pprint.pformat(pose1.position),
pprint.pformat(pose1.orientation)))
# search another object by tag
pose2 = client.simGetObjectPose("PulsingCone");
print("PulsingCone - Position: %s, Orientation: %s" % (pprint.pformat(pose2.position),
pprint.pformat(pose2.orientation)))
# search non-existent object
pose3 = client.simGetObjectPose("Non-Existent"); # should return nan pose
print("Non-Existent - Position: %s, Orientation: %s" % (pprint.pformat(pose3.position),
pprint.pformat(pose3.orientation)))
#------------------------------------ Set new pose ------------------------------------------------
# here we move with teleport enabled so collisions are ignored
pose1.position = pose1.position + airsim.Vector3r(-2, -2, -2)
success = client.simSetObjectPose("OrangeBall", pose1, True);
airsim.wait_key("OrangeBall moved. Success: %i" % (success))
# here we move with teleport enabled so collisions are not ignored
pose2.position = pose2.position + airsim.Vector3r(3, 3, -2)
success = client.simSetObjectPose("PulsingCone", pose2, False);
airsim.wait_key("PulsingCone moved. Success: %i" % (success))
# move non-existent object
success = client.simSetObjectPose("Non-Existent", pose2); # should return nan pose
airsim.wait_key("Non-Existent moved. Success: %i" % (success))
#------------------------------------ Get new pose ------------------------------------------------
pose1 = client.simGetObjectPose("OrangeBall");
print("OrangeBall - Position: %s, Orientation: %s" % (pprint.pformat(pose1.position),
pprint.pformat(pose1.orientation)))
# search another object by tag
pose2 = client.simGetObjectPose("PulsingCone");
print("PulsingCone - Position: %s, Orientation: %s" % (pprint.pformat(pose2.position),
pprint.pformat(pose2.orientation)))
# search non-existent object
pose3 = client.simGetObjectPose("Non-Existent"); # should return nan pose
print("Non-Existent - Position: %s, Orientation: %s" % (pprint.pformat(pose3.position),
pprint.pformat(pose3.orientation)))