def getStaticScenario(testName): beamng = BeamNGpy('localhost', 64256, home=getBeamngDirectory() ) # This is the host & port used to communicate over staticScenario = Scenario('smallgrid', str(testName)) testVehicle = Vehicle('Test_Vehicule', model=SelectCar(), licence='LIFLAB', colour='Blue') # Create an Electrics sensor and attach it to the vehicle electrics = Electrics() testVehicle.attach_sensor('electrics', electrics) # Create a Damage sensor and attach it to the vehicle if module is selected damage = Damage() testVehicle.attach_sensor('damage', damage) # Create a Gforce sensor and attach it to the vehicle if module is selected gForce = GForces() testVehicle.attach_sensor('GForces', gForce) staticScenario.add_vehicle(testVehicle, (0, 0, 0), (0, 0, -90)) scenarioDict = { 'beamng': beamng, 'scenario': staticScenario, 'vehicule': testVehicle } return scenarioDict
def setup_sensors(self, vehicle): # Set up sensors pos = (-0.3, 1, 1.0) direction = (0, 0.75, 0) #(0, 0.75, -1.5) #(0, 0.75, 0) #(0,1,0) fov = 120 resolution = (512, 512) front_camera = Camera(pos, direction, fov, resolution, colour=True, depth=True, annotation=True) pos = (0.0, 3, 1.0) direction = (0, -1, 0) fov = 90 resolution = (512, 512) back_camera = Camera(pos, direction, fov, resolution, colour=True, depth=True, annotation=True) gforces = GForces() electrics = Electrics() damage = Damage() #lidar = Lidar(visualized=False) timer = Timer() # Attach them vehicle.attach_sensor('front_cam', front_camera) vehicle.attach_sensor('back_cam', back_camera) vehicle.attach_sensor('gforces', gforces) vehicle.attach_sensor('electrics', electrics) vehicle.attach_sensor('damage', damage) vehicle.attach_sensor('timer', timer) return vehicle
def getSquareRoadScenario(): beamng = BeamNGpy('localhost', 64256, home=getBeamngDirectory() ) # This is the host & port used to communicate over squareRoadScenario = Scenario('smallgrid', 'Straight_Foward_Test') testRoad = Road('track_editor_C_center', rid='Test_Road', looped=True) roadNode = [(0, 0, 0, 7), (250, 0, 0, 7), (250, 250, 0, 7), (0, 250, 0, 7)] testRoad.nodes.extend(roadNode) testVehicle = Vehicle('Test_Vehicule', model='etkc', licence='LIFLAB', colour='Blue') # Create an Electrics sensor and attach it to the vehicle electrics = Electrics() testVehicle.attach_sensor('electrics', electrics) # Create a Damage sensor and attach it to the vehicle if module is selected damage = Damage() testVehicle.attach_sensor('damage', damage) # Create a Gforce sensor and attach it to the vehicle if module is selected gForce = GForces() testVehicle.attach_sensor('GForces', gForce) squareRoadScenario.add_road(testRoad) squareRoadScenario.add_vehicle(testVehicle, pos=(0, 0, 0), rot=(0, 0, -90)) scenarioDict = { 'beamng': beamng, 'scenario': squareRoadScenario, 'vehicule': testVehicle } return scenarioDict
def setup_sensors(vehicle, pos=(-0.5, 0.38, 1.3), direction=(0, 1.0, 0)): # Set up sensors # pos = (-0.3, 1, 1.0) # default #pos = (-0.5, 2, 1.0) #center edge of hood # pos = (-0.5, 1, 1.0) # center middle of hood # pos = (-0.5, 0.4, 1.0) # dashboard # pos = (-0.5, 0.38, 1.5) # roof # pos = (-0.5, 0.38, 1.3) # windshield # direction = (0, 1.0, 0) fov = 50 resolution = (200, 150) #(1280,960) #(512, 512) front_camera = Camera(pos, direction, fov, resolution, colour=True, depth=True, annotation=True) gforces = GForces() electrics = Electrics() damage = Damage() timer = Timer() # Attach them vehicle.attach_sensor('front_cam', front_camera) vehicle.attach_sensor('gforces', gforces) vehicle.attach_sensor('electrics', electrics) vehicle.attach_sensor('damage', damage) vehicle.attach_sensor('timer', timer) return vehicle
def create_vehicle(vehicle_objs): vehicles = [] for v in vehicle_objs: # Creates vehicle with associated id and attaches damage sensor to each vehicle vehicle = Vehicle(str(v.id)) damage = Damage() vehicle.attach_sensor('damage', damage) # Attach Sensor vehicles.append(vehicle) return vehicles
def __init__(self, host='localhost', port=64256): self.steps = WCARaceGeometry.sps // WCARaceGeometry.rate self.host = host self.port = port self.action_space = self._action_space() self.observation_space = self._observation_space() self.episode_steps = 0 self.spine = None self.l_edge = None self.r_edge = None self.polygon = None front_factor = WCARaceGeometry.front_dist / WCARaceGeometry.front_step trail_factor = WCARaceGeometry.trail_dist / WCARaceGeometry.trail_step self.front = lambda step: +front_factor * step self.trail = lambda step: -trail_factor * step self.bng = BeamNGpy(self.host, self.port) self.vehicle = Vehicle('racecar', model='sunburst', licence='BEAMNG', colour='red', partConfig='vehicles/sunburst/hillclimb.pc') electrics = Electrics() damage = Damage() self.vehicle.attach_sensor('electrics', electrics) self.vehicle.attach_sensor('damage', damage) scenario = Scenario('west_coast_usa', 'wca_race_geometry_v0') scenario.add_vehicle(self.vehicle, pos=(394.5, -247.925, 145.25), rot=(0, 0, 90)) scenario.make(self.bng) self.bng.open(launch=True) self.bng.set_deterministic() self.bng.set_steps_per_second(WCARaceGeometry.sps) self.bng.load_scenario(scenario) self._build_racetrack() self.observation = None self.last_observation = None self.last_spine_proj = None self.bng.start_scenario() self.bng.pause()
def setup_sensors(vehicle): # Set up sensors # pos = (-0.3, 1, 1.0) # default pos = (-0.5, 2, 1.0) #center edge of hood # pos = (-0.5, 1, 1.0) # center middle of hood # pos = (-0.5, 0.4, 1.0) # dashboard # pos = (-0.5, 0.38, 1.5) # roof # pos = (-0.5, 0.38, 1.1) # windshield pos = (-0.5, 0.38, 1.3) # windshield # direction = (0, 1, 0) direction = (0, 1.0, 0) fov = 50 resolution = (1280, 960) #(512, 512) front_camera = Camera(pos, direction, fov, resolution, colour=True, depth=True, annotation=True) pos = (-0.5, 0.38, 1.1) # windshield direction = (0, 1, 0) fov = 120 resolution = (512, 512) back_camera = Camera(pos, direction, fov, resolution, colour=True, depth=True, annotation=True) gforces = GForces() electrics = Electrics() damage = Damage() #lidar = Lidar(visualized=False) timer = Timer() # Attach them # vehicle.attach_sensor('headlight_cam', front_camera) vehicle.attach_sensor('front_cam', front_camera) vehicle.attach_sensor('windshield_cam', back_camera) vehicle.attach_sensor('gforces', gforces) vehicle.attach_sensor('electrics', electrics) vehicle.attach_sensor('damage', damage) vehicle.attach_sensor('timer', timer) return vehicle
def getWallCrashScenario(testName): beamng = BeamNGpy('localhost', 64256, home=getBeamngDirectory() ) # This is the host & port used to communicate over wallCrashScenario = Scenario('smallgrid', str(testName)) wall = StaticObject( name="Crash_Test_Wall", pos=(420, 0, 0), rot=(0, 0, 0), scale=(1, 10, 75), shape='/levels/smallgrid/art/shapes/misc/gm_alpha_barrier.dae') testRoad = Road('track_editor_B_center', rid='Test_Road') roadNode = [(-2, 0, 0, 7), (420, 0, 0, 7)] testRoad.nodes.extend(roadNode) testVehicle = Vehicle('Test_Vehicule', model=SelectCar(), licence='LIFLAB', colour='Blue') # Create an Electrics sensor and attach it to the vehicle electrics = Electrics() testVehicle.attach_sensor('electrics', electrics) # Create a Damage sensor and attach it to the vehicle if module is selected damage = Damage() testVehicle.attach_sensor('damage', damage) # Create a Gforce sensor and attach it to the vehicle if module is selected gForce = GForces() testVehicle.attach_sensor('GForces', gForce) wallCrashScenario.add_road(testRoad) wallCrashScenario.add_object(wall) wallCrashScenario.add_vehicle(testVehicle, pos=(0, 0, 0), rot=(0, 0, -90)) scenarioDict = { 'beamng': beamng, 'scenario': wallCrashScenario, 'vehicule': testVehicle } return scenarioDict
def __init__(self, vehicle: Vehicle, beamng: BeamNGpy, additional_sensors: List[Tuple[str, Sensor]] = None): self.vehicle = vehicle self.beamng = beamng self.state: VehicleState = None self.vehicle_state = {} gforces = GForces() electrics = Electrics() damage = Damage() timer = Timer() self.vehicle.attach_sensor('gforces', gforces) self.vehicle.attach_sensor('electrics', electrics) self.vehicle.attach_sensor('damage', damage) self.vehicle.attach_sensor('timer', timer) if additional_sensors: for (name, sensor) in additional_sensors: self.vehicle.attach_sensor(name, sensor)
def test_damage(beamng): with beamng as bng: scenario = Scenario('smallgrid', 'damage_test') dummy = Vehicle('dummy', model='pickup') scenario.add_vehicle(dummy, pos=(0, 0, 0)) scenario.make(beamng) vehicle = Vehicle('test_car', model='etk800') damage = Damage() vehicle.attach_sensor('damage', damage) bng.load_scenario(scenario) bng.start_scenario() scenario.add_vehicle(vehicle, pos=(0, 0, 32), rot=(-90, 0, 0), cling=False) bng.step(600) vehicle.poll_sensors() assert damage.data['damage'] > 100
from beamngpy.sensors import Electrics, Damage from IPython.display import display # Instantiate a BeamNGpy instance the other classes use for reference & communication beamng = BeamNGpy('localhost', 64256, home='F:\Softwares\BeamNG_Research_SVN' ) # This is the host & port used to communicate over # Create a vehile instance that will be called 'ego' in the simulation # using the etk800 model the simulator ships with vehicle = Vehicle('ego', model='etk800', licence='PYTHON', colour='white') vehicleV = Vehicle('victim', model='etk800', licence='PYTHON', colour='red') # Create an Electrics sensor and attach it to the vehicle electrics = Electrics() vehicle.attach_sensor('electrics', electrics) damage = Damage() vehicle.attach_sensor('damages', damage) # Create a scenario called vehicle_state taking place in the west_coast_usa map the simulator ships with scenario = Scenario('west_coast_usa', 'vehicle_state') # Add the vehicle and specify that it should start at a certain position and orientation. # The position & orientation values were obtained by opening the level in the simulator, # hitting F11 to open the editor and look for a spot to spawn and simply noting down the # corresponding values. scenario.add_vehicle(vehicle, pos=(-727.121, 101, 118.675), rot=(0, 0, 45)) # 45 degree rotation around the z-axis #scenario.add_vehicle(vehicleV,pos=(-707.121, 101, 118.675), rot=(0, 0, 45)) # The make function of a scneario is used to compile the scenario and produce a scenario file the simulator can load scenario.make(beamng)
sns.set() # Instantiate a BeamNGpy instance the other classes use for reference & communication # This is the host & port used to communicate over beamng = BeamNGpy('localhost', 64294) #loads Custom Map scenario = Scenario('Mytest', 'demo') #adding ego Vehicle to the scenario vehicle = Vehicle('ego_vehicle', model='etk800', licence='RED', color='Green') electrics = Electrics() vehicle.attach_sensor('electrics', electrics) damage1 = Damage() vehicle.attach_sensor('damage1', damage1) scenario.add_vehicle(vehicle, pos=(104.647, -1.92827, -3.54338), rot=(0, 0, 90)) #add vehicle as Obstacle vehicle1 = Vehicle('test_vehicle', model='etk800', licence='RED', color='Blue') scenario.add_vehicle(vehicle1, pos=(-9.66595, -90.7465, -3.45737), rot=(0, 0, 180)) scenario.make(beamng) bng = beamng.open() bng.load_scenario(scenario)
nodes0 = [ ( point1[0], point1[1], 0, 8 ), # method to get the road width from elastic search or number of lanes. (forward and backward) (point2[0], point2[1], 0, 8) ] road_a.nodes.extend(nodes0) scenario.add_road(road_a) vehicleStriker = Vehicle('striker', model='etk800', licence='Striker', colour='Yellow') damageStriker = Damage() vehicleStriker.attach_sensor('damagesS', damageStriker) vehicleVictim = Vehicle('victim', model='etk800', licence='Victim', colour='White') damageVictim = Damage() vehicleVictim.attach_sensor('damagesV', damageVictim) # road creation and vehicle initializatoin with sensors completed.------------------------------------------- def getDistance(node_a, node_b): dist = math.sqrt((node_a[1] - node_b[1])**2 + (node_a[0] - node_b[0])**2) return dist
def add_sensor_to(self, vehicle: Vehicle) -> None: from beamngpy.sensors import Damage vehicle.attach_sensor(self.rid, Damage())
def getDonutScenario(): beamng = BeamNGpy('localhost', 64256, home=getBeamngDirectory() ) # This is the host & port used to communicate over donutScenario = Scenario('smallgrid', 'road_test') concreteWallSide1 = StaticObject( name="Crash_Test_Wall", pos=(20, 10, 0), rot=(0, 0, 0), scale=(10, 1, 1), shape= '/levels/driver_training/art/shapes/race/concrete_road_barrier_a.dae') concreteWallSide2 = StaticObject( name="Crash_Test_Wall2", pos=(35, -5, 0), rot=(0, 0, 90), scale=(10, 1, 1), shape= '/levels/driver_training/art/shapes/race/concrete_road_barrier_a.dae') concreteWallSide3 = StaticObject( name="Crash_Test_Wall3", pos=(20, -20, 0), rot=(0, 0, 0), scale=(10, 1, 1), shape= '/levels/driver_training/art/shapes/race/concrete_road_barrier_a.dae') concreteWallSide4 = StaticObject( name="Crash_Test_Wall4", pos=(5, -5, 0), rot=(0, 0, 90), scale=(10, 1, 1), shape= '/levels/driver_training/art/shapes/race/concrete_road_barrier_a.dae') testRoad = Road('track_editor_C_center', rid='Test_Road') roadNode = [(*(-25, 25, 0), 45), (*(15, 25, 0), 45)] testRoad.nodes.extend(roadNode) testVehicle = Vehicle('Test_Vehicule', model='etkc', licence='LIFLAB', colour='Blue') # Create an Electrics sensor and attach it to the vehicle electrics = Electrics() testVehicle.attach_sensor('electrics', electrics) # Create a Damage sensor and attach it to the vehicle if module is selected damage = Damage() testVehicle.attach_sensor('damage', damage) # Create a Gforce sensor and attach it to the vehicle if module is selected gForce = GForces() testVehicle.attach_sensor('GForces', gForce) donutScenario.add_vehicle(testVehicle, pos=(20, 0, 0), rot=(0, 0, 0)) donutScenario.add_object(concreteWallSide1) donutScenario.add_object(concreteWallSide2) donutScenario.add_object(concreteWallSide3) donutScenario.add_object(concreteWallSide4) donutScenario.add_road(testRoad) scenarioDict = { 'beamng': beamng, 'scenario': donutScenario, 'vehicule': testVehicle } return scenarioDict
def create_vehicle(self, vehicles): for i in range(len(vehicles)): vehicle = Vehicle(str(vehicles[i].id), model='etk800') vehicle.attach_sensor('damage', Damage()) self.cars.append(Car(i + 1, vehicle)) # Vehicle name is v1, v2,...
nodesa = [ (30, 0, -4, 4), (0, 0, -4, 4) ] nodesb = [ (0, 30, -4, 4), (0, 0, -4, 4) ] road_a.nodes.extend(nodesa) road_b.nodes.extend(nodesb) vehicleA = Vehicle('ego_vehicle', model='etk800', licence='PYTHON') damageS = Damage(); vehicleA.attach_sensor('damagesS', damageS); scenario.add_vehicle(vehicleA, pos=(30, 0, 0), rot=(0, 0, 90)) vehicleB = Vehicle('victim_vehicle', model='etk800', licence='PYTHON') damageV = Damage(); vehicleB.attach_sensor('damagesV', damageV); scenario.add_vehicle(vehicleB, pos=(0, 30, 0), rot=(0, 0, 0)) scenario.add_road(road_a) scenario.add_road(road_b)
def main(): random.seed(1703) setup_logging() beamng = BeamNGpy('localhost', 64256, home='C:/Users/merie/Documents/BeamNG.research.v1.7.0.1') config = Config() loaded_config = config.load("{}/config.json".format(beamng.home)) # Create a scenario in west_coast_usa scenario = Scenario('west_coast_usa', 'research_test', description='Random driving for research') # Set up first vehicle, with two cameras, gforces sensor, lidar, electrical # sensors, and damage sensors vehicle = Vehicle('ego_vehicle', model='etk800', licence='RED', color='Red') # Set up sensors pos = (-0.3, 1, 1.0) direction = (0, 1, 0) fov = 120 resolution = (512, 512) front_camera = Camera(pos, direction, fov, resolution, colour=True, depth=True, annotation=True) pos = (0.0, 3, 1.0) direction = (0, -1, 0) fov = 90 resolution = (512, 512) back_camera = Camera(pos, direction, fov, resolution, colour=True, depth=True, annotation=True) gforces = GForces() electrics = Electrics() damage = Damage() lidar = Lidar(visualized=False) timer = Timer() # Attach them vehicle.attach_sensor('front_cam', front_camera) vehicle.attach_sensor('back_cam', back_camera) vehicle.attach_sensor('gforces', gforces) vehicle.attach_sensor('electrics', electrics) vehicle.attach_sensor('damage', damage) vehicle.attach_sensor('timer', timer) #scenario.add_vehicle(vehicle, pos=(-717.121, 101, 118.675), rot=None, rot_quat=(0, 0, 0.3826834, 0.9238795)) #config_rot_quat = beamngpy.angle_to_quat(config.dir) # N.B. using rot is deprecated in favor of rot_quat #scenario.add_vehicle(vehicle, pos=tuple(config.pos), rot=tuple(config.dir), rot_quat=None) scenario.add_vehicle(vehicle, pos=tuple(config.pos), rot=None, rot_quat=beamngpy.angle_to_quat(config.dir)) # Compile the scenario and place it in BeamNG's map folder scenario.make(beamng) # Start BeamNG and enter the main loop bng = beamng.open(launch=True) try: bng.hide_hud() bng.set_deterministic() # Set simulator to be deterministic bng.set_steps_per_second(60) # With 60hz temporal resolution # Load and start the scenario bng.load_scenario(scenario) bng.start_scenario() # Put simulator in pause awaiting further inputs bng.pause() assert vehicle.skt # Send random inputs to vehicle and advance the simulation 20 steps #for _ in range(1024): for _ in range(100): throttle = random.uniform(0.0, 1.0) steering = random.uniform(-1.0, 1.0) brake = random.choice([0, 0, 0, 1]) vehicle.control(throttle=throttle, steering=steering, brake=brake) # bng.step(20) bng.step(20) # Retrieve sensor data and show the camera data. sensors = bng.poll_sensors(vehicle) print('\n{} seconds passed.'.format(sensors['timer']['time'])) print("step in loop {}".format(_)) for s in sensors.keys(): print("{} : {}".format(s, sensors[s])) damage_dict = vehicle.sensors['damage'].encode_vehicle_request() damage_dict = sensors['damage'] config.update(sensors['damage']) config.update(vehicle.state) config.save('{}/config.json'.format(beamng.home)) gamestate = beamng.get_gamestate() if _ > 990: print("late in sim") finally: bng.close()
def main(): random.seed(1703) setup_logging() # Plotting code setting up a 3x2 figure fig = plt.figure(1, figsize=(10, 5)) axarr = fig.subplots(2, 3) a_colour = axarr[0, 0] b_colour = axarr[1, 0] a_depth = axarr[0, 1] b_depth = axarr[1, 1] a_annot = axarr[0, 2] b_annot = axarr[1, 2] plt.ion() beamng = BeamNGpy('localhost', 64256) bng = beamng.open(launch=True) # Create a scenario in west_coast_usa scenario = Scenario('west_coast_usa', 'tech_test', description='Random driving for research') # Set up first vehicle, with two cameras, gforces sensor, lidar, electrical # sensors, and damage sensors vehicle = Vehicle('ego_vehicle', model='etk800', licence='RED', color='Red') # Set up sensors pos = (-0.3, 1, 1.0) direction = (0, 1, 0) fov = 120 resolution = (512, 512) front_camera = Camera(pos, direction, fov, resolution, colour=True, depth=True, annotation=True) pos = (0.0, 3, 1.0) direction = (0, -1, 0) fov = 90 resolution = (512, 512) back_camera = Camera(pos, direction, fov, resolution, colour=True, depth=True, annotation=True) gforces = GForces() electrics = Electrics() damage = Damage() lidar = Lidar(visualized=False) timer = Timer() # Attach them vehicle.attach_sensor('front_cam', front_camera) vehicle.attach_sensor('back_cam', back_camera) vehicle.attach_sensor('gforces', gforces) vehicle.attach_sensor('electrics', electrics) vehicle.attach_sensor('damage', damage) vehicle.attach_sensor('timer', timer) scenario.add_vehicle(vehicle, pos=(-717.121, 101, 118.675), rot=None, rot_quat=(0, 0, 0.3826834, 0.9238795)) # Compile the scenario and place it in BeamNG's map folder scenario.make(bng) # Start BeamNG and enter the main loop try: bng.hide_hud() bng.set_deterministic() # Set simulator to be deterministic bng.set_steps_per_second(60) # With 60hz temporal resolution # Load and start the scenario bng.load_scenario(scenario) bng.start_scenario() # Put simulator in pause awaiting further inputs bng.pause() assert vehicle.skt # Send random inputs to vehice and advance the simulation 20 steps for _ in range(1024): throttle = random.uniform(0.0, 1.0) steering = random.uniform(-1.0, 1.0) brake = random.choice([0, 0, 0, 1]) vehicle.control(throttle=throttle, steering=steering, brake=brake) bng.step(20) # Retrieve sensor data and show the camera data. sensors = bng.poll_sensors(vehicle) print('{} seconds passed.'.format(sensors['timer']['time'])) a_colour.imshow(sensors['front_cam']['colour'].convert('RGB')) a_depth.imshow(sensors['front_cam']['depth'].convert('L')) a_annot.imshow(sensors['front_cam']['annotation'].convert('RGB')) b_colour.imshow(sensors['back_cam']['colour'].convert('RGB')) b_depth.imshow(sensors['back_cam']['depth'].convert('L')) b_annot.imshow(sensors['back_cam']['annotation'].convert('RGB')) plt.pause(0.00001) finally: bng.close()
def createCrashSimulation(): print("Crash Simulation") beamng = BeamNGpy('localhost', 64256, home='F:\Softwares\BeamNG_Research_SVN') scenario = Scenario('GridMap', 'road_crash_simulation') road_a = Road('track_editor_C_center', looped=False) road_b = Road('track_editor_C_center', looped=False) nodesa = [(30, 0, -4, 4), (0, 0, -4, 4)] nodesb = [(0, 30, -4, 4), (0, 0, -4, 4)] road_a.nodes.extend(nodesa) road_b.nodes.extend(nodesb) # Create an ETK800 with the licence plate 'PYTHON' vehicleA = Vehicle('ego_vehicleA', model='etk800', licence='PYTHON') # Add it to our scenario at this position and rotation damageS = Damage() vehicleA.attach_sensor('damagesS', damageS) scenario.add_vehicle(vehicleA, pos=(30, 0, 0), rot=(0, 0, 90)) # Create an ETK800 with the licence plate 'PYTHON' vehicleB = Vehicle('ego_vehicleB', model='etk800', licence='PYTHON') # Add it to our scenario at this position and rotation damageV = Damage() vehicleB.attach_sensor('damagesV', damageV) scenario.add_vehicle(vehicleB, pos=(0, 30, 0), rot=(0, 0, 0)) scenario.add_road(road_a) scenario.add_road(road_b) scenario.make(beamng) bng = beamng.open(launch=True) try: bng.load_scenario(scenario) bng.start_scenario() node0 = { 'pos': (30, 0, 0), 'speed': 0, } node1 = { 'pos': (0, 0, 0), 'speed': 20, } script = list() script.append(node0) script.append(node1) vehicleA.ai_set_line(script) node3 = { 'pos': (0, 30, 0), 'speed': 0, } node4 = { 'pos': (0, 0, 0), 'speed': 20, } script = list() script.append(node3) script.append(node4) vehicleB.ai_set_line(script) time.sleep(12) # input('Press enter when done...') vehicleA.update_vehicle( ) # Synchs the vehicle's "state" variable with the simulator sensors = bng.poll_sensors(vehicleA) damage_striker = sensors['damagesS'] print(sensors['damagesS']) print(vehicleA.state['pos']) vehicleB.update_vehicle( ) # Synchs the vehicle's "state" variable with the simulator sensors = bng.poll_sensors(vehicleB) damage_victim = sensors['damagesV'] print(sensors['damagesV']) print(vehicleB.state['pos']) multiObjectiveFitnessFunction(123456789, damage_striker, vehicleA.state['pos'], (0, 0), damage_victim, vehicleB.state['pos'], (0, 0)) # multiobjective fitness function. bng.stop_scenario() # bng.load_scenario(scenario) # bng.start_scenario() # # print("sleep") # time.sleep(10) # print("wake") # # node0 = { # 'pos': (30, 0, 0), # 'speed': 0, # } # # node1 = { # 'pos': (0, 0, 0), # 'speed': 30, # } # # script = list() # script.append(node0) # script.append(node1) # # vehicleA.ai_set_line(script) # # node0 = { # 'pos': (0, 30, 0), # 'speed': 0, # } # # node1 = { # 'pos': (0, 0, 0), # 'speed': 30, # } # # script = list() # script.append(node0) # script.append(node1) # # vehicleB.ai_set_line(script) # # input('Press enter when done...') finally: bng.close()