lgsvl / PythonAPI

Python API for Simulator
Other
58 stars 73 forks source link

Remote pc running Python API does not connect to LGSVL Sim #31

Open ancabilloni opened 3 years ago

ancabilloni commented 3 years ago

Hi, I'm following this tutorial https://www.lgsvlsimulator.com/docs/api-how-to-run-scenario/ and trying to run the API through a remote machine.

Sim machine runs Windows 10. API machine runs Linux. I could ping both machines back and forth. But I cannot run the Python API from remote machine. The code is basically stopped where the it tries to establish sim connection before print ("pass") line. The ip "195.0.0.35" is the Windows machine IP. The two machines are connected through ethernet directly.

I also added new rule for Inbound Rules and Outbound Rules on Windows 10 machine to allow TCP connection on port 8181. But that still didn't help. Can you provide some insight on this issue?

Here is the code

#!/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
import time 
import os

env = Env()
print("here")
# sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181))
# sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "195.0.0.35"), 8181)
sim = lgsvl.Simulator( "195.0.0.35", 8181)
print("pass")

if sim.current_scene == "BorregasAve":
    sim.reset()
else:
    sim.load("BorregasAve", 42)

spawns = sim.get_spawn()
layer_mask = 0
layer_mask |= 1 << 0  # 0 is the layer for the road (default)

# EGO
state = lgsvl.AgentState()
forward = lgsvl.utils.transform_to_forward(spawns[0])
right = lgsvl.utils.transform_to_right(spawns[0])
spawn_state = spawns[0]
hit = sim.raycast(
    spawn_state.position + forward * 40, lgsvl.Vector(0, -1, 0), layer_mask
)
spawn_state.position = hit.point
state.transform = spawn_state
state.velocity = forward * 2
ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Jaguar2015XE (Apollo 3.0)"), lgsvl.AgentType.EGO, state)

# NPC
state = lgsvl.AgentState()
npc_position = lgsvl.Vector(-4, -1, -48)
hit = sim.raycast(npc_position, lgsvl.Vector(0, -1, 0), layer_mask)
npc_rotation = lgsvl.Vector(0, 16, 0)
state.transform.position = hit.point
state.transform.rotation = npc_rotation
npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, state)

vehicles = {
    ego: "EGO",
    npc: "Sedan",
}

# Executed upon receiving collision callback -- NPC is expected to drive through colliding objects
def on_collision(agent1, agent2, contact):
    name1 = vehicles[agent1]
    name2 = vehicles[agent2] if agent2 is not None else "OBSTACLE"
    print("{} collided with {}".format(name1, name2))

ego.on_collision(on_collision)
npc.on_collision(on_collision)

# This block creates the list of waypoints that the NPC will follow
# Each waypoint is an position vector paired with the speed that the NPC will drive to it
waypoints = []

for i in range(2):
    speed = 8  # if i % 2 == 0 else 12
    # Waypoint angles are input as Euler angles (roll, pitch, yaw)
    angle = npc_rotation
    # Raycast the points onto the ground because BorregasAve is not flat
    npc_position.x += 6
    npc_position.z += 21
    hit = sim.raycast(npc_position, lgsvl.Vector(0, -1, 0), layer_mask)

    trigger = None
    if i == 0:
        parameters = {"max_distance": 4.0}
        effector = lgsvl.TriggerEffector("WaitForDistance", parameters)
        trigger = lgsvl.WaypointTrigger([effector])
    wp = lgsvl.DriveWaypoint(
        position=hit.point,
        speed=speed,
        angle=angle,
        idle=0,
        trigger_distance=0,
        trigger=trigger,
    )
    waypoints.append(wp)

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

def agents_traversed_waypoints():
    print("All agents traversed their waypoints.")
    sim.stop()

# The above function needs to be added to the list of callbacks for the NPC
npc.on_waypoint_reached(on_waypoint)
sim.agents_traversed_waypoints(agents_traversed_waypoints)

# The NPC needs to be given the list of waypoints.
# A bool can be passed as the 2nd argument that controls whether or not the NPC loops over the waypoints (default false)
npc.follow(waypoints)

input("Press Enter to run")

sim.run()
ethanxu-tab commented 3 years ago

How did you solve the problem,would you please give me some advice?

ancabilloni commented 3 years ago

How did you solve the problem,would you please give me some advice?

@1591662691 I couldn't get it to work, so I stopped trying after a couple days.

ethanxu-tab commented 3 years ago

so could you please tell me your solution,thankyou ------------------ 原始邮件 ------------------ 发件人: "lgsvl/PythonAPI" @.>; 发送时间: 2021年5月10日(星期一) 中午12:18 @.>; @.**@.>; 主题: Re: [lgsvl/PythonAPI] Remote pc running Python API does not connect to LGSVL Sim (#31)

How did you solve the problem,would you please give me some advice?

I couldn't get it to work, so I moved on from trying this.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

ancabilloni commented 3 years ago

@1591662691 I don't have any solution. I ended up just using PythonAPI and LGSVL on the same machine. And it's pretty straight forward, you just need to connect to localhost or 127.0.0.1.

ethanxu-tab commented 3 years ago

thankyou very much ,and i have figured it out on the same machine,it needs to launch some essential mouldles .

------------------ 原始邮件 ------------------ 发件人: "lgsvl/PythonAPI" @.>; 发送时间: 2021年5月12日(星期三) 凌晨2:18 @.>; @.**@.>; 主题: Re: [lgsvl/PythonAPI] Remote pc running Python API does not connect to LGSVL Sim (#31)

@1591662691 I don't have any solution. I ended up just using PythonAPI and LGSVL on the same machine. And it's pretty straight forward, you just need to connect to localhost or 127.0.0.1.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

zerolover commented 3 years ago

edit config.yml at svlsimulator-linux64-2021.3 change api_hostname: "localhost" to api_hostname: "*"

# set host ip export LGSVL__SIMULATOR_HOST=192.168.1.x ./01-connecting-to-simulator.py