-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.h
90 lines (75 loc) · 2.08 KB
/
control.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
#pragma once
#include <vector>
#include "Eigen.h"
#include "leg.h"
class Robot {
public:
void Init(LegConfig* FL, LegConfig* FR, LegConfig* BL, LegConfig* BR);
void ApplyConfig();
void Disable();
void SetTiltAndAngle(const Eigen::Vector3f& tilt, float swing);
void SetOffset(const Eigen::Vector3f& offset);
void SetAngle(int leg_index, float front_servo, float back_servo,
float side_servo);
Leg* GetLegFL() { return &FL; }
Leg* GetLegFR() { return &FR; }
Leg* GetLegBL() { return &BL; }
Leg* GetLegBR() { return &BR; }
Leg* GetLeg(int leg_index) { return legs[leg_index]; }
Leg* GetLegFixMe(int leg_index) {
return const_cast<Leg*>(
const_cast<const Robot*>(this)->GetLegFixMe(leg_index));
}
const Leg* GetLegFL() const { return &FL; }
const Leg* GetLegFR() const { return &FR; }
const Leg* GetLegBL() const { return &BL; }
const Leg* GetLegBR() const { return &BR; }
const Leg* GetLeg(int leg_index) const { return legs[leg_index]; }
const Leg* GetLegFixMe(int leg_index) const {
switch (leg_index) {
case 0:
return &FL;
case 1:
return &FR;
case 2:
return &BR;
case 3:
return &BL;
}
return nullptr;
}
private:
Leg FL;
Leg FR;
Leg BL;
Leg BR;
Leg* legs[4] = {&FL, &FR, &BL, &BR};
};
class ControlBase {
public:
ControlBase(Robot* actor);
virtual void ProcessInput(float axes[6], uint32_t buttons) = 0;
Robot* GetActor() const { return actor_; }
private:
Robot* actor_;
};
class ControlOffset : public ControlBase {
public:
ControlOffset(Robot* actor);
void ProcessInput(float axes[6], uint32_t buttons) override;
};
class ControlAngles : public ControlBase {
public:
ControlAngles(Robot* actor);
void ProcessInput(float axes[6], uint32_t buttons) override;
};
class Control2DIK : public ControlBase {
public:
Control2DIK(Robot* actor);
void ProcessInput(float axes[6], uint32_t buttons) override;
};
class ControlIK : public ControlBase {
public:
ControlIK(Robot* actor);
void ProcessInput(float axes[6], uint32_t buttons) override;
};