gpt4 book ai didi

linux - 向 ROS 发送消息时遇到问题

转载 作者:太空宇宙 更新时间:2023-11-04 09:20:34 26 4
gpt4 key购买 nike

我是 ROS 的新手。我只是想使用以下代码向 Linux 服务器中的节点发布消息:

#include "stdafx.h"
#include "ros.h"
#include <string>
#include <stdio.h>
#include <Windows.h>

using std::string;

int _tmain(int argc, _TCHAR * argv[])
{
ros::NodeHandle nh;
char *ros_master = "*.*.*.*";

printf("Connecting to server at %s\n", ros_master);
nh.initNode(ros_master);

printf("Advertising cmd_vel message\n");
string sent = "Hello robot";
ros::Publisher cmd_vel_pub("try", sent);
nh.advertise(cmd_vel_pub);

printf("All done!\n");
return 0;
}

编译器给我这些错误:

 Error  C2664 'ros::Publisher::Publisher(ros::Publisher &&)': cannot convert argument 2 from 'std::string' to 'ros::Msg *'  LeapMotion     c:\users\vive-vr-pc\documents\visual studio    2015\projects\leapmotion\leapmotion\leapmotion.cpp    22  
Error (active) no instance of constructor "ros::Publisher::Publisher" matches the argument list LeapMotion c:\Users\Vive-VR-PC\Documents\Visual Studio 2015\Projects\LeapMotion\LeapMotion\LeapMotion.cpp 22

我在使用 Visual Studio,从 Windows 到 Linux 的教程不多,所以我不知道该怎么做。非常感谢您的帮助! :D

最佳答案

看看 Hello World例子。您不能发送未定义为消息的类型,即 std::string 不是 ros 消息类型。你需要的是

#include <std_msgs/String.h>

定义并填充字符串消息

std_msgs::String sent;
ros::Publisher cmd_vel_pub("try", &sent);
nh.advertise(cmd_vel_pub);

ros::Rate r(1); // once a second
sent.data = "Hello robot";
while (n.ok()){
cmd_vel_pun.publish(sent);
ros::spinOnce();
r.sleep();
}

看看这个 blabbler例子和这些tutorials .

关于linux - 向 ROS 发送消息时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42438894/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com