当前位置:   article > 正文

智能车室内光电组ROS-2020—— 创建工作空间以及移植比赛模型文件_ubuntu 智能车比赛修改工作空间名称

ubuntu 智能车比赛修改工作空间名称

主要参考:

智能车竞赛——室外光电创意组仿真之脱缰的野马

这个教程基本可以实现,在自己操作之前最好先把这个大佬的教程捋一遍!!!

最后附上大佬的bug总汇!在最下面!还有自己遇到的bug!


1、创建工作空间

  1. mkdir -p ~/hg_racecar_ws/src
  2. cd ~/racecar_ws/src
  3. catkin_init_workplace

2、创建智能车模型文件夹、智能车控制文件夹、智能车仿真文件夹

  1. mkdir hg_racecar_control
  2. mkdir hg_racecar_description
  3. mkdir hg_racecar_gazebo

3、移植文件

将下载下来的比赛以及赛道模型文件打开

打开racecar_description文件夹,将其中的所有的文件全部copy到我们自己创建的hg_racecar_description文件夹中;

将smart_plane整个文件夹全部copy到hg_racecar_ws/src文件夹下;

打开hg_racecar_control文件夹,创建script文件夹,将control_plugin.py文件copy到script文件夹里面去;

打开hg_racecar_gazebo文件夹,创建worlds文件夹,将racetrack.world文件copy到worlds文件夹里面去;

至此,下载下来的比赛以及赛道模型文件中的全部内容移植完毕!

4、文件内容重命名

打开roboware stdio,将创建好的工作空间拖到其中,由于我们功能包的文件名叫做hg_...,因此我们需要修改文件中的内容

打开roboware stdio中左侧面板的搜索功能

将racecar_description字段全部替换为hg_racecar_description;

将racecar_gazebo字段全部替换为hg_racecar_gazebo;

5、添加文件

