def setup_lidar(mountpoint='roof'):
    lidar = Lidar()
    if mountpoint == 'hood':
        lidar.__init__(offset=(-0.4, 1, 1.0),
                       direction=(-0.707, -0.707, 0),
                       vres=2,
                       vangle=0.1,
                       rps=10000,
                       hz=20,
                       angle=180,
                       max_dist=200,
                       visualized=True)
    else:
        lidar.__init__(offset=(0, 0, 1.7),
                       direction=(-0.707, -0.707, -0.0625),
                       vres=2,
                       vangle=0.1,
                       rps=10000,
                       hz=20,
                       angle=180,
                       max_dist=200,
                       visualized=True)
    return lidar
Example #2
0
def setup_lidar(mountpoint='roof'):
    lidar = Lidar()
    if mountpoint == 'hood':
        #lidar.__init__(offset=(-0.3, 1.0, 1.0), direction=(-0.707, -0.707, 0), vres=2,
        #lidar.__init__(offset=(-5, 0, 1.0), direction=(-0.707, -0.707, 0), vres=2,
        lidar.__init__(offset=(2.4, 1, 1),
                       direction=(-0.707, -0.707, 0),
                       vres=2,
                       vangle=0.1,
                       rps=10000,
                       hz=60,
                       angle=180,
                       max_dist=200,
                       visualized=True)
    elif mountpoint == 'roof':
        lidar.__init__(offset=(0, 0, 1.7),
                       direction=(-0.707, -0.707, -0.0625),
                       vres=3,
                       vangle=0.1,
                       rps=100000,
                       hz=20,
                       angle=180,
                       max_dist=200,
                       visualized=True)
    elif mountpoint == 'orig':
        lidar.__init__(offset=(0, 0, 1.7),
                       direction=(0, -1, 0),
                       vres=32,
                       vangle=26.9,
                       rps=2200000,
                       hz=20,
                       angle=360,
                       max_dist=200,
                       visualized=True)
    else:
        print("returning lidar")
        return lidar
    return lidar
Example #3
0
import mmap
def main():
    global sp
    setup_logging()

    beamng = BeamNGpy('localhost', 64256, home='H:/BeamNG.research.v1.7.0.1clean')
    scenario = Scenario('west_coast_usa', 'lidar_tour',
                        description='Tour through the west coast gathering '
                                    'Lidar data')

    vehicle = Vehicle('ego_vehicle', model='etk800', licence='LIDAR', color='Red')
    lidar = Lidar()
    lidar.__init__(offset=(0, 0, 1.7), direction=(-0.707, -0.707, 0), vres=32,
                   vangle=0.01, rps=2200000, hz=20, angle=360, max_dist=200,
                   visualized=True)
    vehicle.attach_sensor('lidar', lidar)
    ego_sp = spawn_point(sp)
    ego_pos = ego_sp['pos']
    ego_rot_quat = ego_sp['rot_quat']
    scenario.add_vehicle(vehicle, pos=ego_pos, rot=None, rot_quat=ego_rot_quat)
    tvs = traffic_vehicles()
    #ps = [(-722.121, 103, 118.675), (-714.121, 101, 118.675), (-715.121, 105, 118.675), (-721.121, 100, 118.675)]
    ps = [(ego_pos[0]-10, ego_pos[1]+2, ego_pos[2]),
          (ego_pos[0]-10, ego_pos[1]-2, ego_pos[2]),
          (ego_pos[0]-14, ego_pos[1]+5, ego_pos[2]),
          (ego_pos[0]+5, ego_pos[1]-1, ego_pos[2]),
          (ego_pos[0]+8, ego_pos[1]-4, ego_pos[2]),
          (ego_pos[0]+10, ego_pos[1]+9, ego_pos[2]),
          (ego_pos[0]+1, ego_pos[1]+11, ego_pos[2])]
    ps1 = [(ego_pos[0] - 10, ego_pos[1] + 3, ego_pos[2]),
          (ego_pos[0] - 10, ego_pos[1] - 1, ego_pos[2]),
          (ego_pos[0] - 14, ego_pos[1] + 5, ego_pos[2]),
          (ego_pos[0] + 5, ego_pos[1] - 1, ego_pos[2]),
          (ego_pos[0] + 8, ego_pos[1] - 4, ego_pos[2]),
          (ego_pos[0] + 10, ego_pos[1] + 9, ego_pos[2]),
          (ego_pos[0] + 1, ego_pos[1] + 11, ego_pos[2])]
    ps_oldorig = [(ego_pos[0]-7, ego_pos[1]+3, ego_pos[2]),
          (ego_pos[0]+5, ego_pos[1]-1, ego_pos[2]),
          (ego_pos[0]+4, ego_pos[1]+5, ego_pos[2]),
          (ego_pos[0]+5, ego_pos[1]-1, ego_pos[2]),
          (ego_pos[0]+8, ego_pos[1]-4, ego_pos[2]),
          (ego_pos[0]+10, ego_pos[1]+9, ego_pos[2]),
          (ego_pos[0]+1, ego_pos[1]+11, ego_pos[2])]
    for i in range(len(tvs)):
        scenario.add_vehicle(tvs[i], pos=ps[i], rot_quat=ego_rot_quat)
    scenario.make(beamng)
    bng = beamng.open(launch=True)

    try:
        bng.load_scenario(scenario)
        bng.set_steps_per_second(60)
        bng.set_deterministic()
        bng.hide_hud()
        bng.start_scenario()
        vehicle.ai_set_mode('traffic')
        vehicle.ai_drive_in_lane(True)
        #vehicle.ai_set_speed(16, mode='limit')
        #vehicle.ai_set_target('traffic')
        vehicle.ai_set_aggression(0.5) #0.7)
        bng.start_traffic(tvs)
        bng.switch_vehicle(vehicle)

        start = time.time()
        end = time.time()
        damage_prev = bng.poll_sensors(vehicle)
        with open('lidar_data.csv', 'w') as f:
            for _ in range(1024):
                sensors = bng.poll_sensors(vehicle)
                points = sensors['lidar']['points']
                #print(points.tolist())
                #print()
                #f.write("{}\n".format(points.tolist()))

                print("Time passed since last step: {}".format(time.time() - end))
                end = time.time()
                print("Time passed since scenario begun: {}\n".format(end - start))
                if end - start >= 30:
                    bng.close()

                bng.step(30, wait=False)

    except Exception as e:
        print(e)
    finally:
        bng.close()