msg/stm32_messageecho "uint8 da_ubuntu18串口通信协议代码">
赞
踩
1、安装串口包
sudo apt-get install ros-melodic-serial
2、使用rospy、roscpp、serial这三个包,创建talker功能包
catkin_create_pkg stm32_talker rospy roscpp serial
注意:如果没有工作空间需要先建立工作空间
mkdir -p ~/catkin_workspace/src
cd ~/catkin_workspace
catkin_make
source devel/setup.bash //配置环境变量
echo $ROS_PACKAGE_PATH //检查环境变量配置
cd ~/catkin_workplace/src
catkin_create_pkg stm32_talker rospy roscpp serial
catkin_make
3、创建消息
1)建立消息目录
cd stm32_talker
mkdir msg
2) 建立消息体
echo "uint8 data0" > msg/stm32_message.msg
echo "uint8 data1" >> msg/stm32_message.msg //追加
echo "uint8 data2" >> msg/stm32_message.msg
echo "uint8 data3" >> msg/stm32_message.msg
echo "uint8 data4" >> msg/stm32_message.msg
echo "uint8 data5" >> msg/stm32_message.msg
echo "uint8 data6" >> msg/stm32_message.msg
echo "uint8 data7" >> msg/stm32_message.msg
3)修改包脚本
gedit package.xml
添加:
<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>
4)修改CMake文件
a、添加message_generation
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
serial
stm32_talker# std_msgs是软件包名称
message_generation
)
b、添加message_runtime(这个若报错则不加)
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES stm32_talker
# CATKIN_DEPENDS roscpp rospy serial
# DEPENDS system_lib
CATKIN_DEPENDS message_runtime
)
c、添加stm32_message(取消注释,更改消息文件名)
add_message_files(
FILES
stm32_message.msg
)
d、确保generate_messages被调用(取消注释即可)
generate_messages(
DEPENDENCIES
stm32_talker # Or other packages containing msgs
)
5)编译
cd ~/catkin_workplace/
catkin_make
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。