def test_orientation_sensor_after_teleport(): """Make sure that the orientation sensor correctly updates after using a teleport command to rotate the agent """ binary_path = holodeck.packagemanager.get_binary_path_for_package( "DefaultWorlds") with holodeck.environments.HolodeckEnvironment(scenario=base_cfg, binary_path=binary_path, show_viewport=False, uuid=str( uuid.uuid4())) as env: for _ in range(10): env.tick() loc = [123, 3740, 1030] rot_deg = np.array([0, 90, 0]) env.teleport("sphere0", loc, rot_deg) state = env.tick() sensed_orientation = state["OrientationSensor"] accurate_or = np.zeros((3, 3)) accurate_or[0, 2] = 1 accurate_or[1, 1] = -1 accurate_or[2, 0] = -1 assert almost_equal(accurate_or, sensed_orientation), \ "Expected orientation did not match the expected orientation!"
def test_range_finder_sensor_falling(): """Makes sure that the range sensor updates as the UAV falls, and after it comes to a rest. """ binary_path = holodeck.packagemanager.get_binary_path_for_package("DefaultWorlds") with holodeck.environments.HolodeckEnvironment(scenario=uav_config, binary_path=binary_path, show_viewport=False, uuid=str(uuid.uuid4())) as env: last_range = env.tick()["RangeFinderSensor"][0] for _ in range(10): new_range = env.tick(4)["RangeFinderSensor"][0] assert new_range < last_range, "UAV's range sensor did not detect falling!" last_range = new_range # Give the UAV time to bounce and settle env.tick(80) # Make sure it is stationary now last_range = env.tick()["RangeFinderSensor"][0] new_range = env.tick()["RangeFinderSensor"][0] assert almost_equal(last_range, new_range), "The UAV did not seem to settle!"
def test_location_sensor_falling(): """Makes sure that the location sensor updates as the UAV falls, and after it comes to a rest """ cfg = deepcopy(uav_config) # Spawn the UAV 10 meters up cfg["agents"][0]["location"] = [0, 0, 10] binary_path = holodeck.packagemanager.get_binary_path_for_package( "DefaultWorlds") with holodeck.environments.HolodeckEnvironment(scenario=cfg, binary_path=binary_path, show_viewport=False, uuid=str( uuid.uuid4())) as env: last_location = env.tick()["LocationSensor"] for _ in range(85): new_location = env.tick()["LocationSensor"] assert new_location[2] < last_location[ 2], "UAV's location sensor did not detect falling!" last_location = new_location # Give the UAV time to bounce and settle for _ in range(80): env.tick() # Make sure it is stationary now last_location = env.tick()["LocationSensor"] new_location = env.tick()["LocationSensor"] assert almost_equal(last_location, new_location), "The UAV did not seem to settle!"
def test_location_sensor_after_teleport(): """Make sure the location sensor updates after a teleport. Also verifies that the coordinates for the teleport command match the coordinates used by the location sensor """ binary_path = holodeck.packagemanager.get_binary_path_for_package( "DefaultWorlds") with holodeck.environments.HolodeckEnvironment(scenario=sphere_config, binary_path=binary_path, show_viewport=False, uuid=str( uuid.uuid4())) as env: for _ in range(10): env.tick() loc = [507, 301, 1620] env.agents['sphere0'].teleport(loc, [0, 0, 0]) state = env.tick() sensed_loc = state["LocationSensor"] assert almost_equal( loc, sensed_loc), "Sensed location did not match the expected location!"
def test_sim_physics_prop(): """Tests whether spawning a sphere with simulated physics creates a sphere that falls and rams the agent. """ binary_path = holodeck.packagemanager.get_binary_path_for_package( "DefaultWorlds") with holodeck.environments.HolodeckEnvironment(scenario=uav_config, binary_path=binary_path, show_viewport=False, uuid=str( uuid.uuid4())) as env: env.agents["uav0"].teleport([0, 0, .1]) # get the initial location after the uav has settled init_location = env.tick(20)["LocationSensor"] # spawn a ball to fall on top of the agent env.spawn_prop("sphere", location=[0, 0.1, 3], scale=3, sim_physics=True) # get the final location after the uav has been knocked over final_location = env.tick(100)["LocationSensor"] assert not almost_equal(init_location, final_location), "Uav \
def test_rotation_sensor_after_teleport(): """Make sure that the rotation sensor correctly updates after using a teleport command to rotate the agent """ binary_path = holodeck.packagemanager.get_binary_path_for_package( "DefaultWorlds") with holodeck.environments.HolodeckEnvironment(scenario=base_cfg, binary_path=binary_path, show_viewport=False, uuid=str( uuid.uuid4())) as env: for _ in range(10): env.tick() loc = [123, 3740, 1030] rot_deg = np.array([0, 90, 0]) env.teleport("sphere0", loc, rot_deg) rotation = env.tick()["RotationSensor"] assert almost_equal( rot_deg, rotation), "The agent rotated in an unexpected manner!"
def test_static_prop(): """Tests whether spawning a box without sim_physics creates a static box that keeps the agent from falling. """ binary_path = holodeck.packagemanager.get_binary_path_for_package( "DefaultWorlds") with holodeck.environments.HolodeckEnvironment(scenario=uav_config, binary_path=binary_path, show_viewport=False, uuid=str( uuid.uuid4())) as env: # spawn a platform for the uav to rest on env.spawn_prop("box", location=[0, 0, 4.5], scale=[5, 5, 0.5]) # get the initial location after the uav has settled init_location = env.tick(10)["LocationSensor"] # get the final location final_location = env.tick(50)["LocationSensor"] assert almost_equal(init_location, final_location), "Uav \