|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <optional> |
| 4 | + |
| 5 | +#include <Eigen/Core> |
| 6 | + |
| 7 | + |
| 8 | +namespace ruckig { |
| 9 | + |
| 10 | +enum class Result { |
| 11 | + Working, |
| 12 | + Finished, |
| 13 | + Error |
| 14 | +}; |
| 15 | + |
| 16 | + |
| 17 | +template<size_t DOFs> |
| 18 | +struct InputParameter { |
| 19 | + using Vector = Eigen::Matrix<double, DOFs, 1, Eigen::ColMajor>; |
| 20 | + static constexpr size_t degrees_of_freedom {DOFs}; |
| 21 | + |
| 22 | + enum class Type { |
| 23 | + Position, |
| 24 | + Velocity, |
| 25 | + } type {Type::Position}; |
| 26 | + |
| 27 | + Vector current_position; |
| 28 | + Vector current_velocity {Vector::Zero()}; |
| 29 | + Vector current_acceleration {Vector::Zero()}; |
| 30 | + |
| 31 | + Vector target_position; |
| 32 | + Vector target_velocity {Vector::Zero()}; |
| 33 | + Vector target_acceleration {Vector::Zero()}; |
| 34 | + |
| 35 | + Vector max_velocity; |
| 36 | + Vector max_acceleration; |
| 37 | + Vector max_jerk; |
| 38 | + |
| 39 | + std::array<bool, DOFs> enabled; |
| 40 | + std::optional<double> minimum_duration; |
| 41 | + |
| 42 | + InputParameter() { |
| 43 | + enabled.fill(true); |
| 44 | + } |
| 45 | + |
| 46 | + bool operator!=(const InputParameter<DOFs>& rhs) const { |
| 47 | + return ( |
| 48 | + current_position != rhs.current_position |
| 49 | + || current_velocity != rhs.current_velocity |
| 50 | + || current_acceleration != rhs.current_acceleration |
| 51 | + || target_position != rhs.target_position |
| 52 | + || target_velocity != rhs.target_velocity |
| 53 | + || target_acceleration != rhs.target_acceleration |
| 54 | + || max_velocity != rhs.max_velocity |
| 55 | + || max_acceleration != rhs.max_acceleration |
| 56 | + || max_jerk != rhs.max_jerk |
| 57 | + || enabled != rhs.enabled |
| 58 | + || minimum_duration != rhs.minimum_duration |
| 59 | + || type != rhs.type |
| 60 | + ); |
| 61 | + } |
| 62 | + |
| 63 | + std::string to_string(size_t dof) const { |
| 64 | + std::stringstream ss; |
| 65 | + ss << "p0: " << current_position[dof] << ", "; |
| 66 | + ss << "v0: " << current_velocity[dof] << ", "; |
| 67 | + ss << "a0: " << current_acceleration[dof] << ", "; |
| 68 | + ss << "pf: " << target_position[dof] << ", "; |
| 69 | + ss << "vf: " << target_velocity[dof] << ", "; |
| 70 | + ss << "vMax: " << max_velocity[dof] << ", "; |
| 71 | + ss << "aMax: " << max_acceleration[dof] << ", "; |
| 72 | + ss << "jMax: " << max_jerk[dof]; |
| 73 | + return ss.str(); |
| 74 | + } |
| 75 | + |
| 76 | + std::string to_string() const { |
| 77 | + Eigen::IOFormat formatter(10, 0, ", ", "\n", "[", "]"); |
| 78 | + |
| 79 | + std::stringstream ss; |
| 80 | + ss << "\ninp.current_position = " << current_position.transpose().format(formatter) << "\n"; |
| 81 | + ss << "inp.current_velocity = " << current_velocity.transpose().format(formatter) << "\n"; |
| 82 | + ss << "inp.current_acceleration = " << current_acceleration.transpose().format(formatter) << "\n"; |
| 83 | + ss << "inp.target_position = " << target_position.transpose().format(formatter) << "\n"; |
| 84 | + ss << "inp.target_velocity = " << target_velocity.transpose().format(formatter) << "\n"; |
| 85 | + ss << "inp.target_acceleration = " << target_acceleration.transpose().format(formatter) << "\n"; |
| 86 | + ss << "inp.max_velocity = " << max_velocity.transpose().format(formatter) << "\n"; |
| 87 | + ss << "inp.max_acceleration = " << max_acceleration.transpose().format(formatter) << "\n"; |
| 88 | + ss << "inp.max_jerk = " << max_jerk.transpose().format(formatter) << "\n"; |
| 89 | + return ss.str(); |
| 90 | + } |
| 91 | +}; |
| 92 | + |
| 93 | + |
| 94 | +template<size_t DOFs> |
| 95 | +struct OutputParameter { |
| 96 | + using Vector = Eigen::Matrix<double, DOFs, 1, Eigen::ColMajor>; |
| 97 | + static constexpr size_t degrees_of_freedom {DOFs}; |
| 98 | + |
| 99 | + Vector new_position; |
| 100 | + Vector new_velocity; |
| 101 | + Vector new_acceleration; |
| 102 | + |
| 103 | + double duration; // [s] |
| 104 | + bool new_calculation {false}; |
| 105 | + double calculation_duration; // [µs] |
| 106 | + |
| 107 | + // Vector independent_min_durations; |
| 108 | + // Vector min_positions, max_positions; |
| 109 | + // Vector time_min_positions, time_max_positions; |
| 110 | +}; |
| 111 | + |
| 112 | +} // namespace ruckig |
0 commit comments