无人车系统(九):基于ROS与Gazebo的无人驾驶仿真环境——car_demo

在car_demo|无人车仿真环境全教程介绍了在系统:Ubuntu 14.04 indigo中安装配置car_demo。由于当时的电脑中的ubuntu与ros版本较低,我按照原教程的配置方法,安装Docker,nvidia-docker2,还有rocker。最终实现的是,让car_demo在独立的docker环境下运行,利用ROS的多机通信的机制配置(如何配置请参见car_demo|无人车仿真环境全教程),使得在自己电脑上能够与仿真环境进行数据交互。但是,这个过程真的好麻烦,使用感觉极为不佳。最近正好换了电脑,索性直接把系统换到ubuntu 18.04+ ros melodic。发现直接在本地编译能通过,之后就是本地的一个ros package,这样使用就方便多了。

系统: ubuntu 18.04+ros melodic
目的:配置car_demo无人车仿真环境


安装与配置过程

  • git clone car_demo项目到本地:
cd ~/Downloads
git clone https://github.com/osrf/car_demo.git
  • 建立并定位到新工作空间,或已有工作空间~/cardemo_ws,这个位置与名字无所谓:
mkdir -p ~/cardemo_ws/src
  • 将对应包复制到新建的工作空间的src目录下:
cd ~/Downloads/car_demo_master 
cp -r prius_description ~/cardemo_ws/src/prius_description
cp -r prius_msgs ~/cardemo_ws/src/prius_msgs
cp -r car_demo ~/cardemo_ws/src/car_demo
  • 编译:
cd ~/cardemo_ws
catkin_make
  • 添加环境
echo "source ~/cardemo_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc

简单测试

roslaunch car_demo demo.launch 

我们会看到RVIZ与Gazebo两个界面

  • RVIZ
    无人车系统(九):基于ROS与Gazebo的无人驾驶仿真环境——car_demo_第1张图片
  • Gazebo
  • 查看topic数据(有激光、声呐、相机、车自身状态等数据):
rostopic list
/amcl_pose
/base_pose_ground_truth
/clicked_point
/clock
/diagnostics
/gazebo/link_states
/gazebo/model_states
/gazebo/parameter_descriptions
/gazebo/parameter_updates
/gazebo/set_link_state
/gazebo/set_model_state
/initialpose
/joint_states
/joy
/joy/set_feedback
/move_base_simple/goal
/particlecloud
/prius   # 控制车的topic,包括刹车、油门、档位、方向盘转向等命令
/prius/back_camera/camera_info
/prius/back_camera/image_raw
/prius/back_camera/image_raw/compressed
/prius/back_camera/image_raw/compressed/parameter_descriptions
/prius/back_camera/image_raw/compressed/parameter_updates
/prius/back_camera/image_raw/compressedDepth
/prius/back_camera/image_raw/compressedDepth/parameter_descriptions
/prius/back_camera/image_raw/compressedDepth/parameter_updates
/prius/back_camera/image_raw/theora
/prius/back_camera/image_raw/theora/parameter_descriptions
/prius/back_camera/image_raw/theora/parameter_updates
/prius/back_camera/parameter_descriptions
/prius/back_camera/parameter_updates
/prius/back_sonar/left_far_range
/prius/back_sonar/left_middle_range
/prius/back_sonar/right_far_range
/prius/back_sonar/right_middle_range
/prius/center_laser/scan
/prius/front_camera/camera_info
/prius/front_camera/image_raw
/prius/front_camera/image_raw/compressed
/prius/front_camera/image_raw/compressed/parameter_descriptions
/prius/front_camera/image_raw/compressed/parameter_updates
/prius/front_camera/image_raw/compressedDepth
/prius/front_camera/image_raw/compressedDepth/parameter_descriptions
/prius/front_camera/image_raw/compressedDepth/parameter_updates
/prius/front_camera/image_raw/theora
/prius/front_camera/image_raw/theora/parameter_descriptions
/prius/front_camera/image_raw/theora/parameter_updates
/prius/front_camera/parameter_descriptions
/prius/front_camera/parameter_updates
/prius/front_left_laser/scan
/prius/front_right_laser/scan
/prius/front_sonar/left_far_range
/prius/front_sonar/left_middle_range
/prius/front_sonar/right_far_range
/prius/front_sonar/right_middle_range
/prius/left_camera/camera_info
/prius/left_camera/image_raw
/prius/left_camera/image_raw/compressed
/prius/left_camera/image_raw/compressed/parameter_descriptions
/prius/left_camera/image_raw/compressed/parameter_updates
/prius/left_camera/image_raw/compressedDepth
/prius/left_camera/image_raw/compressedDepth/parameter_descriptions
/prius/left_camera/image_raw/compressedDepth/parameter_updates
/prius/left_camera/image_raw/theora
/prius/left_camera/image_raw/theora/parameter_descriptions
/prius/left_camera/image_raw/theora/parameter_updates
/prius/left_camera/parameter_descriptions
/prius/left_camera/parameter_updates
/prius/right_camera/camera_info
/prius/right_camera/image_raw
/prius/right_camera/image_raw/compressed
/prius/right_camera/image_raw/compressed/parameter_descriptions
/prius/right_camera/image_raw/compressed/parameter_updates
/prius/right_camera/image_raw/compressedDepth
/prius/right_camera/image_raw/compressedDepth/parameter_descriptions
/prius/right_camera/image_raw/compressedDepth/parameter_updates
/prius/right_camera/image_raw/theora
/prius/right_camera/image_raw/theora/parameter_descriptions
/prius/right_camera/image_raw/theora/parameter_updates
/prius/right_camera/parameter_descriptions
/prius/right_camera/parameter_updates

其中,/prius # 控制车的topic,包括刹车、油门、档位、方向盘转向等命令

  • 简单的控制(随便给的控制命令)
import rospy
from prius_msgs.msg import Control

def control_test():
    pub = rospy.Publisher("/prius", Control, queue_size=1)
    rospy.init_node('sim_control', anonymous=True)
    rate = rospy.Rate(10) # 10hz
    command = Control()
    command.header.stamp = rospy.Time.now()
    command.throttle = 1.0
    command.brake = 0.0
    command.shift_gears = Control.FORWARD
    
    while not rospy.is_shutdown():
        pub.publish(command)
        rate.sleep()

if __name__ == '__main__':
    try:
        control_test()
    except rospy.ROSInterruptException:
        pass 

我们看到车动机了。

总结

这个无人车仿真环境非常适合,有ROS基础的,并且想基于ROS进行一些研究的童鞋。其它的仿真环境真的很大,非常考验电脑的性能。

你可能感兴趣的:(无人驾驶技术系统)