Ask Your Question
0

how to save data subscriber to a variabel

asked 2019-11-28 11:28:16 -0600

ilham hermi gravatar image

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

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.init_node('sukreb')
    rospy.Subscriber('mode',std_msgs.msg.String, self.callback)
    # rospy.Subscriber()
    rospy.spin()

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
1

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

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

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-11-28 11:28:16 -0600

Seen: 10 times

Last updated: Nov 29