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

Client can't reach action server [closed]

asked 2016-11-27 11:31:14 -0600

highWaters gravatar image

updated 2016-11-27 15:20:11 -0600

Hello,

I'm launching two agents simultaneously, both of which create an action server, but only one makes a request (hardcoded that way). The problem is that while both processes seem to run fine on their own, the request from the client doesn't seem to reach the server. I don't understand what might be wrong. I'm putting below a snippet of code.

class Agent:
    def __init__(self, ...):
            ..............
            self.server = actionlib.SimpleActionServer(rospy.get_name(), doMeFavorAction, self.execute, False)
            self.server.start()

    def run():
        if self.ID == 1: #
            print 'I am asking for smth'
            self.test_action_server()

    def test_action_server(self):
        #the names of the agents are as follows /robot[ID]/brain_node
        client = actionlib.SimpleActionClient('/robot2/brain_node', doMeFavorAction)
        client.wait_for_server()
        print rospy.get_name()
        print 'I am requesting a favor'
        goal = doMeFavorGoal(3500)
        print str(goal)
        # Fill in the goal here
        client.send_goal(goal)
        client.wait_for_result(rospy.Duration.from_sec(5.0))
        print client.get_result()

    def execute(self, goal):
        # Do lots of awesome groundbreaking robot stuff here
        print dishwasher_id

        time.sleep(100)
        percent = 0
        while percent < 100:
             percent = percent + 10
             print percent
             self.server.publish_feedback(percent)
        self.server.set_succeeded(48)
        time.sleep(100)

Any help is very much appreciated :).

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by NEngelhard
close date 2016-11-29 01:13:34.518114

Comments

Could you please check and correct the indentation of your Python code? def run() and the code below seem to be at the same indent level at the moment, which is rather confusing.

gvdhoorn gravatar image gvdhoorn  ( 2016-11-27 14:21:34 -0600 )edit

Sorry about that, I fixed!

highWaters gravatar image highWaters  ( 2016-11-27 15:21:06 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-11-28 07:40:23 -0600

highWaters gravatar image

After revising what I had written, I found many minor things that were wrong, so I rewrote in the following way, and now it works like a charm:

def __init__(self):
     ......
     self.server = actionlib.SimpleActionServer(rospy.get_name(), doMeFavorAction, self.execute, False)
     self.server.start()

def done(self, state, result):
    print state
    print result 

def active(self):
    print 'Goal just sent!'

def feedback(self, feedback):
    print 'Feedback: %f\n' % feedback.percent_complete

def test_action_server(self):
    client = actionlib.SimpleActionClient('/robot2/brain_node', doMeFavorAction)
    client.wait_for_server()
    print rospy.get_name()
    print 'I am requesting a favor'
    goal = doMeFavorGoal(3500)
    print str(goal)
    print goal

        client.send_goal(goal, self.done, self.active, self.feedback)

def execute(self, goal):
    # Do lots of awesome groundbreaking robot stuff here
    print goal.dishwasher_id
    feedback = doMeFavorFeedback()
    result = doMeFavorResult()
    percent = 0
    while percent < 100.0:
        percent = percent + 10.0
        feedback.percent_complete = percent
        self.server.publish_feedback(feedback)
    result.total_dishes_cleaned = 30
    self.server.set_succeeded(result)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-11-27 11:31:14 -0600

Seen: 1,222 times

Last updated: Nov 28 '16