Skip to content

Commit d747813

Browse files
committed
fix(franka_gazebo): fix tau_ext internal controller bug
This commit makes sure that internal controller forces are not used while calculating the external torque when a joint is in its joint limits.
1 parent 30dc6b8 commit d747813

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

franka_gazebo/include/franka_gazebo/joint.h

+5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ struct Joint {
6767
/// be controlled.
6868
ControlMethod control_method = POSITION;
6969

70+
/// The currently CLAMPED applied command from the controller acting on this joint either in \f$N\f$ or
71+
/// \f$Nm\f$ without gravity.
72+
/// NOTE: Clamped to zero when the joint is in its limits.
73+
double clamped_command = 0;
74+
7075
/// The currently acting gravity force or torque acting on this joint in \f$N\f$ or \f$Nm\f$
7176
double gravity = 0;
7277

franka_gazebo/src/franka_hw_sim.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,9 @@ void FrankaHWSim::updateRobotState(ros::Time time) {
585585
}
586586

587587
if (this->robot_initialized_) {
588-
double tau_ext = joint->effort - joint->command + joint->gravity;
588+
// NOTE: Here we use the clamped command to filter out the internal controller
589+
// force when the joint is in its limits.
590+
double tau_ext = joint->effort - joint->clamped_command + joint->gravity;
589591

590592
// Exponential moving average filter from tau_ext -> tau_ext_hat_filtered
591593
this->robot_state_.tau_ext_hat_filtered[i] =

franka_gazebo/src/joint.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ void Joint::update(const ros::Duration& dt) {
5050
}
5151
this->jerk = (this->acceleration - this->lastAcceleration) / dt.toSec();
5252
this->lastAcceleration = this->acceleration;
53+
54+
// Store the clamped command
55+
// NOTE: Clamped to zero when joint is in its joint limits.
56+
this->clamped_command =
57+
(this->position > this->limits.min_position && this->position < this->limits.max_position)
58+
? this->command
59+
: 0.0;
5360
}
5461

5562
double Joint::getLinkMass() const {
@@ -64,10 +71,10 @@ double Joint::getLinkMass() const {
6471
}
6572

6673
bool Joint::isInCollision() const {
67-
return std::abs(this->effort - this->command) > this->collision_threshold;
74+
return std::abs(this->effort - this->clamped_command + this->gravity) > this->collision_threshold;
6875
}
6976

7077
bool Joint::isInContact() const {
71-
return std::abs(this->effort - this->command) > this->contact_threshold;
78+
return std::abs(this->effort - this->clamped_command + this->gravity) > this->contact_threshold;
7279
}
7380
} // namespace franka_gazebo

0 commit comments

Comments
 (0)