Skip to content

Commit 321ed1a

Browse files
committed
Support rising tag
Signed-off-by: Tatsuro Sakaguchi <[email protected]>
1 parent 31b7fbb commit 321ed1a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/dynamixel_hardware_interface.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include "dynamixel_hardware_interface/dynamixel_hardware_interface.hpp"
1818

19+
#include <tinyxml2.h>
20+
1921
#include <chrono>
2022
#include <cmath>
2123
#include <limits>
@@ -215,6 +217,43 @@ hardware_interface::CallbackReturn DynamixelHardware::on_init(
215217
}
216218
}
217219

220+
auto urdf = info_.original_xml;
221+
tinyxml2::XMLDocument doc;
222+
if (doc.Parse(urdf.c_str()) != tinyxml2::XML_SUCCESS) {
223+
RCLCPP_ERROR(logger_, "Failed to parse URDF XML");
224+
return hardware_interface::CallbackReturn::ERROR;
225+
}
226+
const auto * joint_element = doc.RootElement()->FirstChildElement("joint");
227+
while (joint_element != nullptr) {
228+
const auto * name_attr = joint_element->FindAttribute("name");
229+
const auto * calibration_element = joint_element->FirstChildElement("calibration");
230+
if (calibration_element != nullptr) {
231+
const auto * rising_attr = calibration_element->FindAttribute("rising");
232+
if ((rising_attr != nullptr) && (name_attr != nullptr)) {
233+
auto rising = std::atof(calibration_element->Attribute("rising"));
234+
std::string name = joint_element->Attribute("name");
235+
auto itr = std::find_if(
236+
info_.joints.begin(), info_.joints.end(),
237+
[&name](const hardware_interface::ComponentInfo & joint) {
238+
return joint.name == name;
239+
});
240+
if (itr != info_.gpios.end()) {
241+
auto params = info_.gpios[std::distance(info_.joints.begin(), itr)].parameters;
242+
if (std::find_if(params.begin(), params.end(),
243+
[](const std::pair<std::string, std::string> & p) {
244+
return p.first == "Homing Offset";
245+
}) == params.end())
246+
{
247+
info_.gpios[std::distance(info_.joints.begin(), itr)].parameters.emplace(
248+
"Homing Offset",
249+
std::to_string(std::round(rising * (180.0 / M_PI) / (360.0 / 4095))));
250+
}
251+
}
252+
}
253+
}
254+
joint_element = joint_element->NextSiblingElement("joint");
255+
}
256+
218257
torque_enabled_comm_id_id_.clear();
219258
for (const hardware_interface::ComponentInfo & gpio : info_.gpios) {
220259
uint8_t id = static_cast<uint8_t>(stoi(gpio.parameters.at("ID")));

0 commit comments

Comments
 (0)