WaitForUserDecision Class
Shows a prompt with two buttons in the MoveIt Pro Desktop App and waits for the user to click one. More...
Declaration
Included Headers
Base class
| class | AsyncBehaviorBase |
|
A base class for behaviors which need to asynchronously run a function that might take a long time to complete. More... | |
Public Constructors Index
| WaitForUserDecision (const std::string &name, const BT::NodeConfiguration &config, const std::shared_ptr< BehaviorContext > &shared_resources) | |
Private Member Functions Index
| tl::expected< bool, std::string > | doWork () override |
|
Publish the prompt and wait for the user's answer. More... | |
| tl::expected< void, std::string > | doHalt () override |
|
Cancel the in-flight prompt when the Behavior is halted. More... | |
| std::shared_future< tl::expected< bool, std::string > > & | getFuture () override |
|
Gets the shared future which is used to monitor the progress of the async process. More... | |
Private Member Attributes Index
| std::shared_future< tl::expected< bool, std::string > > | future_ |
| std::shared_ptr< utils::UIRequestResponseClient > | request_client_ |
Public Static Functions Index
| static BT::PortsList | providedPorts () |
|
Returns list of ports for this Behavior. More... | |
| static BT::KeyValueVector | metadata () |
|
Returns metadata for this Behavior. More... | |
Description
Shows a prompt with two buttons in the MoveIt Pro Desktop App and waits for the user to click one.
The approve_label button returns SUCCESS. The reject_label button returns FAILURE and logs the answer at INFO level, so a Sequence or Fallback can branch on it without an error in the Alert Sidebar. The Behavior logs an error and fails when a port value is invalid, when no Desktop App is connected or it reports an error, or when nobody answers within timeout_sec seconds. Halting the Behavior closes the prompt in the Desktop App.
| Data Port Name | Port Type | Object Type |
|---|---|---|
| prompt | input | std::string |
| approve_label | input | std::string |
| reject_label | input | std::string |
| timeout_sec | input | double |
Definition at line 29 of file wait_for_user_decision.hpp.
Public Constructors
WaitForUserDecision()
| explicit |
Declaration at line 32 of file wait_for_user_decision.hpp, definition at line 131 of file wait_for_user_decision.cpp.
Private Member Functions
doHalt()
| virtual |
Cancel the in-flight prompt when the Behavior is halted.
- Returns
An empty success result.
Declaration at line 59 of file wait_for_user_decision.hpp, definition at line 185 of file wait_for_user_decision.cpp.
doWork()
| virtual |
Publish the prompt and wait for the user's answer.
- Returns
true when the user approves, false when the user rejects, or an error message. The tree discards the result of a halted Behavior.
Declaration at line 53 of file wait_for_user_decision.hpp, definition at line 157 of file wait_for_user_decision.cpp.
getFuture()
| inline virtual |
Gets the shared future which is used to monitor the progress of the async process.
Classes derived from AsyncBehaviorBase must implement getFuture() so that it returns a shared_future class member.
This exists to prevent destruction of the derived class while the async process is still in-progress. If the derived class is destroyed, the definitions of the functions used within doWork() will be destroyed too, which will result in the virtual functions in the base class being called instead and cause a fault.
This function will force derived classes to add an instance of this type and return a reference to it. The base class can then use this virtual function to access the shared future in functions like onStart.
By adding this virtual function we're properly demonstrating how this future depends on things from the derived class and the natural flow of object lifetimes will do the hard work for us. The std::shared_future destructor will get the value of the future before the derived class is destructed assuming it's the last reference to the shared state. Doing it this way means neither the base nor derived class should need to implement a destructor which is a nice property to have.
- Returns
Returns the shared_future, which should be owned by the child class.
Definition at line 61 of file wait_for_user_decision.hpp.
Private Member Attributes
future_
|
Definition at line 66 of file wait_for_user_decision.hpp.
request_client_
|
Definition at line 67 of file wait_for_user_decision.hpp.
Public Static Functions
metadata()
| static |
Returns metadata for this Behavior.
- Returns
BT::KeyValueVector The Behavior metadata.
Declaration at line 45 of file wait_for_user_decision.hpp, definition at line 152 of file wait_for_user_decision.cpp.
providedPorts()
| static |
Returns list of ports for this Behavior.
- Returns
BT::PortsList The list of I/O Ports.
Declaration at line 39 of file wait_for_user_decision.hpp, definition at line 139 of file wait_for_user_decision.cpp.
The documentation for this class was generated from the following files:
Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.9.8.