Franky  0.9.1
A High-Level Motion API for Franka
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 
10 #include "franky/motion/motion.hpp"
12 
13 namespace franky {
14 
15 template<typename ControlSignalType>
16 class Motion;
17 
24 template<typename ControlSignalType>
25 class Reaction {
26  using MotionFunc = std::function<std::shared_ptr<Motion<ControlSignalType>>(const franka::RobotState &, double, double)>;
27 
28  public:
33  explicit Reaction(const Condition &condition, std::shared_ptr<Motion<ControlSignalType>> new_motion = nullptr);
34 
39  explicit Reaction(Condition condition, const MotionFunc &motion_func);
40 
49  std::shared_ptr<Motion<ControlSignalType>> operator()(const franka::RobotState &robot_state, double rel_time, double abs_time);
50 
59  [[nodiscard]] inline bool condition(const franka::RobotState &robot_state, double rel_time, double abs_time) const {
60  return condition_(robot_state, rel_time, abs_time);
61  }
62 
68  void registerCallback(std::function<void(const franka::RobotState &, double, double)> callback);
69 
70  private:
71  MotionFunc motion_func_;
72  Condition condition_;
73  std::mutex callback_mutex_;
74  std::vector<std::function<void(const franka::RobotState &, double, double)>> callbacks_{};
75 };
76 
77 } // namespace franky
A condition on the robot state.
Definition: condition.hpp:18
Base class for motions.
Definition: motion.hpp:22
A reaction that can be attached to a motion.
Definition: reaction.hpp:25
std::shared_ptr< Motion< ControlSignalType > > operator()(const franka::RobotState &robot_state, double rel_time, double abs_time)
Get the new motion if the condition is met.
Definition: reaction.cpp:28
Reaction(const Condition &condition, std::shared_ptr< Motion< ControlSignalType >> new_motion=nullptr)
Definition: reaction.cpp:19
bool condition(const franka::RobotState &robot_state, double rel_time, double abs_time) const
Check if the condition is met.
Definition: reaction.hpp:59
void registerCallback(std::function< void(const franka::RobotState &, double, double)> callback)
Register a callback that is called when the condition of this reaction is met.
Definition: reaction.cpp:37
Definition: gripper.cpp:3