31 double full_stance = 0.4;
37 double max_height = 0.05;
43 t = std::fmod(
t + 0.5, 1);
45 if (
t <= full_stance/2)
52 double x = radius - (
t - t0)*(2*radius/(0.5 - t0));
56 else if (
t <= 0.5 + full_stance/2)
62 t0 = 0.5 + full_stance/2;
64 double x = -radius + (
t - t0)*(2*radius/(0.5 - t0));
66 double z = max_height*(1 - std::pow(
x/radius, 2));
74 Eigen::PolynomialSolver<double, Eigen::Dynamic> solver;
78 std::list<double> real_roots;
80 solver.realRoots(real_roots);
84 for (
auto it = real_roots.begin(); it != real_roots.end(); ++it)
95 double polynomialSpine(
double t,
double t_tot,
double d_tot,
double a_max,
double v_rob)
97 Eigen::Vector3d tr_coeffs(-d_tot - t_tot*v_rob, (2.0/3)*a_max*t_tot, (-4.0/3) + (8.0/9 - 4.0/15)*a_max);
101 Eigen::PolynomialSolver<double, Eigen::Dynamic> solver;
103 double a = -(2.0/3)*a_max/std::pow(t_r, 3);
105 double b = (4.0/3)*a_max/t_r;
109 Eigen::Matrix<double, 5, 1>
coeffs;
113 std::cout <<
"t_tot: " << t_tot <<
" t_r: " <<t_r << std::endl;
116 return Eigen::poly_eval(
coeffs,
t);
118 else if (
t <= t_tot - t_r)
120 return Eigen::poly_eval(
coeffs, t_r);
124 return Eigen::poly_eval(
coeffs, t_tot -
t);
196 void CalculatePolynomialTrajectory(
double t,
double swing_period,
double rise_percentage,
double distance,
double vel_cmd,
double &_pos,
double &_vel,
double &_acc,
double &_jerk)
208 double rise_period = swing_period * rise_percentage;
210 double high_period = swing_period - 2.0 * rise_period;
212 double beta = 1.0/(1.0/rise_percentage - 2.0);
214 double rise_distance = (- vel_cmd * rise_period + 8.0 / 7.0 * beta * distance) / (15.0 / 7.0 + beta * 16.0 / 7.0);
216 double c = beta * (distance - 2.0 * rise_distance) / rise_distance;
218 double a = 15.0 / 7.0 * (
c - 1.0);
222 double b = - 2.0 *
a;
224 Eigen::Matrix<double, 6, 1> pos_coefficients;
226 Eigen::Matrix<double, 5, 1> vel_coefficients;
228 Eigen::Matrix<double, 4, 1> acc_coefficients;
230 Eigen::Matrix<double, 3, 1> jerk_coefficients;
232 pos_coefficients << d,
c, 0,
b/3.0, 0,
a/5.0;
234 vel_coefficients <<
c, 0,
b, 0,
a;
236 acc_coefficients << 0, 2.0*
b, 0, 4.0*
a;
238 jerk_coefficients << 2.0*
b, 0, 12.0*
a;
242 double x =
t / rise_period;
245 _pos = rise_distance * (
a / 5.0 * pow(
x - 1.0, 5) +
b / 3.0 * pow(
x - 1.0, 3) +
c *
x + d);
253 _vel = rise_distance / rise_period * Eigen::poly_eval(vel_coefficients,
x - 1.0);
254 _acc = rise_distance / pow(rise_period, 2) * Eigen::poly_eval(acc_coefficients,
x - 1.0);
255 _jerk = rise_distance / pow(rise_period, 3) * Eigen::poly_eval(jerk_coefficients,
x - 1.0);
258 else if (
t <= rise_period + high_period)
260 _pos = rise_distance * (
a / 5.0 * pow(0.0, 5) +
b / 3.0 * pow(0.0, 3) +
c * 1.0 + d) + rise_distance / rise_period * Eigen::poly_eval(vel_coefficients, 0.0) * (
t - rise_period);
261 _vel = rise_distance / rise_period * Eigen::poly_eval(vel_coefficients, 0.0);
262 _acc = rise_distance / pow(rise_period, 2.0) * Eigen::poly_eval(acc_coefficients, 0.0);
263 _jerk = rise_distance / pow(rise_period, 3.0) * Eigen::poly_eval(jerk_coefficients, 0.0);
267 double x = (
t - high_period) / rise_period;
269 _pos = _pos = rise_distance * (
a / 5.0 * pow(
x - 1.0, 5) +
b / 3.0 * pow(
x - 1.0, 3) +
c *
x + d) + rise_distance / rise_period * Eigen::poly_eval(vel_coefficients, 0.0) * high_period;
270 _vel = rise_distance / rise_period * Eigen::poly_eval(vel_coefficients,
x - 1.0);
271 _acc = rise_distance / pow(rise_period, 2) * Eigen::poly_eval(acc_coefficients,
x - 1.0);
272 _jerk = rise_distance / pow(rise_period, 3) * Eigen::poly_eval(jerk_coefficients,
x - 1.0);
283 double rise_period = swing_period / 2.0;
285 double x =
t/rise_period - 1.0;
287 _pos = distance * (
a * pow(
x, 4) +
b * pow(
x, 2) +
c);
289 _vel = distance / rise_period * (4.0 *
a * pow(
x, 3) + 2.0 *
b *
x);
291 _acc = distance / pow(rise_period, 2) * (12.0 * pow(
x, 2) + 2 *
b);
293 ROS_INFO(
"Height - pos: %f, vel: %f, acc: %f, x: %f, dis: %f", _pos, _vel, _acc,
x, distance);
LegType
Leg type enumerator.
double polynomialSpine(double t, double t_tot, double d_tot, double a_max, double v_rob)
void CalculateFourthOrderPolynomialTrajectory(double t, double swing_period, double distance, double &_pos, double &_vel, double _acc)
Eigen::Vector3d mirrorOffset(Eigen::Vector3d offset, Kinematics::LegType leg)
void CalculatePolynomialTrajectory(double t, double swing_period, double rise_percentage, double distance, double vel_cmd, double &_pos, double &_vel, double &_acc, double &_jerk)
Eigen::Vector3d classicGait(double t, Kinematics::LegType leg)
double smallestPositiveRoot(Eigen::Matrix< double, Eigen::Dynamic, 1 > coeffs)