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

How to access complex rosmsg elements in cpp?

asked 2022-02-16 15:15:42 -0600

abhijelly gravatar image

updated 2022-02-16 17:59:00 -0600

I trying to access osrf_gear::Order message elements within orderCallback scope. The structure of the message is as following:

string order_id
osrf_gear/Shipment[] shipments
  string shipment_type
  string agv_id
  osrf_gear/Product[] products
    string type
    geometry_msgs/Pose pose
      geometry_msgs/Point position
        float64 x
        float64 y
        float64 z
      geometry_msgs/Quaternion orientation
        float64 x
        float64 y
        float64 z
        float64 w

The orderCallback code is following:

void orderCallback(const osrf_gear::Order::ConstPtr &order){

    if(!empty_vector_check){
        orders.clear();
        empty_vector_check = 1;
    }

    osrf_gear::Shipment order_shipments;
    order_shipments = order->shipments;  // IDE yells that this is an invalid way to assign an osrf_gear::Shipment message type

    ROS_INFO_STREAM("order_id: " << order->order_id);
    ROS_INFO_STREAM("shipment_type: " << order_shipments);
    orders.push_back(*order);

}

The osrf_gear::Shipment message structure is as following:

string shipment_type
string agv_id
osrf_gear/Product[] products
  string type
  geometry_msgs/Pose pose
    geometry_msgs/Point position
      float64 x
      float64 y
      float64 z
    geometry_msgs/Quaternion orientation
      float64 x
      float64 y
      float64 z
      float64 w

Error message while building the package:

no known conversion for argument 1 from ‘const _shipments_type {aka const std::vector<osrf_gear::Shipment_<std::allocator<void> >, std::allocator<osrf_gear::Shipment_<std::allocator<void> > > >}’ to ‘const osrf_gear::Shipment_<std::allocator<void> >&’
/opt/ros/melodic/include/osrf_gear/Shipment.h:23:8:

My questions:

  1. What would be the correct syntactical way to access the shipment[] msg type using the osrf_gear::order callback parameter?
  2. I want to access the osrf_gear::Product products vector to know what type of products I have in the shipment.

Thank you in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2022-02-16 19:57:42 -0600

abhijelly gravatar image

updated 2022-02-18 09:49:45 -0600

shipments in the order message type is a vector of type osrf_gear::Shipment. This change solved the IDE from yelling.

Have a nice day!

edit flag offensive delete link more

Comments

Have a nice day!

we can only have a nice day if you would tell us what you did to resolve your question.

gvdhoorn gravatar image gvdhoorn  ( 2022-02-17 03:25:06 -0600 )edit
1

@gvdhoorn done! hope it helps everyone have a nice day

abhijelly gravatar image abhijelly  ( 2022-02-18 09:50:41 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2022-02-16 15:15:42 -0600

Seen: 70 times

Last updated: Feb 18 '22