rby1-sdk
Loading...
Searching...
No Matches
robot_state.h
1#pragma once
2
3#include <iostream>
4#include <map>
5#include <string>
6#include <vector>
7
8#include "dynamics/link.h"
9#include "export.h"
10#include "math/liegroup.h"
11
12namespace rb {
13
14struct RBY1_SDK_API SystemStat {
15 double cpu_usage{0.}; // (percent)
16 double memory_usage{0.}; // (percent)
17 double uptime{0.}; // (sec)
18 double program_uptime{0.}; // (sec)
19};
20
21struct RBY1_SDK_API BatteryState {
22 double voltage{0.}; // (V)
23 double current{0.}; // (Amp)
24 double level_percent{0.}; // (%)
25};
26
27struct RBY1_SDK_API PowerState {
28 enum class State { kUnknown = 0, kPowerOn = 1, kPowerOff = 2 };
29
30 State state{State::kUnknown};
31 double voltage{0.};
32};
33
34struct RBY1_SDK_API EMOState {
35 enum class State { kReleased = 0, kPressed = 1 };
36
37 State state{State::kReleased};
38};
39
40struct RBY1_SDK_API JointState {
41 enum class FETState { kUnknown = 0, kOn = 1, kOff = 2 };
42 enum class RunState { kUnknown = 0, kControlOn = 1, kControlOff = 2 };
43 enum class InitializationState { kUnknown = 0, kInitialized = 1, kUninitialized = 2 };
44
45 struct timespec time_since_last_update{};
46
47 bool is_ready{false};
48 FETState fet_state{FETState::kUnknown};
49 RunState run_state{RunState::kUnknown};
50 InitializationState init_state{InitializationState::kUnknown};
51
52 uint32_t motor_type{}; // 0: simulator, 1: rbmotor, 2: dynamixel
53 uint64_t motor_state{};
54
55 bool power_on{false};
56 double position{0.}; // (rad)
57 double velocity{0.}; // (rad/s)
58 double current{0.}; // (amp)
59 double torque{0.}; // (Nm)
60
61 double target_position{0.}; // (rad)
62 double target_velocity{0.}; // (rad/s)
63 uint32_t target_feedback_gain{10}; // [0,10]
64 double target_feedforward_torque{0.}; // (Nm)
65
66 int temperature{}; // ÂșC
67};
68
69struct RBY1_SDK_API ToolFlangeState {
70 struct timespec time_since_last_update{};
71
72 Eigen::Vector<double, 3> gyro; // (rad/s)
73 Eigen::Vector<double, 3> acceleration; // (m/s^2)
74
75 bool switch_A{};
76
77 int output_voltage;
78
79 bool digital_input_A{};
80 bool digital_input_B{};
81
82 bool digital_output_A{};
83 bool digital_output_B{};
84};
85
86struct RBY1_SDK_API FTSensorData {
87 struct timespec time_since_last_update{};
88
89 Eigen::Vector<double, 3> force;
90 Eigen::Vector<double, 3> torque;
91};
92
93template <typename T>
94struct RBY1_SDK_API RobotState {
95 struct timespec timestamp{}; // Robot state update timestamp
96
97 SystemStat system_stat{}; // System Statistic
98
99 BatteryState battery_state{}; // Battery state
100
101 std::vector<PowerState> power_states{}; //Power state
102
103 std::vector<EMOState> emo_states{}; // EMO button state
104
105 std::array<JointState, T::kRobotDOF> joint_states{}; // Joint state
106
107 ToolFlangeState tool_flange_right; // Tool flange state / right
108 ToolFlangeState tool_flange_left; // - / left
109
110 FTSensorData ft_sensor_right; // Force torque sensor data / right
111 FTSensorData ft_sensor_left; // - / left
112
113 // Ready state, position, velocity, current, torque
114 Eigen::Vector<bool, T::kRobotDOF> is_ready{Eigen::Vector<bool, T::kRobotDOF>::Constant(false)};
115 Eigen::Vector<double, T::kRobotDOF> position{Eigen::Vector<double, T::kRobotDOF>::Zero()};
116 Eigen::Vector<double, T::kRobotDOF> velocity{Eigen::Vector<double, T::kRobotDOF>::Zero()};
117 Eigen::Vector<double, T::kRobotDOF> current{Eigen::Vector<double, T::kRobotDOF>::Zero()};
118 Eigen::Vector<double, T::kRobotDOF> torque{Eigen::Vector<double, T::kRobotDOF>::Zero()};
119
120 // Last reference
121 Eigen::Vector<double, T::kRobotDOF> target_position{Eigen::Vector<double, T::kRobotDOF>::Zero()};
122 Eigen::Vector<double, T::kRobotDOF> target_velocity{Eigen::Vector<double, T::kRobotDOF>::Zero()};
123 Eigen::Vector<uint32_t, T::kRobotDOF> target_feedback_gain{Eigen::Vector<uint32_t, T::kRobotDOF>::Zero()};
124 Eigen::Vector<double, T::kRobotDOF> target_feedforward_torque{Eigen::Vector<double, T::kRobotDOF>::Zero()};
125
126 // Odometry, if there is mobility
127 math::SE2::MatrixType odometry{math::SE2::Identity()};
128
129 // Center of mass
130 Eigen::Vector<double, 3> center_of_mass; // Cent of mass position with respect to base link
131
132 // Gravity term
133 Eigen::Vector<double, T::kRobotDOF> gravity;
134
135 // Collisions
136 std::vector<dyn::CollisionResult> collisions;
137
138 // Temperature
139 Eigen::Vector<int, T::kRobotDOF> temperature{Eigen::Vector<int, T::kRobotDOF>::Zero()};
140};
141
142RBY1_SDK_API inline std::string to_string(PowerState::State s) {
143 switch (s) {
144 case PowerState::State::kUnknown:
145 return "Unknown";
146 case PowerState::State::kPowerOn:
147 return "PowerOn";
148 case PowerState::State::kPowerOff:
149 return "PowerOff";
150 }
151 return "";
152}
153
154RBY1_SDK_API inline std::string to_string(EMOState::State s) {
155 switch (s) {
156 case EMOState::State::kReleased:
157 return "Released";
158 case EMOState::State::kPressed:
159 return "Pressed";
160 }
161 return "";
162}
163
164RBY1_SDK_API inline std::string to_string(JointState::FETState s) {
165 switch (s) {
166 case JointState::FETState::kUnknown:
167 return "Unknown";
168 case JointState::FETState::kOn:
169 return "On";
170 case JointState::FETState::kOff:
171 return "Off";
172 }
173 return "";
174}
175
176RBY1_SDK_API inline std::string to_string(JointState::RunState s) {
177 switch (s) {
178 case JointState::RunState::kUnknown:
179 return "Unknown";
180 case JointState::RunState::kControlOn:
181 return "ControlOn";
182 case JointState::RunState::kControlOff:
183 return "ControlOff";
184 }
185 return "";
186}
187
188RBY1_SDK_API inline std::string to_string(JointState::InitializationState s) {
189 switch (s) {
190 case JointState::InitializationState::kUnknown:
191 return "Unknown";
192 case JointState::InitializationState::kInitialized:
193 return "Initialized";
194 case JointState::InitializationState::kUninitialized:
195 return "Uninitialized";
196 }
197 return "";
198}
199
200} // namespace rb
Definition robot_state.h:21
Definition robot_state.h:34
Definition robot_state.h:87
Definition robot_state.h:86
Definition robot_state.h:45
Definition robot_state.h:40
Definition robot_state.h:27
Definition robot_state.h:95
Definition robot_state.h:94
Definition robot_state.h:14
Definition robot_state.h:69