sudo sh -c 'echo "deb https://repo.huaweicloud.com/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
如果roscore运行出现报错:
killall -9 roscore //如果提示未找到进程不用管,继续执行下一条
killall -9 rosmaster
在终端中
mkdir -p demo02_ws/src
cd demo02_ws/
catkin_make
code .
contrl+shift+B: 选择catkin_make:build,配置task.json
roscore
source ./devel/setup.bash ——刷新环境变量
rosrun + (文件名)hello_vscode(映射名称) hello_vscode_c
修改完CMakeLists.txt之后
首先运行roscore
然后是cd demo02_ws/
最后是source ./devel/setup.bash
接着时rosrun+功能包名:rosrun plumbing_pub_sub demo01_pub(运行后没有任何日志输出)
在vscode里面使用launch文件同时启动多个结点:
source ./devel/setup.bash
roslaunch hello_vscode start_turtle.launch
scripts在完成python程序之后,需要添加可执行权限,右击scripts选择在终端中打开,执行以下操作
chmod +x *.py
ll
rosrun plumbing_pub_sub demo01_pub_p.py
rostopic echo che
rosrun plumbing_pub_sub demo01_pub_p.py
rosrun plumbing_pub_sub demo02_sub_p.py
find_package作用:如果编译自定义的功能包plumbing_pub_sub的话必须依赖find_package里面的功能包。同时find_package里面的功能包依赖于catkin_package里面的功能包,最好在后面添加message_runtime
在没有关闭的终端中,按向上的箭头可以使用之前输入的命令
输入main,然后选择第2个,自动补齐,去掉const修饰符,就可以了
鼠标指向空号内,ctrl+shift+空格可以看到里面的定义
新建功能包时,一定要添加依赖,就是****roscpp rospy std_msgs
add_dependencies(demo03_pub_person${PROJECT_NAME}_generate_messages_cpp)作用:先保证msg被编译,然后被主要程序调用
配置c_cpp_properies.json 文件,如果以前已经配置且没有变更工作空间,可以忽略
{
"configurations": [
{
"browse": {
"databaseFilename": "",
"limitSymbolsToIncludedHeaders": true
},
"includePath": [
"/opt/ros/noetic/include/**",
"/usr/include/**",
"/xxx/yyy工作空间/devel/include/**" //配置 head 文件的路径
],
"name": "ROS",
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
这里在devel文件里,右击功能包选择在终端里打开,使用pwd可以找到文件路径。
/home/rosnoetic/demo02_ws/devel/include/plumbing_server_client
一共有三个部分
add_executable(AddInts_Server src/AddInts_Server.cpp)
add_executable(AddInts_Client src/AddInts_Client.cpp)
add_dependencies(AddInts_Server ${PROJECT_NAME}_gencpp)
add_dependencies(AddInts_Client ${PROJECT_NAME}_gencpp)
target_link_libraries(AddInts_Server
${catkin_LIBRARIES}
)
target_link_libraries(AddInts_Client
${catkin_LIBRARIES}
)
进入settings.json 文件,如果以前已经配置且没有变更工作空间,可以忽略
{
"python.autoComplete.extraPaths": [
"/opt/ros/noetic/lib/python3/dist-packages",
]
}
右击scripts,选择进入终端执行
chmod +x *.py
ll
catkin_install_python(PROGRAMS
scripts/AddInts_Server_p.py
scripts/AddInts_Client_p.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)