示例#1
0
#!/usr/bin/env python3
#
# Copyright (c) 2020 LG Electronics, Inc.
#
# This software contains code licensed as described in LICENSE.
#

from environs import Env
import lgsvl

env = Env()

sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"),
                      env.int("LGSVL__SIMULATOR_PORT", 8181))
if sim.current_scene == "BorregasAve":
    sim.reset()
else:
    sim.load("BorregasAve", 42)

spawns = sim.get_spawn()

state = lgsvl.AgentState()
forward = lgsvl.utils.transform_to_forward(spawns[0])
right = lgsvl.utils.transform_to_right(spawns[0])
up = lgsvl.utils.transform_to_up(spawns[0])
state.transform = spawns[0]

ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"),
                    lgsvl.AgentType.EGO, state)

print("Python API Quickstart #28: How to Add/Control Traffic Cone")
import os
import lgsvl
import sys
import time
import evaluator

MAX_SPEED = 6.667  # (24 km/h, 15mph)
SPEED_VARIANCE = 4
MAX_POV_SEPARATION = 8 + 8 + 4.6
SEPARATION_VARIANCE = 2
TIME_LIMIT = 30  # seconds

print("PLC_CP_15 - ", end='')

sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181)
if sim.current_scene == "SanFrancisco":
    sim.reset()
else:
    sim.load("SanFrancisco")

# spawn EGO in the 2nd to right lane
egoState = lgsvl.AgentState()
# A point close to the desired lane was found in Editor. This method returns the position and orientation of the closest lane to the point.
egoState.transform = sim.map_point_on_lane(lgsvl.Vector(1699.6, 88.38, -601.9))
ego = sim.add_agent("XE_Rigged-apollo_3_5", lgsvl.AgentType.EGO, egoState)
egoX = ego.state.position.x
egoY = ego.state.position.y
egoZ = ego.state.position.z

# enable sensors required for Apollo 3.5
示例#3
0
文件: config.py 项目: KunSu/cmpe295
 def Simulator(self):
     # Connects to the simulator instance at the ip defined by SIMULATOR_HOST, default is localhost or 127.0.0.1
     sim = lgsvl.Simulator(os.environ.get(self.simulator, self.ip),
                           self.port)
     return sim
示例#4
0
# If the simulator and bridge are running on the same computer, then the default values will work.
# Otherwise the variables must be set for in order to connect to the simulator and the bridge to receive data.
# LGSVL__SIMULATOR_PORT and LGSVL__AUTOPILOT_0_HOST need to be set if non-default ports will be used

import os
import lgsvl

import sys

SIMULATOR_HOST = os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1")
SIMULATOR_PORT = int(os.environ.get("LGSVL__SIMULATOR_PORT", 8181))
BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1")
BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", 9090))

scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanepedestriancrosswalk)
sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT)
if sim.current_scene == scene_name:
    sim.reset()
else:
    sim.load(scene_name)

# spawn EGO
egoState = lgsvl.AgentState()
egoState.transform = sim.get_spawn()[0]
ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState)
ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT)

# spawn PED
pedState = lgsvl.AgentState()
pedState.transform.position = lgsvl.Vector(-7.67, 0.2, 6.299)
ped = sim.add_agent("Bob", lgsvl.AgentType.PEDESTRIAN, pedState)
示例#5
0
log = logging.getLogger(__name__)

env = Env()

MAX_SPEED = 6.667  # (24 km/h, 15 mph)
SPEED_VARIANCE = 4
TIME_LIMIT = 15  # seconds

LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1")
LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181)
LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1")
LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090)

print("PLC_SP_15 - ", end='')

sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT)
scene_name = env.str("LGSVL__MAP",
                     lgsvl.wise.DefaultAssets.map_straight2lanesame)
if sim.current_scene == scene_name:
    sim.reset()
else:
    sim.load(scene_name)

