-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheiccontrol.h
64 lines (53 loc) · 2.01 KB
/
eiccontrol.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
#ifndef EICCONTROL_H
#define EICCONTROL_H
#include "desired_trj.h"
#include "bike_plant.h"
using Eigen::Vector2d;
class eiccontrol
{
public:
eiccontrol(bike_plant, desired_trj);
~eiccontrol();
Vector2d external_track_control(VectorXd, double, double, double);
double solveBEM(VectorXd, double);
double internal_stabilize_BEM(VectorXd, double, double, double);
private:
desired_trj trj2follow;
bike_plant model;
};
eiccontrol::eiccontrol(bike_plant md, desired_trj trj):model(md),trj2follow(trj)
{
}
eiccontrol::~eiccontrol()
{
}
Vector2d eiccontrol::external_track_control(VectorXd x, double t, double kp, double kd) {
double xpos_des = trj2follow.get_desired_xpos(t);
double ypos_des = trj2follow.get_desired_ypos(t);
double xvel_des = trj2follow.get_desired_dot_xpos(t);
double yvel_des = trj2follow.get_desired_dot_ypos(t);
double xacc_des = trj2follow.get_desired_ddot_xpos(t);
double yacc_des = trj2follow.get_desired_ddot_ypos(t);
double xpos = x(0), ypos = x(1), yaw = x(2), speed = x(3);
double xvel = speed*cos(yaw), yvel = speed*sin(yaw);
double ddx_design = xacc_des - kp*(xpos - xpos_des) - kd*(xvel - xvel_des);
double ddy_design = yacc_des - kp*(ypos - ypos_des) - kd*(yvel - yvel_des);
double d_yaw_design = (-sin(yaw)*ddx_design + cos(yaw)*ddy_design) / speed;
double acc_design = cos(yaw)*ddx_design + sin(yaw)*ddy_design;
Vector2d Uext(d_yaw_design, acc_design);
return Uext;
}
double eiccontrol::solveBEM(VectorXd x, double d_yaw_design) {
double bem = model.balance_equilibrium_manifold(x, d_yaw_design);
return bem;
}
double eiccontrol::internal_stabilize_BEM(VectorXd x, double bem, double kp, double kd) {
double roll = x(4);// roll angle x(4)
double droll = x(5);// roll velocity x(5)
double ddroll_design = -kp*(roll - bem) - kd*(droll - 0);
// inverse dynamics controller
// ddroll =f+g*tan(steer)
double steer = atan((ddroll_design - model.get_model_f(x)) / model.get_model_g(x));
return steer;
}
#endif // !EICCONTROL_H