lgsvl / gym-lgsvl

OpenAI Gym Environment for SVL Simulator.
Other
24 stars 8 forks source link

cant add additional sensors #9

Open Michael-Fleicher opened 3 years ago

Michael-Fleicher commented 3 years ago

hey, when im loading an agent through _setup_ego function, which I provide a configuration id as the below example: def _setup_ego(self, name = "30387e1f-4d7f-4b6e-98aa-d721a16c4e75", spawn_index = 0, random_spawn = False):

while the name argument is the configuration ID set on web UI, which loaded with several sensors. but when I am printing all the available sensors, not all of them are exist in the jason file, alltough the simulator itself can show me all the sensors

I'm printing them using the below code:

def _setup_ego(self, name = "30387e1f-4d7f-4b6e-98aa-d721a16c4e75", spawn_index = 0, random_spawn = False):

    state = lgsvl.AgentState()
    if (random_spawn):
      state.transform = self.spawns[random.randint(0, len(self.spawns) - 1)]
    else:
      state.transform = self.spawns[spawn_index]

    self.ego = self.env.add_agent(name, lgsvl.AgentType.EGO, state)
    self.vehicles[self.ego] = "EGO"
    self._occupied.append(state.transform.position)
    self.sensors = self.ego.get_sensors()
    for s in self.sensors:
      print("(_setup_ego) sensor: " ,s.name)
      if (s.name == "Color Camera Sensor"):
        self.camera = s
        break
    self.ego_position = state.transform.position

for example, I've added the lane sensor, and it does not print it as a sensor, while on the simulator UI i can see the lane sensor

hadiTab commented 3 years ago

All sensors are not supported by the PythonAPI. See docs. Only the sensors listed there are supported. For other sensors you will need to add a bridge (i.e. ros bridge) to publish sensor messages.

Michael-Fleicher commented 3 years ago

ok, but for some reason, even some of the supported sensors do not appear. such as GPS / CAN bus / radar doesn't exist in the jason file and therefore it never prints it when I'm using the below:

for s in self.sensors:
   print("(_setup_ego) sensor: " ,s.name)
Michael-Fleicher commented 3 years ago

and by the way, there is some tutorial to make ros bridge publish sensors?

hadiTab commented 3 years ago

@Michael-Fleicher if you add the sensors with ROS bridge to a vehicle sensor configuration and start the ROS bridge, the sensors will publish continuously.

This quickstart script is an example of connecting to a bridge.

You will also need to have a ros installation and the rosbridge installed.

Michael-Fleicher commented 2 years ago

hey, thanks for the support, I have managed to use This quickstart into the file lgsvl_env.py

as described below: ` def _setup_ego(self, name = "489640d1-f698-4be2-8abe-5cd3d43cf4c9", spawn_index = 0, random_spawn = True):

"""
Spawns ego vehicle at the specified (by default index 0) spawn point in the Unity scene.
"""
state = lgsvl.AgentState()
if (random_spawn):
  state.transform = self.spawns[random.randint(0, len(self.spawns) - 1)]
else:
  state.transform = self.spawns[spawn_index]

self.ego = self.env.add_agent(name, lgsvl.AgentType.EGO, state)
self.vehicles[self.ego] = "EGO"
self._occupied.append(state.transform.position)
self.sensors = self.ego.get_sensors()
for s in self.sensors:
  print("(_setup_ego) sensor: " ,s.name)

  if (s.name == "Segmentation Camera"):
    self.s_camera = s

  if (s.name == "Color Camera Sensor"):
    self.camera = s

  if (s.name == "IMU"):
    self.imu = s
self.ego_position = state.transform.position

# An EGO will not connect to a bridge unless commanded to
print("Bridge connected:", self.ego.bridge_connected)

# The EGO is now looking for a bridge at the specified IP and port
self.ego.connect_bridge("127.0.0.1" , 9090)

`

and when i open the terminal, and run the following lines: source (path\to\bridge\repository)/install/setup.bash lgsvl_bridge

the connection is ok, i just cant understand how to to move on from here, and how can i see the sensors outputs.

in the terminal, where the bridge is running, i get plenty of msgs like below: [ERROR] [1637235689.546908592] [lgsvl-bridge]: rcl_publisher_init failed: 103 [ERROR] [1637235689.561664650] [lgsvl-bridge]: No publisher registered on topic , ignorning message

another issue that might be relevant: i cant manage to install lgsvl_msgs using #1

  1. when i try sudo apt update sudo apt install ros-$ROS_DISTRO-lgsvl_msgs

i get the following error:

E: Unable to locate package ros-foxy-lgsvl_msgs

and when i try to install it using build: git clone https://github.com/lgsvl/lgsvl_msgs.git cd lgsvl_msgs colcon build

i get this msg:

--- stderr: lgsvl_msgs
CMake Error at /opt/ros/foxy/share/rosidl_adapter/cmake/rosidl_adapt_interfaces.cmake:60 (message): execute_process(/home/michael/anaconda3/bin/python3 -m rosidl_adapter --package-name lgsvl_msgs --arguments-file /home/michael/ws/lgsvl_msgs/build/lgsvl_msgs/rosidl_adapterargumentslgsvl_msgs.json --output-dir /home/michael/ws/lgsvl_msgs/build/lgsvl_msgs/rosidl_adapter/lgsvl_msgs --output-file /home/michael/ws/lgsvl_msgs/build/lgsvl_msgs/rosidl_adapter/lgsvl_msgs.idls) returned error code 1:

Traceback (most recent call last):

File "/home/michael/anaconda3/lib/python3.8/runpy.py", line 194, in _run_module_as_main
  return _run_code(code, main_globals, None,
File "/home/michael/anaconda3/lib/python3.8/runpy.py", line 87, in _run_code
  exec(code, run_globals)
File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_adapter/__main__.py", line 19, in <module>
  sys.exit(main())
File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_adapter/main.py", line 53, in main
  abs_idl_file = convert_to_idl(
File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_adapter/__init__.py", line 18, in convert_to_idl
  from rosidl_adapter.msg import convert_msg_to_idl
File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_adapter/msg/__init__.py", line 16, in <module>
  from rosidl_adapter.resource import expand_template
File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_adapter/resource/__init__.py", line 19, in <module>
  import em

ModuleNotFoundError: No module named 'em'

Call Stack (most recent call first): /opt/ros/foxy/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:130 (rosidl_adapt_interfaces) CMakeLists.txt:86 (rosidl_generate_interfaces)


Failed <<< lgsvl_msgs [0.73s, exited with code 1]

Summary: 0 packages finished [0.80s] 1 package failed: lgsvl_msgs 1 package had stderr output: lgsvl_msgs


so it might be because i cant install lgsvl_msgs. anyway, i need a support on how to read the sensors data, after i connected to the bridge