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

Flexbe unabel to reache action_server

asked 2019-03-17 16:30:46 -0500

schokkobaer gravatar image

updated 2019-03-17 19:49:18 -0500

I'currently trying to work with Flexbe and trying to include an action but I keep getting the following error:

[22:03:59] Behavior execution failed! [-]
Could not execute state 'turn' of type '': Traceback (most recent call last):
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/smach/state_machine.py", line 247, in _update_once
    self._remappings[self._current_label]))
  File "/home/sil/us_ws/src/flexbe_behavior_engine/flexbe_core/src/flexbe_core/core/event_state.py", line 71, in _event_execute
    self.on_exit(*args, **kwargs)
  File "/home/sil/us_ws/src/husky_behaviors/husky_flexbe_states/src/husky_flexbe_states/turn_state.py", line 66, in on_exit
    if not self._client.has_result(self._server_name):
  File "/home/sil/us_ws/src/flexbe_behavior_engine/flexbe_core/src/flexbe_core/proxy/proxy_action_client.py", line 114, in has_result
    return ProxyActionClient._result[topic] is not None
KeyError: '/TurnHusky'

I checked that the the Action exists by looking at my currently available rostopics. They seem to be there. Are there any other possibilities why flexbe cannot find the action or why I get this error. The state that calls the action is as followed:

#!/usr/bin/env python
import rospy
import math

from action_tut.msg import turn_huskyAction, turn_huskyGoal, turn_huskyResult, turn_huskyFeedback
from flexbe_core import EventState, Logger

from flexbe_core.proxy import ProxyActionClient
'''
This state will turn teh husky by calling the necessary action

-- turn_angel   float       Angel between 180 - (-180) the Husky will turn
-- speed        flaot       Speed with which the robot will try to get to the angle
-- topic        string      topic of the server that turn the Husky

<= done                     if turn is completed successfully
'''

class TurnState(EventState):
    '''
    Class that defines the state to turn the husky 
    '''

    def __init__(self, angle, speed):
        super(TurnState, self).__init__(outcomes=['done', 'failed'])
        self._angle =angle
        self._speed = speed
        self._server_name='/TurnHusky'
        self._client = ProxyActionClient({self._server_name: turn_huskyAction}) # pass required clients as dict (topic: type)
        self._error_flag = False 

    def execute(self, userdata):
        if self._error_flag:
            return 'failed'

        if self._client.has_result(self._server_name):
            result= self._client.get_result(self._server_name)
            restult_val=result.done

            if restult_val=="done":
                return 'done'
            else: 
                return 'failed'
        if self._client.has_feedback(self._server_name):
            feedback= self._client.get_feedback(self._server_name)
            Logger.loginfo('Current heading is : %s' %str(feedback.heading))

    def on_enter(self, userdata):
        goal=turn_huskyGoal()
        goal.angle= self._angle
        goal.turn_speed= self._speed

        #Send the goal
        self._error_flag= False

        try:
            self._client.send_goal(self._server_name)
        except Exception as e:
            Logger.logwarn('Failed to send the Turn command: \n %s' %str(e))
            self._error_flag=True


    def on_exit(self, userdata):
        Logger.loginfo('exit the Turn state')
        if not self._client.has_result(self._server_name):
            self._client.cancel(self._server_name)
            Logger.loginfo('Canceslled the active turning')

    def on_start(self):
        Logger.loginfo('State is read to turn husky')


    def on_stop(self):
        Logger.loginfo('The state has been stopped')
        if not self._client.has_result(self._server_name):
            self._client.cancel(self._server_name)
            Logger.loginfo('Canceslled the active turning')

Any help would be useful.

edit retag flag offensive close merge delete

Comments

Hi, did you find a solution to this problem?

Arteta gravatar image Arteta  ( 2020-04-15 18:00:48 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-07-11 14:28:25 -0500

hbaqueiro gravatar image

The best advice I can give for anybody that faces problems while developing a custom action state in FlexBE is to begin copying the code from the example_action_state.py, which is created by default in src when you run the create_repo command. That was a very helpful thing the author Philipp Schillinger did for us, users.

That said, if you compare with your code, you will notice that the "comments" are placed wrong - the inputs, outputs, and outcomes should come after the class definition (class TurnState(EventState):). The app somehow uses this metadata for creating the boxes there.

Another thing that must be consistent is this "comments" and your class constructor. Note that in your constructor you have the outcomes done and failed but have written just <= done above. Another thing that can lead to unexpected results is indentation: remember this is Python... make sure you do not mix tabs with spaces.

In resume, start simple: start with the working example example_action_state.py and then modify it in small parts to get the feeling of how the framework actually works.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-03-17 16:30:46 -0500

Seen: 209 times

Last updated: Jul 11 '20