無人車系統(九):基於ROS與Gazebo的無人駕駛仿真環境——car_demo

car_demo|無人車仿真環境全教程介紹了在系統:Ubuntu 14.04 indigo中安裝配置car_demo。由於當時的電腦中的ubuntu與ros版本較低,我按照原教程的配置方法,安裝Dockernvidia-docker2,還有rocker。最終實現的是,讓car_demo在獨立的docker環境下運行,利用ROS的多機通信的機制配置(如何配置請參見car_demo|無人車仿真環境全教程),使得在自己電腦上能夠與仿真環境進行數據交互。但是,這個過程真的好麻煩,使用感覺極爲不佳。最近正好換了電腦,索性直接把系統換到ubuntu 18.04+ ros melodic。發現直接在本地編譯能通過,之後就是本地的一個ros package,這樣使用就方便多了。

系統: ubuntu 18.04+ros melodic
目的:配置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
    在這裏插入圖片描述
  • 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進行一些研究的童鞋。其它的仿真環境真的很大,非常考驗電腦的性能。

發佈了67 篇原創文章 · 獲贊 122 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章