0
$\begingroup$

Rosanswers logo

Hello all,

I am writing a package written in c++ for ros-melodic on ubuntu 18.04.

I need to send service call to a node that takes 3 values as following service call from terminal to change LED color.

$ rosservice call /set_led_color "red: ###
green: ###
blue: ##"

The node have service file definition under "node_name/srv" as Color.srv and its contents as following

int64 red
int64 green
int64 blue
--

And in node.py the service is coded as

from omo_r1mini_bringup.srv import Color, ColorResponse

rospy.Service('set_led_color', Color, self.save_led_color_service_handle)

def save_led_color_service_handle(self, req):
command = "$sCOLOR," + str(req.red) + ',' + str(req.green) + ',' + str(req.blue)
self.ph.write_port(command)
return ColorResponse()

I tried to initialize my service client by

svc_client = n.serviceClient("/set_led_color", true);

however it is not working.


Originally posted by kyubot on ROS Answers with karma: 60 on 2021-07-11

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I did not add below lines in package.xml

<build_depend>std_msgs</build_depend>
<build_depend>message_generation</build_depend>
<run_depend>std_msgs</run_depend>

and then it is able to generate service header according to the service files defined in srv folder.

In my node.hpp file I added

#include "r1mini_gui_teleop/Color.h"
...
private:
...
ros::ServiceClient serviceClient; //Client node to call service
my_node::Color serviceSetColor; //Service set color

And in node.cpp file

init(...){
...
serviceClient = n.serviceClient<r1mini_gui_teleop::Color>("/set_led_color");
}
some function(...) ...
serviceClient.call(serviceSetColor);

Solved my problem.


Originally posted by kyubot with karma: 60 on 2021-07-11

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

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