cd ~/hg_racecar_ws/src/hg_racecar_gazebo
  1. gedit CMakeLists.txt
  2. 将一下内容复制到里面,然后保存退出
  3. cmake_minimum_required(VERSION 2.8.3)
  4. project(hg_racecar_gazebo)
  5. ## Find catkin macros and libraries
  6. ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
  7. ## is used, also find other catkin packages
  8. set(OpenCV_DIR /opt/ros/kinetic/share/OpenCV-3.3.1-dev/)
  9. find_package(catkin REQUIRED COMPONENTS
  10. gazebo_ros
  11. geometry_msgs
  12. OpenCV
  13. roscpp
  14. cv_bridge
  15. image_transport
  16. )
  17. ## System dependencies are found with CMake's conventions
  18. # find_package(Boost REQUIRED COMPONENTS system)
  19. ## Uncomment this if the package has a setup.py. This macro ensures
  20. ## modules and global scripts declared therein get installed
  21. ## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
  22. # catkin_python_setup()
  23. ################################################
  24. ## Declare ROS messages, services and actions ##
  25. ################################################
  26. ## To declare and build messages, services or actions from within this
  27. ## package, follow these steps:
  28. ## * Let MSG_DEP_SET be the set of packages whose message types you use in
  29. ## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
  30. ## * In the file package.xml:
  31. ## * add a build_depend tag for "message_generation"
  32. ## * add a build_depend and a run_depend tag for each package in MSG_DEP_SET
  33. ## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
  34. ## but can be declared for certainty nonetheless:
  35. ## * add a run_depend tag for "message_runtime"
  36. ## * In this file (CMakeLists.txt):
  37. ## * add "message_generation" and every package in MSG_DEP_SET to
  38. ## find_package(catkin REQUIRED COMPONENTS ...)
  39. ## * add "message_runtime" and every package in MSG_DEP_SET to
  40. ## catkin_package(CATKIN_DEPENDS ...)
  41. ## * uncomment the add_*_files sections below as needed
  42. ## and list every .msg/.srv/.action file to be processed
  43. ## * uncomment the generate_messages entry below
  44. ## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)
  45. ## Generate messages in the 'msg' folder
  46. # add_message_files(
  47. # FILES
  48. # Message1.msg
  49. # Message2.msg
  50. # )
  51. ## Generate services in the 'srv' folder
  52. # add_service_files(
  53. # FILES
  54. # Service1.srv
  55. # Service2.srv
  56. # )
  57. ## Generate actions in the 'action' folder
  58. # add_action_files(
  59. # FILES
  60. # Action1.action
  61. # Action2.action
  62. # )
  63. ## Generate added messages and services with any dependencies listed here
  64. # generate_messages(
  65. # DEPENDENCIES
  66. # std_msgs # Or other packages containing msgs
  67. # )
  68. ################################################
  69. ## Declare ROS dynamic reconfigure parameters ##
  70. ################################################
  71. ## To declare and build dynamic reconfigure parameters within this
  72. ## package, follow these steps:
  73. ## * In the file package.xml:
  74. ## * add a build_depend and a run_depend tag for "dynamic_reconfigure"
  75. ## * In this file (CMakeLists.txt):
  76. ## * add "dynamic_reconfigure" to
  77. ## find_package(catkin REQUIRED COMPONENTS ...)
  78. ## * uncomment the "generate_dynamic_reconfigure_options" section below
  79. ## and list every .cfg file to be processed
  80. ## Generate dynamic reconfigure parameters in the 'cfg' folder
  81. # generate_dynamic_reconfigure_options(
  82. # cfg/DynReconf1.cfg
  83. # cfg/DynReconf2.cfg
  84. # )
  85. ###################################
  86. ## catkin specific configuration ##
  87. ###################################
  88. ## The catkin_package macro generates cmake config files for your package
  89. ## Declare things to be passed to dependent projects
  90. ## INCLUDE_DIRS: uncomment this if you package contains header files
  91. ## LIBRARIES: libraries you create in this project that dependent projects also need
  92. ## CATKIN_DEPENDS: catkin_packages dependent projects also need
  93. ## DEPENDS: system dependencies of this project that dependent projects also need
  94. catkin_package(
  95. # INCLUDE_DIRS include
  96. # LIBRARIES hg_racecar_gazebo
  97. # CATKIN_DEPENDS gazebo_ros
  98. # DEPENDS system_lib
  99. )
  100. ###########
  101. ## Build ##
  102. ###########
  103. ## Specify additional locations of header files
  104. ## Your package locations should be listed before other locations
  105. # include_directories(include)
  106. include_directories(
  107. ${catkin_INCLUDE_DIRS}
  108. ${OpenCV_INCLUDE_DIRS}
  109. )
  110. ## Declare a C++ library
  111. # add_library(hg_racecar_gazebo
  112. # src/${PROJECT_NAME}/hg_racecar_gazebo.cpp
  113. # )
  114. ## Add cmake target dependencies of the library
  115. ## as an example, code may need to be generated before libraries
  116. ## either from message generation or dynamic reconfigure
  117. # add_dependencies(hg_racecar_gazebo ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
  118. ## Declare a C++ executable
  119. add_executable(findLine src/findLine.cpp)
  120. ## Add cmake target dependencies of the executable
  121. ## same as for the library above
  122. # add_dependencies(hg_racecar_gazebo_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
  123. ## Specify libraries to link a library or executable target against
  124. target_link_libraries(findLine
  125. ${catkin_LIBRARIES}
  126. ${OpenCV_LiBRARIES}
  127. )
  128. add_dependencies(findLine findLine_tutorials_generate_messages_cpp)
  129. #############
  130. ## Install ##
  131. #############
  132. # all install targets should use catkin DESTINATION variables
  133. # See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html
  134. ## Mark executable scripts (Python etc.) for installation
  135. ## in contrast to setup.py, you can choose the destination
  136. # install(PROGRAMS
  137. # scripts/my_python_script
  138. # DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
  139. # )
  140. ## Mark executables and/or libraries for installation
  141. # install(TARGETS hg_racecar_gazebo hg_racecar_gazebo_node
  142. # ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  143. # LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  144. # RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
  145. # )
  146. ## Mark cpp header files for installation
  147. # install(DIRECTORY include/${PROJECT_NAME}/
  148. # DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
  149. # FILES_MATCHING PATTERN "*.h"
  150. # PATTERN ".svn" EXCLUDE
  151. # )
  152. ## Mark other files for installation (e.g. launch and bag files, etc.)
  153. # install(FILES
  154. # # myfile1
  155. # # myfile2
  156. # DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
  157. # )
  158. #############
  159. ## Testing ##
  160. #############
  161. ## Add gtest based cpp test target and link libraries
  162. # catkin_add_gtest(${PROJECT_NAME}-test test/test_hg_racecar_gazebo.cpp)
  163. # if(TARGET ${PROJECT_NAME}-test)
  164. # target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
  165. # endif()
  166. ## Add folders to be run by python nosetests
  167. # catkin_add_nosetests(test)
  1. gedit package.xml
  2. 复制下面内容到文件中,然后保存退出
  3. <?xml version="1.0"?>
  4. <package>
  5. <name>hg_racecar_gazebo</name>
  6. <version>0.0.0</version>
  7. <description>The hg_racecar_gazebo package</description>
  8. <!-- One maintainer tag required, multiple allowed, one person per tag -->
  9. <!-- Example: -->
  10. <!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
  11. <maintainer email="ubuntu@todo.todo">ubuntu</maintainer>
  12. <!-- One license tag required, multiple allowed, one license per tag -->
  13. <!-- Commonly used license strings: -->
  14. <!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
  15. <license>TODO</license>
  16. <!-- Url tags are optional, but mutiple are allowed, one per tag -->
  17. <!-- Optional attribute type can be: website, bugtracker, or repository -->
  18. <!-- Example: -->
  19. <!-- <url type="website">http://wiki.ros.org/hg_racecar_gazebo</url> -->
  20. <!-- Author tags are optional, mutiple are allowed, one per tag -->
  21. <!-- Authors do not have to be maintianers, but could be -->
  22. <!-- Example: -->
  23. <!-- <author email="jane.doe@example.com">Jane Doe</author> -->
  24. <!-- The *_depend tags are used to specify dependencies -->
  25. <!-- Dependencies can be catkin packages or system dependencies -->
  26. <!-- Examples: -->
  27. <!-- Use build_depend for packages you need at compile time: -->
  28. <!-- <build_depend>message_generation</build_depend> -->
  29. <!-- Use buildtool_depend for build tool packages: -->
  30. <!-- <buildtool_depend>catkin</buildtool_depend> -->
  31. <!-- Use run_depend for packages you need at runtime: -->
  32. <!-- <run_depend>message_runtime</run_depend> -->
  33. <!-- Use test_depend for packages you need only for testing: -->
  34. <!-- <test_depend>gtest</test_depend> -->
  35. <buildtool_depend>catkin</buildtool_depend>
  36. <build_depend>gazebo_ros</build_depend>
  37. <run_depend>gazebo_ros</run_depend>
  38. <run_depend>controller_manager</run_depend>
  39. <run_depend>ros_controllers</run_depend>
  40. <run_depend>ros_control</run_depend>
  41. <run_depend>gazebo_ros_control</run_depend>
  42. <build_depend>geometry_msgs</build_depend>
  43. <build_depend>roscpp</build_depend>
  44. <build_depend>image_transport</build_depend>
  45. <build_depend>cv_bridge</build_depend>
  46. <build_depend>trajectory_msgs</build_depend>
  47. <run_depend>geometry_msgs</run_depend>
  48. <run_depend>roscpp</run_depend>
  49. <run_depend>image_transport</run_depend>
  50. <run_depend>cv_bridge</run_depend>
  51. <run_depend>trajectory_msgs</run_depend>
  52. <!-- The export tag contains other, unspecified, tags -->
  53. <export>
  54. <gazebo_ros gazebo_model_path="${prefix}/.." />
  55. </export>
  56. </package>
  1. mkdir src
  2. cd src
  3. gedit findLine.cpp
  4. 复制下面的内容然后到文件中,保存退出
  5. #include <ros/ros.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include "std_msgs/Float64.h"
  9. #include "sensor_msgs/Image.h"
  10. #include "geometry_msgs/Twist.h"
  11. #include "ackermann_msgs/AckermannDrive.h"
  12. #include "ackermann_msgs/AckermannDriveStamped.h"
  13. #include <opencv2/core.hpp>
  14. #include <opencv/highgui.h>
  15. #include <opencv2/opencv.hpp>
  16. #include "cv_bridge/cv_bridge.h"
  17. #include <sensor_msgs/image_encodings.h>
  18. #include <sensor_msgs/Imu.h>
  19. #include <image_transport/image_transport.h>
  20. #include <trajectory_msgs/JointTrajectory.h>
  21. using namespace cv;
  22. class Follower{
  23. public:
  24. ros::NodeHandle node;
  25. static ros::Publisher cmdpub;
  26. static ros::Subscriber imageSub;
  27. static void image_callback(const sensor_msgs::ImageConstPtr& msg);
  28. static void speed_contrl(float speed_car,float angluar_car);
  29. Follower();
  30. };
  31. ros::Publisher Follower::cmdpub;
  32. ros::Subscriber Follower::imageSub;
  33. int main(int argc, char* argv[])
  34. {
  35. ros::init(argc,argv,"follower_cpp");
  36. Follower f;//调用构造函数
  37. while(ros::ok())
  38. {
  39. ros::Rate loop_rate(0.2);
  40. //这里是程序的循环处,可以写你的代码
  41. ros::spinOnce();
  42. }
  43. }
  44. void Follower::image_callback(const sensor_msgs::ImageConstPtr& msg)
  45. {
  46. cv_bridge::CvImagePtr cv_ptr;
  47. try
  48. {
  49. cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
  50. }
  51. catch(cv_bridge::Exception& e)
  52. {
  53. ROS_ERROR("cv_bridge exception: %s", e.what());
  54. return;
  55. }
  56. Mat hsv = cv_ptr->image.clone();
  57. Mat mask = cv_ptr->image.clone();
  58. cvtColor(cv_ptr->image, hsv, COLOR_BGR2HSV);
  59. double low_H = 0;
  60. double low_S = 0;
  61. double low_V = 100;
  62. double high_H = 180;
  63. double high_S = 30;
  64. double high_V = 255;
  65. inRange(hsv, Scalar(low_H, low_S, low_V), Scalar(high_H, high_S, high_V), mask);
  66. speed_contrl(0.5,0.5);
  67. imshow("mask",mask);
  68. waitKey(3);
  69. }
  70. void Follower::speed_contrl(float speed_car,float angluar_car)
  71. {
  72. ackermann_msgs::AckermannDriveStamped ack;
  73. ack.drive.speed = speed_car;
  74. ack.drive.steering_angle = angluar_car;
  75. cmdpub.publish(ack);
  76. }
  77. Follower::Follower()
  78. {
  79. cmdpub = node.advertise<ackermann_msgs::AckermannDriveStamped>("/vesc/low_level/ackermann_cmd_mux/input/teleop", 10, true);
  80. imageSub = node.subscribe("/camera/zed/rgb/image_rect_color",10,image_callback);
  81. }

