-
Notifications
You must be signed in to change notification settings - Fork 2
CARLA ROS Bridge Tutorial
The CARLA simulator renders a synthetic world where vehicles and pedestrians can interact. It provides network ports 2000, 2001, 2002 for communication with other system components, so you can remote control it and retrieve world information that way.
Use following command to start the CARLA simulator on your local machine.
cd ~/carla_0.9.10.1
./CarlaUE4.sh
The ROS environment is used to exchange messages between system components, allowing for a loosely-coupled system design. As ROS is extremely useful for robotics projects, the CARLA simulator provides an interface for ROS called CARLA ROS Bridge. It supports bidirectional communication between ROS and CARLA by converting between ROS messages and CARLA PythonAPI messages.
Use following command to start the CARLA ROS Bridge on your local machine. This will start a ROS node called carla_ros_bridge.
roslaunch carla_ros_bridge carla_ros_bridge.launch
Next, we need to spawn a vehicle that we can remote control.
Use following command to spawn a vehicle by an example definition.
roslaunch carla_ego_vehicle carla_example_ego_vehicle.launch
Later we can override the vehicle's definition, so we can spawn a specific car with our custom sensors, etc.
roslaunch carla_ego_vehicle carla_ego_vehicle.launch \
sensor_definition_file:=config/sensors.json
# assuming the sensors are located in config/sensors.json
For simply accessing the vehicle status, subscribe to the related ROS topic.
Use following command to subscribe to the ego vehicle status.
rostopic echo /carla/ego_vehicle/vehicle_status
Now that we have spawned a vehicle, we need to direct the spectator camera to see it driving.
Use following command to create a spectator camera.
roslaunch carla_spectator_camera carla_spectator_camera.launch
TODO: this doesn't seem to work yet, figure out how this is done
As it is, we have spawned a vehicle and are able to see it. Now we need to attach a remote control to the vehicle for driving it. There are multiple solutions for this, but we'll be using the Ackermann control which is designed for remote control by a machine, not by a human.
Use following command to attach an Ackermann control to your ego vehicle.
roslaunch carla_ackermann_control carla_ackermann_control.launch
Like spwaning a vehicle, this can be customized as well to fit the vehicle under surveillance and control.
Finally, everything is set up to send some driving signals to the vehicle. As a quick example, we'll be sending it a command to drive straight forward which gets repeated every 10 seconds.
rostopic pub /carla/ego_vehicle/ackermann_cmd ackermann_msgs/AckermannDrive \
"{steering_angle: 0.0, steering_angle_velocity: 0.0, speed: 10, acceleration: 0.0, jerk: 0.0}" -r 10
As there's a common demonstration use case for launching an ego vehicle that can be remote controlled by a user, there's a shortcut for that provided as a specific launchfile executing all the commands in one go.
roslaunch carla_ros_bridge carla_ros_bridge_with_example_ego_vehicle.launch