-
Notifications
You must be signed in to change notification settings - Fork 6
/
Inverse-dynamics.h
118 lines (97 loc) · 3.54 KB
/
Inverse-dynamics.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef __inv_dyn_H
#define __inv_dyn_H
#include "fwd.h"
// for robot model
#include "robot_model.h"
// for constraint
#include "constraint-equality.h"
#include "constraint-inequality.h"
#include "constraint-bound.h"
// for tasks
#include "task-com.h"
#include "task-joint-posture.h"
#include "task-operational.h"
#include "task-joint-bounds.h"
// for solvers
#include "solver-HQP-qpoases.h"
#include <string>
#include <vector>
namespace HQP {
class TaskLevel
{
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
tasks::TaskBase & task;
constraint::ConstraintBase * constraint;
unsigned int priority;
TaskLevel(tasks::TaskBase & task, unsigned int priority);
};
//class ContactTransitionInfo
//{
//public:
// EIGEN_MAKE_ALIGNED_OPERATOR_NEW
// double time_start;
// double time_end;
// double fMax_start; /// max normal force at time time_start
// double fMax_end; /// max normal force at time time_end
// //ContactLevel * contactLevel;
//};
class InverseDynamics {
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
typedef robot::RobotModel RobotModel;
typedef tasks::TaskBase TaskBase;
typedef tasks::TaskMotion TaskMotion;
// typedef tasks::TaskCom TaskCom;
typedef tasks::TaskJointPosture TaskJointPosture;
typedef tasks::TaskOperationalSpace TaskSE3Equality;
typedef tasks::TaskJointLimit TaskJointLimit;
//typedef tasks::TaskContactForce TaskContactForce;
//typedef tasks::TaskActuation TaskActuation;
typedef solver::HQPOutput HQPOutput;
typedef solver::HQPData HQPData;
InverseDynamics(RobotModel & robot, bool verbose = false);
~InverseDynamics() {}
unsigned int nVar() const;
unsigned int nEq() const;
unsigned int nIn() const;
unsigned int nBound() const;
bool addMotionTask(TaskMotion & task, double weight, unsigned int priorityLevel, double transition_duration = 0.0);
bool addJointPostureTask(TaskJointPosture & task, double weight, unsigned int priorityLevel, double transition_duration = 0.0);
bool addJointLimitTask(TaskJointLimit & task, double weight, unsigned int priorityLevel, double transition_duration = 0.0);
bool addOperationalTask(TaskSE3Equality & task, double weight, unsigned int priorityLevel, double transition_duration = 0.0);
bool updateTaskWeight(const std::string & task_name, double weight);
bool removeTask(const std::string & taskName, double transition_duration = 0.0);
const HQPData & computeProblemData(double time, VectorXd q, VectorXd v);
const VectorXd & getActuatorForces(const HQPOutput & sol);
const VectorXd & getAccelerations(const HQPOutput & sol);
const VectorXd & getSlack(const HQPOutput & sol);
HQPData & getHQPData() { return m_hqpData; };
void addTask(TaskLevel* task, double weight, unsigned int priorityLevel);
void resizeHqpData();
bool removeFromHqpData(const std::string & name);
bool decodeSolution(const HQPOutput & sol);
public:
bool m_verbose;
RobotModel m_robot;
HQPData m_hqpData;
solver::Solver_HQP_qpoases m_solver;
HQPOutput m_sol;
std::vector<TaskLevel*> m_taskMotions;
double m_t; /// time
unsigned int m_k; /// number of contact-force variables
unsigned int m_v; /// number of acceleration variables
unsigned int m_eq; /// number of equality constraints
unsigned int m_in; /// number of inequality constraints
unsigned int m_bound;
//MatrixXd m_Jc; /// contact force Jacobian
constraint::ConstraintEquality m_baseDynamics;
bool m_solutionDecoded;
VectorXd m_dv;
VectorXd m_f;
VectorXd m_tau;
VectorXd m_slack;
//std::vector<ContactTransitionInfo*> m_contactTransitions;
};
}
#endif