2017-02-24 6 views
0

저는 ROS에서 꽤 새로운입니다.ROS에 메시지를 보내는데 문제가 발생했습니다.

#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 

을 거기되지 않습니다 윈도우에서 리눅스까지 많은 튜토리얼이있어서, 무엇을해야할지 혼란 스럽다. 많은 도움에 감사드립니다! : D

+0

귀하의 질문에 답변 되었습니까? – cassinaj

답변

2

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 정의 및 채우기입니다.