# spawn EGO in the 2nd to right lane
egoState = lgsvl.AgentState()
# A point close to the desired lane was found in Editor.
# This method returns the position and orientation of the closest lane to the point.
egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50))
ego = sim.add_agent(
    env.str("LGSVL__VEHICLE_0",
            lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis),
示例#6
0
# Copyright (c) 2021 LG Electronics, Inc.
#
# This software contains code licensed as described in LICENSE.
#

import time
from environs import Env
import lgsvl

print(
    "Python API Quickstart #35: Spawning multi robots with bridge connections")
env = Env()

sim = lgsvl.Simulator(
    env.str("LGSVL__SIMULATOR_HOST",
            lgsvl.wise.SimulatorSettings.simulator_host),
    env.int("LGSVL__SIMULATOR_PORT",
            lgsvl.wise.SimulatorSettings.simulator_port))

map_seocho = lgsvl.wise.DefaultAssets.map_lgseocho
robots = [
    lgsvl.wise.DefaultAssets.ego_lgcloi_navigation2_multi_robot1,
    lgsvl.wise.DefaultAssets.ego_lgcloi_navigation2_multi_robot2,
    lgsvl.wise.DefaultAssets.ego_lgcloi_navigation2_multi_robot3,
]

if sim.current_scene == map_seocho:
    sim.reset()
else:
    sim.load(map_seocho)
示例#7
0
#!/usr/bin/env python3
#
# Copyright (c) 2020-2021 LG Electronics, Inc.
#
# This software contains code licensed as described in LICENSE.
#

import os
import lgsvl
import time

print("Python API Quickstart #33: Stepping a simulation")
sim = lgsvl.Simulator(
    os.environ.get("LGSVL__SIMULATOR_HOST",
                   lgsvl.wise.SimulatorSettings.simulator_host),
    lgsvl.wise.SimulatorSettings.simulator_port)
if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave:
    sim.reset()
# Re-load scene and set random seed
sim.load(lgsvl.wise.DefaultAssets.map_borregasave, seed=123)

spawns = sim.get_spawn()

state = lgsvl.AgentState()
state.transform = spawns[0]
forward = lgsvl.utils.transform_to_forward(spawns[0])

# Agents can be spawned with a velocity. Default is to spawn with 0 velocity
# state.velocity = 20 * forward

# In order for Apollo to drive with stepped simulation we must add the clock sensor
示例#8
0
import lgsvl
import random
import time

from threading import Thread, Lock

DIS_THROSHOLD = 3
TIME_LIMIT = 300

sim = lgsvl.Simulator(address="localhost", port=8181)
try:
    sim.reset()
except:
    pass

# Inits simulation.
sim.load(scene="Shalun", seed=650387)

# Chooses ego vehicles.
state = lgsvl.AgentState()
state.transform.position = lgsvl.Vector(-7, 0, 76)
state.transform.rotation.y = 190
ego = sim.add_agent(name="Lexus2016RXHybrid (Autoware)",
                    agent_type=lgsvl.AgentType.EGO,
                    state=state)

# Connects to Autoware Ros2 bridge.
ego.connect_bridge("127.0.0.1", 9090)

failed = False
示例#9
0
import os

import lgsvl
from anotherquickstart import SIMULATOR_HOST_KEY, DEFAULT_SIMULATOR_HOST, DEFAULT_SIMULATION_PORT

sim = lgsvl.Simulator(os.environ.get(SIMULATOR_HOST_KEY, DEFAULT_SIMULATOR_HOST), DEFAULT_SIMULATION_PORT)
print("Current Scene = {}".format(sim.current_scene))
sim.run()
示例#10
0
def main():
    sim_host_ip = "127.0.0.1"  # of your local machine running sim
    sim_host_port = 8181
    sim_map = "Shalun"
    ego_car_model = "Jaguar2015XE (Autoware)"  #  Lexus2016RXHybrid (Autoware)
    ros_bridge_ip = "192.168.2.18"  # of the ros machine that runs the websocket_server
    ros_bridge_port = 9090

    time_limit = 0  # 0 means unlimited time otherwise sim will produce this much data in virtual seconds
    time_scale = 1  # 1 means normal speed, 1.5 means 1.5x speed

    ego_pos = Vector(-22, 0, 59.9)
    ego_roll = 0
    ego_pitch = 0
    ego_yaw = 250
    ego_rot = Vector(ego_pitch, ego_yaw, ego_roll)
    ego_tf = Transform(ego_pos, ego_rot)
    ego_v = Vector(0, 0, 0)
    ego_ang_v = Vector(0, 0, 0)
    ego_state = ObjectState(ego_tf, ego_v, ego_ang_v)

    no_of_npc = 5
    spawn_idx = 0
    spawn_pos = Vector(-32.6, 0, 45)
    spawn_tf = Transform(spawn_pos)

    sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", sim_host_ip),
                          sim_host_port)

    initScene(sim, sim_map, ego_car_model, ego_state, ros_bridge_ip,
              ros_bridge_port, spawn_idx)
    addNpcRandomAtlanes(sim, no_of_npc, spawn_idx, ego_tf)

    pedestrian_idle = 0

    pedestrian_pos = Vector(-31, 0, 31)
    pedestrian_state = ObjectState(Transform(pedestrian_pos))
    waypoints = [
        lgsvl.WalkWaypoint(lgsvl.Vector(-18, 0, 29), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(-12, 0, 12), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(-18, 0, 29), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(-31, 0, 2), pedestrian_idle, 0),
    ]
    createPedestrian(sim, pedestrian_state, waypoints)

    pedestrian_pos = Vector(-18, 0, 29)
    pedestrian_state = ObjectState(Transform(pedestrian_pos))
    waypoints = [
        lgsvl.WalkWaypoint(lgsvl.Vector(-35, 0, 30), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(-18, 0, 29), pedestrian_idle, 0),
    ]
    createPedestrian(sim, pedestrian_state, waypoints)

    pedestrian_pos = Vector(-13, 0, 12)
    pedestrian_state = ObjectState(Transform(pedestrian_pos))
    waypoints = [
        lgsvl.WalkWaypoint(lgsvl.Vector(-18, 0, 29), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(-35, 0, 30), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(-18, 0, 29), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(-12, 0, 12), pedestrian_idle, 0),
    ]
    createPedestrian(sim, pedestrian_state, waypoints)

    ### OTHER SIDE

    pedestrian_pos = Vector(11, 0, -18.5)
    pedestrian_state = ObjectState(Transform(pedestrian_pos))
    waypoints = [
        lgsvl.WalkWaypoint(lgsvl.Vector(28, 0, -14), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(11, 0, -15), pedestrian_idle, 0),
    ]
    createPedestrian(sim, pedestrian_state, waypoints)

    pedestrian_pos = Vector(28, 0, -11.5)
    pedestrian_state = ObjectState(Transform(pedestrian_pos))
    waypoints = [
        lgsvl.WalkWaypoint(lgsvl.Vector(11, 0, -19), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(28, 0, -12), pedestrian_idle, 0),
    ]
    createPedestrian(sim, pedestrian_state, waypoints)

    pedestrian_pos = Vector(30, 0, -13)
    pedestrian_state = ObjectState(Transform(pedestrian_pos))
    waypoints = [
        lgsvl.WalkWaypoint(lgsvl.Vector(25, 0, -1), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(30, 0, -13), pedestrian_idle, 0),
    ]
    createPedestrian(sim, pedestrian_state, waypoints)

    pedestrian_pos = Vector(25, 0, -1)
    pedestrian_state = ObjectState(Transform(pedestrian_pos))
    waypoints = [
        lgsvl.WalkWaypoint(lgsvl.Vector(30, 0, -13), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(25, 0, -1), pedestrian_idle, 0),
    ]
    createPedestrian(sim, pedestrian_state, waypoints)

    # PEDESTIRAN NEAR THE VEHICLE TO TEST AVOIDANCE
    # pedestrian_pos = Vector(-32, 0, 57.5)
    # pedestrian_state = ObjectState(Transform(pedestrian_pos))
    # waypoints = [
    #     lgsvl.WalkWaypoint(lgsvl.Vector(-32, 0, 57.5), 1e10, 0),
    # ]
    # createPedestrian(sim, pedestrian_state, waypoints)

    input("Press Enter to run simulation")
    sim.run(time_limit, time_scale)
