Carla安装与使用及ros-bridge

CARLA

官网

  • 主页
http://carla.org/
  • 软件包 github(carla)
https://github.com/carla-simulator/carla/releases
  • 软件包 github(Scenario runner)
https://github.com/carla-simulator/scenario_runner/releases/tag/v0.9.12

文档

  • carla
https://carla.readthedocs.io/en/latest/
  • carla中文网站
https://www.carla.org.cn/#/
  • ros-bridge
https://carla.readthedocs.io/projects/ros-bridge/en/stable/
  • scenario runner
https://carla-scenariorunner.readthedocs.io/en/latest/

CARLA安装与启动

下载后,无需编译,直接运行就可以启动carla;
带画面的启动:

 ./CarlaUE4.sh 

不带画面的启动:

./CarlaUE4.sh -RenderOffScreen

python路径配置

在~/.bashrc文件中添加如下(填写实际的carla路径):

# carla
export CARLA_ROOT=/media/gkk/Data/03_Proj/30_CARLA/CARLA_0.9.12
export PYTHONPATH=$PYTHONPATH:$CARLA_ROOT/PythonAPI/carla/dist/carla-0.9.12-py2.7-linux-x86_64.egg:$CARLA_ROOT/PythonAPI/carla
export SCENARIO_RUNNER_ROOT=/media/gkk/Data/03_Proj/30_CARLA/scenario_runner-0.9.12
export SCENARIO_RUNNER_PATH=/media/gkk/Data/03_Proj/30_CARLA/scenario_runner-0.9.12
export PYTHONPATH=$PYTHONPATH:$SCENARIO_RUNNER_ROOT:$SCENARIO_RUNNER_PATH

ros-bridge

编译与环境配置

建立标准的ros-pkg目录,例如:carla_ros/src/ros-bridge;
使用catkin或者catkin_make工具编译;
将source …/carla_ros/devel/set_up.bash命令添加到文件~/.bashrc中;

各子模块的功能介绍

1. carla_ros_bridge

提供了CARLA仿真环境与ros的信息转接功能;
主要ros接口如下:

  • 发布,从carla仿真环境中获取,发布到ros系统中;
Publications
 * /carla/actor_list [carla_msgs/CarlaActorList]
 * /carla/ego_vehicle/collision [carla_msgs/CarlaCollisionEvent]  # 本车碰撞信息
 * /carla/ego_vehicle/depth_front/camera_info [sensor_msgs/CameraInfo]
 * /carla/ego_vehicle/depth_front/image [sensor_msgs/Image]
 * /carla/ego_vehicle/dvs_front/camera_info [sensor_msgs/CameraInfo]
 * /carla/ego_vehicle/dvs_front/events [sensor_msgs/PointCloud2]
 * /carla/ego_vehicle/dvs_front/image [sensor_msgs/Image]
 * /carla/ego_vehicle/gnss [sensor_msgs/NavSatFix]         # GPS信息
 * /carla/ego_vehicle/imu [sensor_msgs/Imu]				  # IMU信息
 * /carla/ego_vehicle/lane_invasion [carla_msgs/CarlaLaneInvasionEvent]
 * /carla/ego_vehicle/lidar [sensor_msgs/PointCloud2]      # 激光雷达点云数据
 * /carla/ego_vehicle/objects [derived_object_msgs/ObjectArray]
 * /carla/ego_vehicle/odometry [nav_msgs/Odometry]      # 里程话题包含,定位信息,速度信息;
 * /carla/ego_vehicle/radar_front [sensor_msgs/PointCloud2]
 * /carla/ego_vehicle/rgb_front/camera_info [sensor_msgs/CameraInfo]
 * /carla/ego_vehicle/rgb_front/image [sensor_msgs/Image]
 * /carla/ego_vehicle/rgb_view/camera_info [sensor_msgs/CameraInfo]
 * /carla/ego_vehicle/rgb_view/image [sensor_msgs/Image]    # 第三视角图像信息
 * /carla/ego_vehicle/semantic_lidar [sensor_msgs/PointCloud2]
 * /carla/ego_vehicle/semantic_segmentation_front/camera_info [sensor_msgs/CameraInfo]
 * /carla/ego_vehicle/semantic_segmentation_front/image [sensor_msgs/Image]
 * /carla/ego_vehicle/speedometer [std_msgs/Float32]
 * /carla/ego_vehicle/vehicle_info [carla_msgs/CarlaEgoVehicleInfo]
 * /carla/ego_vehicle/vehicle_status [carla_msgs/CarlaEgoVehicleStatus]
 * /carla/map [std_msgs/String]
 * /carla/markers [visualization_msgs/MarkerArray]   # 场景物体的marker(默认只有本车和其它可运动车辆)
 * /carla/markers/static [visualization_msgs/MarkerArray]
 * /carla/objects [derived_object_msgs/ObjectArray]
 * /carla/status [carla_msgs/CarlaStatus]
 * /carla/traffic_lights/info [carla_msgs/CarlaTrafficLightInfoList]
 * /carla/traffic_lights/status [carla_msgs/CarlaTrafficLightStatusList]
 * /carla/world_info [carla_msgs/CarlaWorldInfo]
 * /clock [rosgraph_msgs/Clock]
 * /rosout [rosgraph_msgs/Log]
 * /tf [tf2_msgs/TFMessage]   # 本车ego_vehicle与map,已经本车传感器的tf关系;
  • 订阅,接收ros系统话题,调用carla相应的API实现对指令的响应;
