Skip to content

Commit 73ef898

Browse files
authored
Make gain configurable (#79)
Make gain configurable in HardwareInfo of the description file. Need enactic/openarm_description#38.
1 parent eeca95e commit 73ef898

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

openarm_hardware/include/openarm_hardware/v10_simple_hardware.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,16 @@ class OpenArm_v10HW : public hardware_interface::SystemInterface {
100100
const uint32_t DEFAULT_GRIPPER_SEND_CAN_ID = 0x08;
101101
const uint32_t DEFAULT_GRIPPER_RECV_CAN_ID = 0x18;
102102

103-
// Default gains
104-
const std::vector<double> DEFAULT_KP = {70.0, 70.0, 70.0, 60.0,
105-
10.0, 10.0, 10.0};
106-
const std::vector<double> DEFAULT_KD = {2.75, 2.5, 2.0, 2.0, 0.7, 0.6, 0.5};
103+
// Gains
104+
std::vector<double> kp_ = {70.0, 70.0, 70.0, 60.0, 10.0, 10.0, 10.0};
105+
std::vector<double> kd_ = {2.75, 2.5, 2.0, 2.0, 0.7, 0.6, 0.5};
107106

108107
const double GRIPPER_JOINT_0_POSITION = 0.044;
109108
const double GRIPPER_JOINT_1_POSITION = 0.0;
110109
const double GRIPPER_MOTOR_0_RADIANS = 0.0;
111110
const double GRIPPER_MOTOR_1_RADIANS = -1.0472;
112-
const double GRIPPER_DEFAULT_KP = 5.0;
113-
const double GRIPPER_DEFAULT_KD = 0.1;
111+
const double GRIPPER_KP = 5.0;
112+
const double GRIPPER_KD = 0.1;
114113

115114
// Configuration
116115
std::string can_interface_;

openarm_hardware/src/v10_simple_hardware.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)