cartesian_robot.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (Apache License)
00003  *
00004  * Copyright (c) 2014, Southwest Research Institute
00005  *
00006  * Licensed under the Apache License, Version 2.0 (the "License");
00007  * you may not use this file except in compliance with the License.
00008  * You may obtain a copy of the License at
00009  *
00010  * http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
00017  */
00018 
00019 #include "descartes_trajectory_test/cartesian_robot.h"
00020 #include "descartes_core/pretty_print.hpp"
00021 #include "eigen_conversions/eigen_kdl.h"
00022 #include "ros/console.h"
00023 
00024 namespace descartes_trajectory_test
00025 {
00026 
00027   CartesianRobot::CartesianRobot() : pos_range_(2.0), orient_range_(M_PI_2), dof_(6)
00028   {
00029     ROS_DEBUG_STREAM("Creating cartesian robot with range, position: " << pos_range_
00030                      << ", orientation: " << orient_range_);
00031   }
00032 
00033   bool CartesianRobot::initialize(const std::string& robot_description, const std::string& group_name,
00034                                   const std::string& world_frame,const std::string& tcp_frame)
00035   {
00036     return true;
00037   }
00038 
00039   CartesianRobot::CartesianRobot(double pos_range, double orient_range, int dof) :
00040     pos_range_(pos_range), orient_range_(orient_range), dof_(dof)
00041   {
00042     ROS_DEBUG_STREAM("Creating cartesian robot with range, position: " << pos_range_
00043                      << ", orientation: " << orient_range_);
00044   }
00045 
00046   bool CartesianRobot::getIK(const Eigen::Affine3d &pose, const std::vector<double> &seed_state,
00047                      std::vector<double> &joint_pose) const
00048   {
00049     bool rtn = false;
00050     KDL::Frame kdl_frame;
00051     tf::transformEigenToKDL(pose, kdl_frame);
00052 
00053     joint_pose.resize(6, 0.0);
00054     joint_pose[0] = kdl_frame.p.x();
00055     joint_pose[1] = kdl_frame.p.y();
00056     joint_pose[2] = kdl_frame.p.z();
00057     kdl_frame.M.GetRPY(joint_pose[3], joint_pose[4], joint_pose[5]);
00058 
00059     if(isValid(joint_pose))
00060     {
00061       rtn = true;
00062     }
00063     else
00064     {
00065       rtn = false;
00066     }
00067     return rtn;
00068   }
00069 
00070   bool CartesianRobot::getAllIK(const Eigen::Affine3d &pose,
00071                                 std::vector<std::vector<double> > &joint_poses) const
00072   {
00073     std::vector<double>empty;
00074     joint_poses.resize(1);
00075     return getIK(pose, empty, joint_poses[0]);
00076   }
00077 
00078   bool CartesianRobot::getFK(const std::vector<double> &joint_pose, Eigen::Affine3d &pose) const
00079   {
00080     bool rtn = false;
00081 
00082     if(isValid(joint_pose))
00083     {
00084       pose = Eigen::Translation3d(joint_pose[0], joint_pose[1], joint_pose[2]) *
00085           Eigen::AngleAxisd(joint_pose[5], Eigen::Vector3d::UnitZ()) *
00086           Eigen::AngleAxisd(joint_pose[4], Eigen::Vector3d::UnitY()) *
00087           Eigen::AngleAxisd(joint_pose[3], Eigen::Vector3d::UnitX());
00088       rtn = true;
00089     }
00090     else
00091     {
00092       ROS_WARN_STREAM("Invalid joint pose passed to get FK, joint pose" << joint_pose);
00093       rtn = false;
00094     }
00095 
00096     return rtn;
00097   }
00098 
00099   int CartesianRobot::getDOF() const
00100   {
00101     return dof_;
00102   }
00103 
00104   bool CartesianRobot::isValid(const std::vector<double> &joint_pose) const
00105   {
00106     bool rtn = false;
00107 
00108     double pos_limit = pos_range_/2.0;
00109     double orient_limit = orient_range_/2.0;
00110 
00111     if(dof_ == joint_pose.size())
00112     {
00113 
00114       rtn = ( fabs(joint_pose[0]) <= pos_limit &&
00115               fabs(joint_pose[1]) <= pos_limit &&
00116               fabs(joint_pose[2]) <= pos_limit &&
00117               fabs(joint_pose[3]) <= orient_limit &&
00118               fabs(joint_pose[4]) <= orient_limit &&
00119               fabs(joint_pose[5]) <= orient_limit );
00120     }
00121     else
00122     {
00123       ROS_DEBUG_STREAM("Joint pose size: " << joint_pose.size() << "exceeds "<<dof_);
00124     }
00125 
00126     return rtn;
00127   }
00128 
00129   bool CartesianRobot::isValid(const Eigen::Affine3d &pose) const
00130   {
00131     bool rtn = false;
00132     double R, P, Y;
00133     KDL::Frame kdl_frame;
00134     tf::transformEigenToKDL(pose, kdl_frame);
00135     kdl_frame.M.GetRPY(R, P, Y);
00136 
00137     double pos_limit = pos_range_/2.0;
00138     double orient_limit = orient_range_/2.0;
00139 
00140     rtn = ( fabs(kdl_frame.p.x()) <= pos_limit &&
00141             fabs(kdl_frame.p.y()) <= pos_limit &&
00142             fabs(kdl_frame.p.z()) <= pos_limit &&
00143             fabs(R) <= orient_limit &&
00144             fabs(P) <= orient_limit &&
00145             fabs(Y) <= orient_limit );
00146 
00147     return rtn;
00148   }
00149 
00150   bool CartesianRobot::isValidMove(const std::vector<double>& from_joint_pose, 
00151                                    const std::vector<double>& to_joint_pose,
00152                                    double dt) const
00153   {
00154     return true;
00155   }
00156   
00157 
00158 
00159 } //descartes_trajectory_test
00160 


descartes_trajectory
Author(s): Jorge Nicho
autogenerated on Wed Aug 26 2015 11:21:27