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

How to save nav_msgs/GetMap service and pass it into a function?

asked 2019-12-18 15:10:14 -0500

Parth2851 gravatar image

So, what I'm going for is to rather having a callback function I want to make my node a client to that service and then pass it to the another function.

        ros::init(argc, argv, "dijkstra");
        ros::NodeHandle n("~");
        ros::ServiceClient client = n.serviceClient<nav_msgs::GetMap>("map");
        nav_msgs::GetMap srv;
        client.call(srv);
        nav_msgs::OccupancyGrid = srv.response;

Running the above code gives me the error-

 error: expected unqualified-id before ‘=’ token
   nav_msgs::OccupancyGrid = srv.response;

I need to pass the map to a function void dijkstra(???)

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2019-12-18 16:28:26 -0500

   nav_msgs::OccupancyGrid = srv.response;

You didn't specify an actual variable

   nav_msgs::OccupancyGrid my_variable = srv.response;
edit flag offensive delete link more

Comments

Okay, yes I did that. nav_msgs::OccupancyGrid map = srv.response; I'm getting this-

error: conversion from ‘nav_msgs::GetMap::Response {aka nav_msgs::GetMapResponse_<std::allocator<void> >}’ to non-scalar type ‘nav_msgs::OccupancyGrid {aka nav_msgs::OccupancyGrid_<std::allocator<void> >}’ requested
   nav_msgs::OccupancyGrid my_map = srv.response;

Also, my function call is void dijkstra(const nav_msgs::OccupancyGrid& map), is this correct?

Parth2851 gravatar image Parth2851  ( 2019-12-19 04:58:07 -0500 )edit

Please read the message specification. http://docs.ros.org/melodic/api/nav_m...

srv.response.map

stevemacenski gravatar image stevemacenski  ( 2019-12-19 12:44:37 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2019-12-18 15:10:14 -0500

Seen: 612 times

Last updated: Dec 18 '19