Skip to content

Commit 48b4f31

Browse files
steinmnbmagyar
authored andcommitted
JointTrajectory: Don't use shortest_angular_distance for linear joints
Fixes #432
1 parent b752394 commit 48b4f31

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

joint_trajectory_controller/include/joint_trajectory_controller/joint_trajectory_controller.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ class JointTrajectoryController : public controller_interface::Controller<Hardwa
182182
std::string name_; ///< Controller name.
183183
std::vector<JointHandle> joints_; ///< Handles to controlled joints.
184184
std::vector<bool> angle_wraparound_; ///< Whether controlled joints wrap around or not.
185+
std::vector<bool> is_linear_; ///< Whether controlled joints are linear or not.
185186
std::vector<std::string> joint_names_; ///< Controlled joint names.
186187
SegmentTolerances<Scalar> default_tolerances_; ///< Default trajectory segment tolerances.
187188
HwIfaceAdapter hw_iface_adapter_; ///< Adapts desired trajectory state to HW interface.

joint_trajectory_controller/include/joint_trajectory_controller/joint_trajectory_controller_impl.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ bool JointTrajectoryController<SegmentImpl, HardwareInterface>::init(HardwareInt
254254
// Initialize members
255255
joints_.resize(n_joints);
256256
angle_wraparound_.resize(n_joints);
257+
is_linear_.resize(n_joints);
257258
for (unsigned int i = 0; i < n_joints; ++i)
258259
{
259260
// Joint handle
@@ -267,13 +268,16 @@ bool JointTrajectoryController<SegmentImpl, HardwareInterface>::init(HardwareInt
267268

268269
// Whether a joint is continuous (ie. has angle wraparound)
269270
angle_wraparound_[i] = urdf_joints[i]->type == urdf::Joint::CONTINUOUS;
271+
is_linear_[i] = urdf_joints[i]->type == urdf::Joint::PRISMATIC;
270272
const std::string not_if = angle_wraparound_[i] ? "" : "non-";
273+
const std::string linear = is_linear_[i] ? "linear " : "";
271274

272-
ROS_DEBUG_STREAM_NAMED(name_, "Found " << not_if << "continuous joint '" << joint_names_[i] << "' in '" <<
275+
ROS_DEBUG_STREAM_NAMED(name_, "Found " << not_if << "continuous " << linear << "joint '" << joint_names_[i] << "' in '" <<
273276
this->getHardwareInterfaceType() << "'.");
274277
}
275278

276279
assert(joints_.size() == angle_wraparound_.size());
280+
assert(joints_.size() == is_linear_.size());
277281
ROS_DEBUG_STREAM_NAMED(name_, "Initialized controller '" << name_ << "' with:" <<
278282
"\n- Number of joints: " << getNumberOfJoints() <<
279283
"\n- Hardware interface type: '" << this->getHardwareInterfaceType() << "'" <<
@@ -770,7 +774,14 @@ updateStates(const ros::Time& sample_time, const Trajectory* const traj)
770774
desired_state_.velocity[joint_index] = desired_joint_state_.velocity[0];
771775
desired_state_.acceleration[joint_index] = desired_joint_state_.acceleration[0]; ;
772776

773-
state_joint_error_.position[0] = angles::shortest_angular_distance(current_state_.position[joint_index],desired_joint_state_.position[0]);
777+
if (is_linear_[joint_index])
778+
{
779+
state_joint_error_.position[0] = desired_joint_state_.position[0] - current_state_.position[joint_index];
780+
}
781+
else
782+
{
783+
state_joint_error_.position[0] = angles::shortest_angular_distance(current_state_.position[joint_index],desired_joint_state_.position[0]);
784+
}
774785
state_joint_error_.velocity[0] = desired_joint_state_.velocity[0] - current_state_.velocity[joint_index];
775786
state_joint_error_.acceleration[0] = 0.0;
776787

0 commit comments

Comments
 (0)