Skip to content

Commit

Permalink
Add example script to create objects
Browse files Browse the repository at this point in the history
  • Loading branch information
rajat2004 committed Aug 8, 2021
1 parent 565771e commit f6bd9c4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions PythonClient/environment/create_objects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import setup_path
import airsim
import random
import time

client = airsim.VehicleClient()
client.confirmConnection()

assets = client.simListAssets()
print(f"Assets: {assets}")

scale = airsim.Vector3r(1.0, 1.0, 1.0)

# asset_name = random.choice(assets)
asset_name = '1M_Cube_Chamfer'

desired_name = f"{asset_name}_spawn_{random.randint(0, 100)}"
pose = airsim.Pose(position_val=airsim.Vector3r(5.0, 0.0, 0.0))

obj_name = client.simSpawnObject(desired_name, asset_name, pose, scale, True)

print(f"Created object {obj_name} from asset {asset_name} "
f"at pose {pose}, scale {scale}")

all_objects = client.simListSceneObjects()
if obj_name not in all_objects:
print(f"Object {obj_name} not present!")

time.sleep(30.0)

print(f"Destroying {obj_name}")
client.simDestroyObject(obj_name)

0 comments on commit f6bd9c4

Please sign in to comment.