Skip to content

Commit 98d74f6

Browse files
committed
fix(franka_gazebo): fix tau_ext calculation bug
This commit makes sure that the clamped control command is used for the external torque calculation when a joint is in its joint limit.
1 parent b1ffbde commit 98d74f6

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Requires `libfranka` >= 0.8.0
1313
* `franka_gazebo`: `FrankaHWSim` only acts on joints belonging to a Franka robot. This allows to combine a Franka robot and others (like mobile platforms) in same URDF ([#313](https://github.com/frankaemika/franka_ros/issues/313))
1414
* `franka_description`: `<xacro:franka_robot/>` macro now supports to customize the `parent` frame and its `xyz` + `rpy` offset
1515
* `franka_hw`: Fix the bug where the previous controller is still running after switching the controller. ([#326](https://github.com/frankaemika/franka_ros/issues/326))
16+
* `franka_gazebo`: Fix `tau_ext` calculation by accounting for internal joint limits
1617

1718
## 0.10.1 - 2022-09-15
1819

franka_gazebo/include/franka_gazebo/joint.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ struct Joint {
5555
/// \f$Nm\f$ without gravity
5656
double command = 0;
5757

58+
/// The clamped applied command from a controller acting on this joint either in \f$N\f$ or
59+
/// \f$Nm\f$ without gravity. Set to zero when joint command is saturated due to joint limits.
60+
double clamped_command = 0;
61+
5862
/// The current desired position that is used for the PID controller when the joints control
5963
/// method is "POSITION". When the control method is not "POSITION", this value will only be
6064
/// updated once at the start of the controller and stay the same until a new controller is
@@ -70,11 +74,6 @@ struct Joint {
7074
/// be controlled, or if the joint is entirely uncontrolled
7175
boost::optional<ControlMethod> control_method = boost::none;
7276

73-
/// The currently CLAMPED applied command from the controller acting on this joint either in \f$N\f$ or
74-
/// \f$Nm\f$ without gravity.
75-
/// NOTE: Clamped to zero when the joint is in its limits.
76-
double clamped_command = 0;
77-
7877
/// The currently acting gravity force or torque acting on this joint in \f$N\f$ or \f$Nm\f$
7978
double gravity = 0;
8079

franka_gazebo/src/franka_hw_sim.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,7 @@ void FrankaHWSim::updateRobotState(ros::Time time) {
679679
}
680680

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

686685
// Exponential moving average filter from tau_ext -> tau_ext_hat_filtered

franka_gazebo/src/joint.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ void Joint::update(const ros::Duration& dt) {
5151
this->jerk = (this->acceleration - this->lastAcceleration) / dt.toSec();
5252
this->lastAcceleration = this->acceleration;
5353

54-
// Store the clamped command
55-
// NOTE: Clamped to zero when joint is in its joint limits.
54+
/// Store the clamped command, clamped to zero when joint is at its limits.
5655
this->clamped_command =
5756
(this->position > this->limits.min_position && this->position < this->limits.max_position)
5857
? this->command
@@ -112,10 +111,12 @@ double Joint::getLinkMass() const {
112111
}
113112

114113
bool Joint::isInCollision() const {
115-
return std::abs(this->effort - this->clamped_command + this->gravity) > this->collision_threshold;
114+
// NOTE: Clamped_command used to handle internal collisions.
115+
return std::abs(this->effort - this->clamped_command) > this->collision_threshold;
116116
}
117117

118118
bool Joint::isInContact() const {
119-
return std::abs(this->effort - this->clamped_command + this->gravity) > this->contact_threshold;
119+
// NOTE: Clamped_command used to handle internal contacts.
120+
return std::abs(this->effort - this->clamped_command) > this->contact_threshold;
120121
}
121122
} // namespace franka_gazebo

0 commit comments

Comments
 (0)