ROS2 native interface
The CARLA simulator supports ROS2 natively from the server. To use ROS2 with CARLA, launch the CARLA simulator from the command line with the --ros2
command line option:
./CarlaUnreal.sh --ros2
Sensor data
The CARLA server will broadcast sensor data for any spawned sensors for which ROS is enabled. To enable a sensor for ROS use the enable_for_ros()
method of the sensor class:
sensor = world.spawn_actor(sensor_blueprint, transform)
sensor.enable_for_ros()
Set the ROS topic name in the sensor blueprint prior to spawning (a random string name will be generated by default):
bp = bp_lib.find('sensor.camera.rgb')
bp.set_attribute('ros_name', 'front_camera')
In this case the image data will be published to: /carla/front_camera/image
.
If the camera is parented to an actor, for example the ego vehicle, the topic name will also include the role name given to the vehicle: /carla/ego/front_camera/image
.
See the ROS2 sensors reference for details about the message formats used for each sensor type.
Control data
Controls may be sent to one ego vehicle:
bp = bp.find("vehicle.lincoln.mkz_2020")
bp.set_attribute("ros_name", "ego")
ego = carla.spawn_actor(bp, spawn_point)
When the ego vehicle is spawned a subscriber will be created with ROS topic name: /carla/ego/vehicle_control_cmd
.
CarlaEgoVehicleControl.msg
To send control messages, install the ros-carla-msgs ROS package. The control message has the following fields:
Field | Type | Description |
---|---|---|
header |
Header | Time stamp and frame ID when the message is published. |
throttle |
float32 | Scalar value to cotrol the vehicle throttle: [0.0, 1.0] |
steer |
float32 | Scalar value to control the vehicle steering direction: [-1.0, 1.0] to control the vehicle steering |
brake |
float32 | Scalar value to control the vehicle brakes: [0.0, 1.0] |
hand_brake |
bool | If True, the hand brake is enabled. |
reverse |
bool | If True, the vehicle will move reverse. |
gear |
int32 | Changes between the available gears in a vehicle. |
manual_gear_shift |
bool | If True, the gears will be shifted using gear . |