0
$\begingroup$

Rosanswers logo

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


Originally posted by Pierre on ROS Answers with karma: 21 on 2012-11-19

Post score: 1


Original comments

Comment by Lorenz on 2012-11-20:
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?

Comment by Pierre on 2012-11-20:
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

Comment by Lorenz on 2012-11-20:
You probably should not use an array but a data type with some semantic meaning, e.g. geometry_msgs/Pose or geometry_msgs/Point.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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


Originally posted by Lorenz with karma: 22731 on 2012-11-20

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.