Skip to content

Commit

Permalink
fix(franka_gazebo): fix tau_ext internal controller bug
Browse files Browse the repository at this point in the history
This commit makes sure that internal controller forces are not
used while calculating the external torque when a joint is in its
joint limits.
  • Loading branch information
rickstaa committed Mar 18, 2022
1 parent 30dc6b8 commit d747813
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions franka_gazebo/include/franka_gazebo/joint.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ struct Joint {
/// be controlled.
ControlMethod control_method = POSITION;

/// The currently CLAMPED applied command from the controller acting on this joint either in \f$N\f$ or
/// \f$Nm\f$ without gravity.
/// NOTE: Clamped to zero when the joint is in its limits.
double clamped_command = 0;

/// The currently acting gravity force or torque acting on this joint in \f$N\f$ or \f$Nm\f$
double gravity = 0;

Expand Down
4 changes: 3 additions & 1 deletion franka_gazebo/src/franka_hw_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,9 @@ void FrankaHWSim::updateRobotState(ros::Time time) {
}

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

// Exponential moving average filter from tau_ext -> tau_ext_hat_filtered
this->robot_state_.tau_ext_hat_filtered[i] =
Expand Down
11 changes: 9 additions & 2 deletions franka_gazebo/src/joint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ void Joint::update(const ros::Duration& dt) {
}
this->jerk = (this->acceleration - this->lastAcceleration) / dt.toSec();
this->lastAcceleration = this->acceleration;

// Store the clamped command
// NOTE: Clamped to zero when joint is in its joint limits.
this->clamped_command =
(this->position > this->limits.min_position && this->position < this->limits.max_position)
? this->command
: 0.0;
}

double Joint::getLinkMass() const {
Expand All @@ -64,10 +71,10 @@ double Joint::getLinkMass() const {
}

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

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

0 comments on commit d747813

Please sign in to comment.