Ask Your Question

boy's profile - activity

2016-05-22 19:14:30 -0500 received badge  Favorite Question (source)
2016-05-22 19:14:26 -0500 received badge  Nice Question (source)
2014-05-18 21:00:20 -0500 received badge  Student (source)
2012-10-04 23:13:28 -0500 received badge  Notable Question (source)
2012-10-04 23:13:28 -0500 received badge  Famous Question (source)
2012-10-04 23:13:28 -0500 received badge  Popular Question (source)
2012-09-09 22:42:11 -0500 received badge  Famous Question (source)
2012-09-09 22:42:11 -0500 received badge  Notable Question (source)
2012-06-13 13:46:44 -0500 received badge  Popular Question (source)
2011-07-21 05:23:11 -0500 marked best answer How do ros service responses work.

The response is returned by the call. See this tutorial: http://www.ros.org/wiki/ROS/Tutorials/WritingServiceClient(python)

You need to adapt this code to yours:

rospy.wait_for_service('add_two_ints')
try:
    add_two_ints = rospy.ServiceProxy('add_two_ints', AddTwoInts)
    resp1 = add_two_ints(x, y)
    return resp1.sum
except rospy.ServiceException, e:
    print "Service call failed: %s"%e
2011-07-18 05:23:19 -0500 commented question How do ros service responses work.
I will do that, SORRY!
2011-07-17 23:38:41 -0500 commented answer How do ros service responses work.
I have it working :) Thanks
2011-07-17 22:32:48 -0500 commented answer How do ros service responses work.
thats what I thought too, but I cannot adapt the code without getting a lot of errors. Maybe It's my lack in experience in python and ROS. Could you give me some more hints??
2011-07-17 20:47:54 -0500 commented answer How do ros service responses work.
Thanks for the answer, but I still don't have it yet. Could you give me some hits or small example?? Reminder: I have to make a decision with the info obtained from server
2011-07-15 01:51:41 -0500 asked a question How do ros service responses work.

hello everyone,

I have the following problem:

When I can call a service"server node" to calculate something(for simplicity float_A/float_B), how can i use the response to do something in my client node(for instance make a dissension in my state_2). The code of the server node and client node is given below. (.srv file float32[] a ------- float32[] sum)

#client node
class State_2(smach.State):

def __init__(self):
    smach.State.__init__(self, outcomes=['outcome1','outcome2'])

self.check = False
self.subscriber = rospy.Subscriber("chatter",Array, self.callback)

def callback(self,data):
self.ranges_list = list(data.ranges)

def execute(self, userdata):
rospy.sleep(1.0)
rospy.wait_for_service('check_teammember_behind_turtle')

check_teammember_behind_turtle = rospy.ServiceProxy('check_teammember_behind_turtle', teammember)
check_teammember_behind_turtle(self.ranges_list[0:3])
## THINK I MISS HERE SOMETHING##
    ## MAYBE YOU CAN HELP ME##


rospy.loginfo('Executing state STATE_2')

if self.check: 
    return 'outcome1'
else:
    return 'outcome2'

## CODE SERVER ##
def handle_teammember(req):
list_teammember = list(req.a)
tx = list_teammember[0]/list_teammember[1]
ty = list_teammember[1]/list_teammember[2]
if (tx>ty):
tx_list = [tx]
print ("tx")
else:
tx_list = [ty]
print ("ty")

return teammemberResponse(tx_list)

def add_two_ints_server():
rospy.init_node('add_two_ints_server')
s = rospy.Service('check_teammember_behind_turtle', teammember, handle_teammember)
print "Ready to add two ints."
rospy.spin()
2011-07-12 01:00:32 -0500 asked a question Publisher Subcriber Python Int(8/16/32)MultiArray

hello everyone,

