Skip to content

Commit

Permalink
attic: Move RBT DiffIK implementation to attic (RobotLocomotion#10047)
Browse files Browse the repository at this point in the history
This removes the runtime dependency from //manipulation/planner into
//attic.  The unit test is still based on RigidBodyTree.
  • Loading branch information
jwnimmer-tri authored Nov 17, 2018
1 parent a5bbf14 commit a231084
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 96 deletions.
12 changes: 12 additions & 0 deletions attic/manipulation/planner/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ drake_cc_package_library(
name = "planner",
deps = [
":constraint_relaxing_ik",
":rbt_differential_inverse_kinematics",
":robot_plan_interpolator",
],
)
Expand All @@ -32,6 +33,17 @@ drake_cc_library(
],
)

# N.B. This is unit tested in //manipulation/planner (non-attic).
drake_cc_library(
name = "rbt_differential_inverse_kinematics",
srcs = ["rbt_differential_inverse_kinematics.cc"],
hdrs = ["rbt_differential_inverse_kinematics.h"],
deps = [
"//attic/multibody:rigid_body_tree",
"//manipulation/planner:differential_inverse_kinematics",
],
)

drake_cc_library(
name = "robot_plan_interpolator",
srcs = ["robot_plan_interpolator.cc"],
Expand Down
38 changes: 38 additions & 0 deletions attic/manipulation/planner/rbt_differential_inverse_kinematics.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "drake/manipulation/planner/rbt_differential_inverse_kinematics.h"

namespace drake {
namespace manipulation {
namespace planner {
namespace rbt {

DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
const RigidBodyTree<double>& robot, const KinematicsCache<double>& cache,
const Isometry3<double>& X_WE_desired,
const RigidBodyFrame<double>& frame_E,
const DifferentialInverseKinematicsParameters& parameters) {
const Isometry3<double> X_WE =
robot.CalcFramePoseInWorldFrame(cache, frame_E);
const Vector6<double> V_WE_desired =
ComputePoseDiffInCommonFrame(X_WE, X_WE_desired) /
parameters.get_timestep();
// Call the below function.
return drake::manipulation::planner::rbt::DoDifferentialInverseKinematics(
robot, cache, V_WE_desired, frame_E, parameters);
}

DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
const RigidBodyTree<double>& robot, const KinematicsCache<double>& cache,
const Vector6<double>& V_WE_desired, const RigidBodyFrame<double>& frame_E,
const DifferentialInverseKinematicsParameters& parameters) {
Isometry3<double> X_WE = robot.CalcFramePoseInWorldFrame(cache, frame_E);
MatrixX<double> J_WE =
robot.CalcFrameSpatialVelocityJacobianInWorldFrame(cache, frame_E);
// Call the (non-attic) helper function.
return drake::manipulation::planner::detail::DoDifferentialInverseKinematics(
cache.getQ(), cache.getV(), X_WE, J_WE, V_WE_desired, parameters);
}

} // namespace rbt
} // namespace planner
} // namespace manipulation
} // namespace drake
60 changes: 60 additions & 0 deletions attic/manipulation/planner/rbt_differential_inverse_kinematics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#pragma once

#include "drake/manipulation/planner/differential_inverse_kinematics.h"
#include "drake/multibody/rigid_body_tree.h"

