Franky 1.0.2
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
31template <typename ControlSignalType, typename TargetType>
32class PositionWaypointMotion : public WaypointMotion<ControlSignalType, PositionWaypoint<TargetType>, TargetType> {
33 public:
43 std::vector<PositionWaypoint<TargetType>> waypoints, const RelativeDynamicsFactor &relative_dynamics_factor = 1.0,
44 bool return_when_finished = true)
45 : WaypointMotion<ControlSignalType, PositionWaypoint<TargetType>, TargetType>(waypoints, return_when_finished),
46 relative_dynamics_factor_(relative_dynamics_factor) {}
47
48 protected:
50 const PositionWaypoint<TargetType> &waypoint, ruckig::InputParameter<7> &input_parameter) const override {
51 auto [vel_lim, acc_lim, jerk_lim] = getAbsoluteInputLimits();
52
53 auto relative_dynamics_factor =
54 waypoint.relative_dynamics_factor * relative_dynamics_factor_ * this->robot()->relative_dynamics_factor();
55
56 input_parameter.max_velocity = toStdD<7>(relative_dynamics_factor.velocity() * vel_lim);
57 input_parameter.max_acceleration = toStdD<7>(relative_dynamics_factor.acceleration() * acc_lim);
58 input_parameter.max_jerk = toStdD<7>(relative_dynamics_factor.jerk() * jerk_lim);
59
60 if (relative_dynamics_factor.max_dynamics()) {
61 input_parameter.synchronization = ruckig::Synchronization::TimeIfNecessary;
62 } else {
63 input_parameter.synchronization = ruckig::Synchronization::Time;
64 if (waypoint.minimum_time.has_value()) input_parameter.minimum_duration = waypoint.minimum_time.value().toSec();
65 }
66 }
67
69 const RobotState &robot_state, const franka::Duration &time_step,
70 const ruckig::InputParameter<7> &input_parameter, ruckig::OutputParameter<7> &output_parameter) const override {
72
73 // We use the desired state here as this is likely what the robot uses internally as well
75
76 auto vel = toEigenD<7>(input_parameter.current_velocity);
77 auto pos = toEigenD<7>(input_parameter.current_position);
78
79 auto vel_delta = acc_d * time_step.toSec();
80 auto new_vel_d = (vel_d + vel_delta).cwiseMin(vel_lim).cwiseMax(-vel_lim);
81 auto new_pos = pos + (vel_d + new_vel_d) * time_step.toSec() / 2.0;
82 auto new_vel = (vel + vel_delta).cwiseMin(vel_lim).cwiseMax(-vel_lim);
83
84 // Franka assumes a constant acceleration model if no new input is received.
85 // See https://frankaemika.github.io/docs/libfranka.html#under-the-hood
86 output_parameter.new_acceleration = input_parameter.current_acceleration;
87 output_parameter.new_velocity = toStdD<7>(new_vel);
88 output_parameter.new_position = toStdD<7>(new_pos);
89 }
90
91 [[nodiscard]] std::tuple<Vector7d, Vector7d, Vector7d> getAbsoluteInputLimits() const override = 0;
92
93 [[nodiscard]] virtual std::tuple<Vector7d, Vector7d, Vector7d> getDesiredState(
94 const RobotState &robot_state) const = 0;
95
96 private:
97 RelativeDynamicsFactor relative_dynamics_factor_;
98};
99
100} // namespace franky
Robot * robot() const
Definition motion.hpp:114
A motion following multiple positional waypoints in a time-optimal way. Works with arbitrary initial ...
Definition position_waypoint_motion.hpp:32
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:68
void setInputLimits(const PositionWaypoint< TargetType > &waypoint, ruckig::InputParameter< 7 > &input_parameter) const override
Definition position_waypoint_motion.hpp:49
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:42
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:128
A motion following multiple waypoints in a time-optimal way. Works with arbitrary initial conditions.
Definition waypoint_motion.hpp:53
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:10
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:20
A waypoint with a target and optional parameters.
Definition waypoint_motion.hpp:33
RelativeDynamicsFactor relative_dynamics_factor
Definition waypoint_motion.hpp:36