Skip to content

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

Description

@ancabilloni

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

Activity

  1. changed the title [-]Remote pc running Python API does not connect[/-] [+]Remote pc running Python API does not connect to LGSVL Sim[/+] on Dec 28, 2020
  2. ethanxu-tab commented on May 10, 2021

    @ethanxu-tab

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

  3. ancabilloni commented on May 10, 2021

    @ancabilloni
    Author

    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.

  4. ethanxu-tab commented on May 11, 2021

    @ethanxu-tab
  5. ancabilloni commented on May 11, 2021

    @ancabilloni
    Author

    @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.

  6. ethanxu-tab commented on May 13, 2021

    @ethanxu-tab
  7. zerolover commented on Nov 8, 2021

    @zerolover

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions