Robotics StackExchange | Archived questions

publish sevomoteur angle

hi, i created a program that published angle of servomotor, and also this code to subscribe to this angle:

    #include "ros/ros.h"
#include "std_msgs/Uint16.h"
int angle = 0;
void angleCallback(const std_msgs::String::ConstPtr& servo_msg)
{
Angle = servo_msg->angle
ROS_INFO("I turn: [%d]degree", angle
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "angle_listener");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("/servo", 1000, angleCallback);
ros::spin();
return 0;
}

but i have an error in my code in fonction angleCallback. Can you help me please?

Asked by Emilien on 2016-04-05 08:40:18 UTC

Comments

Answers

You should maybe start with a C++-Tutorial.

  1. 'Angle' is not defined
  2. std_msgs/String has no "angle" member but only a 'data'-member
  3. Your ROS_INFO is not terminated so your program does not even compile.
  4. " i have an error in my code" is the WORST error description so please at least post the error message.
  5. There is a missing ';' after servo_msg->angle

Asked by NEngelhard on 2016-04-05 10:05:15 UTC

Comments

While the points you mention are definitely issues, perhaps a bit more of a constructive tone would work better ;).

Asked by gvdhoorn on 2016-04-05 10:19:32 UTC

You are probably right. But the last posts showed a similar effort to create a meaningful question...

Asked by NEngelhard on 2016-04-05 10:38:18 UTC