How use Float32MultiArray to control some servos

asked 2015-08-12 08:00:13 -0500

Emilio gravatar image

updated 2015-08-12 10:25:06 -0500

Hi !! I want to have a publisher node and a subscriber node. The publisher node publish an array that contains the position of two servos in a topic, then the subscriber use each of that datas of the array to set de servo position.so , how i use Float32MultiArray and bluid the code?

I make this code that subscribe to the topic servo.

#if (ARDUINO >= 100)
 #include <Arduino.h>
#else
 #include <WProgram.h>
#endif

#include <Servo.h>
#include <ros.h>
#include <std_msgs/Float32MultiArray.h>

int main(int argc, char **argv)
   {
     if (argc != 3)
     {
       return 1;
     }

}

ros::NodeHandle  nh;


std_msgs::Float32MultiArray pos;
Servo servo,servo1;

void move( const std_msgs::Float32MultiArray& pos){

  servo.write(pos.data[1]);
  servo1.write(pos.data[2]);

}

ros::Subscriber<std_msgs::Float32MultiArray> sub("servo", &move);

void setup()
{
  nh.initNode();
  nh.subscribe(sub);
  servo.attach(9);
  servo1.attach(8);
  delay(1000);
}

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

Comments

This is not a real question. So what is your problem exactly?

Have a look at this Tutorial for how a ROS node should be built in general. And maybe the rosserial_arduino Tutorials

mgruhler gravatar image mgruhler  ( 2015-08-13 01:00:24 -0500 )edit