joint_trajectory_pt.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (Apache License)
00003  *
00004  * Copyright (c) 2014, Dan Solomon
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  * joint_trajectory_pt.cpp
00020  *
00021  *  Created on: Oct 3, 2014
00022  *      Author: Dan Solomon
00023  */
00024 
00025 #include <console_bridge/console.h>
00026 #include "descartes_trajectory/joint_trajectory_pt.h"
00027 
00028 #define NOT_IMPLEMENTED_ERR(ret) logError("%s not implemented", __PRETTY_FUNCTION__); return ret;
00029 
00030 // Utility function to unpack joint bounds from a TolerancedJointValue struct
00031 // Note that this does not clear the existing vectors.
00032 static void unpackTolerancedJoints(const std::vector<descartes_trajectory::TolerancedJointValue>& tolerances,
00033                                    std::vector<double>& lower,
00034                                    std::vector<double>& nominal,
00035                                    std::vector<double>& upper)
00036 {
00037   lower.reserve(tolerances.size());
00038   nominal.reserve(tolerances.size());
00039   upper.reserve(tolerances.size());
00040   
00041   for (std::size_t i = 0; i < tolerances.size(); ++i)
00042   {
00043     lower.push_back(tolerances[i].lower);
00044     nominal.push_back(tolerances[i].nominal);
00045     upper.push_back(tolerances[i].upper);
00046   }
00047 }
00048 
00049 
00050 using namespace descartes_core;
00051 namespace descartes_trajectory
00052 {
00053 
00054 JointTrajectoryPt::JointTrajectoryPt(const descartes_core::TimingConstraint& timing)
00055   : descartes_core::TrajectoryPt(timing) 
00056   , tool_(Eigen::Affine3d::Identity())
00057   , wobj_(Eigen::Affine3d::Identity())
00058 {}
00059 
00060 JointTrajectoryPt::JointTrajectoryPt(const std::vector<TolerancedJointValue> &joints,
00061                                      const Frame &tool, const Frame &wobj,
00062                                      const descartes_core::TimingConstraint& timing)
00063   : descartes_core::TrajectoryPt(timing)
00064   , tool_(tool)
00065   , wobj_(wobj)
00066 {
00067   unpackTolerancedJoints(joints, lower_, nominal_, upper_);
00068 }
00069 
00070 JointTrajectoryPt::JointTrajectoryPt(const std::vector<TolerancedJointValue> &joints, 
00071                                      const descartes_core::TimingConstraint& timing)
00072   : descartes_core::TrajectoryPt(timing)
00073   , tool_(Eigen::Affine3d::Identity())
00074   , wobj_(Eigen::Affine3d::Identity())
00075 {
00076   unpackTolerancedJoints(joints, lower_, nominal_, upper_);
00077 }
00078 
00079 JointTrajectoryPt::JointTrajectoryPt(const std::vector<double> &joints,
00080                                      const descartes_core::TimingConstraint& timing)
00081   : nominal_(joints)
00082   , lower_(joints)
00083   , upper_(joints)
00084   , descartes_core::TrajectoryPt(timing)
00085   , tool_(Eigen::Affine3d::Identity())
00086   , wobj_(Eigen::Affine3d::Identity())
00087 {}
00088 
00089 
00090 bool JointTrajectoryPt::getClosestCartPose(const std::vector<double> &seed_state,
00091                                            const RobotModel &model, Eigen::Affine3d &pose) const
00092 {
00093   NOT_IMPLEMENTED_ERR(false)
00094 }
00095 
00096 bool JointTrajectoryPt::getNominalCartPose(const std::vector<double> &seed_state,
00097                                            const RobotModel &model, Eigen::Affine3d &pose) const
00098 {
00099   return model.getFK(nominal_, pose);
00100 }
00101 
00102 void JointTrajectoryPt::getCartesianPoses(const RobotModel &model, EigenSTL::vector_Affine3d &poses) const
00103 {
00104   poses.clear();
00105 }
00106 
00107 bool JointTrajectoryPt::getClosestJointPose(const std::vector<double> &seed_state,
00108                                             const RobotModel &model,
00109                                             std::vector<double> &joint_pose) const
00110 {
00111   if(nominal_.empty())
00112   {
00113     return false;
00114   }
00115   else
00116   {
00117     return getNominalJointPose(seed_state,model,joint_pose);
00118   }
00119 }
00120 
00121 bool JointTrajectoryPt::getNominalJointPose(const std::vector<double> &seed_state,
00122                                             const RobotModel &model,
00123                                             std::vector<double> &joint_pose) const
00124 {
00125   joint_pose.assign(nominal_.begin(), nominal_.end());
00126   return true;
00127 }
00128 
00129 void JointTrajectoryPt::getJointPoses(const RobotModel &model,
00130                                       std::vector<std::vector<double> > &joint_poses) const
00131 {
00132   std::vector<double> empty_seed;
00133   joint_poses.resize(1);
00134   getNominalJointPose(empty_seed,model,joint_poses[0]);
00135 }
00136 
00137 bool JointTrajectoryPt::isValid(const RobotModel &model) const
00138 {
00139   return model.isValid(lower_) && model.isValid(upper_);
00140 }
00141 
00142 bool JointTrajectoryPt::setDiscretization(const std::vector<double> &discretization)
00143 {
00144   if (discretization.size() != 1 || discretization.size() != nominal_.size())
00145   {
00146     logError("discretization must be size 1 or same size as joint count.");
00147     return false;
00148   }
00149 
00150   if (discretization.size() == 1)
00151   {
00152     discretization_ = std::vector<double>(nominal_.size(), discretization[0]);
00153     return true;
00154   }
00155 
00156   /* Do not copy discretization values until all values are confirmed */
00157   for (size_t ii=0; ii<discretization.size(); ++ii)
00158   {
00159     if (discretization[ii] < 0. || discretization[ii] > (upper_[ii] - lower_[ii]))
00160     {
00161       logError("discretization value out of range.");
00162       return false;
00163     }
00164   }
00165 
00166   discretization_ = discretization;
00167 
00168   return true;
00169 }
00170 
00171 void JointTrajectoryPt::setJoints(const std::vector<TolerancedJointValue> &joints)
00172 {
00173   lower_.clear(); nominal_.clear(); upper_.clear();
00174   unpackTolerancedJoints(joints, lower_, nominal_, upper_);
00175 }
00176 
00177 } /* namespace descartes_trajectory */


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