ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Can't find correct sytax for ros::nodehandle::advertise

asked 2015-04-26 19:25:56 -0500

fborok gravatar image

updated 2015-04-26 19:26:58 -0500

I have just started learning ROS and I have written a publisher node based on the following tutorials:

https://support.clearpathrobotics.com... ------ ROS 101: Drive a Husky

http://wiki.ros.org/ROS/Tutorials/Wri...

I can't get it to compile, and after checking the tutorials and trying to understand the correct syntax I have been left completely baffled. I have no idea how to fix the problem.

The problem is on line 28: ros::Publisher velocity_pub = node.advertise<geometry_msgs twist="">(topic_name, 1000);

I am very new to ROS. Can someone explain how to correctly write a ros::nodehandle::advertise statement?

Here is the console output:

[100%] Building CXX object drive_husky/CMakeFiles/drive_husky.dir/src/drive.cpp.o
/home/francis/husky_cws/src/drive_husky/src/drive.cpp: In function ‘int main(int, char**)’:
/home/francis/husky_cws/src/drive_husky/src/drive.cpp:28:37: error: parse error in template argument list
  ros::Publisher velocity_pub = node.advertise<geometry_msgs/Twist>(topic_name, 1000);
                                     ^
/home/francis/husky_cws/src/drive_husky/src/drive.cpp:28:84: error: no matching function for call to ‘ros::NodeHandle::advertise(const string&, int)’
  ros::Publisher velocity_pub = node.advertise<geometry_msgs/Twist>(topic_name, 1000);
                                                                                    ^
/home/francis/husky_cws/src/drive_husky/src/drive.cpp:28:84: note: candidates are:
In file included from /opt/ros/indigo/include/ros/ros.h:45:0,
                 from /home/francis/husky_cws/src/drive_husky/src/drive.cpp:1:
/opt/ros/indigo/include/ros/node_handle.h:236:15: note: template<class M> ros::Publisher ros::NodeHandle::advertise(const string&, uint32_t, bool)
     Publisher advertise(const std::string& topic, uint32_t queue_size, bool latch = false)
               ^
/opt/ros/indigo/include/ros/node_handle.h:236:15: note:   template argument deduction/substitution failed:
/home/francis/husky_cws/src/drive_husky/src/drive.cpp:28:84: error: template argument 1 is invalid
  ros::Publisher velocity_pub = node.advertise<geometry_msgs/Twist>(topic_name, 1000);
                                                                                    ^
In file included from /opt/ros/indigo/include/ros/ros.h:45:0,
                 from /home/francis/husky_cws/src/drive_husky/src/drive.cpp:1:
/opt/ros/indigo/include/ros/node_handle.h:300:13: note: template<class M> ros::Publisher ros::NodeHandle::advertise(const string&, uint32_t, const SubscriberStatusCallback&, const SubscriberStatusCallback&, const VoidConstPtr&, bool)
   Publisher advertise(const std::string& topic, uint32_t queue_size,
             ^
/opt/ros/indigo/include/ros/node_handle.h:300:13: note:   template argument deduction/substitution failed:
/home/francis/husky_cws/src/drive_husky/src/drive.cpp:28:84: error: template argument 1 is invalid
  ros::Publisher velocity_pub = node.advertise<geometry_msgs/Twist>(topic_name, 1000);
                                                                                    ^
make[2]: *** [drive_husky/CMakeFiles/drive_husky.dir/src/drive.cpp.o] Error 1
make[1]: *** [drive_husky/CMakeFiles/drive_husky.dir/all] Error 2
make: *** [all] Error 2

And here are my files: drive.cpp:

#include <ros/ros.h>
//#include "std_msgs/String.h"
#include <geometry_msgs/Twist.h>

#include <string>
#include <cstring>

/*** Make the Husky drive forwards and backwards three times, and then come to a halt ***/

int main(int argc, char **argv) //argc and argv required for ros::init to create node
{
    ros::init(argc, argv, "Driver");    //Must call ros::init, requires argc and argv and the name of the node to be initiated

    ros ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2015-04-26 22:13:45 -0500

ahendrix gravatar image

You need to use the C++ namespace separator (::) instead of the / when specifying the topic type:

ros::Publisher velocity_pub = node.advertise<geometry_msgs::Twist>(topic_name, 1000);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-04-26 19:25:56 -0500

Seen: 2,246 times

Last updated: Apr 26 '15