ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

roscpp ServiceClient to standalone nodelet

asked 2020-12-05 06:33:45 -0500

Zonared gravatar image

Hi there, I hope my question is easy to answer. I'm trying to software trigger my ifm3d sensor using its service "Trigger" I have built this sample test code but the client always returns FALSE.

#include "ros/ros.h"
#include <cstdlib>
#include </include/ifm3d/camera_nodelet.h>

int main(int argc, char **argv)
{
    ros::init(argc, argv, "trigger_ifm3d");
    if (argc != 1)
    {
         ROS_INFO("usage: one args required, got %d", argc);
         return 1;
    }

    ros::NodeHandle n;
    ros::ServiceClient client = n.serviceClient<ifm3d::Trigger>("Trigger");
    ifm3d::Trigger srv;

    int res = client.call(srv);
    if (res)
    {
        ROS_INFO("Status: %ld", (long int)srv.response.status);
    }
    else
    {
        ROS_ERROR("Failed to call service ifm3d::Trigger");
        return 1;
    }

    return 0;
}

Note: my ifm3d include path is wrong, if I specify the full path from root it compiles, so there is something not quite right with my cmake file. I don't believe this is related to my service problem.

I can trigger camera using "rosservice call /ifm3d/camera/Trigger" command line command. So I know the camera is working and accepting triggers.

I think something is wrong with namespace or nodelet standalone thing. The source code for ifm3d is here on github ifm3d_ros

The code in camera_nodelet.h is way above my head and doesn't match the example shown here

any help appreciated, thanks.

Zonared...

edit retag flag offensive close merge delete

Comments

I was just wondering if anybody has ever tried to access a rosservice served by a nodelet? My trigger_test cpp will only compile if i use node 'name' :: 'service name', like ifm3d::Trigger. But the actual service is running on ifm3d/camera/Trigger Is it because it's a nodelet? Thanks.

Zonared gravatar image Zonared  ( 2020-12-09 14:09:09 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-12-09 20:08:04 -0500

Zonared gravatar image

updated 2020-12-09 23:14:27 -0500

Solved it by putting the path (properly not the correct terminology) inside the " " section.

ros::ServiceClient client = n.serviceClient<ifm3d::Trigger>("ifm3d/camera/Trigger");

So adding ifm3d/camera/ to the Trigger part looks like it directs the trigger to the the correct service and now it works. Thanks for listening.

๐Ÿ‘

edit flag offensive delete link more

Comments

It is usually best practice to use rosrunremap arguments or a launch file with the remaptag to specify topic/service/action connections, instead of hardcoding the value in source code.

If your service client is setup using the following:

ros::ServiceClient client = n.serviceClient<ifm3d::Trigger>("Trigger");

You can reamp using rosrun:

rosrun <your_package> <your_node> Trigger:=/ifm3d/camera/Trigger
danambrosio gravatar image danambrosio  ( 2020-12-11 10:32:45 -0500 )edit

Hi danambrosio, I only just noticed this here. Thanks heaps, I knew there would be a proper way to do it. Cheers, ๐Ÿ™‚

Zonared gravatar image Zonared  ( 2021-02-16 06:14:01 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2020-12-05 06:33:45 -0500

Seen: 208 times

Last updated: Dec 09 '20