-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRoboticArm.h
More file actions
80 lines (63 loc) · 2.01 KB
/
RoboticArm.h
File metadata and controls
80 lines (63 loc) · 2.01 KB
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
#pragma once
#include <atomic>
#include "Linux-DC-Motor/Motor.h"
#include "Linux-Quadrature-Encoder/QuadratureEncoder.h"
#include "Linux-Visual-Encoder/VisualEncoder.h"
#define epsilon (double)1E-09
/* 5 millimeter tolerance */
#define tolerance (double)5E-04
class Point
{
public:
double x, y, z;
bool operator==(const Point &p) {
return ((std::abs(p.x - x) < tolerance) &&
(std::abs(p.y - y) < tolerance) &&
(std::abs(p.z - z) < tolerance));
};
bool operator!=(const Point &p) { return !(*this == p); };
};
class RoboticJoint
{
public:
explicit RoboticJoint(const int &id);
virtual ~RoboticJoint(void);
void Init(void);
double GetAngle(void);
void SetAngle(const double &theta);
void SetZero(void);
/* Quadrature encoders + DC motors */
std::shared_ptr<QuadratureEncoder> Position;
std::shared_ptr<Motor> Movement;
private:
const int _id;
std::atomic<double> _reference_angle;
/* Per joint position correction control */
void AngularControl(void);
std::thread AutomaticControlThread;
std::atomic<bool> _control_thread_stop_event;
};
class RoboticArm
{
public:
explicit RoboticArm(void);
virtual ~RoboticArm(void);
void Init(void);
void GetPosition(Point &pos);
void SetPosition(const Point &pos);
void SetPositionSync(const Point &pos);
void ForwardKinematics(Point &pos, const std::vector<double> &theta);
void InverseKinematics(const Point &pos, std::vector<double> &theta);
void EnableTrainingMode(void);
private:
const int _joints_nr;
/* A container of joints form a chain,
* joints[0] = root
* joints[1] = node1
* :
* joints[n] = nodeN
*/
std::vector<std::shared_ptr<RoboticJoint>> joints;
void CalibrateMovement(void);
void CalibratePosition(void);
};