I'm struggling a little bit with publishing and subscribing an int(8/16/32)multiarray.I've already made a publisher and subscriber with the message type int(8/16/32),so I thought it shouldn't be that difficult to transform these to a message type int(8/16/32)multiarray.But frustratingly enough it wasn't that easy(for me :(). So here comes the question:

How can I transform this publisher and subscriber to a publisher and subscriber with message type Int(8/16/32)MultiArray???

import roslib; roslib.load_manifest('some_name')
import rospy
from std_msgs.msg import Int8

def talker():
pub = rospy.Publisher('chatter', Int8)
rospy.init_node('talker')
str = 0

    while not rospy.is_shutdown():
    rospy.loginfo(str)
    pub.publish(str)
    rospy.sleep(1.0)
str = str+1

if __name__ == '__main__':
try:
    talker()
except rospy.ROSInterruptException:pas

#!/usr/bin/env python
import roslib; roslib.load_manifest('some_name')
import rospy
import smach
import smach_ros
from std_msgs.msg import Int8
import threading
import time


class Foo(smach.State):
def __init__(self):
    smach.State.__init__(self, outcomes=['outcome1','outcome2'])

    self.two_received = False
self.subscriber = rospy.Subscriber("chatter", Int8, self.callback)

def callback(self,data):
if data.data == 2:  
    self.two_received = True


def execute(self,userdata):
    rospy.loginfo('Executing state FOO')
pub = rospy.Publisher('chatter2', Int8)
str = 4
pub.publish(str)
    if self.two_received:
        return 'outcome2'
    else:
        return 'outcome1'
    ..................................

enter code here

2011-07-12 00:39:53 -0500 asked a question publish int(8/16/32)MultiArray

hello everyone,

I'm struggling a little bit with publishing and subscribing an int(8/16/32)multiarray.I've already made a publisher and subscriber with the message type int(8/16/32),so I thought it shouldn't be that difficult to transform these to a message type int(8/16/32)multiarray.But frustratingly enough it wasn't that easy(for me :(). So here comes the question:

How can I transform this publisher and subscriber to a publisher and subscriber with message type Int(8/16/32)MultiArray????

INT8

import roslib; roslib.load_manifest('intercept_strategy') import rospy from std_msgs.msg import Int8 #maybe I'm using the wrong msg package???

def talker(): pub = rospy.Publisher('chatter', Int8) rospy.init_node('talker') str = 0 while not rospy.is_shutdown(): rospy.loginfo(str) pub.publish(str) rospy.sleep(1.0) str = str+1 if __name__ == '__main__': try: talker() except rospy.ROSInterruptException: pass

################################################################## #!/usr/bin/env python import roslib; roslib.load_manifest('intercept_strategy') import rospy import smach import smach_ros from std_msgs.msg import Int8 import threading import time

class Foo(smach.State): def __init__(self): smach.State.__init__(self, outcomes=['outcome1','outcome2'])

    self.two_received = False
self.subscriber = rospy.Subscriber("chatter", Int8, self.callback)

def callback(self,data):
if data.data == 2:  
    self.two_received = True


def execute(self,userdata):
    rospy.loginfo('Executing state FOO')
pub = rospy.Publisher('chatter2', Int8)
str = 4
pub.publish(str)
    if self.two_received:
        return 'outcome2'
    else:
        return 'outcome1'

define state Bar.....

........

2011-07-08 00:47:51 -0500 marked best answer smach subscriber publisher

A smach state is simply a Python class (see the example in this tutorial), so you can add a normal ROS subscriber to that class if you want.

This means, in the subscriber callback you can store the message data (a string in your case) as a class memeber, and in the execute callback you can make decisions about outcomes based on tis class member.

2011-07-07 23:56:36 -0500 marked best answer smach subscriber publisher

Hi,

This small (and untested) example subscribes on a topic and return success if 2 is received on this topic in the next 30 seconds.

#!/usr/bin/env python
import roslib; roslib.load_manifest('smach_example')
import rospy
import smach
import smach_ros
from std_msgs.msg import Int16
import time
import threading

class WaitForTwo(smach.State):
    def __init__(self):
        smach.State.__init__(self, outcomes=['success', 'in_progress', 'failed'])

        self.mutex = threading.Lock()
        self.two_received = False

        self.subscriber = rospy.Subscriber('/test', Int16, self.callback)

    def callback(self, data):
        self.mutex.acquire()
        if data.data == 2:
            self.two_received = True
        self.mutex.release()

    def execute(self):
        #wait for a maximum of 30 seconds 
        for i in range(0, 300):
            self.mutex.acquire()
            if self.two_received:
                #ok we received 2
                return 'success'

            self.mutex.release()

            time.sleep(.1)
            #still waiting
            return 'in_progress'
        #we didn't get 2 in the 30 sec
        return 'failed'
2011-07-07 23:56:36 -0500 received badge  Scholar (source)
2011-07-07 23:56:33 -0500 received badge  Supporter (source)
2011-07-07 21:48:21 -0500 commented answer smach subscriber publisher
Thanks for the answer Wim, but I still have some problems with it( Maybe its because I'm a rookie) . Could you(if it is not too much) give a small example??
2011-07-07 00:59:24 -0500 asked a question smach subscriber publisher

hello everyone,

I'm new to the ROS society, and I have some questions.

I've made a simple state machine,publisher and subscriber as was shown in the tutorials, but how can I use date obtained from the subscriber(e.g a simple String) to make a transition between two states in the state machine??

greetings