lgsvl / PythonAPI

Python API for Simulator
Other
58 stars 73 forks source link

When I use waypoints in pythonAPI, the physical collision attribute of NPC is lost #34

Open Gump0116 opened 3 years ago

Gump0116 commented 3 years ago

image

Here is my code !!!!!

#!/usr/bin/env python3
#

from environs import Env
import lgsvl
import os

env = Env()

def on_waypoint(agent, index):
    print("waypoint {} reached".format(index))

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")

spawns = sim.get_spawn()

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

for spawn in sim.get_spawn():
    print(spawn)

#state.transform.position = lgsvl.Vector(3.07,0,-87.25)
forward = lgsvl.utils.transform_to_forward(spawns[0])
right = lgsvl.utils.transform_to_right(spawns[0])

state.velocity.x = -5
state.transform.position = lgsvl.Vector(20,0,5.5)
state.transform.rotation.y = 270

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

state.transform.position = lgsvl.Vector(10,0,5.5)
state.transform.rotation.y = 270

state.velocity.x = -7

npc1= sim.add_agent("BoxTruck",lgsvl.AgentType.NPC,state)

waypoints=[
    lgsvl.DriveWaypoint(lgsvl.Vector(-5,-2,5.5), 4, lgsvl.Vector(0, 270, 0)),
    lgsvl.DriveWaypoint(lgsvl.Vector(-3,-2,5.5), 3, lgsvl.Vector(0, 270, 0)),
    lgsvl.DriveWaypoint(lgsvl.Vector(-2,-2,5.5), 2, lgsvl.Vector(0, 270, 0)),
    lgsvl.DriveWaypoint(lgsvl.Vector(-1,-2,5.5), 1, lgsvl.Vector(0, 270, 0)),

]

npc1.on_waypoint_reached(on_waypoint)
npc1.follow(waypoints)

# ego.connect_bridge(os.environ.get("BRIDGE_HOST", "192.168.137.3"), 9090)

sim.run()

# sim.run(time_limit=1.0)
hadiTab commented 3 years ago

Hi @Gump0116 . Can you explain a bit more what you mean by "physical collision attribute"? When NPC's operate in waypoint mode they do not actually collide with anything (they will drive through objects). However, the collision will be detected by the collision callback.