@@ -60,6 +60,18 @@ bool OpenArm_v10HW::parse_config(const hardware_interface::HardwareInfo& info) {
6060 can_fd_ = (value == " true" );
6161 }
6262
63+ // Parse control gains
64+ for (size_t i = 1 ; i <= ARM_DOF; ++i) {
65+ it = info.hardware_parameters .find (" kp" + std::to_string (i));
66+ if (it != info.hardware_parameters .end ()) {
67+ kp_[i - 1 ] = std::stod (it->second );
68+ }
69+ it = info.hardware_parameters .find (" kd" + std::to_string (i));
70+ if (it != info.hardware_parameters .end ()) {
71+ kd_[i - 1 ] = std::stod (it->second );
72+ }
73+ }
74+
6375 RCLCPP_INFO (rclcpp::get_logger (" OpenArm_v10HW" ),
6476 " Configuration: CAN=%s, arm_prefix=%s, hand=%s, can_fd=%s" ,
6577 can_interface_.c_str (), arm_prefix_.c_str (),
@@ -260,16 +272,16 @@ hardware_interface::return_type OpenArm_v10HW::write(
260272 // Control arm motors with MIT control
261273 std::vector<openarm::damiao_motor::MITParam> arm_params;
262274 for (size_t i = 0 ; i < ARM_DOF; ++i) {
263- arm_params.push_back ({DEFAULT_KP[i], DEFAULT_KD[i], pos_commands_[i],
264- vel_commands_[i], tau_commands_[i]});
275+ arm_params.push_back (
276+ {kp_[i], kd_[i], pos_commands_[i], vel_commands_[i], tau_commands_[i]});
265277 }
266278 openarm_->get_arm ().mit_control_all (arm_params);
267279 // Control gripper if enabled
268280 if (hand_ && joint_names_.size () > ARM_DOF) {
269281 // TODO the true mappings are unimplemented.
270282 double motor_command = joint_to_motor_radians (pos_commands_[ARM_DOF]);
271283 openarm_->get_gripper ().mit_control_all (
272- {{GRIPPER_DEFAULT_KP, GRIPPER_DEFAULT_KD , motor_command, 0 , 0 }});
284+ {{GRIPPER_KP, GRIPPER_KD , motor_command, 0 , 0 }});
273285 }
274286 openarm_->recv_all (1000 );
275287 return hardware_interface::return_type::OK;
@@ -282,15 +294,14 @@ void OpenArm_v10HW::return_to_zero() {
282294 // Return arm to zero with MIT control
283295 std::vector<openarm::damiao_motor::MITParam> arm_params;
284296 for (size_t i = 0 ; i < ARM_DOF; ++i) {
285- arm_params.push_back ({DEFAULT_KP [i], DEFAULT_KD [i], 0.0 , 0.0 , 0.0 });
297+ arm_params.push_back ({kp_ [i], kd_ [i], 0.0 , 0.0 , 0.0 });
286298 }
287299 openarm_->get_arm ().mit_control_all (arm_params);
288300
289301 // Return gripper to zero if enabled
290302 if (hand_) {
291303 openarm_->get_gripper ().mit_control_all (
292- {{GRIPPER_DEFAULT_KP, GRIPPER_DEFAULT_KD, GRIPPER_JOINT_0_POSITION, 0.0 ,
293- 0.0 }});
304+ {{GRIPPER_KP, GRIPPER_KD, GRIPPER_JOINT_0_POSITION, 0.0 , 0.0 }});
294305 }
295306 std::this_thread::sleep_for (std::chrono::microseconds (1000 ));
296307 openarm_->recv_all ();
0 commit comments