cubic_parameterized_spline_velocity_scaler.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2009, 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 the Willow Garage 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 
00037 #ifndef CUBIC_PARAMETERIZED_SPLINE_VELOCITY_SCALER_H_
00038 #define CUBIC_PARAMETERIZED_SPLINE_VELOCITY_SCALER_H_
00039 
00040 #include <spline_smoother/spline_smoother.h>
00041 #include <spline_smoother/cubic_parameterized_trajectory.h>
00042 namespace spline_smoother
00043 {
00044 
00048   template <typename T>
00049   class CubicParameterizedSplineVelocityScaler: public SplineSmoother<T>
00050   {
00051     public:
00052     CubicParameterizedSplineVelocityScaler();
00053     virtual ~CubicParameterizedSplineVelocityScaler();
00054 
00055     virtual bool smooth(const T& trajectory_in, 
00056                         T& trajectory_out) const;
00057   };
00058 
00059   template <typename T>
00060   CubicParameterizedSplineVelocityScaler<T>::CubicParameterizedSplineVelocityScaler()
00061   {
00062   }
00063 
00064   template <typename T>
00065   CubicParameterizedSplineVelocityScaler<T>::~CubicParameterizedSplineVelocityScaler()
00066   {
00067   }
00068 
00069   template <typename T>
00070   bool CubicParameterizedSplineVelocityScaler<T>::smooth(const T& trajectory_in, T& trajectory_out) const
00071   {
00072     spline_smoother::CubicParameterizedTrajectory traj;
00073     spline_smoother::SplineTrajectory spline;
00074     T trajectory_local = trajectory_in;
00075     if (!checkTrajectoryConsistency(trajectory_local))
00076       return false;
00077     bool success = traj.parameterize(trajectory_local.request.trajectory,trajectory_local.request.limits,spline);
00078     if(!success)
00079       return false;
00080 
00081     trajectory_out = trajectory_local;
00082 
00083     double dT = 0.01;
00084     std::set<double> times;
00085     double total_time;
00086     spline_smoother::getTotalTime(spline,total_time);
00087     for(int i=1; i< (int) (total_time/dT); i++)
00088       times.insert(i*dT);
00089     times.insert(total_time);
00090 
00091     double insert_time = 0;
00092     for(unsigned int i=0; i < spline.segments.size(); i++)
00093     {
00094       insert_time += spline.segments[i].duration.toSec();
00095       times.insert(insert_time);
00096     }
00097 
00098     std::vector<double> times_vec;
00099     for(std::set<double>::iterator set_iter = times.begin(); set_iter != times.end(); set_iter++)
00100     {
00101       times_vec.push_back(*set_iter);
00102     }
00103     std::sort(times_vec.begin(), times_vec.end());
00104 
00105     if(!spline_smoother::sampleSplineTrajectory(spline,times_vec,trajectory_out.request.trajectory))
00106       return false;
00107 
00108     return true;
00109   }
00110 }
00111 
00112 #endif /* CUBIC_PARAMETERIZED_SPLINE_SMOOTHER_H_ */


spline_smoother
Author(s): Mrinal Kalakrishnan / mail@mrinal.net
autogenerated on Mon Dec 2 2013 12:35:44