File robot_backend.hpp¶
-
namespace robot_interfaces
Enums
-
enum RobotBackendTerminationReason¶
Possible termination reasons of a RobotBackend.
Values:
-
enumerator NOT_TERMINATED¶
Backend is still running.
-
enumerator SHUTDOWN_REQUESTED¶
Shutdown requested for non-failure reason (e.g. by SIGINT).
-
enumerator MAXIMUM_NUMBER_OF_ACTIONS_REACHED¶
Maximum number of actions was reached.
-
enumerator DRIVER_ERROR¶
Some error in the driver.
-
enumerator FIRST_ACTION_TIMEOUT¶
First action timeout was triggered.
-
enumerator NEXT_ACTION_TIMEOUT¶
Next action timeout was triggered.
-
enumerator NOT_TERMINATED¶
-
template<typename Action, typename Observation>
class RobotBackend - #include <robot_backend.hpp>
Communication link between RobotDriver and RobotData.
At each time-step, it gets the observation from the RobotDriver and writes it to RobotData, and it takes the desired_action from RobotData and applies it on the RobotDriver.
- Template Parameters
Action –
Observation –
Public Functions
- Parameters
robot_driver – Driver instance for the actual robot.
robot_data – Data is send to/retrieved from here.
real_time_mode – Enable/disable real-time mode. In real-time mode, the backend will repeat previous actions if the new one is not provided in time or fail with an error if the allowed number of repetitions is exceeded. In non-real-time mode, it will simply block and wait until the action is provided.
first_action_timeout – See RobotBackend::first_action_timeout_.
max_number_of_actions – See RobotBackend::max_number_of_actions_.
-
inline virtual ~RobotBackend()
-
inline uint32_t get_max_action_repetitions()
-
inline void set_max_action_repetitions(const uint32_t &max_action_repetitions)
Set how often an action is repeated if no new one is provided.
If the next action is due to be executed but the user did not provide one yet (i.e. there is no new action in the robot data time series), the last action will be repeated by automatically adding it to the time series again.
Use this this method to specify how often the action shall be repeated (default is 0, i.e. no repetition at all). If this limit is exceeded, the robot will be shut down and the RobotBackend stops.
Note: This is ignored in non-real-time mode.
- Parameters
max_action_repetitions –
-
inline void initialize()
-
inline void request_shutdown()
Request shutdown of the backend loop.
The loop may take some time to actually terminate after calling this function. Use wait_until_terminated() to ensure it has really terminated.
-
inline void wait_until_first_action() const
Wait until the first desired action is received.
-
inline int wait_until_terminated() const
Wait until the backend loop terminates.
- Returns
Termination code (see RobotBackendTerminationReason).
-
inline bool is_running() const
Check if the backend loop is still running.
- Returns
True if the loop is still running.
-
inline int get_termination_reason() const
Get the termination reason.
Private Functions
-
inline bool has_shutdown_request() const
-
inline void loop()
Main loop.
Iterate over robot_data_.desired_action and apply these actions to the robot, and read the applied_action and the observation from the robot and append them to the corresponding timeseries in robot_data_.
Private Members
-
std::shared_ptr<RobotDriver<Action, Observation>> robot_driver_
-
std::shared_ptr<RobotData<Action, Observation>> robot_data_
-
const bool real_time_mode_
Enable/disable real time mode.
If real time mode is enabled (true), the back end expects new actions to be provided in time by the user. If this does not happen, the last received action is repeated until the configured number of repetitions is exceeded in which case it stops with an error.
If real time mode is disabled (false), the back-end loop blocks and waits for the next action if it is not provided in time.
See also
-
const double first_action_timeout_
Timeout for the first action to arrive.
Timeout for the time between starting the backend loop and receiving the first action from the user. If exceeded, the backend shuts down. Set to infinity to disable the timeout.
-
const uint32_t max_number_of_actions_
Maximum number of actions that are executed by the backend.
If set to a value greater than zero, the backend will automatically shut down after the specified number of actions is executed.
-
std::atomic<bool> is_shutdown_requested_
Set to true when shutdown is requested.
This is used to notify the background loop about requested shutdown, so it terminates itself.
-
std::atomic<bool> loop_is_running_
Indicates if the background loop is still running.
-
uint32_t max_action_repetitions_
Number of times the previous action is repeated if no new one is provided.
-
real_time_tools::CheckpointTimer<6, false> timer_
-
real_time_tools::Timer frequency_timer_
Measure the duration of the control loop (for analysing time consistency).
-
std::shared_ptr<real_time_tools::RealTimeThread> thread_
-
std::atomic<int> termination_reason_
Private Static Functions
-
static inline void *loop(void *instance_pointer)
-
enum RobotBackendTerminationReason¶