ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

service problem

asked 2013-04-02 00:01:31 -0600

camilla gravatar image

updated 2013-04-02 02:42:28 -0600

Hi, I defined a server called DetectsObs.srv

float32 x
float32 y
float32 theta
float32 threshold
---
Points obstacles
bool obs
bool processFinished

and two msg type
Point.msg

float32 x
float32 y

and Points.msg

Point[] points

I have a service whose response is obstacle_detection::DetectsObs::Response &res (obstacle_detection is my package) I want to set the field obstacles of my response but if I do

obstacle_detection::Point obstacle;
obstacle.x = 0;
obstacle.y = 0;
res.obstacles[0] = obstacle;

I get this error

error: no match for ‘operator[]’ in ‘res->obstacle_detection::DetectsObsResponse_<std::allocator<void> >::obstacles[0]’

What should i do to fix it.
Thank you in advance

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2013-04-02 04:27:58 -0600

thebyohazard gravatar image

updated 2013-04-02 04:28:55 -0600

The way you have defined it, obstacles is a Points msg, not a vector of Points, and thus has only one member: points. You would access it with res.obstacles.points[0]. Since points is a vector, make sure you resize it first or push_back the element instead.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-04-02 00:01:31 -0600

Seen: 264 times

Last updated: Apr 02 '13