Franky 0.12.0
A High-Level Motion API for Franka
Loading...
Searching...
No Matches
reaction.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4#include <iostream>
5#include <functional>
6#include <memory>
7#include <optional>
8#include <franka/robot_state.h>
9
12
13namespace franky {
14
15template<typename ControlSignalType>
16class Motion;
17
24template<typename ControlSignalType>
25class Reaction {
26 using MotionFunc = std::function<std::shared_ptr<Motion<ControlSignalType>>(
27 const RobotState &, franka::Duration, franka::Duration)>;
28
29 public:
34 explicit Reaction(const Condition &condition, std::shared_ptr<Motion<ControlSignalType>> new_motion = nullptr);
35
40 explicit Reaction(Condition condition, const MotionFunc &motion_func);
41
50 std::shared_ptr<Motion<ControlSignalType>> operator()(const RobotState &robot_state,
51 franka::Duration rel_time,
52 franka::Duration abs_time);
53
63 franka::Duration rel_time,
64 franka::Duration abs_time) const {
65 return condition_(robot_state, rel_time, abs_time);
66 }
67
74 const std::function<void(
75 const RobotState &,
76 franka::Duration,
77 franka::Duration)>& callback);
78
79 private:
80 MotionFunc motion_func_;
81 Condition condition_;
82 std::mutex callback_mutex_;
83 std::vector<std::function<void(
84 const RobotState &,
85 franka::Duration,
86 franka::Duration)>> callbacks_{};
87};
88
89} // namespace franky
A condition on the robot state.
Definition condition.hpp:15
Base class for motions.
Definition motion.hpp:23
A reaction that can be attached to a motion.
Definition reaction.hpp:25
bool condition(const RobotState &robot_state, franka::Duration rel_time, franka::Duration abs_time) const
Check if the condition is met.
Definition reaction.hpp:62
void registerCallback(const std::function< void(const RobotState &, franka::Duration, franka::Duration)> &callback)
Register a callback that is called when the condition of this reaction is met.
Definition reaction.cpp:51
std::shared_ptr< Motion< ControlSignalType > > operator()(const RobotState &robot_state, franka::Duration rel_time, franka::Duration abs_time)
Get the new motion if the condition is met.
Definition reaction.cpp:40
Definition dynamics_limit.cpp:8
std::array< double, dims > toStdD(const Eigen::Matrix< double, dims, 1 > &vector)
Definition util.hpp:18
Full state of the robot.
Definition robot_state.hpp:20