def main():
    sim_host_ip = "127.0.0.1"  # of your local machine running sim
    sim_host_port = 8181
    sim_map = "CubeTown"
    ego_car_model = "Jaguar2015XE (Autoware)"  #  Lexus2016RXHybrid (Autoware)
    ros_bridge_ip = "192.168.1.78"  # of the ros machine that runs the websocket_server
    ros_bridge_port = 9090

    time_limit = 0  # 0 means unlimited time otherwise sim will produce this much data in virtual seconds
    time_scale = 1  # 1 means normal speed, 1.5 means 1.5x speed

    sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", sim_host_ip),
                          sim_host_port)

    ego_pos = Vector(-22, 0, 59.9)
    ego_roll = 0
    ego_pitch = 0
    ego_yaw = 250
    ego_rot = Vector(ego_pitch, ego_yaw, ego_roll)
    ego_tf = Transform(ego_pos, ego_rot)
    ego_v = Vector(0, 0, 0)
    ego_ang_v = Vector(0, 0, 0)
    ego_state = ObjectState(ego_tf, ego_v, ego_ang_v)

    no_of_npc = 0
    spawn_idx = 0
    spawn_pos = Vector(-32.6, 0, 45)
    spawn_tf = Transform(spawn_pos)

    initScene(sim, sim_map, ego_car_model, ego_state, ros_bridge_ip,
              ros_bridge_port, spawn_idx)
    # addNpcRandomAtlanes(sim, no_of_npc, spawn_idx, ego_tf)

    spawns = sim.get_spawn()
    state = lgsvl.AgentState()

    forward = lgsvl.utils.transform_to_forward(spawns[0])
    right = lgsvl.utils.transform_to_right(spawns[0])

    state.transform.position = spawns[0].position + 88 * forward + 55 * right
    state.transform.rotation = spawns[0].rotation - Vector(0, 90, 0)
    npcSpeed = 10

    waypoints = [
        DriveWaypoint(state.transform.position, npcSpeed,
                      state.transform.rotation, 0, False, 0),
        DriveWaypoint(state.transform.position, npcSpeed,
                      state.transform.rotation, 20, False, 0)
    ]

    pos = state.transform.position
    increment = 100
    start = 55
    end = -25

    for i in range(increment):
        pos += (end - start) / increment * right
        waypoints.append(
            DriveWaypoint(pos, npcSpeed, state.transform.rotation, 0, False,
                          0))

    addNpcAFollowWaypoints(sim, state, waypoints, True)

    state.transform.position = spawns[0].position + 94 * forward + -70 * right
    state.transform.rotation = spawns[0].rotation + Vector(0, 90, 0)
    npcSpeed = 10

    waypoints = [
        DriveWaypoint(state.transform.position, npcSpeed,
                      state.transform.rotation, 0, False, 0),
        DriveWaypoint(state.transform.position, npcSpeed,
                      state.transform.rotation, 20, False, 0)
    ]

    pos = state.transform.position
    increment = 100
    start = -70
    end = 50

    for i in range(increment):
        pos += (end - start) / increment * right
        waypoints.append(
            DriveWaypoint(pos, npcSpeed, state.transform.rotation, 0, False,
                          0))

    addNpcAFollowWaypoints(sim, state, waypoints, True)

    # start the sim
    input("Press Enter to run simulation")
    sim.run(time_limit, time_scale)
# add_egocar() is been remodeling now to match IF as  add_static_car()

from copy import deepcopy
import os
import lgsvl
import math
import copy
import time
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--host",help='simulator execute pc\'s ip address / --host 192.168.0.1',default='127.0.0.1')
parser.add_argument("--bridge",help='bridge execute pc\'s ip address / --bridge 192.168.0.1',default='127.0.0.1')
args = parser.parse_args()

sim = lgsvl.Simulator(args.host, 8181)

scene_name = "Borregas Avenue"
vehicle_name = "Lexus"

if sim.current_scene == scene_name:
    sim.reset()
else:
    sim.load(scene_name)
spawns = sim.get_spawn()

print("<< START FROM  INTERSECTION 1 (waypoint:#372) >>")
INIT_POS_X = -99.6277
INIT_POS_Z = -301.8317 # <- Caution!!, NOT Y, BUT Z
INIT_POS_Y = -6.9193 # <- Caution!!, NOT Z, BUT Y
示例#13
0
 def initSimulator(self):
     sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"),
                           8181)
     self.sim = sim