Kinematics.h
Go to the documentation of this file.
00001 /*
00002  * hrl_kinematics - a kinematics library for humanoid robots based on KDL
00003  *
00004  * Copyright 2011-2012 Armin Hornung, University of Freiburg
00005  * License: BSD
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are met:
00009  *
00010  *     * Redistributions of source code must retain the above copyright
00011  *       notice, this list of conditions and the following disclaimer.
00012  *     * Redistributions in binary form must reproduce the above copyright
00013  *       notice, this list of conditions and the following disclaimer in the
00014  *       documentation and/or other materials provided with the distribution.
00015  *     * Neither the name of the University of Freiburg nor the names of its
00016  *       contributors may be used to endorse or promote products derived from
00017  *       this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029  * POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00032 #ifndef HRL_KINEMATICS_KINEMATICS_H_
00033 #define HRL_KINEMATICS_KINEMATICS_H_
00034 
00035 #include <string>
00036 #include <map>
00037 #include <exception>
00038 #include <math.h>
00039 
00040 #include <ros/ros.h>
00041 #include <tf/transform_listener.h>
00042 #include <tf_conversions/tf_kdl.h>
00043 #include <tf/transform_datatypes.h>
00044 #include <urdf/model.h>
00045 #include <kdl_parser/kdl_parser.hpp>
00046 #include <kdl/jntarray.hpp>
00047 #include <kdl/frames.hpp>
00048 #include <kdl/segment.hpp>
00049 #include <kdl/joint.hpp>
00050 
00051 #include <robot_state_publisher/robot_state_publisher.h>
00052 #include <kdl_parser/kdl_parser.hpp>
00053 #include <sensor_msgs/JointState.h>
00054 #include <visualization_msgs/MarkerArray.h>
00055 
00056 
00057 namespace hrl_kinematics {
00058 typedef std::map<std::string, double> JointMap;
00059 
00065 class Kinematics {
00066 public:
00067   enum FootSupport {SUPPORT_DOUBLE, SUPPORT_SINGLE_RIGHT, SUPPORT_SINGLE_LEFT};
00068   class InitFailed : public std::runtime_error
00069   {
00070   public:
00071     InitFailed(const std::string &what)
00072     : std::runtime_error(what) {}
00073   };
00074 
00082   Kinematics(std::string root_link_name = "base_link", std::string rfoot_link_name = "r_sole", std::string lfoot_link_name = "l_sole",
00083              const boost::shared_ptr<const urdf::ModelInterface>& urdf_model = boost::shared_ptr<const urdf::ModelInterface>());
00084 
00085   virtual ~Kinematics();
00086   void initialize();
00087 
00098   void computeCOM(const JointMap& joint_positions, tf::Point& com, double& mass,
00099                   tf::Transform& tf_right_foot, tf::Transform& tf_left_foot);
00100 
00101 
00102   protected:
00103   bool loadKDLModel();
00104   void addChildren(const KDL::SegmentMap::const_iterator segment);
00105 
00106   void computeCOMRecurs(const KDL::SegmentMap::const_iterator& currentSeg, const std::map<std::string, double>& joint_positions,
00107                         const KDL::Frame& tf, KDL::Frame& tf_right_foot, KDL::Frame& tf_left_foot, double& m, KDL::Vector& cog);
00108   void createCoGMarker(const std::string& ns, const std::string& frame_id, double radius, const KDL::Vector& cog, visualization_msgs::Marker& marker) const;
00109 
00110   boost::shared_ptr<const urdf::ModelInterface> urdf_model_;
00111   KDL::Tree kdl_tree_;
00112   KDL::Chain kdl_chain_right_;
00113   KDL::Chain kdl_chain_left_;
00114 
00115   ros::NodeHandle nh_, nh_private_;
00116   std::string root_link_name_;
00117   std::string rfoot_link_name_;
00118   std::string lfoot_link_name_;
00119 
00120   unsigned int num_joints_;
00121   std::map<std::string, robot_state_publisher::SegmentPair> segments_;
00122 };
00123 
00124 } /* namespace hrl_kinematics */
00125 #endif


hrl_kinematics
Author(s): Armin Hornung
autogenerated on Wed Aug 26 2015 11:51:09