Subscriptions
 * /carla/control [carla_msgs/CarlaControl]
 * /carla/debug_marker [visualization_msgs/MarkerArray]   # 可将marker显示到carla环境中;
 * /carla/ego_vehicle/control/set_target_velocity [geometry_msgs/Twist]    # 控制ego_vehicle按照此速度运动(不受运动学约束)
 * /carla/ego_vehicle/control/set_transform [unknown type]
 * /carla/ego_vehicle/enable_autopilot [std_msgs/Bool]     # 使能自动驾驶(时能后,本车漫无目的运动,会避免碰撞并遵守交通规则)
 * /carla/ego_vehicle/rgb_view/control/set_target_velocity [unknown type]
 * /carla/ego_vehicle/rgb_view/control/set_transform [unknown type]
 * /carla/ego_vehicle/vehicle_control_cmd [carla_msgs/CarlaEgoVehicleControl]   # 非手动模式的控制量(油门\刹车\方向盘)
 * /carla/ego_vehicle/vehicle_control_cmd_manual [carla_msgs/CarlaEgoVehicleControl] # 手动控制量
 * /carla/ego_vehicle/vehicle_control_manual_override [std_msgs/Bool]  # 是否启用手动控制
 * /carla/weather_control [unknown type]   # 场景天气
 * /clock [rosgraph_msgs/Clock]
  • 服务,接收ros客户端的调用,调用carla相应的API实现对指令的响应;
Services
 * /carla/destroy_object
 * /carla/get_blueprints
 * /carla/spawn_object
 * /carla_ros_bridge/get_loggers
 * /carla_ros_bridge/set_logger_level

carla_ackerman_control

订阅

/carla/ego_vehicle/vehicle_info;
/carla/ego_vehicle/vehicle_status;

发布

/carla/ego_vehicle/vehicle_control_cmd;

内部原理

该模块根据ackerman指令,生成控制车辆底盘的油门\刹车\档位\手刹等量;

  1. 方向盘控制
    output.steer = target.streering_angle/max_steering_angle;(归一化)
    输出的方向盘控制量为归一化的值;

  2. 停车与档位控制
    (1) 若 current_speed_abs < 0.1: (在低速下执行换挡与手刹动作)
    if target_speed_abs < 0.001: 手刹;
    else if target_speed > 0: D档;
    else : R档位;
    (2) 当实际车速与目标车速正负相反时:设定参考车速为0(通过控制回路执行减速);

  3. 速度控制回路
    若ackerman指令有加速度,则直接利用此加速度信息作为输出:acc_target = acc_from_ackerman;
    否则,执行速度调节:
    acc_delta = PID(reference_speed, current_speed);
    acc_target = acc_target + acc_delta;

  4. 加速度控制回路
    根据目标加速度和实际加速度的差值,通过PID调节,计算出油门刹车开度值的增量;
    pedal_delta = PID(acc_target, acc_feedback);
    pedal_target = pedal_target + pedal_delta;

  5. 底盘控制量生成
    将开度值分成了三个等级:油门踏板输出,油门与刹车都不输出,刹车踏板输出;
    若 pedal_target > throttle_lower_border:
    throttle = pedal_target - throttle_lower_border;
    brake = 0.0;
    若 brake_upper_border <= pedal_target <= throttle_lower_border:
    throttle = 0.0;
    brake = 0.0;
    若 pedal_target < brake_upper_border:
    throttle = 0.0;
    brake = brake_upper_border - pedal_target;

carla_ad_agent

在此ros包中有两个节点:
carla_ad_agent,根据红绿灯控制车辆的目标速度;
local_planner,生成控制车辆运动的底盘指令;

local_planner的基本原理

在参考路径上选择前瞻点,根据前瞻点与实际位置做横纵向的运动控制;

  1. 寻找前瞻点
    在参考路径上寻找车前s=current_speed*look_ahead_time处的路径点goal_waypoint;
  2. 横纵向运动控制
    2.1 纵向控制:控制车辆速度
    根据车辆目标速度和实际速度,生成油门刹车开度值;
    pedal_target = PID(target_speed, current_speed);
    2.2 横向控制:控制方向盘转角
    根据车辆朝向与前瞻点夹角的角度差值,调节方向盘转角输出值;
    v_vec = [ cos(current_yaw), sin(current_yaw) ];
    w_vec = [ goal_waypoint.x - current_x, goal_waypoint.y - current_y ];
    theta_error = acos(v_vec, w_vec) * sign(v_vec X w_vec );
    steering_target = PID(theta_error);

你可能感兴趣的:(工具技巧,自动驾驶,自动驾驶)