def main(): client = airsim.UrdfBotClient() print('Building request...') position = at.Vector3r(x_val = 0, y_val = 0, z_val = 100) direction = at.Vector3r(x_val = 0, y_val = 0, z_val = -100) through_blocking = True persist_seconds = 100 reference_frame_link = '' request = at.RayCastRequest(position, direction, reference_frame_link, through_blocking, persist_seconds) print('Casting ray') response = client.simRayCast(request) print('Response:') print('{0} hits.'.format(len(response['hits']))) for i in range(0, len(response['hits']), 1): hit = response['hits'][i] print('=================') print('hit {0}'.format(i)) print('collided actor: {0}'.format(hit['collided_actor_name'])) print('hit_point: <{0}, {1}, {2}>'.format(hit['hit_point']['x_val'], hit['hit_point']['y_val'], hit['hit_point']['z_val'])) print('hit normal: <{0}, {1}, {2}>'.format(hit['hit_normal']['x_val'], hit['hit_normal']['y_val'], hit['hit_normal']['z_val'])) print('=================') print('') print('Graceful termination.')
def __init__(self): self.airsim_client = airsim.UrdfBotClient() self.airsim_client.confirmConnection() self.airsim_client.enableApiControl(True) self.__front_wheel_force_name = 'front_wheel_force' self.__back_wheel_force_name = 'back_wheel_force' self.__sideways_force_name = 'sideways_force' self.__actuator_name = 'base_to_linear_actuated' self.__servo_name = 'linear_actuated_to_servo' self.__wheel_speed = 50.0 self.__sideways_force_mag = 10000.0 #Add forces front_wheel_angular_force = at.AddAngularForce( force_name_val=self.__front_wheel_force_name, link_name_val='front_cyl', axis_val=at.Vector3r(x_val=0, y_val=1, z_val=0)) back_wheel_angular_force = at.AddAngularForce( force_name_val=self.__back_wheel_force_name, link_name_val='back_cyl', axis_val=at.Vector3r(x_val=0, y_val=1, z_val=0)) sideways_force_name = at.AddLinearForce( force_name_val=self.__sideways_force_name, link_name_val='base_link', application_point_val=at.Vector3r(x_val=0, y_val=0, z_val=0.5), axis_val=at.Vector3r(x_val=0, y_val=1, z_val=0)) self.airsim_client.addAngularForce(front_wheel_angular_force) self.airsim_client.addAngularForce(back_wheel_angular_force) self.airsim_client.addLinearForce(sideways_force_name)
def main(): client = airsim.UrdfBotClient() print('Building shape request...') dsr = at.DrawableShapeRequest(shapes={}, persist_unmentioned=True) reference_frame_link = '' dsr = client.addDrawableShapePoint(dsr, 'point', reference_frame_link, 3, 0, 0, 1, 255, 0, 0, 0) dsr = client.addDrawableShapeSphere(dsr, 'sphere', reference_frame_link, 5, 0, 0, 1, 3, 64, 0, 255, 0, 0) dsr = client.addDrawableShapeCircle(dsr, 'circle', reference_frame_link, 0, 0, 5, 0, 1, 0, 1, 3, 64, 0, 0, 255, 0) dsr = client.addDrawableShapeBox(dsr, 'box', reference_frame_link, 0, -3, 0, 1, 2, 1, 10, 255, 255, 0, 0) dsr = client.addDrawableShapeLine(dsr, 'line', reference_frame_link, 1, 1, 1, 5, 5, 5, 1, 0, 255, 255, 0) print('Sending request') client.simSetDrawableShapes(dsr) print('Waiting...') time.sleep(2) print('Changing color of the sphere') dsr2 = at.DrawableShapeRequest(shapes={}, persist_unmentioned=True) dsr2 = client.addDrawableShapeSphere(dsr2, 'sphere', reference_frame_link, 5, 0, 0, 1, 3, 64, 255, 0, 255, 0) print('Sending request') client.simSetDrawableShapes(dsr2) print('Waiting...') time.sleep(2) print('Dropping all but the sphere') dsr3 = at.DrawableShapeRequest(shapes={}, persist_unmentioned=False) dsr3 = client.addDrawableShapeSphere(dsr3, 'sphere', reference_frame_link, 5, 0, 0, 1, 3, 64, 255, 0, 0, 0) print('Sending request') client.simSetDrawableShapes(dsr3) print('Waiting...') time.sleep(2) print('Dropping all') dsr4 = at.DrawableShapeRequest() print('Sending request') client.simSetDrawableShapes(dsr4) print('Graceful termination')
def __init__(self, wheel_base, wheel_radius, max_speed): self.airsim_client = airsim.UrdfBotClient() self.airsim_client.confirmConnection() self.airsim_client.enableApiControl(True) self.wheel_base = wheel_base self.wheel_radius = wheel_radius self.max_speed = max_speed self.right_wheel_joint_name = 'base_rwheel' self.left_wheel_joint_name = 'base_lwheel' self.pi = 3.1415926535
def __init__(self): self.airsim_client = airsim.UrdfBotClient() self.airsim_client.confirmConnection() self.airsim_client.enableApiControl(True) self.platform_joint_name = 'base_to_platform' self.first_joint_name = 'platform_to_base_sphere' self.second_joint_name = 'first_link_to_first_link_sphere' self.third_joint_name = 'second_link_to_second_link_sphere' self.fourth_joint_name = 'second_link_sphere_to_final_link' self.manipulator_left_joint_name = 'manipulator_base_to_left_manipulator' self.manipulator_right_joint_name = 'manipulator_base_to_right_manipulator'
def main(): client = airsim.UrdfBotClient() random.seed(42) print('Reading annotations...') annotations = annotations_common.map_annotation.MapAnnotation( client, 'three_bridges_annotations/three_bridges_annotations.json') drawable_shape_request = at.DrawableShapeRequest(shapes={}, persist_unmentioned=True) print('Drawing directed paths...') for key in annotations.annotations[ annotations.DIRECTED_PATH_ANNOTATION_TYPE]: drawable_shape_request = add_annotated_path( annotations.annotations[annotations.DIRECTED_PATH_ANNOTATION_TYPE] [key], drawable_shape_request, client) print('Drawing points of interest...') for key in annotations.annotations[annotations.POI_ANNOTATION_TYPE]: drawable_shape_request = add_annotated_poi( annotations.annotations[annotations.POI_ANNOTATION_TYPE][key], drawable_shape_request, client) print('Drawing polygons...') for key in annotations.annotations[annotations.POLYGON_ANNOTATION_TYPE]: drawable_shape_request = add_annotated_polygon( annotations.annotations[annotations.POLYGON_ANNOTATION_TYPE][key], drawable_shape_request, client) print('Drawing maze bounds...') for key in annotations.annotations[annotations.MAZE_ANNOTATION_TYPE]: drawable_shape_request = add_maze_bounds( annotations.annotations[annotations.MAZE_ANNOTATION_TYPE][key], drawable_shape_request, client) print('Sending draw request...') client.simSetDrawableShapes(drawable_shape_request) print('Creating maze grid image...') maze_grid = annotations.annotations[ annotations.MAZE_ANNOTATION_TYPE]['MazeAnnotations'].grid fig = plt.figure(figsize=(10, 10)) plt.title('Visual representation of maze occupancy matrix.') plt.imshow(maze_grid, cmap='cool') plt.show() print('Done!')
def main(): client = airsim.UrdfBotClient() random.seed(42) cone_class_name = "/Game/StarterContent/Props/SM_Couch.SM_Couch" xs = [0, 0.1] ys = [0, 0.1] time_stamp = 0 for i in range(0, 3, 1): xs.append(random.randint(0, 10)) ys.append(random.randint(0, 10)) for i in range(0, len(xs), 1): x = xs[i] y = ys[i] random_position = at.Vector3r(x_val=x, y_val=y, z_val=5) random_orientation = at.Quaternionr(x_val=0, y_val=0, z_val=0, w_val=1) random_pose = at.Pose(position_val=random_position, orientation_val=random_orientation) print('Spawning cone at ({0}, {1})...'.format(x, y)) client.simSpawnStaticMeshObject(cone_class_name, 'cone_{0}'.format(i), random_pose) time.sleep(2) ci = client.simGetCollisionInfo() if (ci.has_collided and ci.time_stamp > time_stamp): print('\tBot has collided with {0}.'.format(ci.object_name)) time_stamp = ci.time_stamp else: print('\tBot has not collided.') time.sleep(3) for i in range(0, len(xs), 1): cone_name = 'cone_{0}'.format(i) cone_pose = client.simGetObjectPose(cone_name) print('Cone "{0}" is at position <{1}, {2}, {3}>'.format(cone_name, cone_pose.position.x_val, cone_pose.position.y_val, cone_pose.position.z_val)) time.sleep(3) for i in range(0, len(xs), 1): cone_name = 'cone_{0}'.format(i) print('Deleting cone {0}...'.format(cone_name)) client.simDeleteObject(cone_name) print('Graceful termination')
def main(): client = airsim.UrdfBotClient() print('Testing X') setPose(2, 0, 0, 0, 0, 0, client) time.sleep(2) setPose(-2, 0, 0, 0, 0, 0, client) time.sleep(2) print('Testing Y') setPose(0, 2, 0, 0, 0, 0, client) time.sleep(2) setPose(0, -2, 0, 0, 0, 0, client) time.sleep(2) print('Testing Z') setPose(0, 0, 2, 0, 0, 0, client) time.sleep(2) setPose(0, 0, -2, 0, 0, 0, client) time.sleep(2) print('Testing Yaw') setPose(0, 0, 2, 45, 0, 0, client) time.sleep(2) setPose(0, 0, 2, -45, 0, 0, client) time.sleep(2) print('Testing Pitch') setPose(0, 0, 2, 0, 45, 0, client) time.sleep(2) setPose(0, 0, 2, 0, -45, 0, client) time.sleep(2) print('Testing Roll') setPose(0, 0, 2, 0, 0, 45, client) time.sleep(2) setPose(0, 0, 2, 0, 0, -45, client) time.sleep(2) print('Graceful Termination')