ros怎么让订阅方1秒订阅一次
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ros怎么让订阅方1秒订阅一次相关的知识,希望对你有一定的参考价值。
参考技术A 1、首先,创建广播话题文件。2、其次,创建Arduino订阅节点文件。
3.、最后,运行节点,将命令整合成launch文件即可实现让对方1秒订阅一次。
ROS消息, 服务, 主题, 订阅 5
#include "ros/ros.h" #include "geometry_msgs/Twist.h" #include "geometry_msgs/Vector3.h" int main(int argc, char ** argv){ ros::init(argc, argv, "sendCMD2Turtule"); ros::NodeHandle nodeHandle; ros::Publisher cmdPub = nodeHandle.advertise<geometry_msgs::Twist>("/turtle1/cmd_vel" , 1000); ros::Rate loop_rate(1); while(ros::ok()){ geometry_msgs::Twist twist; geometry_msgs::Vector3 setLinear; setLinear.x = 1.0f; twist.linear = setLinear; ROS_INFO("liner x: %f, moving!", 1.0f); cmdPub.publish(twist); ros::spinOnce(); loop_rate.sleep(); } return 0; }
My turtlesim control node.
and CMakeLists.txt:
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs message_generation geometry_msgs ) catkin_package( # INCLUDE_DIRS include # LIBRARIES beginner_tutorials CATKIN_DEPENDS message_runtime roscpp rospy std_msgs geometry_msgs # DEPENDS system_lib ) generate_messages( DEPENDENCIES std_msgs geometry_msgs ) ... add_executable(sendCmd2TurtleSim src/sendCmd2TurtleSim.cpp) target_link_libraries(sendCmd2TurtleSim ${catkin_LIBRARIES}) add_dependencies(sendCmd2TurtleSim beginner_tutorials_generate_messages_cpp)
package.xml:
<build_depend>geometry_msgs</build_depend> <run_depend>geometry_msgs</run_depend>
以上是关于ros怎么让订阅方1秒订阅一次的主要内容,如果未能解决你的问题,请参考以下文章