MCPcopy Create free account
hub / github.com/InternRobotics/OpenHomie / LowStateHandler

Method LowStateHandler

HomieDeploy/unitree_sdk2/g1_control.cpp:277–310  ·  view source on GitHub ↗

set data, todo: send by lcm

Source from the content-addressed store, hash-verified

275
276 // set data, todo: send by lcm
277 void LowStateHandler(const void *message) {
278 unitree_hg::msg::dds_::LowState_ low_state =
279 *(const unitree_hg::msg::dds_::LowState_ *)message;
280
281 if (low_state.crc() !=
282 Crc32Core((uint32_t *)&low_state,
283 (sizeof(unitree_hg::msg::dds_::LowState_) >> 2) - 1)) {
284 std::cout << "low_state CRC Error" << std::endl;
285 return;
286 }
287
288 // get motor state
289 MotorState ms_tmp;
290 for (int i = 0; i < G1_NUM_MOTOR; ++i) {
291 ms_tmp.q.at(i) = low_state.motor_state()[i].q();
292 ms_tmp.dq.at(i) = low_state.motor_state()[i].dq();
293 }
294 motor_state_buffer_.SetData(ms_tmp);
295
296 // get imu state
297 ImuState imu_tmp;
298 imu_tmp.omega = low_state.imu_state().gyroscope();
299 imu_tmp.rpy = low_state.imu_state().rpy();
300 imu_tmp.quat = low_state.imu_state().quaternion();
301 imu_tmp.abody = low_state.imu_state().accelerometer();
302 imu_state_buffer_.SetData(imu_tmp);
303 // update mode machine
304 if (mode_machine_ != low_state.mode_machine()) {
305 if (mode_machine_ == 0)
306 std::cout << "G1 type: " << unsigned(low_state.mode_machine())
307 << std::endl;
308 mode_machine_ = low_state.mode_machine();
309 }
310 }
311
312 void LowCommandWriter() {
313 unitree_hg::msg::dds_::LowCmd_ dds_low_command;

Callers

nothing calls this directly

Calls 12

Crc32CoreFunction · 0.85
SetDataMethod · 0.80
crcMethod · 0.45
qMethod · 0.45
motor_stateMethod · 0.45
dqMethod · 0.45
gyroscopeMethod · 0.45
imu_stateMethod · 0.45
rpyMethod · 0.45
quaternionMethod · 0.45
accelerometerMethod · 0.45
mode_machineMethod · 0.45

Tested by

no test coverage detected