-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathleap_controller.h
More file actions
105 lines (84 loc) · 2.3 KB
/
leap_controller.h
File metadata and controls
105 lines (84 loc) · 2.3 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
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
#include <leap_hand_utils/leap_hand_utils.h>
#include <leap_hand_utils/dynamixel_client.h>
class LeapController
{
private:
int kP;
int kI;
int kD;
int curr_lim;
Eigen::VectorXd prev_pos;
Eigen::VectorXd curr_pos;
Eigen::MatrixXd pos;
std::vector<int> motors;
DynamixelClient dxl_client;
public:
LeapController(const std::string &usb_port = "/dev/ttyUSB0");
~LeapController();
/**
* @brief Connect leap hand
*
*/
void connect();
/**
* @brief Disconnect hand
*
*/
void disconnect();
/**
* @brief Set kp, ki, kd gains
*
* @param kp
* @param ki
* @param kd
*/
void setGains(int kp = 600, int ki = 0, int kd = 200);
/**
* @brief Get kp, ki, kd gains
*
* @return std::tuple<int, int, int>
*/
inline std::tuple<int, int, int> getGains() {return {kP, kI, kD};}
inline const std::vector<int> & getMotors() const {return motors;}
/**
* @brief Set the leap hand pose
*
* @param pose radians per joint
*/
void set_leap(Eigen::VectorXd pose);
/**
* @brief Set joint angle
*
* @param idx motor index
* @param rad
*/
void setJointPose(int idx, float rad);
/**
* @brief Get joint pose
*
* @param idx
* @return double angle in rad
*/
double getJointPose(int idx);
/**
* @brief Get joint pos, vel, cur
*
* @param idx
* @return std::tuple<double, double, double>
*/
std::tuple<double, double, double> getJointData(int idx);
//allegro compatibility
void set_allegro(Eigen::VectorXd pose);
//Sim compatibility, first read the sim value in range [-1,1] and then convert to leap
void set_ones(Eigen::VectorXd pose) ;
//Read pos and vel. NOTE: if you want both pos and vel, this is a faster way to read from the motors than individually!
std::vector<Eigen::MatrixXd> read_pos_vel() ;
//Read pos and vel. NOTE: if you want both pos and vel and cur, this is a faster way to read from the motors than individually!
std::vector<Eigen::MatrixXd> read_pos_vel_cur();
//read position
Eigen::VectorXd read_pos();
//read velocity
Eigen::VectorXd read_vel();
//read current
Eigen::VectorXd read_cur();
};