-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftsolver.h
71 lines (63 loc) · 2.62 KB
/
ftsolver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/////////////////////////////////////////////////
// ftsolver.h: declaration of class forcetorquesolver
// that solves linear force-torque system in various
// settings. In general, the system is underdetermined,
// which requires intruduction of additional constraints.
// We use a perturbation theory approach to ensure,
// that whenver possible, the solver finds a physically
// realizable solution for a given trajectory, as should
// always be the case for a hexapod sufficiently close
// to a (stable) static limit.
/////////////////////////////////////////////////
#ifndef FTSOLVER_H
#define FTSOLVER_H
#include <list>
#include <Eigen/Dense>
#include <Eigen/Sparse>
#include "periodic.h"
#include "dynrec.h"
using namespace Eigen;
typedef SparseQR<SpMat, COLAMDOrdering<int> > SpSolver; // sparse solver
class dynrecord;
// Class forcetorquesolver for unknown forces and torques.
// A (possibly) underactuated problem is turned into
// a fully actuated problem by allowing non-zero forces
// and torques on the torso (i.e. free joint). Then one
// attempts to find a physically realizable solution
// using perturbation theory by imposing torso penalty
// on forces and torques in the 0th order, while imposing
// motor joint torque penalties in the 1st order.
class forcetorquesolver{
int n; // number of dynparts
int nf; // number of feet
int *parentis, *footis; // see periodic.h
double* masses;
list<pair<int,int> > penal_mask0, penal_mask1; // 0th and 1st order masks
int mask_l0, mask_l1; // mask lengths
dynrecord* dynrec; // curent dynamics record
double* jzaxis; // joint z axis, all dynparts
VectorXd fts; // last force-torques solution
list<int> jpart_ids;
public:
forcetorquesolver(const periodic* per);
~forcetorquesolver();
inline double* get_jzaxis(){return jzaxis;}
inline VectorXd* get_fts(){return &fts;}
void print();
void solve_forcetorques(dynrecord* dynrec_);
void solve_forcetorques(dynrecord* dynrec_, VectorXd& x, VectorXd& y);
void switch_torso_penalty(bool force_flag, bool torque_flag);
void set_action_penalties(VectorXd& c);
void solve_forces(dynrecord* dynrec_, VectorXd& z, VectorXd& y);
private:
void solve_forcetorques_particular(VectorXd& x, SpMat& B, VectorXd& f);
void solve_forcetorques_null_space(SpMat& B, MatrixXd& N);
void solve_contact_forces(VectorXd& x, VectorXd& y, const MatrixXd& N);
void extract_N_contact(const MatrixXd& N, MatrixXd& N_cont);
void set_penal_mask1();
void set_jzaxis();
void set_B_and_f_for_zero_cfs(SpMat& B, VectorXd& f);
void add_torque_constraints_to_B(SpMat& B, VectorXd& f, const VectorXd& z);
void set_dynrec(dynrecord* dynrec_);
};
#endif