6、编译

  1. cd ~/hg_racecar_ws/src
  2. catkin_make

如果编译成功则会输出: 

7、修改.bashrc文件

  1. gedit ~/.bashrc
  2. 然后将下面这句话添加到最后一行,保存退出:
  3. source ~/hg_racecar_ws/devel/setup.bash

8、运行launch文件查看赛道以及小车模型

  1. roslaunch hg_racecar_description racecar_rviz.launch
  2. 或者只是运行gazebo
  3. roslaunch hg_racecar_description racecar.launch

如果输出成功那么就会显示如下:

10、bug汇总

注意,添加source...到 ~/.bashrc文件的时候一定要添加到最后一行,不然可能找不到功能包!!!

  1. 'ascii' codec can't decode byte 0xe6 in position 258: ordinal not in ra
  2. The traceback for the exception was written to the log file
  3. 如果运行launch出现这个错误,多半就是文件中含有中文字母!!!
  4. 还有可能就是
  5. 如果找地图的模型的时候,要是没有添加CMakeLists.txt和package.xml文件,也会报这样的错误,这个时候需要在放置地图的文件夹中添加CMakeLists.txt和package.xml文件,同时主要文件内容的功能包的名字的修改!!!

 如果遇到这个cmd 139 Segmentation fault的问题就是gazebo的版本不合适,比如你用的是gazebo9,但是其实换成gazebo7就解决问题了

