Ask Your Question
0

can't use push_back for a array ros message in arduino

asked 2016-05-22 23:05:12 -0600

crazymumu gravatar image

Arduino code:

#include <ros.h>
#include <geometry_msgs/Pose.h>
#include <geometry_msgs/PoseArray.h>

ros::NodeHandle nh;

geometry_msgs::PoseArray array;
ros::Publisher p("array", &array);

void setup()
{ 
  pinMode(13, OUTPUT);
  nh.initNode();
  nh.advertise(p);
}

void loop()
{  
  geometry_msgs::Pose pose;

  pose.position.x=1;
  pose.position.y=1;
  pose.position.z=1;

  array.poses.push_back(pose);

  p.publish(&array);
  nh.spinOnce();
  delay(10);
}

Here is simple test to publish a PoseArray. When I compile it, I got the errors like:

/Users/Crazymumu/Desktop/array_test_1/array_test_1.ino: In function 'void loop()': array_test_1:37: error: request for member 'push_back' in 'array.geometry_msgs::PoseArray::poses', which is of pointer type 'geometry_msgs::Pose' (maybe you meant to use '->' ?)
array.poses.push_back(pose); ^ exit status 1 request for member 'push_back' in 'array.geometry_msgs::PoseArray::poses', which is of pointer type 'geometry_msgs::Pose
' (maybe you meant to use '->' ?)

I am not sure. This should be all right in original ROS environment. Any suggestions? Thanks

edit retag flag offensive close merge delete

Comments

Have you tried what the error suggest? I am not familiar with ROS Arduino, but it says that you must use array.poses->push_back

Javier V. Gómez gravatar imageJavier V. Gómez ( 2016-05-23 10:19:11 -0600 )edit

yes, I tried.

crazymumu gravatar imagecrazymumu ( 2016-05-23 20:59:06 -0600 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2016-05-23 21:08:54 -0600

crazymumu gravatar image

updated 2016-05-23 21:10:08 -0600

use array.poses[i]=pose; No vector available in arudino. Also be aware that the arrays in the messages are not defined as vector objects.

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

1 follower

Stats

Asked: 2016-05-22 23:05:12 -0600

Seen: 480 times

Last updated: May 23 '16