Ask Your Question
1

How to subscribe coordinates in the terminal / arduino?

asked 2012-11-19 03:55:21 -0500

Pierre gravatar image

updated 2012-11-20 02:52:13 -0500

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

edit retag flag offensive close merge delete

Comments

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?

Lorenz gravatar imageLorenz ( 2012-11-20 01:42:31 -0500 )edit

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

Pierre gravatar imagePierre ( 2012-11-20 02:39:23 -0500 )edit
1

You probably should not use an array but a data type with some semantic meaning, e.g. geometry_msgs/Pose or geometry_msgs/Point.

Lorenz gravatar imageLorenz ( 2012-11-20 02:40:34 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2012-11-20 02:41:31 -0500

Lorenz gravatar image

For examples on how to publish messages from the command line, have a look at the wiki.

edit flag offensive delete link more
0

answered 2012-11-20 05:55:44 -0500

Pierre gravatar image

OK, thank you for you advice. I used a geometry_msg

here the new code and that work perfectly:

#include <Servo.h>
#include <math.h> 
#include <ros.h>
#include <geometry_msgs/Point.h>

......  
......

ros::NodeHandle  nh;

void Moves_cb( const geometry_msgs::Point& cmd_msg){
Moves(cmd_msg.x,cmd_msg.y,cmd_msg.z); // 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<geometry_msgs::Point> 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); 
 }

 .......
 .......
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-11-19 03:55:21 -0500

Seen: 590 times

Last updated: Nov 20 '12