但是!!!要是遇到类似的问题,根据一个大佬说,你可以这么考虑:

对于情况三而言,平时避免,就是不要直接插掉软件,可以通过ctrl+c的方法来kill,要是不行的话,直接 运行下面的命令:

  1. killall gzserver
  2. killall gzclient

!!!

要是少了什么依赖,直接少什么加什么,或者直接百度都有!!!

其他问题可以在大佬的bug总汇中查到:(这个实在这个大佬的教程的基础上进行的,最好把大佬的运行一遍熟悉熟悉)

  1. # 智能车仿真
  2. 代码使用参考教程:[教程地址](https://www.guyuehome.com/6463)
  3. # bug汇总
  4. ## 报错controllers相关
  5. ```bash
  6. sudo apt-get install ros-kinetic-controller-manager
  7. sudo apt-get install ros-kinetic-gazebo-ros-control
  8. sudo apt-get install ros-kinetic-effort-controllers
  9. sudo apt-get install ros-kinetic-joint-state-controller
  10. ```
  11. ## 报错driver_base相关
  12. ```bash
  13. sudo apt-get install ros-kinetic-driver-base
  14. ```
  15. ## 报错rtabmap相关
  16. ```bash
  17. sudo apt-get install ros-kinetic-rtabmap-ros
  18. ```
  19. ## 报错ackermann_msgs相关
  20. ```bash
  21. sudo apt-get install ros-kinetic-ackermann-msgs
  22. ```
  23. ## 报错findline.cpp找不到opencv头文件
  24. 执行:`locate OpenCVConfig.cmake`得到你的opencv的路径
  25. 执行:`gedit ~/racecar_ws/src/racecar_gazebo/CMakeLists.txt`
  26. 修改第7行的路径成你的路径:set(OpenCV_DIR /opt/ros/kinetic/share/OpenCV-3.3.1-dev/)
  27. ## 报错Failed to create the teb_local_planner/TebLocalPlannerROS planner
  28. ```bash
  29. sudo apt-get install ros-kinetic-teb-local-planner
  30. ```
  31. ## 没有laser相关话题,无法建图
  32. **这个纯属个人失误,写四轮摄像头组的博客的时候觉得激光雷达的蓝色太碍事了就把它关了......我单纯的以为只是关闭了激光显示,原来是把数据都关了!抱歉~**
  33. ~/racecar_ws/src/racecar_description/urdf/racecar.gazebo在这个文件中61行改成false即可,代码我已修复,直接下载没有问题的

 

 

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/619213
推荐阅读
相关标签
  

闽ICP备14008679号