00001 /* **-*-c++-*-************************************************************** 00002 Copyright (C)2003 David Jung <opensim@pobox.com> 00003 00004 This program/file is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. (http://www.gnu.org) 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 $Id: ManipulatorJointTrajectory 1039 2004-02-11 20:50:52Z jungd $ 00019 $Revision: 1.4 $ 00020 $Date: 2004-02-11 15:50:52 -0500 (Wed, 11 Feb 2004) $ 00021 $Author: jungd $ 00022 00023 ****************************************************************************/ 00024 00025 #ifndef _ROBOT_MANIPULATORJOINTTRAJECTORY_ 00026 #define _ROBOT_MANIPULATORJOINTTRAJECTORY_ 00027 00028 #include <robot/robot> 00029 00030 #include <base/Serializable> 00031 #include <base/Externalizable> 00032 #include <base/Vector> 00033 #include <base/Time> 00034 00035 00036 namespace robot { 00037 00038 00039 /** 00040 * Specifies a trajectory through a manipulator's joint-space. 00041 * Each joint-position vector occurs at a specific time. 00042 * The parameter s varies over time t:[start-time, end-time]. 00043 * @see base::Trajectory for the equivelent trajectory in 6-space. 00044 */ 00045 class ManipulatorJointTrajectory : public base::Serializable, public base::Externalizable 00046 { 00047 public: 00048 enum AngularUnits { Degrees, Radians }; 00049 00050 /// default trajectory - all points & times range over [0..1] secs. 00051 ManipulatorJointTrajectory(Int numJoints=6, AngularUnits units = Radians); 00052 00053 /// copy trajectory t 00054 ManipulatorJointTrajectory(const ManipulatorJointTrajectory& t); 00055 00056 /// simple line segment start[joint configuration|time] - end[joint configuration|time] 00057 ManipulatorJointTrajectory(const base::Vector& sq, const base::Time& st, 00058 const base::Vector& eq, const base::Time& et, 00059 AngularUnits units = Radians); 00060 00061 /// a set of joint configuration 'waypoints' - and their corresponding times. 00062 /// if deltas is true, the arrays are considered to specify the inter-waypoint deltas instead 00063 /// (with the first point/orient being 0) 00064 ManipulatorJointTrajectory(const array<base::Vector>& qs, 00065 const array<base::Time>& times = array<base::Time>(), 00066 bool deltas=false, 00067 AngularUnits units = Radians); 00068 00069 00070 virtual String className() const { return String("ManipulatorJointTrajectory"); } 00071 00072 /// get the number of joints for each trajectory point (dim of qi's) 00073 Int getNumJoints() const { return qs[0].size(); } 00074 00075 /// change the number of joints in the trajectory points. 00076 /// If numJoints is larger than the current dimension, the extra dimensions will have 00077 /// their elements set to 0. If numJoints is smaller than the current, the extra dimension 00078 /// are discarded (additionally if truncateInitial is true, the initial elements are 00079 // discarded instead of the end elements) 00080 void setNumJoints(Int numJoints, bool truncateInitial=false); 00081 00082 /// even though this class doesn't interpret the values of the joint configuration vectors, 00083 /// it can be specified if the angular components are in degrees or radians 00084 /// (although which are angular is unknown to this class). 00085 /// This can be used to convert the appropriate elements when necessary 00086 AngularUnits getAngularUnits() const { return angUnits; } 00087 void setAngularUnits(AngularUnits units) { angUnits = units; } 00088 00089 /// given a set of component indices, this will convert the components of all trajectory 00090 /// points to the specified units if they are not already expressed in those units as 00091 /// indicated by getAngularUnits() 00092 void convertComponentUnits(array<Int> components, AngularUnits units = Radians); 00093 00094 /// get joint-configuration at time t 00095 base::Vector q(const base::Time& t) const; 00096 00097 /// get time at s:[0..1] 00098 base::Time time(Real s) const; 00099 00100 /// some values of s correspond to distinguished points along a trajectory. 00101 /// the values s=0 and s=1 are always distinguished values. 00102 /// There will be a distinguished value of s for each waypoint. 0 <= i < numDistinguishedValues() 00103 Real distinguishedValue(Int i) const { return si[i]; } 00104 00105 Int numDistinguishedValues() const ///< number of distinguished s values 00106 { return si.size(); } 00107 00108 /// shift time by dt 00109 void shiftTime(const base::Time& dt); 00110 00111 /// scale time by s 00112 void scaleTime(Real s); 00113 00114 /// get parameter s value at time t 00115 virtual Real gets(const base::Time& t) const; 00116 00117 virtual void serialize(base::Serializer& s); ///< read or write object state to Serializer 00118 00119 virtual bool formatSupported(String format, Real version = 1.0, ExternalizationType type = IO) const; ///< query if specific format is supported (for input, output or both) 00120 virtual void externalize(base::Externalizer& e, String format = "", Real version = 1.0); ///< read or write object state to Externalizer 00121 00122 protected: 00123 void init(const array<base::Vector>& qs, const array<base::Time>& times, bool deltas); // waypoints init 00124 00125 Int findIndex(Real s) const; 00126 00127 array<base::Vector> qs; ///< joint-configuration 'waypoints' 00128 array<base::Time> times; ///< corresponding times 00129 array<Real> si; ///< value of s:[0..1] corresponding to each waypoint. 00130 00131 AngularUnits angUnits; ///< are the angular elements to be considered as degrees or radians? (NB: there is no interpretation by this class) 00132 00133 /// compute si's s.t. s:[0..1] maps to t:[start-time..end-time] 00134 virtual void computeSis(Int dof); 00135 00136 friend std::ostream& operator<<(std::ostream& out, const ManipulatorJointTrajectory& t); 00137 }; 00138 00139 00140 // Operations 00141 00142 inline std::ostream& operator<<(std::ostream& out, const ManipulatorJointTrajectory& t) // Output 00143 { 00144 for(Int i=0; i<t.si.size(); i++) 00145 out << "s:" << t.si[i] << " q:" << t.qs[i] << " t:" << t.times[i].seconds() << std::endl; 00146 return out; 00147 } 00148 00149 00150 } // robot 00151 00152 #endif