Skip to content

Commit e4b5f3e

Browse files
committed
read1 temperature and voltage
1 parent 87b9e94 commit e4b5f3e

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

mep3_hardware/include/mep3_hardware/dynamixel_hardware_interface/dynamixel_hardware.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ struct JointValue
3939
double position{0.0};
4040
double velocity{0.0};
4141
double effort{0.0};
42+
double voltage{0.0};
43+
double temperature{0.0};
4244
bool overloaded;
4345
std::deque<double> previous_efforts_{};
4446
};

mep3_hardware/src/dynamixel_hardware_interface/dynamixel_hardware.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ namespace dynamixel_hardware
7272
joints_[i].state.position = std::numeric_limits<double>::quiet_NaN();
7373
joints_[i].state.velocity = std::numeric_limits<double>::quiet_NaN();
7474
joints_[i].state.effort = std::numeric_limits<double>::quiet_NaN();
75+
joints_[i].state.voltage = std::numeric_limits<double>::quiet_NaN();
76+
joints_[i].state.temperature = std::numeric_limits<double>::quiet_NaN();
77+
joints_[i].state.overloaded = false;
7578
joints_[i].state.previous_efforts_ = std::deque<double>();
7679
joints_[i].state.previous_efforts_.resize(effort_filter_);
7780
joints_[i].command.position = std::numeric_limits<double>::quiet_NaN();
@@ -428,7 +431,7 @@ namespace dynamixel_hardware
428431
// ax12 present temperature address: 43 [1B]
429432

430433
const unsigned PRESENT_DATA_ADDRESS = 36;
431-
const unsigned PRESENT_DATA_BYTES = 2+2+2;
434+
const unsigned PRESENT_DATA_BYTES = 2+2+2+1+1;
432435
const unsigned TORQUE_LOAD_MAX = 1023;
433436

434437
unsigned int present_data[PRESENT_DATA_BYTES];
@@ -446,13 +449,18 @@ namespace dynamixel_hardware
446449
speed = -speed;
447450

448451
int16_t load = (present_data[4] | ((0x3 & present_data[5]) << 8));
449-
bool overload = load > TORQUE_LOAD_MAX;
452+
bool overload = (unsigned) load > TORQUE_LOAD_MAX;
450453
// data[5] third bit determines effort sign
451454
if (present_data[5] & 0x4)
452455
load = -load;
453456

457+
uint8_t voltage = present_data[6];
458+
uint8_t temperature = present_data[7];
459+
454460
joints_[i].state.position = dynamixel_workbench_.convertValue2Radian(ids[i], position) + offset_;
455461
joints_[i].state.velocity = dynamixel_workbench_.convertValue2Velocity(ids[i], speed);
462+
joints_[i].state.voltage = voltage / 10.0;
463+
joints_[i].state.temperature = temperature;
456464
joints_[i].state.overloaded = overload;
457465

458466
if (!overload) {
@@ -469,6 +477,16 @@ namespace dynamixel_hardware
469477
} else {
470478
joints_[i].state.effort = std::numeric_limits<double>::infinity();
471479
}
480+
481+
// RCLCPP_WARN(
482+
// rclcpp::get_logger(kDynamixelHardware),
483+
// "DYNAMIXEL [ position: %6.2f rad | speed: %6.2f rad/s | load: %6.2f mA | voltage: %6.2f V | temperature: %6.2f C ]",
484+
// joints_[i].state.position,
485+
// joints_[i].state.velocity,
486+
// joints_[i].state.effort,
487+
// joints_[i].state.voltage,
488+
// joints_[i].state.temperature
489+
// );
472490
}
473491
}
474492

0 commit comments

Comments
 (0)