0
$\begingroup$

Rosanswers logo

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 :).


Originally posted by highWaters on ROS Answers with karma: 176 on 2016-11-27

Post score: 0


Original comments

Comment by gvdhoorn on 2016-11-27:
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.

Comment by highWaters on 2016-11-27:
Sorry about that, I fixed!

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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)

Originally posted by highWaters with karma: 176 on 2016-11-28

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.