Example #1
0
    def __init__(self):
        '''
        initialize class
        '''
        self.config = None

        client, world = util.link_server()
        self.client = client
        self.world = world
        self.blueprint_library = world.get_blueprint_library()

        self.tm = client.get_trafficmanager()
        self.tm.set_synchronous_mode(True)  #needed for v0.9.11
        self.tm.set_hybrid_physics_mode(True)
        self.tm.set_global_distance_to_leading_vehicle(1)
        self.tm.global_percentage_speed_difference(
            AUTOPILOT_SPEED_PERCENT_DIFFERENCE)

        world.constant_velocity_enabled = True

        #actor id containers
        self.cars_list = []
        self.peds_list = []
        self.ai_list = []
        self.target_list = []
Example #2
0
def simple_spawn(search=None):
    '''simple spawn of a car and camera'''
    #connect to client and retrieve world
    client, world = util.link_server()

    #get blueprints
    blueprint_library = world.get_blueprint_library()

    #select vehicle blueprint
    if search == None:
        search = 'vehicle.lincoln.*'
    vehicles = blueprint_library.filter(search)
    car_bp = vehicles[0]
    #car_bp.set_attribute('color','255,20,147')
    # car_bp.set_attribute('color','158,255,0')

    #select camera blueprint, set location
    cam_bp = blueprint_library.find('sensor.camera.rgb')
    #sensor update dt
    cam_bp.set_attribute('sensor_tick', '0.05')
    cam_bp.set_attribute('image_size_x', '1280')
    cam_bp.set_attribute('image_size_y', '720')
    cam_trans = carla.Transform(carla.Location(x=-5, z=2.5),
                                carla.Rotation(pitch=-10))

    #spawn vehicle and camera
    spawn_points = world.get_map().get_spawn_points()
    sp = spawn_points[27]

    car = world.spawn_actor(car_bp, sp)
    camera = world.spawn_actor(cam_bp, cam_trans, attach_to=car)
    #camera = world.try_spawn_actor(cam_bp, cam_trans, attach_to=car, attachment_type=carla.AttachmentType.SpringArm)
    print('Spawned car and spectator camera')

    return car, camera
Example #3
0
def spawn_3cam(car, img_x=200, img_y=88, yaw_deg=20, hz=0.2):
    '''
    spawn 3 cameras in same location on car with yaw offset
    yaw_deg is absolute angle between each side cam and car symmetry plane
    returns a list of 3 camera objects
    '''
    client, world = util.link_server()

    #get bp
    cam_bp = world.get_blueprint_library().find('sensor.camera.rgb')

    #set refresh rate, size (same between all)
    cam_bp.set_attribute('sensor_tick', str(hz))
    cam_bp.set_attribute('image_size_x', str(img_x))
    cam_bp.set_attribute('image_size_y', str(img_y))

    #calculate rotated camera location
    center_cam_x = 2.2
    center_cam_y = 0
    center_cam_z = 1
    rotated_x, rotated_y = util.rotz(center_cam_x, center_cam_y, yaw_deg)

    #chassis coordinate system is right hand
    #carla world coord is left hand
    #spawn left cam
    relative_loc = carla.Location(x=rotated_x, y=-rotated_y, z=center_cam_z)
    relative_rot = carla.Rotation(yaw=-yaw_deg, pitch=-8)
    cam_trans = carla.Transform(relative_loc, relative_rot)
    left = world.spawn_actor(cam_bp, cam_trans, attach_to=car)

    #spawn center cam
    relative_loc = carla.Location(x=center_cam_x, z=center_cam_z)
    relative_rot = carla.Rotation(yaw=0, pitch=-8)
    cam_trans = carla.Transform(relative_loc, relative_rot)
    center = world.spawn_actor(cam_bp, cam_trans, attach_to=car)

    #spawn right cam
    relative_loc = carla.Location(x=rotated_x, y=rotated_y, z=center_cam_z)
    relative_rot = carla.Rotation(yaw=yaw_deg, pitch=-8)
    cam_trans = carla.Transform(relative_loc, relative_rot)
    right = world.spawn_actor(cam_bp, cam_trans, attach_to=car)

    return [left, center, right]
Example #4
0
def simple_kill():
    #simple removal of ONE earliest spawned actor and sensor
    client, world = util.link_server()
    #get list of vehicle and sensor actors
    carlist = world.get_actors().filter('vehicle.*')
    sensorlist = world.get_actors().filter('sensor.*')

    if (len(carlist) != 0):
        #if there is at least one car
        print('cars to be removed:')
        print(carlist[0])
        carlist[0].destroy()
    else:
        print('no cars found on server')
    print('')

    if (len(sensorlist) != 0):
        #if there is at least one sensor
        print('sensors to be removed:')
        print(sensorlist[0])
        sensorlist[0].destroy()
    else:
        print('no sensors found on server')
    print('')
Example #5
0
def spawn_ss(car=None, world=None, img_x=200, img_y=88, hz=7.463, pitch=-8):
    '''Spawns sensor on a car. Input is a vehicle actor object'''
    if world == None:
        client, world = util.link_server()

    #get camera blueprint
    blueprints = world.get_blueprint_library()
    cam_bp = blueprints.find('sensor.camera.semantic_segmentation')

    #set refresh rate, image size, and location on car
    if hz == 0:
        cam_bp.set_attribute('sensor_tick', str(0))
    else:
        cam_bp.set_attribute('sensor_tick', str(1.0 / hz))
    cam_bp.set_attribute('image_size_x', str(img_x))
    cam_bp.set_attribute('image_size_y', str(img_y))
    relative_loc = carla.Location(x=2, z=1.4)
    relative_rot = carla.Rotation(pitch=pitch)
    cam_trans = carla.Transform(relative_loc, relative_rot)

    #spawn camera
    camera = world.spawn_actor(cam_bp, cam_trans, attach_to=car)
    print("Spawned semantic segmentation camera sensor")
    return camera
Example #6
0

map_name = ""

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument('-cr', '--car-radius', type=int, default=70)
    parser.add_argument('-cn', '--car-num', type=int, default=10)
    parser.add_argument('-es', '--ego-spawn', type=int, default=0)
    parser.add_argument('-fn', '--front-num', type=int, default=0)
    parser.add_argument('-rn', '--rear-num', type=int, default=0)
    parser.add_argument('-pn', '--ped-num', type=int, default=4)
    parser.add_argument('-pr', '--ped-radius', type=int, default=30)
    args = parser.parse_args()

    client, world = util.link_server()
    map = world.get_map()
    map_name = map.name
    bpl = world.get_blueprint_library()
    sp = map.get_spawn_points()[args.ego_spawn]

    util.top_down(sp, world)

    r = args.car_radius
    num_cars = args.car_num
    num_peds = args.ped_num
    #put ego spawn waypoint in wps list so no npc spawn there
    car_wps = [map.get_waypoint(sp.location)]
    car_wps = generate_front_back_wp(sp, map, args.front_num,args.rear_num,15, car_wps)
    car_wps = generate_npc_car_wp(sp, map, r, num_cars, car_wps)