joint_state_group.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2012, Willow Garage, Inc.
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of Willow Garage, Inc. nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 /* Author: Ioan Sucan */
00036 
00037 #ifndef MOVEIT_ROBOT_STATE_JOINT_STATE_GROUP_
00038 #define MOVEIT_ROBOT_STATE_JOINT_STATE_GROUP_
00039 
00040 #include <moveit/robot_model/joint_model_group.h>
00041 #include <moveit/robot_state/link_state.h>
00042 #include <moveit/robot_state/joint_state.h>
00043 #include <sensor_msgs/JointState.h>
00044 #include <moveit_msgs/RobotTrajectory.h>
00045 #include <geometry_msgs/Twist.h>
00046 #include <boost/scoped_ptr.hpp>
00047 #include <boost/function.hpp>
00048 
00049 namespace robot_state
00050 {
00051 
00052 class JointStateGroup;
00053 
00054 typedef boost::function<bool(JointStateGroup *joint_state_group, const std::vector<double> &joint_group_variable_values)> StateValidityCallbackFn;
00055 typedef boost::function<bool(const JointStateGroup *joint_state_group, Eigen::VectorXd &stvector)> SecondaryTaskFn;
00056 
00057 class RobotState;
00058 
00062 class JointStateGroup
00063 {
00064 public:
00065 
00066   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00067 
00073   JointStateGroup(RobotState *state, const robot_model::JointModelGroup *jmg);
00074   ~JointStateGroup();
00075 
00077   const RobotState *getRobotState() const
00078   {
00079     return kinematic_state_;
00080   }
00081 
00083   RobotState *getRobotState()
00084   {
00085     return kinematic_state_;
00086   }
00087 
00089   const robot_model::JointModelGroup* getJointModelGroup() const
00090   {
00091     return joint_model_group_;
00092   }
00093 
00095   const std::string& getName() const
00096   {
00097     return joint_model_group_->getName();
00098   }
00099 
00101   unsigned int getVariableCount() const
00102   {
00103     return joint_model_group_->getVariableCount();
00104   }
00105 
00110   bool setVariableValues(const std::vector<double>& joint_state_values);
00111 
00117   bool setVariableValues(const Eigen::VectorXd& joint_state_values);
00118 
00123   void setVariableValues(const std::map<std::string, double>& joint_state_map);
00124 
00129   void setVariableValues(const sensor_msgs::JointState& js);
00130 
00132   void updateLinkTransforms();
00133 
00135   bool hasJointState(const std::string &joint) const;
00136 
00138   JointState* getJointState(const std::string &joint) const;
00139 
00141   void getVariableValues(std::vector<double>& joint_state_values) const;
00142 
00144   void getVariableValues(Eigen::VectorXd& joint_state_values) const;
00145 
00147   void getVariableValues(std::map<std::string, double>& joint_state_values) const;
00148 
00152   void setToDefaultValues();
00153 
00155   bool setToDefaultState(const std::string &name);
00156 
00158   void setToRandomValues();
00159 
00163   void setToRandomValuesNearBy(const std::vector<double> &near, const std::map<robot_model::JointModel::JointType, double> &distance_map);
00164 
00170   void setToRandomValuesNearBy(const std::vector<double> &near, const std::vector<double> &distances);
00171 
00173   bool satisfiesBounds(double margin = 0.0) const;
00174 
00176   void enforceBounds();
00177 
00179   double infinityNormDistance(const JointStateGroup *other) const;
00180 
00181   double distance(const JointStateGroup *other) const;
00182 
00190   std::pair<double, int> getMinDistanceToBounds() const;
00191 
00192   void interpolate(const JointStateGroup *to, const double t, JointStateGroup *dest) const;
00193 
00195   const std::vector<JointState*>& getJointRoots() const
00196   {
00197     return joint_roots_;
00198   }
00199 
00201   const std::vector<std::string>& getJointNames() const
00202   {
00203     return joint_model_group_->getJointModelNames();
00204   }
00205 
00207   const std::vector<JointState*>& getJointStateVector() const
00208   {
00209     return joint_state_vector_;
00210   }
00211 
00213   random_numbers::RandomNumberGenerator& getRandomNumberGenerator();
00214 
00222   bool getJacobian(const std::string &link_name, const Eigen::Vector3d &reference_point_position, Eigen::MatrixXd& jacobian,
00223                    bool use_quaterion_representation = false) const;
00224 
00226   double getDefaultIKTimeout() const
00227   {
00228     return joint_model_group_->getDefaultIKTimeout();
00229   }
00230 
00232   unsigned getDefaultIKAttempts() const
00233   {
00234     return joint_model_group_->getDefaultIKAttempts();
00235   }
00236 
00244   bool setFromIK(const geometry_msgs::Pose &pose, const std::string &tip, unsigned int attempts = 0, double timeout = 0.0,
00245                  const StateValidityCallbackFn &constraint = StateValidityCallbackFn(), const kinematics::KinematicsQueryOptions &options = kinematics::KinematicsQueryOptions());
00246 
00252   bool setFromIK(const geometry_msgs::Pose &pose, unsigned int attempts = 0, double timeout = 0.0, const kinematics::KinematicsQueryOptions &options = kinematics::KinematicsQueryOptions());
00253 
00260   bool setFromIK(const geometry_msgs::Pose &pose, unsigned int attempts = 0, double timeout = 0.0, const StateValidityCallbackFn &constraint =  StateValidityCallbackFn(), const kinematics::KinematicsQueryOptions &options = kinematics::KinematicsQueryOptions());
00261 
00268   bool setFromIK(const Eigen::Affine3d &pose, unsigned int attempts = 0, double timeout = 0.0,
00269                  const StateValidityCallbackFn &constraint = StateValidityCallbackFn(), const kinematics::KinematicsQueryOptions &options = kinematics::KinematicsQueryOptions());
00270 
00277   bool setFromIK(const Eigen::Affine3d &pose_in, const std::string &tip_in, unsigned int attempts, double timeout, const kinematics::KinematicsQueryOptions &options = kinematics::KinematicsQueryOptions());
00278 
00284   bool setFromIK(const Eigen::Affine3d &pose_in, unsigned int attempts, double timeout, const kinematics::KinematicsQueryOptions &options);
00285 
00293   bool setFromIK(const Eigen::Affine3d &pose, const std::string &tip, unsigned int attempts = 0, double timeout = 0.0,
00294                  const StateValidityCallbackFn &constraint = StateValidityCallbackFn(), const kinematics::KinematicsQueryOptions &options = kinematics::KinematicsQueryOptions());
00295 
00304   bool setFromIK(const Eigen::Affine3d &pose, const std::string &tip,
00305                  const std::vector<double> &consistency_limits, unsigned int attempts = 0, double timeout = 0.0,
00306                  const StateValidityCallbackFn &constraint = StateValidityCallbackFn(), const kinematics::KinematicsQueryOptions &options = kinematics::KinematicsQueryOptions());
00307 
00318   bool setFromIK(const EigenSTL::vector_Affine3d &poses, const std::vector<std::string> &tips, unsigned int attempts = 0, double timeout = 0.0, const StateValidityCallbackFn &constraint = StateValidityCallbackFn(), const kinematics::KinematicsQueryOptions &options = kinematics::KinematicsQueryOptions());
00319 
00331   bool setFromIK(const EigenSTL::vector_Affine3d &poses, const std::vector<std::string> &tips, const std::vector<std::vector<double> > &consistency_limits, unsigned int attempts = 0, double timeout = 0.0, const StateValidityCallbackFn &constraint = StateValidityCallbackFn(), const kinematics::KinematicsQueryOptions &options = kinematics::KinematicsQueryOptions());
00332 
00339   bool setFromDiffIK(const Eigen::VectorXd &twist, const std::string &tip, double dt, const StateValidityCallbackFn &constraint = StateValidityCallbackFn(), const SecondaryTaskFn &st = SecondaryTaskFn());
00340 
00347   bool setFromDiffIK(const geometry_msgs::Twist &twist, const std::string &tip, double dt, const StateValidityCallbackFn &constraint = StateValidityCallbackFn(), const SecondaryTaskFn &st = SecondaryTaskFn());
00348 
00350   void computeJointVelocity(Eigen::VectorXd &qdot, const Eigen::VectorXd &twist, const std::string &tip, const SecondaryTaskFn &st = SecondaryTaskFn()) const;
00351 
00354   bool integrateJointVelocity(const Eigen::VectorXd &qdot, double dt, const StateValidityCallbackFn &constraint = StateValidityCallbackFn());
00355 
00362   bool avoidJointLimitsSecondaryTask(const JointStateGroup *joint_state_group, Eigen::VectorXd &stvector,
00363                                      double activation_threshold, double gain) const;
00364 
00384   double computeCartesianPath(std::vector<boost::shared_ptr<RobotState> > &traj, const std::string &link_name, const Eigen::Vector3d &direction, bool global_reference_frame,
00385                               double distance, double max_step, double jump_threshold, const StateValidityCallbackFn &validCallback = StateValidityCallbackFn(), const kinematics::KinematicsQueryOptions &options = kinematics::KinematicsQueryOptions());
00386 
00406   double computeCartesianPath(std::vector<boost::shared_ptr<RobotState> > &traj, const std::string &link_name, const Eigen::Affine3d &target, bool global_reference_frame,
00407                               double max_step, double jump_threshold, const StateValidityCallbackFn &validCallback = StateValidityCallbackFn(), const kinematics::KinematicsQueryOptions &options = kinematics::KinematicsQueryOptions());
00408 
00427   double computeCartesianPath(std::vector<boost::shared_ptr<RobotState> > &traj, const std::string &link_name, const EigenSTL::vector_Affine3d &waypoints,
00428                               bool global_reference_frame, double max_step, double jump_threshold, const StateValidityCallbackFn &validCallback = StateValidityCallbackFn(), const kinematics::KinematicsQueryOptions &options = kinematics::KinematicsQueryOptions());
00429 
00430   JointStateGroup& operator=(const JointStateGroup &other);
00431 
00432 private:
00433 
00435   void copyFrom(const JointStateGroup &other_jsg);
00436 
00438   void ikCallbackFnAdapter(const StateValidityCallbackFn &constraint, const geometry_msgs::Pose &ik_pose,
00439                            const std::vector<double> &ik_sol, moveit_msgs::MoveItErrorCodes &error_code);
00440 
00442   RobotState *kinematic_state_;
00443 
00445   const robot_model::JointModelGroup     *joint_model_group_;
00446 
00448   std::vector<JointState*>                joint_state_vector_;
00449 
00451   std::map<std::string, JointState*>      joint_state_map_;
00452 
00454   std::vector<JointState*>                joint_roots_;
00455 
00457   std::vector<LinkState*>                 updated_links_;
00458 
00463   boost::scoped_ptr<random_numbers::RandomNumberGenerator> rng_;
00464 
00465 };
00466 }
00467 
00468 #endif


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Mon Oct 6 2014 02:24:47