0
$\begingroup$

Rosanswers logo

Hello everyone,

I am currently trying to get my arduino ROS node to work. I programmed an tested the whole code using the catkin workspace.

I now copied the code into the arduino IDE and suddenly a lot of functions, which previously worked just fine throw errors. I already fixed all but one: I need to determine an array length for further data processing. The code I used until now is:

int wp_size = msg.goal.trajectory.joint_trajectory.points.size();

Another method of finding out an arrays length seems to be:

int wp_size = sizeof(  msg.goal.trajectory.joint_trajectory.points ) / sizeof( double );

This does not work, because the array is empty at compile time and thus the code above returns "1" every time.

The length of the array changes with every service call. Is there any other method to find out the length of the array?

Maybe the error message might help someone:

error: request for member ‘size’ in ‘msg.moveit_msgs::ExecuteTrajectoryActionGoal::goal.moveit_msgs::ExecuteTrajectoryGoal::trajectory.moveit_msgs::RobotTrajectory::joint_trajectory.trajectory_msgs::JointTrajectory::points’, which is of pointer type ‘trajectory_msgs::JointTrajectory::_points_type* const {aka trajectory_msgs::JointTrajectoryPoint* const}’ (maybe you meant to use ‘->’ ?)

If I use "->" though, I get:

 error: ‘trajectory_msgs::JointTrajectory::_points_type’ has no member named ‘size’

Thank you in advance,

Felix


Originally posted by Felix_N on ROS Answers with karma: 115 on 2017-06-28

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

From your references to size(), I get the feeling that you've been converting 'regular' roscpp based code to rosserial. You might already have realised it, but roscpp == C++, while rosserial is C only. size() is a method on a std::vector. rosserial only uses raw pointers as arrays and those don't have any intrinsic size property that you could query. The sizeof(..) trick would work, if those arrays had a static size, but they don't, as you found out.

The only way -- that I know of -- to know the size of an array for a message that you populate is to keep track of what you pass to malloc(..) to init those arrays and use that.

For messages that you receive things are slightly different. See wiki/rosserial/Overview - Limitations - Arrays for some that.

And cccording to [wiki/rosserial/Overview/Messages](http://wiki.ros.org/rosserial/Overview - Messages):

Also be aware that the arrays in the messages are not defined as vector objects. Thus you have to predefine the array and then pass it as pointer to the message. To determine the end of the array each one has an auto-generated integer companion with the same name and the suffix _length.


Originally posted by gvdhoorn with karma: 86574 on 2017-06-29

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Felix_N on 2017-06-29:
Well.... No i did not realize that. And I wondered why my c++ functions suddenly do not work anymore...... In my project I can luckily do the .size() job on the pc and pass the processed data to the arduino as well. Thank you very much for your time again @gvdhoorn!!

$\endgroup$

Your Answer

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