carla-simulator / ros-bridge

ROS bridge for CARLA Simulator
MIT License
523 stars 431 forks source link

How to modify the rotation frequency of lidar in ros_bridge #671

Closed gitouni closed 1 year ago

gitouni commented 1 year ago

Dear developers: I don't know how to modify the rotation frequency of lidar in ros_bridge. The default frequency is 20, which is shonw in objects.json. I modified the rotation frequency and used rosbag record to record lidar topic. However, the recorded lidar point clouds flashed in the rviz, indicating the collected point cloud did not match the rotation frequency.

I guess the modification of rotation frequency parameter will not modify the spinning speed of the Lidar, so it caused a asysnchronization between rotating and data receiving. My settings are shown below.

Envrioment

Carla: 0.9.13 ROS: Noetic Sys: Ubuntu 20.04.5

Command

roslaunch roslaunch carla_ros_bridge carla_with_sensors.launch

carla_with_sensors.launch

<!-- -->
<launch>
  <!-- CARLA connection -->
  <arg name='host' default='localhost'/>
  <arg name='port' default='2000'/>
  <arg name='timeout' default='10'/>

  <!-- Ego vehicle -->
  <arg name='role_name' default='ego_vehicle'/>
  <arg name="vehicle_filter" default='vehicle.*'/>
  <arg name="spawn_point" default=""/><!-- use comma separated format "x,y,z,roll,pitch,yaw" -->

  <!-- Map to load on startup (either a predefined CARLA town (e.g. 'Town01'), or a OpenDRIVE map file) -->
  <arg name="town" default='Town02'/>

  <!-- Enable/disable passive mode -->
  <arg name='passive' default=''/>

  <!-- Synchronous mode-->
  <arg name='synchronous_mode_wait_for_vehicle_control_command' default='False'/>
  <arg name='fixed_delta_seconds' default='0.05'/>

  <include file="$(find carla_ros_bridge)/launch/carla_ros_bridge.launch">
    <arg name='host' value='$(arg host)'/>
    <arg name='port' value='$(arg port)'/>
    <arg name='town' value='$(arg town)'/>
    <arg name='timeout' value='$(arg timeout)'/>
    <arg name='passive' value='$(arg passive)'/>
    <arg name='synchronous_mode_wait_for_vehicle_control_command' value='$(arg synchronous_mode_wait_for_vehicle_control_command)'/>
    <arg name='fixed_delta_seconds' value='$(arg fixed_delta_seconds)'/>
  </include>

  <!-- the ego vehicle, that will be controlled by an agent (e.g. carla_ad_agent) -->
  <include file="$(find carla_spawn_objects)/launch/carla_example_ego_vehicle.launch">
    <arg name="objects_definition_file" value='$(find carla_spawn_objects)/config/lidar_only.json'/>
    <arg name='role_name' value='$(arg role_name)'/>
    <arg name="spawn_point_ego_vehicle" value="$(arg spawn_point)"/>
    <arg name="spawn_sensors_only" value="false"/>
  </include>

  <include file="$(find carla_manual_control)/launch/carla_manual_control.launch">
    <arg name='role_name' value='$(arg role_name)'/>
  </include>

</launch>

lidar_only.json

