首先查看自己的ROS版本:我的是melodic
roscore
rosparam list
rosparam get /rosdistro
cd /home/yao/My_Ros_WorkSpace
mkdir can_workspace
cd can_workspace
mkdir src
cd src
git clone https://github.com/ros-industrial/ros_canopen.git
如果下载源码的时候连接超时,就Ctrl + C
取消进程,然后重新输入指令多试几次,这是个玄学问题
sudo apt-get install libmuparser-dev
网上说,如果这一步安装遇到问题,可以执行这一步(我自己没试过)
sudo apt-get install libmuparser libmuparser2v5 libmuparser-doc libmuparserx-dev libmuparser-dev libmuparserx4.0.7
cd /home/yao/My_Ros_WorkSpace/can_workspace
catkin_make
终端输出了一大堆乱七八糟的日志,不用管他,成功了就行
yao@HP:~$ cd /home/yao/My_Ros_WorkSpace/can_workspace
yao@HP:~/My_Ros_WorkSpace/can_workspace$ catkin_make
Base path: /home/yao/My_Ros_WorkSpace/can_workspace
Source space: /home/yao/My_Ros_WorkSpace/can_workspace/src
Build space: /home/yao/My_Ros_WorkSpace/can_workspace/build
Devel space: /home/yao/My_Ros_WorkSpace/can_workspace/devel
Install space: /home/yao/My_Ros_WorkSpace/can_workspace/install
Creating symlink "/home/yao/My_Ros_WorkSpace/can_workspace/src/CMakeLists.txt" pointing to "/opt/ros/melodic/share/catkin/cmake/toplevel.cmake"
####
#### Running command: "cmake /home/yao/My_Ros_WorkSpace/can_workspace/src -DCATKIN_DEVEL_PREFIX=/home/yao/My_Ros_WorkSpace/can_workspace/devel -DCMAKE_INSTALL_PREFIX=/home/yao/My_Ros_WorkSpace/can_workspace/install -G Unix Makefiles" in "/home/yao/My_Ros_WorkSpace/can_workspace/build"
####
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using CATKIN_DEVEL_PREFIX: /home/yao/My_Ros_WorkSpace/can_workspace/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/melodic
-- This workspace overlays: /opt/ros/melodic
-- Found PythonInterp: /usr/bin/python2 (found suitable version "2.7.17", minimum required is "2")
-- Using PYTHON_EXECUTABLE: /usr/bin/python2
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/yao/My_Ros_WorkSpace/can_workspace/build/test_results
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python2 (found version "2.7.17")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.29
-- BUILD_SHARED_LIBS is on
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~ traversing 8 packages in topological order:
-- ~~ - ros_canopen (metapackage)
-- ~~ - can_msgs
-- ~~ - socketcan_interface
-- ~~ - canopen_master
-- ~~ - canopen_402
-- ~~ - canopen_chain_node
-- ~~ - socketcan_bridge
-- ~~ - canopen_motor_node
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin metapackage: 'ros_canopen'
-- ==> add_subdirectory(ros_canopen/ros_canopen)
-- +++ processing catkin package: 'can_msgs'
-- ==> add_subdirectory(ros_canopen/can_msgs)
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
-- can_msgs: 1 messages, 0 services
-- +++ processing catkin package: 'socketcan_interface'
-- ==> add_subdirectory(ros_canopen/socketcan_interface)
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- chrono
-- system
-- thread
-- date_time
-- atomic
-- +++ processing catkin package: 'canopen_master'
-- ==> add_subdirectory(ros_canopen/canopen_master)
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- atomic
-- chrono
-- thread
-- system
-- date_time
-- +++ processing catkin package: 'canopen_402'
-- ==> add_subdirectory(ros_canopen/canopen_402)
-- Boost version: 1.65.1
-- +++ processing catkin package: 'canopen_chain_node'
-- ==> add_subdirectory(ros_canopen/canopen_chain_node)
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- filesystem
-- system
-- canopen_chain_node: 0 messages, 2 services
-- +++ processing catkin package: 'socketcan_bridge'
-- ==> add_subdirectory(ros_canopen/socketcan_bridge)
-- +++ processing catkin package: 'canopen_motor_node'
-- ==> add_subdirectory(ros_canopen/canopen_motor_node)
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- thread
-- chrono
-- system
-- date_time
-- atomic
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Found MUPARSER: /usr/lib/x86_64-linux-gnu/libmuparser.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/yao/My_Ros_WorkSpace/can_workspace/build
####
#### Running command: "make -j4 -l4" in "/home/yao/My_Ros_WorkSpace/can_workspace/build"
####
Scanning dependencies of target std_msgs_generate_messages_lisp
Scanning dependencies of target _can_msgs_generate_messages_check_deps_Frame
Scanning dependencies of target std_msgs_generate_messages_cpp
Scanning dependencies of target std_msgs_generate_messages_py
[ 0%] Built target std_msgs_generate_messages_cpp
[ 0%] Built target std_msgs_generate_messages_lisp
[ 0%] Built target std_msgs_generate_messages_py
Scanning dependencies of target std_msgs_generate_messages_eus
Scanning dependencies of target std_msgs_generate_messages_nodejs
Scanning dependencies of target socketcan_interface_string
[ 0%] Built target std_msgs_generate_messages_eus
[ 0%] Built target std_msgs_generate_messages_nodejs
[ 1%] Building CXX object ros_canopen/socketcan_interface/CMakeFiles/socketcan_interface_string.dir/src/string.cpp.o
Scanning dependencies of target socketcan_interface_plugin
[ 1%] Built target _can_msgs_generate_messages_check_deps_Frame
Scanning dependencies of target _canopen_chain_node_generate_messages_check_deps_SetObject
Scanning dependencies of target _canopen_chain_node_generate_messages_check_deps_GetObject
[ 3%] Building CXX object ros_canopen/socketcan_interface/CMakeFiles/socketcan_interface_plugin.dir/src/socketcan_interface_plugin.cpp.o
[ 3%] Built target _canopen_chain_node_generate_messages_check_deps_SetObject
Scanning dependencies of target rosgraph_msgs_generate_messages_cpp
[ 3%] Built target _canopen_chain_node_generate_messages_check_deps_GetObject
[ 3%] Built target rosgraph_msgs_generate_messages_cpp
Scanning dependencies of target std_srvs_generate_messages_cpp
[ 3%] Built target std_srvs_generate_messages_cpp
Scanning dependencies of target rosgraph_msgs_generate_messages_eus
Scanning dependencies of target rosgraph_msgs_generate_messages_py
[ 3%] Built target rosgraph_msgs_generate_messages_eus
[ 3%] Built target rosgraph_msgs_generate_messages_py
Scanning dependencies of target rosgraph_msgs_generate_messages_nodejs
Scanning dependencies of target roscpp_generate_messages_lisp
[ 3%] Built target rosgraph_msgs_generate_messages_nodejs
[ 3%] Built target roscpp_generate_messages_lisp
Scanning dependencies of target std_srvs_generate_messages_lisp
Scanning dependencies of target roscpp_generate_messages_nodejs
[ 3%] Built target std_srvs_generate_messages_lisp
[ 3%] Built target roscpp_generate_messages_nodejs
Scanning dependencies of target roscpp_generate_messages_eus
Scanning dependencies of target diagnostic_msgs_generate_messages_cpp
[ 3%] Built target roscpp_generate_messages_eus
[ 3%] Built target diagnostic_msgs_generate_messages_cpp
Scanning dependencies of target rosgraph_msgs_generate_messages_lisp
Scanning dependencies of target diagnostic_msgs_generate_messages_lisp
[ 3%] Built target rosgraph_msgs_generate_messages_lisp
[ 3%] Built target diagnostic_msgs_generate_messages_lisp
Scanning dependencies of target diagnostic_msgs_generate_messages_nodejs
Scanning dependencies of target roscpp_generate_messages_py
[ 3%] Built target diagnostic_msgs_generate_messages_nodejs
[ 3%] Built target roscpp_generate_messages_py
Scanning dependencies of target diagnostic_msgs_generate_messages_py
Scanning dependencies of target std_srvs_generate_messages_py
[ 3%] Built target diagnostic_msgs_generate_messages_py
[ 3%] Built target std_srvs_generate_messages_py
Scanning dependencies of target roscpp_generate_messages_cpp
Scanning dependencies of target diagnostic_msgs_generate_messages_eus
[ 3%] Built target roscpp_generate_messages_cpp
[ 3%] Built target diagnostic_msgs_generate_messages_eus
Scanning dependencies of target std_srvs_generate_messages_nodejs
Scanning dependencies of target std_srvs_generate_messages_eus
[ 3%] Built target std_srvs_generate_messages_nodejs
[ 3%] Built target std_srvs_generate_messages_eus
Scanning dependencies of target controller_manager_msgs_generate_messages_cpp
Scanning dependencies of target controller_manager_msgs_generate_messages_py
[ 3%] Built target controller_manager_msgs_generate_messages_cpp
[ 3%] Built target controller_manager_msgs_generate_messages_py
Scanning dependencies of target controller_manager_msgs_generate_messages_nodejs
Scanning dependencies of target controller_manager_msgs_generate_messages_eus
[ 3%] Built target controller_manager_msgs_generate_messages_nodejs
[ 3%] Built target controller_manager_msgs_generate_messages_eus
Scanning dependencies of target controller_manager_msgs_generate_messages_lisp
Scanning dependencies of target can_msgs_generate_messages_py
[ 3%] Built target controller_manager_msgs_generate_messages_lisp
[ 4%] Generating Python from MSG can_msgs/Frame
Scanning dependencies of target can_msgs_generate_messages_cpp
[ 4%] Generating C++ code from can_msgs/Frame.msg
[ 6%] Generating Python msg __init__.py for can_msgs
[ 6%] Built target can_msgs_generate_messages_cpp
Scanning dependencies of target can_msgs_generate_messages_lisp
[ 7%] Generating Lisp code from can_msgs/Frame.msg
[ 7%] Built target can_msgs_generate_messages_lisp
Scanning dependencies of target can_msgs_generate_messages_eus
[ 9%] Generating EusLisp code from can_msgs/Frame.msg
[ 9%] Built target can_msgs_generate_messages_py
[ 10%] Generating EusLisp manifest code for can_msgs
Scanning dependencies of target can_msgs_generate_messages_nodejs
[ 12%] Generating Javascript code from can_msgs/Frame.msg
[ 12%] Built target can_msgs_generate_messages_nodejs
Scanning dependencies of target canopen_chain_node_generate_messages_eus
[ 13%] Generating EusLisp code from canopen_chain_node/SetObject.srv
[ 15%] Generating EusLisp code from canopen_chain_node/GetObject.srv
[ 15%] Generating EusLisp manifest code for canopen_chain_node
[ 15%] Built target can_msgs_generate_messages_eus
Scanning dependencies of target canopen_chain_node_generate_messages_py
[ 16%] Generating Python code from SRV canopen_chain_node/SetObject
[ 18%] Generating Python code from SRV canopen_chain_node/GetObject
[ 20%] Generating Python srv __init__.py for canopen_chain_node
[ 20%] Built target canopen_chain_node_generate_messages_eus
Scanning dependencies of target canopen_chain_node_generate_messages_lisp
[ 21%] Generating Lisp code from canopen_chain_node/SetObject.srv
[ 23%] Generating Lisp code from canopen_chain_node/GetObject.srv
[ 23%] Built target canopen_chain_node_generate_messages_py
Scanning dependencies of target canopen_chain_node_generate_messages_nodejs
[ 24%] Generating Javascript code from canopen_chain_node/SetObject.srv
[ 24%] Built target canopen_chain_node_generate_messages_lisp
Scanning dependencies of target canopen_chain_node_generate_messages_cpp
[ 26%] Generating Javascript code from canopen_chain_node/GetObject.srv
[ 27%] Generating C++ code from canopen_chain_node/SetObject.srv
[ 27%] Built target canopen_chain_node_generate_messages_nodejs
[ 29%] Generating C++ code from canopen_chain_node/GetObject.srv
Scanning dependencies of target can_msgs_generate_messages
[ 29%] Built target can_msgs_generate_messages
[ 29%] Built target canopen_chain_node_generate_messages_cpp
Scanning dependencies of target canopen_chain_node_generate_messages
[ 29%] Built target canopen_chain_node_generate_messages
[ 30%] Linking CXX shared library /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/libsocketcan_interface_string.so
[ 30%] Built target socketcan_interface_string
Scanning dependencies of target canopen_bcm_sync
Scanning dependencies of target socketcan_dump
Scanning dependencies of target socketcan_bcm
[ 33%] Building CXX object ros_canopen/socketcan_interface/CMakeFiles/socketcan_dump.dir/src/candump.cpp.o
[ 33%] Building CXX object ros_canopen/canopen_master/CMakeFiles/canopen_bcm_sync.dir/src/bcm_sync.cpp.o
[ 35%] Building CXX object ros_canopen/socketcan_interface/CMakeFiles/socketcan_bcm.dir/src/canbcm.cpp.o
[ 36%] Linking CXX executable /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/socketcan_interface/socketcan_bcm
[ 36%] Built target socketcan_bcm
Scanning dependencies of target canopen_master
[ 38%] Building CXX object ros_canopen/canopen_master/CMakeFiles/canopen_master.dir/src/emcy.cpp.o
[ 40%] Linking CXX shared library /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/libsocketcan_interface_plugin.so
[ 40%] Built target socketcan_interface_plugin
Scanning dependencies of target socketcan_to_topic
[ 41%] Building CXX object ros_canopen/socketcan_bridge/CMakeFiles/socketcan_to_topic.dir/src/rosconsole_bridge.cpp.o
[ 43%] Linking CXX executable /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/socketcan_interface/socketcan_dump
[ 44%] Building CXX object ros_canopen/socketcan_bridge/CMakeFiles/socketcan_to_topic.dir/src/socketcan_to_topic.cpp.o
[ 44%] Built target socketcan_dump
Scanning dependencies of target topic_to_socketcan
[ 46%] Building CXX object ros_canopen/socketcan_bridge/CMakeFiles/topic_to_socketcan.dir/src/rosconsole_bridge.cpp.o
[ 47%] Building CXX object ros_canopen/socketcan_bridge/CMakeFiles/topic_to_socketcan.dir/src/topic_to_socketcan.cpp.o
[ 49%] Linking CXX executable /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/canopen_master/canopen_bcm_sync
[ 49%] Built target canopen_bcm_sync
[ 50%] Building CXX object ros_canopen/canopen_master/CMakeFiles/canopen_master.dir/src/node.cpp.o
[ 52%] Building CXX object ros_canopen/canopen_master/CMakeFiles/canopen_master.dir/src/objdict.cpp.o
[ 53%] Linking CXX shared library /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/libsocketcan_to_topic.so
[ 53%] Built target socketcan_to_topic
Scanning dependencies of target socketcan_to_topic_node
[ 55%] Building CXX object ros_canopen/socketcan_bridge/CMakeFiles/socketcan_to_topic_node.dir/src/socketcan_to_topic_node.cpp.o
[ 56%] Linking CXX shared library /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/libtopic_to_socketcan.so
[ 56%] Built target topic_to_socketcan
Scanning dependencies of target socketcan_bridge_node
[ 58%] Building CXX object ros_canopen/socketcan_bridge/CMakeFiles/socketcan_bridge_node.dir/src/socketcan_bridge_node.cpp.o
[ 60%] Building CXX object ros_canopen/canopen_master/CMakeFiles/canopen_master.dir/src/pdo.cpp.o
[ 61%] Linking CXX executable /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/socketcan_bridge/socketcan_to_topic_node
[ 61%] Built target socketcan_to_topic_node
[ 63%] Building CXX object ros_canopen/canopen_master/CMakeFiles/canopen_master.dir/src/sdo.cpp.o
Scanning dependencies of target topic_to_socketcan_node
[ 64%] Building CXX object ros_canopen/socketcan_bridge/CMakeFiles/topic_to_socketcan_node.dir/src/topic_to_socketcan_node.cpp.o
[ 66%] Linking CXX executable /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/socketcan_bridge/socketcan_bridge_node
[ 66%] Built target socketcan_bridge_node
[ 67%] Linking CXX shared library /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/libcanopen_master.so
[ 69%] Linking CXX executable /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/socketcan_bridge/topic_to_socketcan_node
[ 69%] Built target canopen_master
Scanning dependencies of target canopen_402
Scanning dependencies of target canopen_master_plugin
Scanning dependencies of target canopen_sync_node
[ 70%] Building CXX object ros_canopen/canopen_402/CMakeFiles/canopen_402.dir/src/motor.cpp.o
[ 72%] Building CXX object ros_canopen/canopen_master/CMakeFiles/canopen_master_plugin.dir/src/master_plugin.cpp.o
[ 73%] Building CXX object ros_canopen/canopen_chain_node/CMakeFiles/canopen_sync_node.dir/src/rosconsole_bridge.cpp.o
[ 73%] Built target topic_to_socketcan_node
Scanning dependencies of target canopen_ros_chain
[ 75%] Building CXX object ros_canopen/canopen_chain_node/CMakeFiles/canopen_ros_chain.dir/src/ros_chain.cpp.o
[ 76%] Building CXX object ros_canopen/canopen_chain_node/CMakeFiles/canopen_sync_node.dir/src/sync_node.cpp.o
[ 78%] Linking CXX shared library /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/libcanopen_master_plugin.so
[ 78%] Built target canopen_master_plugin
[ 80%] Building CXX object ros_canopen/canopen_chain_node/CMakeFiles/canopen_ros_chain.dir/src/rosconsole_bridge.cpp.o
[ 81%] Linking CXX shared library /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/libcanopen_402.so
[ 81%] Built target canopen_402
Scanning dependencies of target canopen_402_plugin
[ 83%] Building CXX object ros_canopen/canopen_402/CMakeFiles/canopen_402_plugin.dir/src/plugin.cpp.o
[ 84%] Linking CXX executable /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/canopen_chain_node/canopen_sync_node
[ 84%] Built target canopen_sync_node
[ 86%] Linking CXX shared library /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/libcanopen_402_plugin.so
[ 86%] Built target canopen_402_plugin
[ 87%] Linking CXX shared library /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/libcanopen_ros_chain.so
[ 87%] Built target canopen_ros_chain
Scanning dependencies of target canopen_chain_node
Scanning dependencies of target canopen_motor
[ 89%] Building CXX object ros_canopen/canopen_chain_node/CMakeFiles/canopen_chain_node.dir/src/chain_node.cpp.o
[ 90%] Building CXX object ros_canopen/canopen_motor_node/CMakeFiles/canopen_motor.dir/src/controller_manager_layer.cpp.o
[ 90%] Building CXX object ros_canopen/canopen_motor_node/CMakeFiles/canopen_motor.dir/src/handle_layer.cpp.o
[ 92%] Building CXX object ros_canopen/canopen_motor_node/CMakeFiles/canopen_motor.dir/src/motor_chain.cpp.o
[ 93%] Linking CXX executable /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/canopen_chain_node/canopen_chain_node
[ 93%] Built target canopen_chain_node
[ 95%] Building CXX object ros_canopen/canopen_motor_node/CMakeFiles/canopen_motor.dir/src/robot_layer.cpp.o
[ 96%] Linking CXX shared library /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/libcanopen_motor.so
[ 96%] Built target canopen_motor
Scanning dependencies of target canopen_motor_node
[ 98%] Building CXX object ros_canopen/canopen_motor_node/CMakeFiles/canopen_motor_node.dir/src/canopen_motor_chain_node.cpp.o
[100%] Linking CXX executable /home/yao/My_Ros_WorkSpace/can_workspace/devel/lib/canopen_motor_node/canopen_motor_node
[100%] Built target canopen_motor_node
yao@HP:~/My_Ros_WorkSpace/can_workspace$
然后用VScode打开这个工作空间
具体的配置方法可以看我前面的博客:ROS集成开发环境
cd /home/yao/My_Ros_WorkSpace/can_workspace
code .
主要是使用socketcan-bridg这个功能包,它帮我们做了很多底层的工作
比如socketcan_to_topicnode.cpp:可以将上位机发布的can消息转为话题发布;topic_to_socketcannode.cpp:可以将底盘发送的信息转为话题进行订阅。