TurtleQUAD 2.0
Loading...
Searching...
No Matches
Leg.hpp
Go to the documentation of this file.
1
4
5#pragma once
6
7#include "spatial.hpp"
8#include <cmath>
9#include <iostream>
10#include <numbers>
11
12constexpr int njoints = 3;
13
20class Leg {
21public:
36 Leg(Eigen::Vector<double, njoints + 1> &l,
37 Eigen::Matrix<double, 6, njoints> &Slist, Eigen::Isometry3d &M,
38 std::array<Eigen::Isometry3d, njoints + 1> &Mlist,
39 std::array<Eigen::Matrix6d, njoints> &Glist,
40 Eigen::Matrix<double, njoints, 2> &thetaRange,
41 Eigen::Vector<double, njoints> &thetadMax,
42 Eigen::Vector<double, njoints> &thetaddMax,
43 Eigen::Vector<double, njoints> &tauMax)
44 : l{l}, Slist{Slist}, M{M}, Mlist{Mlist}, Glist{Glist},
45 thetaRange{thetaRange}, thetadMax{thetadMax}, thetaddMax{thetaddMax},
46 tauMax{tauMax} {};
47
56 bool fk(const Eigen::Vector3d &thetalist, Eigen::Vector3d &pf);
57
67 bool ik(const Eigen::Vector3d &pf, Eigen::Vector3d &thetalist,
68 Eigen::Matrix3d *Jinv = nullptr);
69
79 bool ivk(const Eigen::Vector3d &vf, const Eigen::Matrix3d &Jinv,
80 Eigen::Vector3d &thetadlist);
81
89 bool id(Eigen::Vector<double, njoints> &taulist);
90
91 // Initiate lift and set target
92 void liftTo(const Eigen::Isometry3d &T);
93
105 bool jointTrajectory(const Eigen::Isometry3d &Tstart,
106 const Eigen::Isometry3d &Tgoal, const double t0,
107 const double t, Eigen::Isometry3d &Tcurrent);
108
112 void run();
113
117 enum state_t {
118 IDLE,
119 HOMING,
120 RUNNING,
121 LIFT,
122 PLACE
123 } state = IDLE,
124 statep = IDLE;
125
126 // Foot space
127 Eigen::Vector3d pf;
128 Eigen::Vector3d vf;
129 Eigen::Vector3d dvf;
130 Eigen::Vector3d ff;
131 Eigen::Vector3d g;
132 // Eigen::Vector3d liftpf; //< m
133 // double llift = 0.02; // m TODO: Set from config
134
135 // Joint space (updated by motor controller)
136 Eigen::Vector<double, njoints> thetalist; // rad
137 Eigen::Vector<double, njoints> thetadlist; // rad/s
138 Eigen::Vector<double, njoints> thetaddlist; // rad/s^2
139 Eigen::Vector<double, njoints> taulist; // N*m
140
141private:
142 /* Leg geometry & mass properties */
143 const Eigen::Vector<double, njoints + 1> l; // m
144 const Eigen::Matrix<double, 6, njoints> Slist; //
145 const Eigen::Isometry3d M; // SE(3)
146 const std::array<Eigen::Isometry3d, njoints + 1> Mlist; // SE(3)
147 const std::array<Eigen::Matrix6d, njoints> Glist; // kg, kg*m^2
148
149 /* Joint limits */
150 const Eigen::Matrix<double, njoints, 2> thetaRange; // rad
151 const Eigen::Vector<double, njoints> thetadMax; // rad/s
152 const Eigen::Vector<double, njoints> thetaddMax; // rad/s^2
153 const Eigen::Vector<double, njoints> tauMax; // N*m
154
155 /* Joint directions */
156 const Eigen::Vector<double, njoints> thetadir{Slist(0, 0) * Slist(1, 1),
157 Slist(1, 1), Slist(1, 1)};
158
159 /* Inverse velocity kinematics */
160 Eigen::Matrix<double, njoints, 3> Jinv; // rad/m
161
162 /* Inverse dynamics */
163 Eigen::Isometry3d Mi; // SE(3)
164 Eigen::Matrix<double, 6, njoints> Ai; //
165 Eigen::Matrix<double, 6, njoints + 1> Vi; // rad/s, m/s
166 Eigen::Matrix<double, 6, njoints + 1> dVi; // rad/s^2, m/s^2
167 std::array<Eigen::Matrix6d, njoints + 1> AdTi; //
168 Eigen::Vector6d Fi; // N*m, N
169};
bool ivk(const Eigen::Vector3d &vf, const Eigen::Matrix3d &Jinv, Eigen::Vector3d &thetadlist)
Inverse Velocity Kinematics.
Definition Leg.cpp:72
state_t
Leg State.
Definition Leg.hpp:117
void run()
Run foot operations.
Definition Leg.cpp:111
bool ik(const Eigen::Vector3d &pf, Eigen::Vector3d &thetalist, Eigen::Matrix3d *Jinv=nullptr)
Inverse Kinematics.
Definition Leg.cpp:19
Eigen::Vector3d g
Gravity [m/s^2].
Definition Leg.hpp:131
bool jointTrajectory(const Eigen::Isometry3d &Tstart, const Eigen::Isometry3d &Tgoal, const double t0, const double t, Eigen::Isometry3d &Tcurrent)
Joint Trajectory.
Definition Leg.cpp:138
Eigen::Vector3d vf
Foot velocity [m/s].
Definition Leg.hpp:128
bool id(Eigen::Vector< double, njoints > &taulist)
Inverse Dynamics.
Definition Leg.cpp:78
Eigen::Vector3d ff
Foot force [N].
Definition Leg.hpp:130
Eigen::Vector3d pf
Foot position [m].
Definition Leg.hpp:127
Eigen::Vector3d dvf
Foot acceleration [m/s^2].
Definition Leg.hpp:129
bool fk(const Eigen::Vector3d &thetalist, Eigen::Vector3d &pf)
Forward Kinematics.
Definition Leg.cpp:4
Leg(Eigen::Vector< double, njoints+1 > &l, Eigen::Matrix< double, 6, njoints > &Slist, Eigen::Isometry3d &M, std::array< Eigen::Isometry3d, njoints+1 > &Mlist, std::array< Eigen::Matrix6d, njoints > &Glist, Eigen::Matrix< double, njoints, 2 > &thetaRange, Eigen::Vector< double, njoints > &thetadMax, Eigen::Vector< double, njoints > &thetaddMax, Eigen::Vector< double, njoints > &tauMax)
Leg Constructor.
Definition Leg.hpp:36