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

Arduino Twist subscriber won't work

asked 2016-07-16 17:56:16 -0500

updated 2016-07-17 00:43:09 -0500

ahendrix gravatar image

This small program on Arduino sure gives lengthy errors! What am I doing wrong? This is Auduino UNO attached to Jetson TX1, with Rosserial.

ERROR

simple_subscriber_cmd_vel4.ino:17:74: error: invalid conversion from 'int' to 'ros::Subscriber<geometry_msgs::Twist>::CallbackT {aka void (*)(const geometry_msgs::Twist&)}' [-fpermissive]
In file included from /home/ubuntu/sketchbook/libraries/ros_lib/ros/node_handle.h:84:0,
                 from /home/ubuntu/sketchbook/libraries/ros_lib/ros.h:38,
                 from simple_subscriber_cmd_vel4.ino:2:
/home/ubuntu/sketchbook/libraries/ros_lib/ros/subscriber.h:65:7: error:   initializing argument 2 of 'ros::Subscriber<MsgT>::Subscriber(const char*, ros::Subscriber<MsgT>::CallbackT, int) [with MsgT = geometry_msgs::Twist; ros::Subscriber<MsgT>::CallbackT = void (*)(const geometry_msgs::Twist&)]' [-fpermissive]
       Subscriber(const char * topic_name, CallbackT cb, int endpoint=rosserial_msgs::TopicInfo::ID_SUBSCRIBER) :
       ^
simple_subscriber_cmd_vel4.ino:17:74: error: invalid conversion from 'void (*)(const geometry_msgs::Twist&)' to 'int' [-fpermissive]
In file included from /home/ubuntu/sketchbook/libraries/ros_lib/ros/node_handle.h:84:0,
                 from /home/ubuntu/sketchbook/libraries/ros_lib/ros.h:38,
                 from simple_subscriber_cmd_vel4.ino:2:
/home/ubuntu/sketchbook/libraries/ros_lib/ros/subscriber.h:65:7: error:   initializing argument 3 of 'ros::Subscriber<MsgT>::Subscriber(const char*, ros::Subscriber<MsgT>::CallbackT, int) [with MsgT = geometry_msgs::Twist; ros::Subscriber<MsgT>::CallbackT = void (*)(const geometry_msgs::Twist&)]' [-fpermissive]
       Subscriber(const char * topic_name, CallbackT cb, int endpoint=rosserial_msgs::TopicInfo::ID_SUBSCRIBER) :

   ^

SKETCH

#include <ArduinoHardware.h>
#include <ros.h>
#include <geometry_msgs/Twist.h>

ros::NodeHandle nh;
geometry_msgs::Twist msg;

float move1;
float move2;

void roverCallBack(const geometry_msgs::Twist& cmd_vel)
{
  move1 = cmd_vel.linear.x * 127 ;
  move2 = cmd_vel.angular.z * 127 ;
}

ros::Subscriber <geometry_msgs::Twist> sub("/cmd_vel", 100, roverCallBack);

void setup()
{
  nh.initNode();
  nh.subscribe(sub);
} 

void loop()
{
  nh.spinOnce();
  delay(1);
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-07-17 00:49:32 -0500

ahendrix gravatar image

Both of these errors are on the same line:

ros::Subscriber <geometry_msgs::Twist> sub("/cmd_vel", 100, roverCallBack);

The error message says that the signature for the Subscriber constructor is Subscriber(const char * topic_name, CallbackT cb, int endpoint=rosserial_msgs::TopicInfo::ID_SUBSCRIBER). The third argument has a default, and it isn't the queue size, so it looks like you don't need that argument.

Try:

ros::Subscriber <geometry_msgs::Twist> sub("/cmd_vel", roverCallBack);
edit flag offensive delete link more

Comments

It works! Thank you, that was simple. Just remove the 100!

Rodolfo8 gravatar image Rodolfo8  ( 2016-07-19 16:25:28 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-07-16 17:56:16 -0500

Seen: 2,245 times

Last updated: Jul 17 '16