玩命加载中 . . .

ROS自定义msg


自定义msg消息

Header header
int32 num
float64[] data

修改CMakeLists.txt

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  message_generation
)
// 添加自定义的msg文件
add_message_files(
  FILES
  test.msg
)
// 自定义的msg使用了哪些包
generate_messages(
  DEPENDENCIES
  std_msgs
)

catkin_package(
 CATKIN_DEPENDS roscpp rospy std_msgs message_runtime
)

修改package.xml

<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>

代码示例

#include <ros/ros.h>
#include <iostream>
#include "ros_learning/test.h"

using namespace std;
using namespace Eigen;
using namespace cv;

int main(int argc, char** argv)
{
    ros::init(argc, argv, "talker");
    ros::NodeHandle n;

    ros::Publisher pub = n.advertise<ros_learning::test>("chatting", 10);

    ros::Rate loop_rate(10);

    double arr[3] = {14, 15, 16};
    std::vector<double> vi(arr, arr+3);

    ros_learning::test input_msg;
    input_msg.header.stamp = ros::Time::now();
    input_msg.header.seq = 0;
    input_msg.header.frame_id = "base_frame";
    input_msg.num = 0;
    input_msg.data = vi;
    while(ros::ok())
    {
        input_msg.header.seq++;
        input_msg.header.stamp = ros::Time::now();
        for (auto & i : input_msg.data)
            std::cout << i << " ";
        std::cout << std::endl;
        pub.publish(input_msg);
        loop_rate.sleep();
    }
}

是否使用仿真时间

$ rosparam get use_sim_time
true
$ rosparam set use_sim_time false

文章作者: kunpeng
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 kunpeng !
  目录