Franky 1.1.0
A High-Level Motion API for Franka
Loading...
Searching...
No Matches
motion.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4#include <mutex>
5
6#include "franky/robot.hpp"
8#include "reaction.hpp"
9
10namespace franky {
11
12class Robot;
13
14template <typename ControlSignalType>
15class Reaction;
16
23template <typename ControlSignalType>
24class Motion {
25 public:
26 virtual ~Motion() = default;
27 using CallbackType = std::function<void(
28 const RobotState &, franka::Duration, franka::Duration, franka::Duration, const ControlSignalType &)>;
29
37 void addReaction(std::shared_ptr<Reaction<ControlSignalType>> reaction);
38
46 void addReactionFront(std::shared_ptr<Reaction<ControlSignalType>> reaction);
47
51 std::vector<std::shared_ptr<Reaction<ControlSignalType>>> reactions();
52
59 void registerCallback(CallbackType callback);
60
67 void init(Robot *robot, const RobotState &robot_state, const std::optional<ControlSignalType> &previous_command);
68
79 const RobotState &robot_state, franka::Duration time_step, franka::Duration rel_time, franka::Duration abs_time,
80 const std::optional<ControlSignalType> &previous_command);
81
89 std::shared_ptr<Motion<ControlSignalType>> checkAndCallReactions(
90 const RobotState &robot_state, franka::Duration rel_time, franka::Duration abs_time);
91
92 protected:
93 explicit Motion();
94
95 virtual void initImpl(const RobotState &robot_state, const std::optional<ControlSignalType> &previous_command) {}
96
98 const RobotState &robot_state, franka::Duration time_step, franka::Duration rel_time, franka::Duration abs_time,
99 const std::optional<ControlSignalType> &previous_command) = 0;
100
101 [[nodiscard]] Robot *robot() const { return robot_; }
102
103 private:
104 std::mutex reaction_mutex_;
105 std::list<std::shared_ptr<Reaction<ControlSignalType>>> reactions_;
106 std::mutex callback_mutex_;
107 std::vector<CallbackType> callbacks_;
108 Robot *robot_;
109};
110
111} // namespace franky
Base class for motions.
Definition motion.hpp:24
void registerCallback(CallbackType callback)
Register a callback that is called in every step of the motion.
Definition motion.cpp:24
std::shared_ptr< Motion< ControlSignalType > > checkAndCallReactions(const RobotState &robot_state, franka::Duration rel_time, franka::Duration abs_time)
Check and call reactions.
Definition motion.cpp:67
void init(Robot *robot, const RobotState &robot_state, const std::optional< ControlSignalType > &previous_command)
Initialize the motion.
Definition motion.cpp:50
Robot * robot() const
Definition motion.hpp:101
void addReaction(std::shared_ptr< Reaction< ControlSignalType > > reaction)
Add a reaction to the motion.
Definition motion.cpp:30
void addReactionFront(std::shared_ptr< Reaction< ControlSignalType > > reaction)
Add a reaction to the front of the reaction list.
Definition motion.cpp:37
virtual ~Motion()=default
std::function< void(const RobotState &, franka::Duration, franka::Duration, franka::Duration, const ControlSignalType &)> CallbackType
Definition motion.hpp:28
Motion()
Definition motion.cpp:18
ControlSignalType nextCommand(const RobotState &robot_state, franka::Duration time_step, franka::Duration rel_time, franka::Duration abs_time, const std::optional< ControlSignalType > &previous_command)
Get the next command of the motion.
Definition motion.cpp:57
virtual void initImpl(const RobotState &robot_state, const std::optional< ControlSignalType > &previous_command)
Definition motion.hpp:95
virtual ControlSignalType nextCommandImpl(const RobotState &robot_state, franka::Duration time_step, franka::Duration rel_time, franka::Duration abs_time, const std::optional< ControlSignalType > &previous_command)=0
std::vector< std::shared_ptr< Reaction< ControlSignalType > > > reactions()
Currently registered reactions of the motion.
Definition motion.cpp:44
A reaction that can be attached to a motion.
Definition reaction.hpp:27
A class representing a Franka robot.
Definition robot.hpp:48
Definition dynamics_limit.cpp:8
ControlSignalType
Type of control signal.
Definition control_signal_type.hpp:8
Full state of the robot.
Definition robot_state.hpp:23