55 for (
auto it = act_coeffs.
begin(); it != act_coeffs.
end(); ++it)
60 if (it->second.hasMember(
"act2pos"))
61 act_coeff.act2pos =
xmlRpcGetDouble(act_coeffs[it->first],
"act2pos", 0.);
63 ROS_ERROR_STREAM(
"Actuator type " << it->first <<
" has no associated act2pos.");
64 if (it->second.hasMember(
"act2vel"))
65 act_coeff.act2vel =
xmlRpcGetDouble(act_coeffs[it->first],
"act2vel", 0.);
67 ROS_ERROR_STREAM(
"Actuator type " << it->first <<
" has no associated act2vel.");
68 if (it->second.hasMember(
"act2effort"))
69 act_coeff.act2effort =
xmlRpcGetDouble(act_coeffs[it->first],
"act2effort", 0.);
71 ROS_ERROR_STREAM(
"Actuator type " << it->first <<
" has no associated act2effort.");
72 if (it->second.hasMember(
"pos2act"))
73 act_coeff.pos2act =
xmlRpcGetDouble(act_coeffs[it->first],
"pos2act", 0.);
75 ROS_DEBUG_STREAM(
"Actuator type " << it->first <<
" has no associated pos2act.");
76 if (it->second.hasMember(
"vel2act"))
77 act_coeff.vel2act =
xmlRpcGetDouble(act_coeffs[it->first],
"vel2act", 0.);
79 ROS_DEBUG_STREAM(
"Actuator type " << it->first <<
" has no associated vel2act.");
80 if (it->second.hasMember(
"effort2act"))
83 ROS_ERROR_STREAM(
"Actuator type " << it->first <<
" has no associated effort2act.");
84 if (it->second.hasMember(
"max_out"))
85 act_coeff.max_out =
xmlRpcGetDouble(act_coeffs[it->first],
"max_out", 0.0);
87 ROS_ERROR_STREAM(
"Actuator type " << it->first <<
" has no associated max_out.");
90 if (it->second.hasMember(
"act2pos_offset"))
91 act_coeff.act2pos_offset =
xmlRpcGetDouble(act_coeffs[it->first],
"act2pos_offset", -12.5);
93 ROS_DEBUG_STREAM(
"Actuator type " << it->first <<
" has no associated act2pos_offset.");
94 if (it->second.hasMember(
"act2vel_offset"))
95 act_coeff.act2vel_offset =
xmlRpcGetDouble(act_coeffs[it->first],
"act2vel_offset", -65.0);
97 ROS_DEBUG_STREAM(
"Actuator type " << it->first <<
" has no associated act2vel_offset.");
98 if (it->second.hasMember(
"act2effort_offset"))
99 act_coeff.act2effort_offset =
xmlRpcGetDouble(act_coeffs[it->first],
"act2effort_offset", -18.0);
101 ROS_DEBUG_STREAM(
"Actuator type " << it->first <<
" has no associated act2effort_offset.");
102 if (it->second.hasMember(
"kp2act"))
103 act_coeff.kp2act =
xmlRpcGetDouble(act_coeffs[it->first],
"kp2act", 8.19);
105 ROS_DEBUG_STREAM(
"Actuator type " << it->first <<
" has no associated kp2act.");
106 if (it->second.hasMember(
"kp2act"))
107 act_coeff.kp2act =
xmlRpcGetDouble(act_coeffs[it->first],
"kd2act", 819);
109 ROS_DEBUG_STREAM(
"Actuator type " << it->first <<
" has no associated kd2act.");
111 std::string type = it->first;
121 <<
"configuration: " << e.
getMessage() <<
".\n"
122 <<
"Please check the configuration, particularly parameter types.");
133 for (
auto it = act_datas.
begin(); it != act_datas.
end(); ++it)
135 if (!it->second.hasMember(
"bus"))
140 else if (!it->second.hasMember(
"type"))
145 else if (!it->second.hasMember(
"id"))
150 bool need_calibration =
false;
151 if (!it->second.hasMember(
"need_calibration"))
152 ROS_DEBUG_STREAM(
"Actuator " << it->first <<
" set no need calibration by default.");
154 need_calibration = it->second[
"need_calibration"];
155 std::string bus = act_datas[it->first][
"bus"], type = act_datas[it->first][
"type"];
156 int id =
static_cast<int>(act_datas[it->first][
"id"]);
165 bus_id2act_data_.insert(std::make_pair(bus, std::unordered_map<int, ActData>()));
180 .need_calibration = need_calibration,
182 .calibration_reading =
false,
212 if (type.find(
"rm") != std::string::npos || type.find(
"cheetah") != std::string::npos)
219 ROS_ERROR_STREAM(
"Actuator " << it->first <<
"'s type neither RoboMaster(rm_xxx) nor Cheetah(cheetah_xxx)");
231 <<
"configuration: " << e.
getMessage() <<
".\n"
232 <<
"Please check the configuration, particularly parameter types.");
243 for (
auto it = imu_datas.
begin(); it != imu_datas.
end(); ++it)
245 std::string name = it->first;
246 if (!it->second.hasMember(
"frame_id"))
251 else if (!it->second.hasMember(
"bus"))
256 else if (!it->second.hasMember(
"id"))
261 else if (!it->second.hasMember(
"orientation_covariance_diagonal"))
263 ROS_ERROR_STREAM(
"Imu " << name <<
" has no associated orientation covariance diagonal.");
266 else if (!it->second.hasMember(
"angular_velocity_covariance"))
268 ROS_ERROR_STREAM(
"Imu " << name <<
" has no associated angular velocity covariance.");
271 else if (!it->second.hasMember(
"linear_acceleration_covariance"))
273 ROS_ERROR_STREAM(
"Imu " << name <<
" has no associated linear acceleration covariance.");
276 else if (!it->second.hasMember(
"angular_vel_offset"))
278 ROS_ERROR_STREAM(
"Imu " << name <<
" has no associated angular_vel_offset type");
281 else if (!it->second.hasMember(
"angular_vel_coeff"))
283 ROS_ERROR_STREAM(
"Imu " << name <<
" has no associated angular velocity coefficient.");
286 else if (!it->second.hasMember(
"accel_coeff"))
288 ROS_ERROR_STREAM(
"Imu " << name <<
" has no associated linear acceleration coefficient.");
291 else if (!it->second.hasMember(
"temp_coeff"))
293 ROS_ERROR_STREAM(
"Imu " << name <<
" has no associated temperate coefficient.");
296 else if (!it->second.hasMember(
"filter"))
301 else if (!it->second.hasMember(
"angular_vel_offset"))
303 ROS_ERROR_STREAM(
"Imu " << name <<
" has no associated angular_vel_offset type");
309 for (
int i = 0; i < angular_vel_offsets.
size(); ++i)
314 for (
int i = 0; i < ori_cov.
size(); ++i)
319 for (
int i = 0; i < angular_cov.
size(); ++i)
324 for (
int i = 0; i < linear_cov.
size(); ++i)
326 std::string filter_type = imu_datas[name][
"filter"];
329 if (filter_type.find(
"complementary") != std::string::npos)
333 ROS_ERROR_STREAM(
"Imu " << name <<
" doesn't has filter type " << filter_type);
336 imu_filter->
init(it->second, name);
338 std::string frame_id = imu_datas[name][
"frame_id"], bus = imu_datas[name][
"bus"];
339 int id =
static_cast<int>(imu_datas[name][
"id"]);
342 if (bus_id2imu_data_.find(bus) == bus_id2imu_data_.end())
343 bus_id2imu_data_.insert(std::make_pair(bus, std::unordered_map<int, ImuData>()));
345 if (!(bus_id2imu_data_[bus].find(
id) == bus_id2imu_data_[bus].end()))
351 bus_id2imu_data_[bus].insert(std::make_pair(
352 id, ImuData{ .time_stamp = {},
357 .angular_vel_offset = {
static_cast<double>(angular_vel_offsets[0]),
358 static_cast<double>(angular_vel_offsets[1]),
359 static_cast<double>(angular_vel_offsets[2]) },
360 .ori_cov = {
static_cast<double>(ori_cov[0]), 0., 0., 0.,
static_cast<double>(ori_cov[1]), 0.,
361 0., 0.,
static_cast<double>(ori_cov[2]) },
362 .angular_vel_cov = {
static_cast<double>(angular_cov[0]), 0., 0., 0.,
363 static_cast<double>(angular_cov[1]), 0., 0., 0.,
364 static_cast<double>(angular_cov[2]) },
365 .linear_acc_cov = {
static_cast<double>(linear_cov[0]), 0., 0., 0.,
366 static_cast<double>(linear_cov[1]), 0., 0., 0.,
367 static_cast<double>(linear_cov[2]) },
369 .angular_vel_coeff =
xmlRpcGetDouble(imu_datas[name],
"angular_vel_coeff", 0.),
373 .accel_updated =
false,
374 .gyro_updated =
false,
375 .camera_trigger =
false,
376 .enabled_trigger =
false,
377 .imu_filter = imu_filter }));
380 name, frame_id, bus_id2imu_data_[bus][
id].ori, bus_id2imu_data_[bus][
id].ori_cov,
381 bus_id2imu_data_[bus][
id].angular_vel, bus_id2imu_data_[bus][
id].angular_vel_cov,
382 bus_id2imu_data_[bus][
id].linear_acc, bus_id2imu_data_[bus][
id].linear_acc_cov);
383 imu_sensor_interface_.registerHandle(imu_sensor_handle);
384 rm_imu_sensor_interface_.registerHandle(
387 registerInterface(&imu_sensor_interface_);
388 registerInterface(&rm_imu_sensor_interface_);
393 <<
"configuration: " << e.
getMessage() <<
".\n"
394 <<
"Please check the configuration, particularly parameter types.");
402 for (
auto it = gpio_datas.
begin(); it != gpio_datas.
end(); ++it)
404 if (it->second.hasMember(
"pin"))
407 gpio_data.
name = it->first;
408 if (std::string(gpio_datas[it->first][
"direction"]) ==
"in")
412 else if (std::string(gpio_datas[it->first][
"direction"]) ==
"out")
418 ROS_ERROR(
"Type set error of %s!", it->first.data());
421 gpio_data.
pin = gpio_datas[it->first][
"pin"];
422 gpio_data.
value =
new bool(
false);
439 ROS_ERROR(
"Module %s hasn't set pin ID", it->first.data());
450 for (
auto it = tof_datas.
begin(); it != tof_datas.
end(); ++it)
452 if (!it->second.hasMember(
"bus"))
457 else if (!it->second.hasMember(
"id"))
463 std::string bus = tof_datas[it->first][
"bus"];
464 int id =
static_cast<int>(tof_datas[it->first][
"id"]);
467 if (bus_id2tof_data_.find(bus) == bus_id2tof_data_.end())
468 bus_id2tof_data_.insert(std::make_pair(bus, std::unordered_map<int, TofData>()));
470 if (!(bus_id2tof_data_[bus].find(
id) == bus_id2tof_data_[bus].end()))
476 bus_id2tof_data_[bus].insert(std::make_pair(
id,
TofData{ .
strength = {}, .distance = {} }));
479 &bus_id2tof_data_[bus][
id].strength);
480 tof_radar_interface_.registerHandle(tof_radar_handle);
482 registerInterface(&tof_radar_interface_);
487 <<
"configuration: " << e.
getMessage() <<
".\n"
488 <<
"Please check the configuration, particularly parameter types.");
510 std::make_unique<transmission_interface::TransmissionInterfaceLoader>(
this, &
robot_transmissions_);
512 catch (
const std::invalid_argument& ex)
514 ROS_ERROR_STREAM(
"Failed to create transmission interface loader. " << ex.what());
519 ROS_ERROR_STREAM(
"Failed to create transmission interface loader. " << ex.what());
536 auto effort_joint_interface = this->get<hardware_interface::EffortJointInterface>();
537 std::vector<std::string> names = effort_joint_interface->getNames();
538 for (
const auto& name : names)
554 bool has_joint_limits{}, has_soft_limits{};
555 std::string name = joint_handle.getName();
557 urdf::JointConstSharedPtr urdf_joint =
urdf_model_->getJoint(joint_handle.getName());
558 if (urdf_joint ==
nullptr)
566 has_joint_limits =
true;
569 else if (urdf_joint->type != urdf::Joint::CONTINUOUS)
574 has_soft_limits =
true;
578 ROS_DEBUG_STREAM(
"Joint " << name <<
" does not have soft joint limits from URDF.");
582 has_joint_limits =
true;
588 has_soft_limits =
true;
589 ROS_DEBUG_STREAM(
"Joint " << name <<
" has soft joint limits from ROS param.");
592 ROS_DEBUG_STREAM(
"Joint " << name <<
" does not have soft joint limits from ROS param.");
597 joint_limits.
min_position += std::numeric_limits<double>::epsilon();
598 joint_limits.
max_position -= std::numeric_limits<double>::epsilon();
606 else if (has_joint_limits)