namespace drake {
namespace manipulation {
namespace planner {
namespace rbt {

/**
* A wrapper over
* DoDifferentialInverseKinematics(q_current, v_current, V, J, params)
* that tracks frame E's spatial velocity.
* q_current and v_current are taken from @p cache. V is computed by first
* transforming @p V_WE to V_WE_E, then taking the element-wise product between
* V_WE_E and the gains (specified in frame E) in @p parameters, and only
* selecting the non zero elements. J is computed similarly.
* @param robot Kinematic tree.
* @param cache Kinematic cache build from the current generalized position and
* velocity.
* @param V_WE_desired Desired world frame spatial velocity of @p frame_E.
* @param frame_E End effector frame.
* @param parameters Collection of various problem specific constraints and
* constants.
* @return If the solver successfully finds a solution, joint_velocities will
* be set to v, otherwise it will be nullopt.
*/
DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
const RigidBodyTree<double>& robot, const KinematicsCache<double>& cache,
const Vector6<double>& V_WE_desired, const RigidBodyFrame<double>& frame_E,
const DifferentialInverseKinematicsParameters& parameters);

/**
* A wrapper over
* DoDifferentialInverseKinematics(robot, cache, V_WE_desired, frame_E, params)
* that tracks frame E's pose in the world frame.
* q_current and v_current are taken from @p cache. V_WE is computed by
* ComputePoseDiffInCommonFrame(X_WE, X_WE_desired) / dt, where X_WE is computed
* from @p cache, and dt is taken from @p parameters.
* @param robot Robot model.
* @param cache KinematiCache built from the current generalized position and
* velocity.
* @param X_WE_desired Desired pose of @p frame_E in the world frame.
* @param frame_E End effector frame.
* @param parameters Collection of various problem specific constraints and
* constants.
* @return If the solver successfully finds a solution, joint_velocities will
* be set to v, otherwise it will be nullopt.
*/
DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
const RigidBodyTree<double>& robot, const KinematicsCache<double>& cache,
const Isometry3<double>& X_WE_desired,
const RigidBodyFrame<double>& frame_E,
const DifferentialInverseKinematicsParameters& parameters);

} // namespace rbt
} // namespace planner
} // namespace manipulation
} // namespace drake
5 changes: 2 additions & 3 deletions manipulation/planner/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ drake_cc_library(
srcs = ["differential_inverse_kinematics.cc"],
hdrs = ["differential_inverse_kinematics.h"],
deps = [
"//attic/multibody:rigid_body_tree",
"//attic/multibody/parsers",
"//multibody/multibody_tree/multibody_plant",
"//solvers:mathematical_program",
],
Expand All @@ -40,7 +38,8 @@ drake_cc_googletest(
],
deps = [
":differential_inverse_kinematics",
"//attic/manipulation/util:world_sim_tree_builder",
"//attic/manipulation/planner:rbt_differential_inverse_kinematics",
"//attic/multibody/parsers",
"//common/test_utilities:eigen_matrix_compare",
"//examples/kuka_iiwa_arm:iiwa_common",
"//multibody/multibody_tree/parsing",
Expand Down
43 changes: 10 additions & 33 deletions manipulation/planner/differential_inverse_kinematics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace drake {
namespace manipulation {
namespace planner {

namespace {
namespace detail {
DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
const Eigen::Ref<const VectorX<double>>& q_current,
const Eigen::Ref<const VectorX<double>>& v_current,
Expand Down Expand Up @@ -44,7 +44,7 @@ DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
q_current, v_current, V_WE_E_scaled.head(num_cart_constraints),
J_WE_E_scaled.topRows(num_cart_constraints), parameters);
}
} // namespace
} // namespace detail

std::ostream& operator<<(std::ostream& os,
const DifferentialInverseKinematicsStatus value) {
Expand Down Expand Up @@ -236,31 +236,6 @@ DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
DifferentialInverseKinematicsStatus::kSolutionFound};
}

DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
const RigidBodyTree<double>& robot, const KinematicsCache<double>& cache,
const Isometry3<double>& X_WE_desired,
const RigidBodyFrame<double>& frame_E,
const DifferentialInverseKinematicsParameters& parameters) {
const Isometry3<double> X_WE =
robot.CalcFramePoseInWorldFrame(cache, frame_E);
const Vector6<double> V_WE_desired =
ComputePoseDiffInCommonFrame(X_WE, X_WE_desired) /
parameters.get_timestep();
return DoDifferentialInverseKinematics(robot, cache, V_WE_desired, frame_E,
parameters);
}

DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
const RigidBodyTree<double>& robot, const KinematicsCache<double>& cache,
const Vector6<double>& V_WE_desired, const RigidBodyFrame<double>& frame_E,
const DifferentialInverseKinematicsParameters& parameters) {
Isometry3<double> X_WE = robot.CalcFramePoseInWorldFrame(cache, frame_E);
MatrixX<double> J_WE =
robot.CalcFrameSpatialVelocityJacobianInWorldFrame(cache, frame_E);
return DoDifferentialInverseKinematics(cache.getQ(), cache.getV(), X_WE, J_WE,
V_WE_desired, parameters);
}

DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
const multibody::multibody_plant::MultibodyPlant<double>& plant,
const systems::Context<double>& context,
Expand All @@ -276,9 +251,10 @@ DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(

const auto& mbt_context =
dynamic_cast<const multibody::MultibodyTreeContext<double>&>(context);
return DoDifferentialInverseKinematics(mbt_context.get_positions(),
mbt_context.get_velocities(), X_WE,
J_WE, V_WE_desired, parameters);
return detail::DoDifferentialInverseKinematics(mbt_context.get_positions(),
mbt_context.get_velocities(),
X_WE, J_WE, V_WE_desired,
parameters);
}

DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
Expand Down Expand Up @@ -311,9 +287,10 @@ DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(

const auto& mbt_context =
dynamic_cast<const multibody::MultibodyTreeContext<double>&>(context);
return DoDifferentialInverseKinematics(mbt_context.get_positions(),
mbt_context.get_velocities(), X_WE,
J_WE, V_WE_desired, parameters);
return detail::DoDifferentialInverseKinematics(mbt_context.get_positions(),
mbt_context.get_velocities(),
X_WE, J_WE, V_WE_desired,
parameters);
}

DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
Expand Down
98 changes: 52 additions & 46 deletions manipulation/planner/differential_inverse_kinematics.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <iostream>
#include <limits>
#include <memory>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
Expand All @@ -13,9 +14,19 @@
#include "drake/common/drake_optional.h"
#include "drake/common/eigen_types.h"
#include "drake/multibody/multibody_tree/multibody_plant/multibody_plant.h"
#include "drake/multibody/rigid_body_tree.h"
#include "drake/solvers/mathematical_program.h"

