4#include <ruckig/ruckig.hpp>
14 using std::runtime_error::runtime_error;
35template <
typename TargetType>
58template <
typename ControlSignalType,
typename Waypo
intType,
typename TargetType>
61 std::is_base_of_v<Waypoint<TargetType>,
WaypointType>,
"WaypointType must inherit from Waypoint<TargetType>");
78 target_reached_time_ = std::nullopt;
79 waypoint_started_time_ = franka::Duration(0);
81 waypoint_iterator_ = waypoints_.begin();
83 if (waypoint_iterator_ != waypoints_.end()) {
87 prev_result_ = ruckig::Result::Working;
89 prev_result_ = ruckig::Result::Finished;
103 output_parameter_.pass_to_input(input_parameter_);
107 if (waypoint_iterator_ != waypoints_.end() && waypoint_iterator_->max_total_duration.has_value()) {
112 if (!target_reached_time_.has_value()) {
115 if (waypoint_iterator_ != waypoints_.end()) {
116 auto hold_target_duration = waypoint_iterator_->hold_target_duration;
117 if (waypoint_iterator_ + 1 == waypoints_.end()) {
120 hold_target_duration = std::max(hold_target_duration, franka::Duration(10));
123 target_reached_time_ = std::nullopt;
124 ++waypoint_iterator_;
125 if (waypoint_iterator_ != waypoints_.end()) {
133 if (waypoint_iterator_ == waypoints_.end()) {
135 if (!return_when_finished_)
return command;
136 return franka::MotionFinished(
command);
140 assert(waypoint_iterator_ != waypoints_.end());
142 prev_result_ = trajectory_generator_.update(input_parameter_, output_parameter_);
143 if (prev_result_ == ruckig::Result::Working || prev_result_ == ruckig::Result::Finished) {
146 for (
int i = 0;
i < 7;
i++) {
147 if (!input_parameter_.enabled[
i]) {
148 output_parameter_.new_position[
i] = 0.0;
149 output_parameter_.new_velocity[
i] = 0.0;
150 output_parameter_.new_acceleration[
i] = 0.0;
153 output_parameter_.pass_to_input(input_parameter_);
184 std::vector<WaypointType> waypoints_;
185 bool return_when_finished_{
true};
188 ruckig::Result prev_result_;
189 ruckig::InputParameter<7> input_parameter_;
190 ruckig::OutputParameter<7> output_parameter_;
192 typename std::vector<WaypointType>::iterator waypoint_iterator_;
194 std::optional<franka::Duration> target_reached_time_;
195 franka::Duration waypoint_started_time_;
Base class for motions.
Definition motion.hpp:25
Relative dynamics factors.
Definition relative_dynamics_factor.hpp:13
static constexpr double control_rate
Definition robot.hpp:157
A motion following multiple waypoints in a time-optimal way. Works with arbitrary initial conditions.
Definition waypoint_motion.hpp:59
virtual void extrapolateMotion(const RobotState &robot_state, const franka::Duration &time_step, const ruckig::InputParameter< 7 > &input_parameter, ruckig::OutputParameter< 7 > &output_parameter) const =0
virtual void initWaypointMotion(const RobotState &robot_state, const std::optional< ControlSignalType > &previous_command, ruckig::InputParameter< 7 > &input_parameter)=0
virtual void setInputLimits(const WaypointType &waypoint, ruckig::InputParameter< 7 > &input_parameter) const =0
WaypointMotion(std::vector< WaypointType > waypoints, bool return_when_finished=true)
Definition waypoint_motion.hpp:69
bool return_when_finished() const
Definition waypoint_motion.hpp:74
const std::vector< WaypointType > & waypoints() const
Definition waypoint_motion.hpp:72
virtual void checkWaypoint(const WaypointType &waypoint) const
Definition waypoint_motion.hpp:173
virtual ControlSignalType getControlSignal(const RobotState &robot_state, const franka::Duration &time_step, const std::optional< ControlSignalType > &previous_command, const ruckig::InputParameter< 7 > &input_parameter)=0
virtual void setNewWaypoint(const RobotState &robot_state, const std::optional< ControlSignalType > &previous_command, const WaypointType &new_waypoint, ruckig::InputParameter< 7 > &input_parameter)=0
void initImpl(const RobotState &robot_state, const std::optional< ControlSignalType > &previous_command) override
Definition waypoint_motion.hpp:77
ControlSignalType nextCommandImpl(const RobotState &robot_state, franka::Duration time_step, franka::Duration rel_time, franka::Duration abs_time, const std::optional< ControlSignalType > &previous_command) override
Definition waypoint_motion.hpp:93
virtual std::tuple< Vector7d, Vector7d, Vector7d > getAbsoluteInputLimits() const =0
Definition dynamics_limit.cpp:8
std::array< double, dims > toStdD(const Eigen::Matrix< double, dims, 1 > &vector)
Definition util.hpp:18
ControlSignalType
Type of control signal.
Definition control_signal_type.hpp:8
Exception thrown if the motion planner fails.
Definition waypoint_motion.hpp:13
Full state of the robot.
Definition robot_state.hpp:40
A waypoint with a target and optional parameters.
Definition waypoint_motion.hpp:36
std::optional< franka::Duration > max_total_duration
Definition waypoint_motion.hpp:45
franka::Duration hold_target_duration
Definition waypoint_motion.hpp:43
TargetType target
Definition waypoint_motion.hpp:37
RelativeDynamicsFactor relative_dynamics_factor
Definition waypoint_motion.hpp:39
std::optional< franka::Duration > minimum_time
Definition waypoint_motion.hpp:41