betfsm_ros.ServiceClient

Bases: Generator

Creates a TickingState that calls a ROS2 service and generates an outcome when the service returns back. While waiting, it continues to tick. The methods fill_in_request and process_results should be overriden. Outcome is whatever process_result returns (should be listed in outcomes argument to constructor)

stateDiagram-v2 direction LR classDef successClass fill:darkgreen,color:white classDef tickingClass fill:yellow,color:black classDef otherClass fill:darkorange,color:white classDef abortClass fill:darkred,color:white state ServiceClient { direction TB [*] --> waiting state "Waiting for service" as waiting state "fill_in_request() <br> calling service" as calling state "Waiting for result<br>process_results()" as result waiting --> calling : ready calling --> result : request send } [*] --> ServiceClient waiting --> TIMEOUT : time exceeded waiting --> TICKING result --> TICKING : ticking result --> TIMEOUT : time exceeded result --> OUTCOME : result processed class SUCCEED successClass+ class OUTCOME otherClass class TICKING tickingClass class TIMEOUT abortClass

__init__(name, srv_name, srv_type, outcomes, timeout=Duration(seconds=1.0), node=None, always_succeed=False)

Creates a TickingState that calls a service and generates an outcome when the service returns back. While waiting, it continues to tick.

Parameters:
  • name (str) –

    name of the state

  • srv_name (str) –

    name of the service

  • srv_type (Type) –

    type of the service

  • outcomes (List[str]) –

    outcomes to be expected (TIMEOUT and TICKING will be added)

  • timeout (Duration, default: Duration(seconds=1.0) ) –

    maximum time for contacting service and processing and retrieving request. (special value: Duration(): ad infinitum)

  • node (Node, default: None ) –

    node, if None, BeTFSMNode.get_instance() will be used.

  • always_succeed

    Do your best, but always return SUCCEED or TICKING

fill_in_request(blackboard, request)

fills in the self.req object (of the type srv_type.Request) with the appropriate parameters of the service call

Parameters:
  • blackboard (Blackboard) –

    blackboard to be used

  • request (Type) –

    request to be filled in

Returns:
  • Type

    request that was filled in

process_result(blackboard, result)

gets the result and puts it in the blackboard (if needed) and returns an outcome

Parameters:
  • blackboard (Blackboard) –

    blackboard to be used

  • result (Result) –

    result returned by the service

Returns:
  • outcome( str ) –

    str the outcome to give back (should be final outcome, i.e. TICKING not allowed)