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

how to save data subscriber to a variabel

asked 2019-11-28 11:28:16 -0500

ilham hermi gravatar image

updated 2019-11-29 03:02:15 -0500

Delb gravatar image

i'd like to try save data from subscriber to a variabel for my condition statement, but when i launch my program, program only execute the subscriber only but not the condition

this is my program

class sukreb():
def __init__(self):
    rospy.Subscriber('mode',std_msgs.msg.String, self.callback)
    # rospy.Subscriber()

def callback(self,data):
    mode = data
    return mode
    if(mode == "a"):
        lowobj = lowMagenta
        upobj  = upMagenta

    if(mode == "b"):
        lowobj = lowCyan
        upobj = upCyan
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-11-29 03:05:38 -0500

Delb gravatar image

return exit the fonction so it's normal not to go into the two conditions. I would advise you to get some knwoledge in python before getting into ROS since ROS isn't a way to learn a programming language.

So just get rid of the line return mode and you will get your data.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2019-11-28 11:28:16 -0500

Seen: 180 times

Last updated: Nov 29 '19