Pi trees service task

29 views
Skip to first unread message

Peter Heim

unread,
Dec 2, 2016, 7:49:44 AM12/2/16
to ros-by-example
Hi Patrick
In the patrol tree example you send the value of 100 with a service task (below) how do you send 2 or more values the service I'm using needs 2 values a b 


CHARGE_ROBOT = ServiceTask("CHARGE_ROBOT",
"battery_simulator/set_battery_level", SetBatteryLevel, 100,
result_cb=self.recharge_cb)


Regards Peter

Patrick Goebel

unread,
Dec 2, 2016, 5:26:52 PM12/2/16
to ros-by-...@googlegroups.com

Hi Peter,

The ServiceTask works just like the regular ServiceProxy so what you are sending via the service is the value of a particular service type.  The CHARGE_ROBOT example is using a service type of SetBatteryLevel which is defined in the rbx2_msgs/srv/SetBatteryLevel.srv file.  This service type accepts a single float32 file and does not return anything back.

For an example of a service that accepts two values (easily extendible to more than two), take a look at the Add Two Integers service example in the ROS Tutorials.  Note that the tutorial assumes that you have already created the service type for accepting the two integers and the steps to do that are explained in the Creating a srv tutorial.  Once you complete those two tutorials, you would use a ServiceTask to add two integers as follows:

add_request =  AddTwoIntsRequest()
add_request.a = 10
add_request.b = 20

ADD_TWO_INTS = ServiceTask("ADD_TWO_INTS", "add_two_ints", AddTwoInts, add_request, result_cb=self.add_two_ints_cb)

where you would define the callback function self.add_two_ints_cb to process any return values.

--patrick

Patrick Goebel

unread,
Dec 2, 2016, 6:00:19 PM12/2/16
to ros-by-...@googlegroups.com

P.S.  If the service you want to use already exists, then presumably it also has a service type and you would create a request using that type and send it in your ServiceTask like the AddTwoInts example below.

--patrick

Peter Heim

unread,
Dec 11, 2016, 4:12:03 PM12/11/16
to ros-by-example
Thank you for that Patrick it works a treat
Reply all
Reply to author
Forward
0 new messages