How to subscribe coordinates in the terminal / arduino?
Hello,
I am trying to subscribe a message to the Arduino using the terminal. The goal, is to control a little robot arm i have created, entering the coordinates in the terminal. I have no problem with the arduino part, but with the ROS part, it's a quite different...
I don't know how to do it.
Here is a part of my code:
#include <Servo.h>
#include <math.h>
#include <ros.h>
#include <std_msgs/UInt16.h>
......
......
ros::NodeHandle nh;
void Moves_cb( const std_msgs::UInt16& cmd_msg){
Moves(cmd_msg.data,0,0); // Moves(x,y,z) it's a function witch move to the arm to the coordinates (x,y,z) using a linear trajectory
}
ros::Subscriber<std_msgs::UInt16> sub("Moves", Moves_cb);
void setup(){
nh.initNode();
nh.subscribe(sub);
servo0.attach(8);
servo1.attach(9);
servo2.attach(10);
servo3.attach(11);
Init(); // initialize the position of the robot
delay(2000);
}
.......
.......
In this code i have just subscribe a std_msgs::UInt16 to check if everything was working well (so i put y=0 and z=0 in the Moves function).
Now, i want to do subscribe the 3 coordinates (and not only one), but i have no idea to do this.
If some one have any idea.
Thanks
--Pierre
Your arduino program subscribes to a topic of type
std_msgs::UInt16
which is not an array. Can you please edit your question and elaborate your problem in more detail?Sorry if it not clear. I used std_msgs::UInt16 just to check that the instruction I put in the terminal are correctly subscribe in Moves_cb. What i want to do, it's to change the code to subscribe the 3 coordinates in Moves_cb. I'll edit my question
You probably should not use an array but a data type with some semantic meaning, e.g. geometry_msgs/Pose or geometry_msgs/Point.