-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleg.h
82 lines (66 loc) · 1.56 KB
/
leg.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
#pragma once
#include "Eigen.h"
#include "calibration.h"
#include "types.h"
class Motor {
public:
bool Attach();
void Detach();
void Init(int pin, float min_angle, float max_angle);
bool IsInRange(float angle);
bool SetPosition(float angle);
// void SetPositionUs(int us_angle);
// void SetPositionDeg(int deg);
void SetCalibrationPoint(int index, int us, float angle);
void SetServoPosition(float deg);
int servo_pin_;
private:
// PWMServo servo_;
float min_angle_;
float max_angle_;
int min_us_ = 544;
int max_us_ = 2400;
CalibrationPoint calibration_points_[2];
};
struct LegDimensions {
float la;
float lb1;
float lb2;
float b1_b2_angle;
float lc;
float ld;
float min_angle[3];
float max_angle[3];
};
struct LegConfig {
Eigen::Vector3f offset;
float swing_direction;
LegDimensions *dimensions;
};
class Leg {
public:
void Attach();
void Detach();
void Init(LegConfig *config, int front, int back, int side);
// void SetPosition(float front_angle, float back_angle, float side_angle);
Motor *GetServo(int index) {
switch (index) {
case 0:
return &front_;
case 1:
return &back_;
case 2:
return &side_;
}
return &front_;
}
bool Solve2DLeg(float xp, float zp, float &theta1, float &theta4);
bool SolveSideLeg(float yp, float zp, float &alpha, float &length);
bool SetEffectorTarget(const Eigen::Vector3f &target);
const LegConfig &GetConfig() const { return *config_; }
private:
Motor front_;
Motor back_;
Motor side_;
LegConfig *config_;
};