{   
    "objects": 
    [
        {
            "type": "sensor.pseudo.objects",
            "id": "objects"
        },
        {
            "type": "sensor.pseudo.actor_list",
            "id": "actor_list"
        },
        {
            "type": "sensor.pseudo.markers",
            "id": "markers"
        },
        {
            "type": "sensor.pseudo.opendrive_map",
            "id": "map"
        },
        {
            "type": "vehicle.tesla.model3",
            "id": "ego_vehicle",
            "sensors": 
            [
                {
                    "type": "sensor.camera.rgb",
                    "id": "rgb_front",
                    "spawn_point": {"x": 2.0, "y": 0.0, "z": 2.0, "roll": 0.0, "pitch": 0.0, "yaw": 0.0},
                    "image_size_x": 800,
                    "image_size_y": 600,
                    "fov": 90.0
                },
                {
                    "type": "sensor.camera.rgb",
                    "id": "rgb_view",
                    "spawn_point": {"x": -4.5, "y": 0.0, "z": 2.8, "roll": 0.0, "pitch": 20.0, "yaw": 0.0},
                    "image_size_x": 800,
                    "image_size_y": 600,
                    "fov": 90.0,
                    "attached_objects":
                    [
                        {
                            "type": "actor.pseudo.control",
                            "id": "control"
                        }
                    ]
                },
                {
                    "type": "sensor.lidar.ray_cast",
                    "id": "lidar",
                    "spawn_point": {"x": 0.0, "y": 0.0, "z": 2.4, "roll": 0.0, "pitch": 0.0, "yaw": 0.0},
                    "range": 50,
                    "channels": 64,
                    "points_per_second": 1200000,
                    "upper_fov": 2.0,
                    "lower_fov": -24.8,
                    "rotation_frequency": 10,
                    "noise_stddev": 0.0
                },
                {
                    "type": "sensor.pseudo.tf",
                    "id": "tf"
                },
                {
                    "type": "sensor.pseudo.objects",
                    "id": "objects"
                },
                {
                    "type": "sensor.pseudo.odom",
                    "id": "odometry"
                },
                {
                    "type": "sensor.pseudo.speedometer",
                    "id": "speedometer"
                },
                {
                    "type": "actor.pseudo.control",
                    "id": "control"
                }
            ]
        }
    ]
}
gitouni commented 1 year ago

I found the answer in https://carla.readthedocs.io/en/0.9.13/ref_sensors/#lidar-sensor. It said the rotation freqeuncy of lidar needs to match the simulation interval. Thus, a feasible solution to modify the rotation frequency is to set the fixed_delta_seconds to 0.1 (equivalent to 10Hz). The modified launch file is shown below:

<!-- -->
<launch>
  <!-- CARLA connection -->
  <arg name='host' default='localhost'/>
  <arg name='port' default='2000'/>
  <arg name='timeout' default='10'/>

  <!-- Ego vehicle -->
  <arg name='role_name' default='ego_vehicle'/>
  <arg name="vehicle_filter" default='vehicle.*'/>
  <arg name="spawn_point" default=""/><!-- use comma separated format "x,y,z,roll,pitch,yaw" -->

  <!-- Map to load on startup (either a predefined CARLA town (e.g. 'Town01'), or a OpenDRIVE map file) -->
  <arg name="town" default='Town02'/>

  <!-- Enable/disable passive mode -->
  <arg name='passive' default=''/>

  <!-- Synchronous mode-->
  <arg name='synchronous_mode_wait_for_vehicle_control_command' default='False'/>
  <arg name='fixed_delta_seconds' default='0.1'/>

  <include file="$(find carla_ros_bridge)/launch/carla_ros_bridge.launch">
    <arg name='host' value='$(arg host)'/>
    <arg name='port' value='$(arg port)'/>
    <arg name='town' value='$(arg town)'/>
    <arg name='timeout' value='$(arg timeout)'/>
    <arg name='passive' value='$(arg passive)'/>
    <arg name='synchronous_mode_wait_for_vehicle_control_command' value='$(arg synchronous_mode_wait_for_vehicle_control_command)'/>
    <arg name='fixed_delta_seconds' value='$(arg fixed_delta_seconds)'/>
  </include>

  <!-- the ego vehicle, that will be controlled by an agent (e.g. carla_ad_agent) -->
  <include file="$(find carla_spawn_objects)/launch/carla_example_ego_vehicle.launch">
    <arg name="objects_definition_file" value='$(find carla_spawn_objects)/config/lidar_only.json'/>
    <arg name='role_name' value='$(arg role_name)'/>
    <arg name="spawn_point_ego_vehicle" value="$(arg spawn_point)"/>
    <arg name="spawn_sensors_only" value="false"/>
  </include>

  <include file="$(find carla_manual_control)/launch/carla_manual_control.launch">
    <arg name='role_name' value='$(arg role_name)'/>
  </include>

</launch>