#ifndef DRAKE_DOXYGEN_CXX
// Forward declarations because we only need the type name for deprecation
// purposes; we never call any methods on an RBT.
template <class T>
class RigidBodyTree;
template <class T>
class RigidBodyFrame;
template <class T>
class KinematicsCache;
#endif

namespace drake {
namespace manipulation {
namespace planner {
Expand Down Expand Up @@ -282,51 +293,34 @@ DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
const Eigen::Ref<const MatrixX<double>>& J,
const DifferentialInverseKinematicsParameters& parameters);

/**
* A wrapper over
* DoDifferentialInverseKinematics(q_current, v_current, V, J, params)
* that tracks frame E's spatial velocity.
* q_current and v_current are taken from @p cache. V is computed by first
* transforming @p V_WE to V_WE_E, then taking the element-wise product between
* V_WE_E and the gains (specified in frame E) in @p parameters, and only
* selecting the non zero elements. J is computed similarly.
* @param robot Kinematic tree.
* @param cache Kinematic cache build from the current generalized position and
* velocity.
* @param V_WE_desired Desired world frame spatial velocity of @p frame_E.
* @param frame_E End effector frame.
* @param parameters Collection of various problem specific constraints and
* constants.
* @return If the solver successfully finds a solution, joint_velocities will
* be set to v, otherwise it will be nullopt.
*/
DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
const RigidBodyTree<double>& robot, const KinematicsCache<double>& cache,
const Vector6<double>& V_WE_desired, const RigidBodyFrame<double>& frame_E,
const DifferentialInverseKinematicsParameters& parameters);

/**
* A wrapper over
* DoDifferentialInverseKinematics(robot, cache, V_WE_desired, frame_E, params)
* that tracks frame E's pose in the world frame.
* q_current and v_current are taken from @p cache. V_WE is computed by
* ComputePoseDiffInCommonFrame(X_WE, X_WE_desired) / dt, where X_WE is computed
* from @p cache, and dt is taken from @p parameters.
* @param robot Robot model.
* @param cache KinematiCache built from the current generalized position and
* velocity.
* @param X_WE_desired Desired pose of @p frame_E in the world frame.
* @param frame_E End effector frame.
* @param parameters Collection of various problem specific constraints and
* constants.
* @return If the solver successfully finds a solution, joint_velocities will
* be set to v, otherwise it will be nullopt.
*/
DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
const RigidBodyTree<double>& robot, const KinematicsCache<double>& cache,
const Isometry3<double>& X_WE_desired,
const RigidBodyFrame<double>& frame_E,
const DifferentialInverseKinematicsParameters& parameters);
#ifndef DRAKE_DOXYGEN_CXX
// TODO(jwnimmer-tri) Remove these stubs on or about 2019-03-01.
// Remember to remove the forward declaration above at the same time.
DRAKE_DEPRECATED(
"DiffIK for RigidBodyTree no longer uses this file; for new "
"instructions, see https://github.com/RobotLocomotion/drake/pull/10047")
inline DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
const RigidBodyTree<double>&, const KinematicsCache<double>&,
const Vector6<double>&, const RigidBodyFrame<double>&,
const DifferentialInverseKinematicsParameters&) {
throw std::runtime_error(
"DiffIK for RigidBodyTree no longer uses this file; for new "
"instructions, see https://github.com/RobotLocomotion/drake/pull/10047");
}
// TODO(jwnimmer-tri) Remove these stubs on or about 2019-03-01.
// Remember to remove the forward declaration above at the same time.
DRAKE_DEPRECATED(
"DiffIK for RigidBodyTree no longer uses this file; for new "
"instructions, see https://github.com/RobotLocomotion/drake/pull/10047")
inline DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
const RigidBodyTree<double>&, const KinematicsCache<double>&,
const Isometry3<double>&, const RigidBodyFrame<double>&,
const DifferentialInverseKinematicsParameters&) {
throw std::runtime_error(
"DiffIK for RigidBodyTree no longer uses this file; for new "
"instructions, see https://github.com/RobotLocomotion/drake/pull/10047");
}
#endif

/**
* A wrapper over
Expand Down Expand Up @@ -399,6 +393,18 @@ DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
const multibody::Frame<double>& frame_E,
const DifferentialInverseKinematicsParameters& parameters);

#ifndef DRAKE_DOXYGEN_CXX
namespace detail {
DifferentialInverseKinematicsResult DoDifferentialInverseKinematics(
const Eigen::Ref<const VectorX<double>>&,
const Eigen::Ref<const VectorX<double>>&,
const Isometry3<double>&,
const Eigen::Ref<const MatrixX<double>>&,
const Vector6<double>&,
const DifferentialInverseKinematicsParameters&);
} // namespace detail
#endif

} // namespace planner
} // namespace manipulation
} // namespace drake
Loading

0 comments on commit a231084

Please sign in to comment.