Franky 1.1.0
A High-Level Motion API for Franka
Loading...
Searching...
No Matches
position_waypoint_motion.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <ruckig/ruckig.hpp>
4
8#include "franky/util.hpp"
9
10namespace franky {
11
19template <typename TargetType>
23
32template <typename ControlSignalType, typename TargetType>
33class PositionWaypointMotion : public WaypointMotion<ControlSignalType, PositionWaypoint<TargetType>, TargetType> {
34 public:
44 std::vector<PositionWaypoint<TargetType>> waypoints, const RelativeDynamicsFactor &relative_dynamics_factor = 1.0,
45 bool return_when_finished = true)
46 : WaypointMotion<ControlSignalType, PositionWaypoint<TargetType>, TargetType>(waypoints, return_when_finished),
47 relative_dynamics_factor_(relative_dynamics_factor) {}
48
49 protected:
51 const PositionWaypoint<TargetType> &waypoint, ruckig::InputParameter<7> &input_parameter) const override {
52 auto [vel_lim, acc_lim, jerk_lim] = getAbsoluteInputLimits();
53
54 auto relative_dynamics_factor =
55 waypoint.relative_dynamics_factor * relative_dynamics_factor_ * this->robot()->relative_dynamics_factor();
56
57 input_parameter.max_velocity = toStdD<7>(relative_dynamics_factor.velocity() * vel_lim);
58 input_parameter.max_acceleration = toStdD<7>(relative_dynamics_factor.acceleration() * acc_lim);
59 input_parameter.max_jerk = toStdD<7>(relative_dynamics_factor.jerk() * jerk_lim);
60
61 if (relative_dynamics_factor.max_dynamics()) {
62 input_parameter.synchronization = ruckig::Synchronization::TimeIfNecessary;
63 } else {
64 input_parameter.synchronization = ruckig::Synchronization::Time;
65 if (waypoint.minimum_time.has_value()) input_parameter.minimum_duration = waypoint.minimum_time.value().toSec();
66 }
67 }
68
70 const RobotState &robot_state, const franka::Duration &time_step,
71 const ruckig::InputParameter<7> &input_parameter, ruckig::OutputParameter<7> &output_parameter) const override {
73
74 // We use the desired state here as this is likely what the robot uses
75 // internally as well
77
78 auto vel = toEigenD<7>(input_parameter.current_velocity);
79 auto pos = toEigenD<7>(input_parameter.current_position);
80
81 auto vel_delta = acc_d * time_step.toSec();
82 auto new_vel_d = (vel_d + vel_delta).cwiseMin(vel_lim).cwiseMax(-vel_lim);
83 auto new_pos = pos + (vel_d + new_vel_d) * time_step.toSec() / 2.0;
84 auto new_vel = (vel + vel_delta).cwiseMin(vel_lim).cwiseMax(-vel_lim);
85
86 // Franka assumes a constant acceleration model if no new input is received.
87 // See https://frankaemika.github.io/docs/libfranka.html#under-the-hood
88 output_parameter.new_acceleration = input_parameter.current_acceleration;
89 output_parameter.new_velocity = toStdD<7>(new_vel);
90 output_parameter.new_position = toStdD<7>(new_pos);
91 }
92
93 [[nodiscard]] std::tuple<Vector7d, Vector7d, Vector7d> getAbsoluteInputLimits() const override = 0;
94
95 [[nodiscard]] virtual std::tuple<Vector7d, Vector7d, Vector7d> getDesiredState(
96 const RobotState &robot_state) const = 0;
97
98 private:
99 RelativeDynamicsFactor relative_dynamics_factor_;
100};
101
102} // namespace franky
Robot * robot() const
Definition motion.hpp:101
A motion following multiple positional waypoints in a time-optimal way. Works with arbitrary initial ...
Definition position_waypoint_motion.hpp:33
virtual std::tuple< Vector7d, Vector7d, Vector7d > getDesiredState(const RobotState &robot_state) const =0
void extrapolateMotion(const RobotState &robot_state, const franka::Duration &time_step, const ruckig::InputParameter< 7 > &input_parameter, ruckig::OutputParameter< 7 > &output_parameter) const override
Definition position_waypoint_motion.hpp:69
void setInputLimits(const PositionWaypoint< TargetType > &waypoint, ruckig::InputParameter< 7 > &input_parameter) const override
Definition position_waypoint_motion.hpp:50
std::tuple< Vector7d, Vector7d, Vector7d > getAbsoluteInputLimits() const override=0
PositionWaypointMotion(std::vector< PositionWaypoint< TargetType > > waypoints, const RelativeDynamicsFactor &relative_dynamics_factor=1.0, bool return_when_finished=true)
Definition position_waypoint_motion.hpp:43
Relative dynamics factors.
Definition relative_dynamics_factor.hpp:13
RelativeDynamicsFactor relative_dynamics_factor()
Returns the current global relative dynamics factor of the robot.
Definition robot.cpp:124
A motion following multiple waypoints in a time-optimal way. Works with arbitrary initial conditions.
Definition waypoint_motion.hpp:59
Definition dynamics_limit.cpp:8
std::array< double, dims > toStdD(const Eigen::Matrix< double, dims, 1 > &vector)
Definition util.hpp:18
ReferenceType
Enum class for reference types.
Definition reference_type.hpp:11
ControlSignalType
Type of control signal.
Definition control_signal_type.hpp:8
A position waypoint with a target and optional parameters.
Definition position_waypoint_motion.hpp:20
ReferenceType reference_type
Definition position_waypoint_motion.hpp:21
Full state of the robot.
Definition robot_state.hpp:23
A waypoint with a target and optional parameters.
Definition waypoint_motion.hpp:36
RelativeDynamicsFactor relative_dynamics_factor
Definition waypoint_motion.hpp:39