Skip to content

Commit 1fb726e

Browse files
committed
fix(franka_gazebo): fix external torque calculation
This commit ensures that the internal controller forces are not used in the external torque (i.e. `tau_ext`) calculation when a joint is in its limit.
1 parent d439fc7 commit 1fb726e

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
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 external torque 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 & 0 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

franka_gazebo/src/franka_hw_sim.cpp

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

681681
if (this->robot_initialized_) {
682-
double tau_ext = joint->effort - joint->command + joint->gravity;
682+
// NOTE: Use clamped_command to account for internal joint saturation.
683+
double tau_ext = joint->effort - joint->clamped_command + joint->gravity;
683684

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

franka_gazebo/src/joint.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ 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, clamped to zero when joint is at its limits.
55+
this->clamped_command =
56+
(this->position > this->limits.min_position && this->position < this->limits.max_position)
57+
? this->command
58+
: 0.0;
5359
}
5460

5561
double Joint::getDesiredPosition(const franka::RobotMode& mode) const {
@@ -105,10 +111,12 @@ double Joint::getLinkMass() const {
105111
}
106112

107113
bool Joint::isInCollision() const {
108-
return std::abs(this->effort - this->command) > this->collision_threshold;
114+
// NOTE: Clamped_command used to handle internal collisions.
115+
return std::abs(this->effort - this->clamped_command) > this->collision_threshold;
109116
}
110117

111118
bool Joint::isInContact() const {
112-
return std::abs(this->effort - this->command) > this->contact_threshold;
119+
// NOTE: Clamped_command used to handle internal contacts.
120+
return std::abs(this->effort - this->clamped_command) > this->contact_threshold;
113121
}
114122
} // namespace franka_gazebo

0 commit comments

Comments
 (0)