安装与配置过程

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

简单测试

roslaunch car_demo demo.launch 

我们会看到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进行一些研究的童鞋。其它的仿真环境真的很大,非常考验电脑的性能。

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