rby1-sdk
Loading...
Searching...
No Matches
master_arm.h
1#pragma once
2
3#include <array>
4#include <functional>
5
6#include "Eigen/Core"
7
8#include "rby1-sdk/base/dynamixel_bus.h"
9#include "rby1-sdk/base/event_loop.h"
10#include "rby1-sdk/base/thread.h"
11#include "rby1-sdk/dynamics/robot.h"
12#include "rby1-sdk/dynamics/state.h"
13#include "rby1-sdk/export.h"
14#include "rby1-sdk/upc/device.h"
15
16namespace rb::upc {
17
18class RBY1_SDK_API MasterArm {
19 public:
20 static constexpr int kDOF = 14;
21 static constexpr int kDeivceCount = kDOF + 2;
22 static constexpr double kTorqueScaling = 0.5;
23 static constexpr double kMaximumTorque = 4.; // 3.0 Nm
24
25 static constexpr int kRightToolId = 0x80;
26 static constexpr int kLeftToolId = 0x81;
27
28 struct State {
29 Eigen::Vector<double, kDOF> q_joint;
30 Eigen::Vector<double, kDOF> qvel_joint;
31 Eigen::Vector<double, kDOF> torque_joint;
32 Eigen::Vector<double, kDOF> gravity_term;
33
34 Eigen::Vector<int, kDOF> operating_mode;
35 Eigen::Vector<double, kDOF> target_position; // Last target position
36
37 DynamixelBus::ButtonState button_right;
38 DynamixelBus::ButtonState button_left;
39
40 math::SE3::MatrixType T_right; // 4 x 4 matrix
41 math::SE3::MatrixType T_left; // 4 x 4 matrix
42 };
43
44 struct ControlInput {
45 Eigen::Vector<int, kDOF> target_operating_mode;
46 Eigen::Vector<double, kDOF> target_position;
47 Eigen::Vector<double, kDOF> target_torque;
48 };
49
50 explicit MasterArm(const std::string& dev_name = kMasterArmDeviceName);
51
52 ~MasterArm();
53
54 void SetControlPeriod(double control_period);
55
56 void SetModelPath(const std::string& model_path);
57
58 void SetTorqueConstant(const std::array<double, kDOF>& torque_constant);
59
60 std::vector<int> Initialize(bool verbose = false);
61
62 bool StartControl(const std::function<ControlInput(const State& state)>& control = nullptr);
63
64 bool StopControl(bool torque_disable = false);
65
66 bool EnableTorque();
67
68 bool DisableTorque();
69
70 private:
71 bool initialized_{false};
72
73 EventLoop ev_;
74 double control_period_; // (sec)
75 std::array<double, kDOF> torque_constant_;
76
77 EventLoop ctrl_ev_;
78 std::atomic<bool> ctrl_running_{false};
79
80 std::shared_ptr<DynamixelBus> handler_;
81 std::shared_ptr<dyn::Robot<kDOF>> dyn_robot_;
82 std::shared_ptr<dyn::State<kDOF>> dyn_state_;
83
84 std::string model_path_;
85
86 std::atomic<bool> is_running_{false};
87 std::vector<int> active_ids_;
88 bool state_updated_;
89 State state_;
90 bool operating_mode_init_{false};
91
92 std::function<ControlInput(const State& state)> control_;
93};
94
95} // namespace rb::upc
Definition event_loop.h:13
Definition master_arm.h:18
Definition dynamixel_bus.h:42
Definition master_arm.h:44
Definition master_arm.h:28