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>

 

转载于:https://www.cnblogs.com/Montauk/p/6866904.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值