Skip to content

Commit 5e6d70c

Browse files
committed
Reorganize calcs.
1 parent c018f7c commit 5e6d70c

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

ign_ros2_control/src/ign_system.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ bool IgnitionSystem::initSim(
246246
this->dataPtr->ecm->Component<ignition::gazebo::components::JointAxis>(
247247
this->dataPtr->joints_[j].sim_joint);
248248
// PID parameters
249-
double p_gain = 100.0;
250-
double i_gain = 1.0;
251-
double d_gain = 50.0;
252-
// set integral max and min component to 10 percent of the max effort
249+
double p_gain = 10.0 * jointAxis->Data().Effort();
250+
double i_gain = 0.0;
251+
double d_gain = 0.0;
252+
// set integral max and min component to 50 percent of the max effort
253253
double iMax = std::isnan(jointAxis->Data().Effort()) ? 500.0 : jointAxis->Data().Effort() *
254254
0.5;
255255
double iMin = std::isnan(jointAxis->Data().Effort()) ? 500.0 : -jointAxis->Data().Effort() *
@@ -710,14 +710,13 @@ hardware_interface::return_type IgnitionSystem::write(
710710
this->dataPtr->joints_[i].joint_position_cmd, jointAxis->Data().Lower(),
711711
jointAxis->Data().Upper());
712712

713-
// error can be maximal 10 percent of the range
714713
error =
715714
copysign(
716715
1.0,
717716
error) *
718717
std::clamp(
719718
std::abs(error), 0.0,
720-
std::abs(jointAxis->Data().Upper() - jointAxis->Data().Lower()) * 0.1);
719+
std::abs(jointAxis->Data().Upper() - jointAxis->Data().Lower()));
721720

722721
// calculate target force/torque
723722
double target_force = this->dataPtr->joints_[i].pid.Update(
@@ -791,11 +790,10 @@ hardware_interface::return_type IgnitionSystem::write(
791790
position_mimicked_joint * mimic_joint.multiplier,
792791
jointAxis->Data().Lower(), jointAxis->Data().Upper());
793792

794-
// error can be maximal 10 percent of the range
795793
position_error = copysign(1.0, position_error) * std::clamp(
796794
std::abs(
797795
position_error), 0.0, std::abs(
798-
jointAxis->Data().Upper() - jointAxis->Data().Lower()) * 0.1);
796+
jointAxis->Data().Upper() - jointAxis->Data().Lower()));
799797

800798
// calculate target force/torque
801799
double target_force = this->dataPtr->joints_[mimic_joint.joint_index].pid.Update(

0 commit comments

Comments
 (0)