|
From: <tf...@us...> - 2008-03-26 01:32:37
|
Revision: 32
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=32&view=rev
Author: tfoote
Date: 2008-03-25 18:32:43 -0700 (Tue, 25 Mar 2008)
Log Message:
-----------
An initial operational demo of the transform library transforming through a tree
Added Paths:
-----------
pkg/trunk/libTF/simple/
pkg/trunk/libTF/simple/Makefile
pkg/trunk/libTF/simple/libTF.cc
pkg/trunk/libTF/simple/libTF.hh
pkg/trunk/libTF/simple/main.cc
Property Changed:
----------------
pkg/trunk/libTF/
Property changes on: pkg/trunk/libTF
___________________________________________________________________
Name: svk:merge
+ 5d0af4bb-b190-461e-89ab-f239232fb17e:/zug/libtf:633
Added: pkg/trunk/libTF/simple/Makefile
===================================================================
--- pkg/trunk/libTF/simple/Makefile (rev 0)
+++ pkg/trunk/libTF/simple/Makefile 2008-03-26 01:32:43 UTC (rev 32)
@@ -0,0 +1,13 @@
+.PHONY=all clean test
+
+
+all: test
+
+
+
+test: main.cc libTF.o
+ g++ -O2 $^ -o test -lnewmat
+
+
+clean:
+ rm -rf *~ test *.o
\ No newline at end of file
Added: pkg/trunk/libTF/simple/libTF.cc
===================================================================
--- pkg/trunk/libTF/simple/libTF.cc (rev 0)
+++ pkg/trunk/libTF/simple/libTF.cc 2008-03-26 01:32:43 UTC (rev 32)
@@ -0,0 +1,193 @@
+#include "libTF.hh"
+
+RefFrame::RefFrame() :
+ parent(0),
+ active(false)
+{
+ return;
+}
+
+void RefFrame::setParams(double a,double b,double c,double d,double e,double f)
+{
+ params[0]=a;
+ params[1]=b;
+ params[2]=c;
+ params[3]=d;
+ params[4]=e;
+ params[5]=f;
+
+}
+
+NEWMAT::Matrix RefFrame::getMatrix()
+{
+ NEWMAT::Matrix mMat(4,4);
+ fill_transformation_matrix(mMat,params[0],params[1],params[2],params[3],params[4],params[5]);
+ return mMat;
+}
+
+NEWMAT::Matrix RefFrame::getInverseMatrix()
+{
+ NEWMAT::Matrix mMat(4,4);
+ fill_transformation_matrix(mMat,params[0],params[1],params[2],params[3],params[4],params[5]);
+ //todo create a fill_inverse_transform_matrix call to be more efficient
+ return mMat.i();
+}
+
+
+TransformReference::TransformReference():
+ mMat(4,4)
+{
+
+
+ return;
+}
+
+void TransformReference::set(unsigned int frameID, unsigned int parentID, double a,double b,double c,double d,double e,double f)
+{
+ frames[frameID].setParent(parentID);
+ frames[frameID].setParams(a,b,c,d,e,f);
+}
+
+
+NEWMAT::Matrix TransformReference::get(unsigned int target_frame, unsigned int source_frame)
+{
+ NEWMAT::Matrix myMat(4,4);
+ TransformLists lists = lookUpList(target_frame, source_frame);
+ myMat = computeTransformFromList(lists);
+ // std::cout << myMat;
+ return myMat;
+}
+
+
+
+
+bool RefFrame::fill_transformation_matrix(NEWMAT::Matrix & matrix, double ax,
+ double ay, double az, double yaw,
+ double pitch, double roll)
+{
+ double ca = cos(yaw);
+ double sa = sin(yaw);
+ double cb = cos(pitch);
+ double sb = sin(pitch);
+ double cg = cos(roll);
+ double sg = sin(roll);
+ double sbsg = sb*sg;
+ double sbcg = sb*cg;
+
+
+ double* matrix_pointer = matrix.Store();
+ if (matrix.Storage() != 16)
+ return false;
+
+ matrix_pointer[0] = ca*cb;
+ matrix_pointer[1] = (ca*sbsg)-(sa*cg);
+ matrix_pointer[2] = (ca*sbcg)+(sa*sg);
+ matrix_pointer[3] = ax;
+ matrix_pointer[4] = sa*cb;
+ matrix_pointer[5] = (sa*sbsg)+(ca*cg);
+ matrix_pointer[6] = (sa*sbcg)-(ca*sg);
+ matrix_pointer[7] = ay;
+ matrix_pointer[8] = -sb;
+ matrix_pointer[9] = cb*sg;
+ matrix_pointer[10] = cb*cg;
+ matrix_pointer[11] = az;
+ matrix_pointer[12] = 0.0;
+ matrix_pointer[13] = 0.0;
+ matrix_pointer[14] = 0.0;
+ matrix_pointer[15] = 1.0;
+
+ return true;
+};
+
+
+
+TransformReference::TransformLists TransformReference::lookUpList(unsigned int target_frame, unsigned int source_frame)
+{
+ TransformLists mTfLs;
+
+ // std::vector<unsigned int> tList;
+ // std::vector<unsigned int> sList;
+
+ // std::vector<unsigned int> retVec;
+
+ unsigned int frame = target_frame;
+ while (frame != 0)
+ {
+ if (frames[frame].getParent() > 100) exit(-1); //todo cleanup
+ mTfLs.inverseTransforms.push_back(frame);
+ // std::cout <<"Frame: " << frame <<std::endl;
+ frame = frames[frame].getParent();
+ }
+ mTfLs.inverseTransforms.push_back(0);
+
+ frame = source_frame;
+ while (frame != 0)
+ {
+ if (frames[frame].getParent() > 100) exit(-1); //todo cleanup
+ mTfLs.forwardTransforms.push_back(frame);
+ frame = frames[frame].getParent();
+ }
+ mTfLs.forwardTransforms.push_back(0);
+
+
+ //todo fixme throw something
+ // if (tList.size() <= 1) exit(-1);
+ // if (sList.size() <= 1) exit(-1); // I think below will catch all these anyway
+
+ while (mTfLs.inverseTransforms.back() == mTfLs.forwardTransforms.back())
+ {
+ // std::cout << "removing " << mTfLs.inverseTransforms.back() << std::endl;
+ mTfLs.inverseTransforms.pop_back();
+ mTfLs.forwardTransforms.pop_back();
+ }
+
+ return mTfLs;
+
+}
+
+NEWMAT::Matrix TransformReference::computeTransformFromList(TransformLists lists)
+{
+ NEWMAT::Matrix retMat(4,4);
+ retMat << 1 << 0 << 0 << 0
+ << 0 << 1 << 0 << 0
+ << 0 << 0 << 1 << 0
+ << 0 << 0 << 0 << 1;
+
+ for (unsigned int i = 0; i < lists.inverseTransforms.size(); i++)
+ {
+ retMat *= frames[lists.inverseTransforms[i]].getInverseMatrix();
+ // std::cout <<"Multiplying by " << std::endl << frames[lists.inverseTransforms[i]].getInverseMatrix() << std::endl;
+ //std::cout <<"Result "<<std::endl << retMat << std::endl;
+ }
+ for (unsigned int i = 0; i < lists.forwardTransforms.size(); i++)
+ {
+ retMat *= frames[lists.forwardTransforms[lists.forwardTransforms.size() -1 - i]].getMatrix(); //Do this list backwards for it was generated traveling the wrong way
+ // std::cout <<"Multiplying by "<<std::endl << frames[lists.forwardTransforms[i]].getMatrix() << std::endl;
+ //std::cout <<"Result "<<std::endl << retMat << std::endl;
+ }
+
+ return retMat;
+}
+
+
+void TransformReference::view(unsigned int target_frame, unsigned int source_frame)
+{
+ TransformLists lists = lookUpList(target_frame, source_frame);
+
+ std::cout << "Inverse Transforms:" <<std::endl;
+ for (unsigned int i = 0; i < lists.inverseTransforms.size(); i++)
+ {
+ std::cout << lists.inverseTransforms[i];
+ // retMat *= frames[lists.inverseTransforms[i]].getInverseMatrix();
+ }
+ std::cout << std::endl;
+
+ std::cout << "Forward Transforms: "<<std::endl ;
+ for (unsigned int i = 0; i < lists.forwardTransforms.size(); i++)
+ {
+ std::cout << lists.forwardTransforms[i];
+ // retMat *= frames[lists.inverseTransforms[lists.forwardTransforms.size() -1 - i]].getMatrix(); //Do this list backwards for it was generated traveling the wrong way
+ }
+ std::cout << std::endl;
+
+}
Added: pkg/trunk/libTF/simple/libTF.hh
===================================================================
--- pkg/trunk/libTF/simple/libTF.hh (rev 0)
+++ pkg/trunk/libTF/simple/libTF.hh 2008-03-26 01:32:43 UTC (rev 32)
@@ -0,0 +1,53 @@
+#ifndef LIBTF_HH
+#define LIBTF_HH
+#include <iostream>
+#include <iomanip>
+#include <newmat/newmat.h>
+#include <newmat/newmatio.h>
+#include <math.h>
+#include <vector>
+
+class RefFrame
+{
+public:
+ // static enum FrameType {SIXDOF, DH //how to tell which mode it's in //todo add this process i'm going to start with 6dof only
+ RefFrame();
+ void setParams(double, double, double, double, double, double);
+ inline unsigned int getParent(){return parent;};
+ inline void setParent(unsigned int parentID){parent = parentID;};
+ NEWMAT::Matrix getMatrix();
+ NEWMAT::Matrix getInverseMatrix();
+private:
+ double params[6];
+ static bool fill_transformation_matrix(NEWMAT::Matrix& matrix_pointer, double ax,
+ double ay, double az, double yaw,
+ double pitch, double roll);
+ unsigned int parent;
+ bool active;
+
+};
+
+class TransformReference
+{
+ public:
+ void set(unsigned int framid, unsigned int parentid, double,double,double,double,double,double);
+ NEWMAT::Matrix get(unsigned int target_frame, unsigned int source_frame);
+
+ TransformReference();
+ void view(unsigned int target_frame, unsigned int source_frame);
+ private:
+ double rD[6];
+ NEWMAT::Matrix mMat;
+ RefFrame frames[100];
+
+ typedef struct
+ {
+ std::vector<unsigned int> inverseTransforms;
+ std::vector<unsigned int> forwardTransforms;
+ } TransformLists;
+
+ TransformLists lookUpList(unsigned int target_frame, unsigned int source_frame);
+ NEWMAT::Matrix computeTransformFromList(TransformLists list);
+
+};
+#endif //LIBTF_HH
Added: pkg/trunk/libTF/simple/main.cc
===================================================================
--- pkg/trunk/libTF/simple/main.cc (rev 0)
+++ pkg/trunk/libTF/simple/main.cc 2008-03-26 01:32:43 UTC (rev 32)
@@ -0,0 +1,104 @@
+#include "libTF.hh"
+#include <time.h>
+
+using namespace std;
+
+int main(void)
+{
+ double dx,dy,dz,dyaw,dp,dr;
+ TransformReference mTR;
+
+
+ // while (true)
+ {
+ /* cout << "delta x:";
+ cin >> dx;
+ cout << "delta y:";
+ cin >> dy;
+ cout << "delta z:";
+ cin >> dz;
+ cout << "delta yaw:";
+ cin >> dyaw;
+ cout << "delta pitch:";
+ cin >> dp;
+ cout << "delta roll:";
+ cin >> dr;
+ */
+ dx = dy= dz = 0;
+ dyaw = dp = dr = .1;
+
+
+
+ mTR.set(1,2,1,1,1,dyaw,dp,dr);
+ mTR.set(2,3,1,1,1,dyaw,dp,dr);
+ mTR.set(3,5,dx,dy,dz,dyaw,dp,dr);
+ mTR.set(5,0,dx,dy,dz,dyaw,dp,dr);
+ mTR.set(6,5,dx,dy,dz,dyaw,dp,dr);
+ mTR.set(7,6,1,1,1,dyaw,dp,dr);
+ mTR.set(8,7,1,1,1,dyaw,dp,dr);
+ mTR.view(1,8);
+
+
+ std::cout <<"Calling get(1,8)"<<std::endl;
+ // NEWMAT::Matrix mat = mTR.get(1,1);
+ NEWMAT::Matrix mat = mTR.get(1,8);
+
+ std::cout << "Result" << std::endl << mat<< std::endl;
+#ifdef DONOTUSE
+
+ // NEWMAT::Matrix mat(4,4);
+ NEWMAT::Matrix MatI(4,4);
+ NEWMAT::Matrix MatI2(4,4);
+
+
+ // double vec[] = {dx,dy,dz,dyaw,dp,dr};
+ // mat <<vec;
+ double init_time = (double)clock()/(double) CLOCKS_PER_SEC;
+ int iterations = 1;
+ for (int i = 0; i < iterations; i++)
+ {
+ MatI = mat.i();
+ }
+ std::cout <<"Straight Inverse" <<std::endl<< MatI;
+ std::cout << "This should be Identity if Inverse is right: "<<std::endl << MatI * mat;
+ std::cout << "Time Elapsed for "<<iterations<<"iterations is:"<<(double)clock()/(double) CLOCKS_PER_SEC - init_time <<std::endl;
+ std::cout << "Net: "<<((double)clock()/(double) CLOCKS_PER_SEC -init_time)/(double)iterations <<std::endl;
+
+
+ NEWMAT::Matrix trans_mask(4,4);
+ trans_mask << 0 << 0 << 0 << -1
+ << 0 << 0 << 0 << -1
+ << 0 << 0 << 0 << -1
+ << 0 << 0 << 0 << 1;
+
+ NEWMAT::Matrix trans_fix(4,4);
+ trans_fix << 1 << 0 << 0 << 0
+ << 0 << 1 << 0 << 0
+ << 0 << 0 << 1 << 0
+ << 0 << 0 << 0 << 0;
+
+
+ NEWMAT::Matrix rot_mask(4,4);
+ rot_mask << 1 << 1 << 1 << 0
+ << 1 << 1 << 1 << 0
+ << 1 << 1 << 1 << 0
+ << 0 << 0 << 0 << 1;
+
+ init_time = (double)clock()/(double) CLOCKS_PER_SEC;
+ for (int i = 0; i < iterations; i++)
+ {
+ MatI2 = SP(mat, rot_mask).t();
+ MatI2 *= (SP(mat,trans_mask) + trans_fix);
+ }
+ std::cout <<"My Inverse:" <<std::endl<< MatI2;
+ std::cout << "Product: " <<std::endl<< MatI2 * mat;
+ std::cout << "Time Elapsed for method 2 "<<iterations<<" iterations is:"<<(double)clock()/(double) CLOCKS_PER_SEC - init_time <<std::endl;
+ std::cout << "Net: "<<((double)clock()/(double) CLOCKS_PER_SEC - init_time) /(double)iterations <<std::endl;
+
+
+ std::cout <<"difference: "<<std::endl<<MatI - MatI2;
+#endif //DONOTUSE
+
+ }
+ return 0;
+};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jl...@us...> - 2008-04-22 20:27:43
|
Revision: 152
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=152&view=rev
Author: jleibs
Date: 2008-04-22 13:27:43 -0700 (Tue, 22 Apr 2008)
Log Message:
-----------
Adding ROS infrastructure to allow use of libTF.
Added Paths:
-----------
pkg/trunk/libTF/build.yaml
pkg/trunk/libTF/include/
pkg/trunk/libTF/include/libTF/
pkg/trunk/libTF/manifest.xml
pkg/trunk/libTF/rosbuild
pkg/trunk/libTF/src/
Added: pkg/trunk/libTF/build.yaml
===================================================================
--- pkg/trunk/libTF/build.yaml (rev 0)
+++ pkg/trunk/libTF/build.yaml 2008-04-22 20:27:43 UTC (rev 152)
@@ -0,0 +1,5 @@
+cpp:
+ make:
+ - src/simple
+
+
Added: pkg/trunk/libTF/manifest.xml
===================================================================
--- pkg/trunk/libTF/manifest.xml (rev 0)
+++ pkg/trunk/libTF/manifest.xml 2008-04-22 20:27:43 UTC (rev 152)
@@ -0,0 +1,12 @@
+<package>
+<description brief='Transform Library'>
+
+Library for doing transformations.
+
+</description>
+<author>Tully Foote</author>
+<license>BSD</license>
+<url>http://pr.willowgarage.com</url>
+<sys_depend lib='newmat'/>
+<repository>http://pr.willowgarage.com/repos</repository>
+</package>
Added: pkg/trunk/libTF/rosbuild
===================================================================
--- pkg/trunk/libTF/rosbuild (rev 0)
+++ pkg/trunk/libTF/rosbuild 2008-04-22 20:27:43 UTC (rev 152)
@@ -0,0 +1,2 @@
+#!/usr/bin/env ruby
+exec("#{`#{ENV['ROS_ROOT']}/rospack find rostools`}/scripts/yamlbuild", 'build.yaml', *ARGV)
Property changes on: pkg/trunk/libTF/rosbuild
___________________________________________________________________
Name: svn:executable
+ *
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jl...@us...> - 2008-04-22 20:29:20
|
Revision: 153
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=153&view=rev
Author: jleibs
Date: 2008-04-22 13:29:25 -0700 (Tue, 22 Apr 2008)
Log Message:
-----------
More restructuring of libtf.
Modified Paths:
--------------
pkg/trunk/libTF/build.yaml
Added Paths:
-----------
pkg/trunk/libTF/src/simple/
pkg/trunk/libTF/src/test/
Removed Paths:
-------------
pkg/trunk/libTF/simple/
Modified: pkg/trunk/libTF/build.yaml
===================================================================
--- pkg/trunk/libTF/build.yaml 2008-04-22 20:27:43 UTC (rev 152)
+++ pkg/trunk/libTF/build.yaml 2008-04-22 20:29:25 UTC (rev 153)
@@ -1,5 +1,6 @@
cpp:
make:
- src/simple
+ - src/test
Copied: pkg/trunk/libTF/src/simple (from rev 151, pkg/trunk/libTF/simple)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jl...@us...> - 2008-04-22 20:31:03
|
Revision: 154
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=154&view=rev
Author: jleibs
Date: 2008-04-22 13:31:08 -0700 (Tue, 22 Apr 2008)
Log Message:
-----------
All done shuffling files to new locations.
Added Paths:
-----------
pkg/trunk/libTF/include/libTF/Quaternion3D.hh
pkg/trunk/libTF/include/libTF/libTF.hh
pkg/trunk/libTF/src/test/main.cc
pkg/trunk/libTF/src/test/testQuat.cc
Removed Paths:
-------------
pkg/trunk/libTF/src/simple/Quaternion3D.hh
pkg/trunk/libTF/src/simple/libTF.hh
pkg/trunk/libTF/src/simple/main.cc
pkg/trunk/libTF/src/simple/testQuat.cc
Copied: pkg/trunk/libTF/include/libTF/Quaternion3D.hh (from rev 153, pkg/trunk/libTF/src/simple/Quaternion3D.hh)
===================================================================
--- pkg/trunk/libTF/include/libTF/Quaternion3D.hh (rev 0)
+++ pkg/trunk/libTF/include/libTF/Quaternion3D.hh 2008-04-22 20:31:08 UTC (rev 154)
@@ -0,0 +1,174 @@
+// Software License Agreement (BSD License)
+//
+// Copyright (c) 2008, Willow Garage, Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of the Willow Garage nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+// POSSIBILITY OF SUCH DAMAGE.
+//
+#ifndef QUATERNION3D_HH
+#define QUATERNION3D_HH
+
+#include <iostream>
+#include <newmat/newmat.h>
+#include <newmat/newmatio.h>
+#include <math.h>
+#include <pthread.h>
+#include <sys/time.h>
+class Euler3D {
+public:
+ //Constructor
+ Euler3D(double _x, double _y, double _z, double _yaw, double _pitch, double _roll);
+
+ //Storage
+ double x,y,z,yaw,pitch,roll;
+};
+
+
+class Quaternion3D {
+
+public:
+ // Storage class
+ class Quaternion3DStorage
+ {
+ public:
+
+ /** Unary operators preserve timestamps
+ * Binary operators destroy timestamps */
+
+ // Utility functions to normalize and get magnitude.
+ void Normalize();
+ double getMagnitude();
+ Quaternion3DStorage & operator=(const Quaternion3DStorage & input);
+
+
+ /* accessors */
+ NEWMAT::Matrix asMatrix();
+
+ /* Internal Data */
+ double xt, yt, zt, xr, yr, zr, w;
+ unsigned long long time;
+ };
+
+ /** Constructors **/
+ // Standard constructor
+ Quaternion3D();
+
+ /** Mutators **/
+ // Set the values manually
+ void fromQuaternion(double _xt, double _yt, double _zt, double _xr, double _yr, double _zr, double _w, unsigned long long time);
+ //Set the values from a matrix
+ void fromMatrix(const NEWMAT::Matrix& matIn, unsigned long long time);
+ // Set the values using Euler angles
+ void fromEuler(double _x, double _y, double _z, double _yaw, double _pitch, double _roll, unsigned long long time);
+ // Set the values using DH Parameters
+ void fromDH(double length, double alpha, double offset, double theta, unsigned long long time);
+
+
+ /** Interpolated Accessors **/
+ // Return a Quaternion
+ Quaternion3D::Quaternion3DStorage getQuaternion(unsigned long long time);
+ // Return a Matrix
+ NEWMAT::Matrix getMatrix(unsigned long long time);
+ // Return the inverse matrix
+ NEWMAT::Matrix getInverseMatrix(unsigned long long time);
+
+ /**** Utility Functions ****/
+ // this is a function to return the current time in microseconds from the beginning of 1970
+ static unsigned long long Qgettime(void);
+
+ // Convert DH Parameters to a Homogeneous Transformation Matrix
+ static NEWMAT::Matrix matrixFromDH(double length, double alpha, double offset, double theta);
+ // Convert Euler Angles to a Homogeneous Transformation Matrix
+ static NEWMAT::Matrix matrixFromEuler(double ax,
+ double ay, double az, double yaw,
+ double pitch, double roll);
+
+ //Print as a matrix
+ void printMatrix(unsigned long long time); //Not a critical part either
+ void printStorage(const Quaternion3DStorage &storage); //Do i need this now that i've got the ostream method??
+
+
+private:
+ /**** Linked List stuff ****/
+ static const long long MAX_STORAGE_TIME = 1000000000; // max of 100 seconds storage
+
+ struct data_LL{
+ Quaternion3DStorage data;
+ data_LL * next;
+ data_LL * previous;
+ };
+
+ bool getValue(Quaternion3DStorage& buff, unsigned long long time, long long &time_diff);
+ void add_value(const Quaternion3DStorage&);//todo fixme finish implementing this
+
+
+
+ // insert a node into the sorted linked list
+ void insertNode(const Quaternion3DStorage & );
+ // prune data older than max_storage_time from the list
+ void pruneList();
+
+ //Find the closest two points in the list
+ //Return the distance to the closest one
+ int findClosest(Quaternion3DStorage& one, Quaternion3DStorage& two, const unsigned long long target_time, long long &time_diff);
+
+ //Interpolate between two nodes and return the interpolated value
+ // This must always take two valid points!!!!!!
+ // Only Cpose version implemented
+ void interpolate(const Quaternion3DStorage &one, const Quaternion3DStorage &two, const unsigned long long target_time, Quaternion3DStorage& output);
+
+ //Used by interpolate to interpolate between double values
+ double interpolateDouble(const double, const unsigned long long, const double, const unsigned long long, const unsigned long long);
+
+ //How long to cache incoming values
+ unsigned long long max_storage_time;
+
+ //A mutex to prevent linked list collisions
+ pthread_mutex_t linked_list_mutex;
+
+ //Pointers for the start and end of a sorted linked list.
+ data_LL* first;
+ data_LL* last;
+
+
+
+};
+
+
+
+//A global ostream overload for displaying storage
+std::ostream & operator<<(std::ostream& mystream,const Quaternion3D::Quaternion3DStorage & storage);
+
+
+
+
+
+
+
+
+#endif //QUATERNION3D_HH
Copied: pkg/trunk/libTF/include/libTF/libTF.hh (from rev 153, pkg/trunk/libTF/src/simple/libTF.hh)
===================================================================
--- pkg/trunk/libTF/include/libTF/libTF.hh (rev 0)
+++ pkg/trunk/libTF/include/libTF/libTF.hh 2008-04-22 20:31:08 UTC (rev 154)
@@ -0,0 +1,172 @@
+//Software License Agreement (BSD License)
+
+//Copyright (c) 2008, Willow Garage, Inc.
+//All rights reserved.
+
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of the Willow Garage nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+//COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+//POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef LIBTF_HH
+#define LIBTF_HH
+#include <iostream>
+#include <iomanip>
+#include <newmat/newmat.h>
+#include <newmat/newmatio.h>
+#include <math.h>
+#include <vector>
+#include <sstream>
+
+#include "Quaternion3D.hh"
+
+/** RefFrame *******
+ * An instance of this class is created for each frame in the system.
+ * This class natively handles the relationship between frames.
+ *
+ * The derived class Quaternion3D provides a buffered history of positions
+ * with interpolation.
+ */
+
+class RefFrame: public Quaternion3D
+{
+public:
+
+ /* Constructor */
+ RefFrame();
+
+ /* Get the parent node */
+ inline unsigned int getParent(){return parent;};
+
+ /* Return tha parent node */
+ inline void setParent(unsigned int parentID){parent = parentID;};
+private:
+
+ /* Storage of the parent */
+ unsigned int parent;
+
+};
+
+/*** Transform Reference ***********
+ * This class provides a simple interface to allow recording and lookup of
+ * relationships between arbitrary frames of the system.
+ *
+ * The positions of frames over time must be pushed in.
+ *
+ * It will provide interpolated positions out given a time argument.
+ */
+
+class TransformReference
+{
+public:
+ /************* Constants ***********************/
+ static const unsigned int ROOT_FRAME = 1; //Hard Value for ROOT_FRAME
+ static const unsigned int NO_PARENT = 0; //Value for NO_PARENT
+
+ static const unsigned int MAX_NUM_FRAMES = 100; /* The maximum number of frames possible */
+ static const unsigned int MAX_GRAPH_DEPTH = 100; /* The maximum number of times to descent before determining that graph has a loop. */
+
+ /* Constructor */
+ TransformReference();
+
+ /********** Mutators **************/
+ /* Set a new frame or update an old one. */
+ /* Use Euler Angles. X forward, Y to the left, Z up, Yaw about Z, pitch about new Y, Roll about new X */
+ void setWithEulers(unsigned int framid, unsigned int parentid, double x, double y, double z, double yaw, double pitch, double roll, unsigned long long time);
+ /* Using DH Parameters */
+ // Conventions from http://en.wikipedia.org/wiki/Robotics_conventions
+ void setWithDH(unsigned int framid, unsigned int parentid, double length, double alpha, double offset, double theta, unsigned long long time);
+ // Possible exceptions TransformReference::LookupException
+
+ /*********** Accessors *************/
+
+ /* Get the transform between two frames by frame ID. */
+ NEWMAT::Matrix getMatrix(unsigned int target_frame, unsigned int source_frame, unsigned long long time);
+ // Possible exceptions TransformReference::LookupException, TransformReference::ConnectivityException,
+ // TransformReference::MaxDepthException
+
+ /* Debugging function that will print to std::cout the transformation matrix */
+ std::string viewChain(unsigned int target_frame, unsigned int source_frame);
+ // Possible exceptions TransformReference::LookupException, TransformReference::ConnectivityException,
+ // TransformReference::MaxDepthException
+
+
+
+
+
+
+ /************ Possible Exceptions ****************************/
+
+ /* An exception class to notify of bad frame number */
+ class LookupException : public std::exception
+ {
+ public:
+ virtual const char* what() const throw() { return "InvalidFrame"; }
+ } InvalidFrame;
+
+ /* An exception class to notify of no connection */
+ class ConnectivityException : public std::exception
+ {
+ public:
+ virtual const char* what() const throw() { return "No connection between frames"; }
+ private:
+ } NoFrameConnectivity;
+
+ /* An exception class to notify that the search for connectivity descended too deep. */
+ class MaxDepthException : public std::exception
+ {
+ public:
+ virtual const char* what() const throw() { return "Search exceeded max depth. Probably a loop in the tree."; }
+ private:
+ } MaxSearchDepth;
+
+private:
+ /******************** Internal Storage ****************/
+
+ /* The pointers to potential frames that the tree can be made of.
+ * The frames will be dynamically allocated at run time when set the first time. */
+ RefFrame* frames[MAX_NUM_FRAMES];
+
+
+ /* This struct is how the list of transforms are stored before being passed to computeTransformFromList. */
+ typedef struct
+ {
+ std::vector<unsigned int> inverseTransforms;
+ std::vector<unsigned int> forwardTransforms;
+ } TransformLists;
+
+ /************************* Internal Functions ****************************/
+
+ /* An accessor to get a frame, which will throw an exception if the frame is no there. */
+ inline RefFrame* getFrame(unsigned int frame_number) { if (frames[frame_number] == NULL) throw InvalidFrame; else return frames[frame_number];};
+
+ /* Find the list of connected frames necessary to connect two different frames */
+ TransformLists lookUpList(unsigned int target_frame, unsigned int source_frame);
+
+ /* Compute the transform based on the list of frames */
+ NEWMAT::Matrix computeTransformFromList(TransformLists list, unsigned long long time);
+
+};
+#endif //LIBTF_HH
Deleted: pkg/trunk/libTF/src/simple/Quaternion3D.hh
===================================================================
--- pkg/trunk/libTF/src/simple/Quaternion3D.hh 2008-04-22 20:29:25 UTC (rev 153)
+++ pkg/trunk/libTF/src/simple/Quaternion3D.hh 2008-04-22 20:31:08 UTC (rev 154)
@@ -1,174 +0,0 @@
-// Software License Agreement (BSD License)
-//
-// Copyright (c) 2008, Willow Garage, Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of the Willow Garage nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-// POSSIBILITY OF SUCH DAMAGE.
-//
-#ifndef QUATERNION3D_HH
-#define QUATERNION3D_HH
-
-#include <iostream>
-#include <newmat/newmat.h>
-#include <newmat/newmatio.h>
-#include <math.h>
-#include <pthread.h>
-#include <sys/time.h>
-class Euler3D {
-public:
- //Constructor
- Euler3D(double _x, double _y, double _z, double _yaw, double _pitch, double _roll);
-
- //Storage
- double x,y,z,yaw,pitch,roll;
-};
-
-
-class Quaternion3D {
-
-public:
- // Storage class
- class Quaternion3DStorage
- {
- public:
-
- /** Unary operators preserve timestamps
- * Binary operators destroy timestamps */
-
- // Utility functions to normalize and get magnitude.
- void Normalize();
- double getMagnitude();
- Quaternion3DStorage & operator=(const Quaternion3DStorage & input);
-
-
- /* accessors */
- NEWMAT::Matrix asMatrix();
-
- /* Internal Data */
- double xt, yt, zt, xr, yr, zr, w;
- unsigned long long time;
- };
-
- /** Constructors **/
- // Standard constructor
- Quaternion3D();
-
- /** Mutators **/
- // Set the values manually
- void fromQuaternion(double _xt, double _yt, double _zt, double _xr, double _yr, double _zr, double _w, unsigned long long time);
- //Set the values from a matrix
- void fromMatrix(const NEWMAT::Matrix& matIn, unsigned long long time);
- // Set the values using Euler angles
- void fromEuler(double _x, double _y, double _z, double _yaw, double _pitch, double _roll, unsigned long long time);
- // Set the values using DH Parameters
- void fromDH(double length, double alpha, double offset, double theta, unsigned long long time);
-
-
- /** Interpolated Accessors **/
- // Return a Quaternion
- Quaternion3D::Quaternion3DStorage getQuaternion(unsigned long long time);
- // Return a Matrix
- NEWMAT::Matrix getMatrix(unsigned long long time);
- // Return the inverse matrix
- NEWMAT::Matrix getInverseMatrix(unsigned long long time);
-
- /**** Utility Functions ****/
- // this is a function to return the current time in microseconds from the beginning of 1970
- static unsigned long long Qgettime(void);
-
- // Convert DH Parameters to a Homogeneous Transformation Matrix
- static NEWMAT::Matrix matrixFromDH(double length, double alpha, double offset, double theta);
- // Convert Euler Angles to a Homogeneous Transformation Matrix
- static NEWMAT::Matrix matrixFromEuler(double ax,
- double ay, double az, double yaw,
- double pitch, double roll);
-
- //Print as a matrix
- void printMatrix(unsigned long long time); //Not a critical part either
- void printStorage(const Quaternion3DStorage &storage); //Do i need this now that i've got the ostream method??
-
-
-private:
- /**** Linked List stuff ****/
- static const long long MAX_STORAGE_TIME = 1000000000; // max of 100 seconds storage
-
- struct data_LL{
- Quaternion3DStorage data;
- data_LL * next;
- data_LL * previous;
- };
-
- bool getValue(Quaternion3DStorage& buff, unsigned long long time, long long &time_diff);
- void add_value(const Quaternion3DStorage&);//todo fixme finish implementing this
-
-
-
- // insert a node into the sorted linked list
- void insertNode(const Quaternion3DStorage & );
- // prune data older than max_storage_time from the list
- void pruneList();
-
- //Find the closest two points in the list
- //Return the distance to the closest one
- int findClosest(Quaternion3DStorage& one, Quaternion3DStorage& two, const unsigned long long target_time, long long &time_diff);
-
- //Interpolate between two nodes and return the interpolated value
- // This must always take two valid points!!!!!!
- // Only Cpose version implemented
- void interpolate(const Quaternion3DStorage &one, const Quaternion3DStorage &two, const unsigned long long target_time, Quaternion3DStorage& output);
-
- //Used by interpolate to interpolate between double values
- double interpolateDouble(const double, const unsigned long long, const double, const unsigned long long, const unsigned long long);
-
- //How long to cache incoming values
- unsigned long long max_storage_time;
-
- //A mutex to prevent linked list collisions
- pthread_mutex_t linked_list_mutex;
-
- //Pointers for the start and end of a sorted linked list.
- data_LL* first;
- data_LL* last;
-
-
-
-};
-
-
-
-//A global ostream overload for displaying storage
-std::ostream & operator<<(std::ostream& mystream,const Quaternion3D::Quaternion3DStorage & storage);
-
-
-
-
-
-
-
-
-#endif //QUATERNION3D_HH
Deleted: pkg/trunk/libTF/src/simple/libTF.hh
===================================================================
--- pkg/trunk/libTF/src/simple/libTF.hh 2008-04-22 20:29:25 UTC (rev 153)
+++ pkg/trunk/libTF/src/simple/libTF.hh 2008-04-22 20:31:08 UTC (rev 154)
@@ -1,172 +0,0 @@
-//Software License Agreement (BSD License)
-
-//Copyright (c) 2008, Willow Garage, Inc.
-//All rights reserved.
-
-//Redistribution and use in source and binary forms, with or without
-//modification, are permitted provided that the following conditions
-//are met:
-
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of the Willow Garage nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-
-//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-//COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-//POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef LIBTF_HH
-#define LIBTF_HH
-#include <iostream>
-#include <iomanip>
-#include <newmat/newmat.h>
-#include <newmat/newmatio.h>
-#include <math.h>
-#include <vector>
-#include <sstream>
-
-#include "Quaternion3D.hh"
-
-/** RefFrame *******
- * An instance of this class is created for each frame in the system.
- * This class natively handles the relationship between frames.
- *
- * The derived class Quaternion3D provides a buffered history of positions
- * with interpolation.
- */
-
-class RefFrame: public Quaternion3D
-{
-public:
-
- /* Constructor */
- RefFrame();
-
- /* Get the parent node */
- inline unsigned int getParent(){return parent;};
-
- /* Return tha parent node */
- inline void setParent(unsigned int parentID){parent = parentID;};
-private:
-
- /* Storage of the parent */
- unsigned int parent;
-
-};
-
-/*** Transform Reference ***********
- * This class provides a simple interface to allow recording and lookup of
- * relationships between arbitrary frames of the system.
- *
- * The positions of frames over time must be pushed in.
- *
- * It will provide interpolated positions out given a time argument.
- */
-
-class TransformReference
-{
-public:
- /************* Constants ***********************/
- static const unsigned int ROOT_FRAME = 1; //Hard Value for ROOT_FRAME
- static const unsigned int NO_PARENT = 0; //Value for NO_PARENT
-
- static const unsigned int MAX_NUM_FRAMES = 100; /* The maximum number of frames possible */
- static const unsigned int MAX_GRAPH_DEPTH = 100; /* The maximum number of times to descent before determining that graph has a loop. */
-
- /* Constructor */
- TransformReference();
-
- /********** Mutators **************/
- /* Set a new frame or update an old one. */
- /* Use Euler Angles. X forward, Y to the left, Z up, Yaw about Z, pitch about new Y, Roll about new X */
- void setWithEulers(unsigned int framid, unsigned int parentid, double x, double y, double z, double yaw, double pitch, double roll, unsigned long long time);
- /* Using DH Parameters */
- // Conventions from http://en.wikipedia.org/wiki/Robotics_conventions
- void setWithDH(unsigned int framid, unsigned int parentid, double length, double alpha, double offset, double theta, unsigned long long time);
- // Possible exceptions TransformReference::LookupException
-
- /*********** Accessors *************/
-
- /* Get the transform between two frames by frame ID. */
- NEWMAT::Matrix getMatrix(unsigned int target_frame, unsigned int source_frame, unsigned long long time);
- // Possible exceptions TransformReference::LookupException, TransformReference::ConnectivityException,
- // TransformReference::MaxDepthException
-
- /* Debugging function that will print to std::cout the transformation matrix */
- std::string viewChain(unsigned int target_frame, unsigned int source_frame);
- // Possible exceptions TransformReference::LookupException, TransformReference::ConnectivityException,
- // TransformReference::MaxDepthException
-
-
-
-
-
-
- /************ Possible Exceptions ****************************/
-
- /* An exception class to notify of bad frame number */
- class LookupException : public std::exception
- {
- public:
- virtual const char* what() const throw() { return "InvalidFrame"; }
- } InvalidFrame;
-
- /* An exception class to notify of no connection */
- class ConnectivityException : public std::exception
- {
- public:
- virtual const char* what() const throw() { return "No connection between frames"; }
- private:
- } NoFrameConnectivity;
-
- /* An exception class to notify that the search for connectivity descended too deep. */
- class MaxDepthException : public std::exception
- {
- public:
- virtual const char* what() const throw() { return "Search exceeded max depth. Probably a loop in the tree."; }
- private:
- } MaxSearchDepth;
-
-private:
- /******************** Internal Storage ****************/
-
- /* The pointers to potential frames that the tree can be made of.
- * The frames will be dynamically allocated at run time when set the first time. */
- RefFrame* frames[MAX_NUM_FRAMES];
-
-
- /* This struct is how the list of transforms are stored before being passed to computeTransformFromList. */
- typedef struct
- {
- std::vector<unsigned int> inverseTransforms;
- std::vector<unsigned int> forwardTransforms;
- } TransformLists;
-
- /************************* Internal Functions ****************************/
-
- /* An accessor to get a frame, which will throw an exception if the frame is no there. */
- inline RefFrame* getFrame(unsigned int frame_number) { if (frames[frame_number] == NULL) throw InvalidFrame; else return frames[frame_number];};
-
- /* Find the list of connected frames necessary to connect two different frames */
- TransformLists lookUpList(unsigned int target_frame, unsigned int source_frame);
-
- /* Compute the transform based on the list of frames */
- NEWMAT::Matrix computeTransformFromList(TransformLists list, unsigned long long time);
-
-};
-#endif //LIBTF_HH
Deleted: pkg/trunk/libTF/src/simple/main.cc
===================================================================
--- pkg/trunk/libTF/src/simple/main.cc 2008-04-22 20:29:25 UTC (rev 153)
+++ pkg/trunk/libTF/src/simple/main.cc 2008-04-22 20:31:08 UTC (rev 154)
@@ -1,84 +0,0 @@
-#include "Quaternion3D.hh"
-#include "libTF.hh"
-#include <time.h>
-
-using namespace std;
-
-int main(void)
-{
- double dx,dy,dz,dyaw,dp,dr;
- TransformReference mTR;
-
-
-
- dx = dy= dz = 0;
- dyaw = dp = dr = 0.1;
-
- unsigned long long atime = Quaternion3D::Qgettime();
-
-
- //Fill in some transforms
- // mTR.setWithEulers(10,2,1,1,1,dyaw,dp,dr,atime); //Switching out for DH params below
- mTR.setWithDH(10,2,1.0,1.0,1.0,dyaw,atime);
- //mTR.setWithEulers(2,3,1-1,1,1,dyaw,dp,dr,atime-1000);
- mTR.setWithEulers(2,3,1,1,1,dyaw,dp,dr,atime-100);
- mTR.setWithEulers(2,3,1,1,1,dyaw,dp,dr,atime-50);
- mTR.setWithEulers(2,3,1,1,1,dyaw,dp,dr,atime-1000);
- //mTR.setWithEulers(2,3,1+1,1,1,dyaw,dp,dr,atime+1000);
- mTR.setWithEulers(3,5,dx,dy,dz,dyaw,dp,dr,atime);
- mTR.setWithEulers(5,1,dx,dy,dz,dyaw,dp,dr,atime);
- mTR.setWithEulers(6,5,dx,dy,dz,dyaw,dp,dr,atime);
- mTR.setWithEulers(7,6,1,1,1,dyaw,dp,dr,atime);
- mTR.setWithDH(8,7,1.0,1.0,1.0,dyaw,atime);
- //mTR.setWithEulers(8,7,1,1,1,dyaw,dp,dr,atime); //Switching out for DH params above
-
-
- //Demonstrate InvalidFrame LookupException
- try
- {
- std::cout<< mTR.viewChain(10,9);
- }
- catch (TransformReference::LookupException &ex)
- {
- std::cout << "Caught " << ex.what()<<std::endl;
- }
-
-
- // See the list of transforms to get between the frames
- std::cout<<"Viewing (10,8):"<<std::endl;
- std::cout << mTR.viewChain(10,8);
-
-
- //See the resultant transform
- std::cout <<"Calling getMatrix(10,8)"<<std::endl;
- // NEWMAT::Matrix mat = mTR.getMatrix(1,1);
- NEWMAT::Matrix mat = mTR.getMatrix(10,8,atime);
-
- std::cout << "Result of getMatrix(10,8,atime):" << std::endl << mat<< std::endl;
-
-
-
- //Break the graph, making it loop and demonstrate catching MaxDepthException
- mTR.setWithEulers(6,7,dx,dy,dz,dyaw,dp,dr,atime);
-
- try {
- std::cout<<mTR.viewChain(10,8);
- }
- catch (TransformReference::MaxDepthException &ex)
- {
- std::cout <<"caught loop in graph"<<std::endl;
- }
-
- //Break the graph, making it disconnected, and demonstrate catching ConnectivityException
- mTR.setWithEulers(6,0,dx,dy,dz,dyaw,dp,dr,atime);
-
- try {
- std::cout<<mTR.viewChain(10,8);
- }
- catch (TransformReference::ConnectivityException &ex)
- {
- std::cout <<"caught unconnected frame"...
[truncated message content] |
|
From: <jl...@us...> - 2008-04-22 20:48:52
|
Revision: 155
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=155&view=rev
Author: jleibs
Date: 2008-04-22 13:43:16 -0700 (Tue, 22 Apr 2008)
Log Message:
-----------
Had to switch extension to .cpp to make rosbuild happy.
Modified Paths:
--------------
pkg/trunk/libTF/src/simple/Makefile
Added Paths:
-----------
pkg/trunk/libTF/lib/
pkg/trunk/libTF/src/simple/Quaternion3D.cpp
pkg/trunk/libTF/src/simple/libTF.cpp
pkg/trunk/libTF/src/test/Makefile
pkg/trunk/libTF/src/test/main.cpp
Removed Paths:
-------------
pkg/trunk/libTF/src/simple/Quaternion3D.cc
pkg/trunk/libTF/src/simple/libTF.cc
pkg/trunk/libTF/src/test/main.cc
Modified: pkg/trunk/libTF/src/simple/Makefile
===================================================================
--- pkg/trunk/libTF/src/simple/Makefile 2008-04-22 20:31:08 UTC (rev 154)
+++ pkg/trunk/libTF/src/simple/Makefile 2008-04-22 20:43:16 UTC (rev 155)
@@ -1,18 +1,4 @@
-.PHONY=all clean test
-
-
-all: test
-
-#%.o:%.cc
-
-#%.o:%.hh
-
-quat: testQuat.cc Quaternion3D.o
- g++ -g -O2 $^ -o quat -lnewmat
-
-test: main.cc libTF.o Quaternion3D.o
- g++ -g -O2 $^ -o test -lnewmat
-
-
-clean:
- rm -rf *~ test *.o
\ No newline at end of file
+SRC = libTF.cpp Quaternion3D.cpp
+OUT = ../../lib/libTF.a
+PKG = libTF
+include $(shell $(ROS_ROOT)/rospack find roscpp)/make_include/lib.mk
\ No newline at end of file
Deleted: pkg/trunk/libTF/src/simple/Quaternion3D.cc
===================================================================
--- pkg/trunk/libTF/src/simple/Quaternion3D.cc 2008-04-22 20:31:08 UTC (rev 154)
+++ pkg/trunk/libTF/src/simple/Quaternion3D.cc 2008-04-22 20:43:16 UTC (rev 155)
@@ -1,561 +0,0 @@
-// Software License Agreement (BSD License)
-//
-// Copyright (c) 2008, Willow Garage, Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of the Willow Garage nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-// POSSIBILITY OF SUCH DAMAGE.
-//
-#include "Quaternion3D.hh"
-
-Euler3D::Euler3D(double _x, double _y, double _z, double _yaw, double _pitch, double _roll) :
- x(_x),y(_y),z(_z),yaw(_yaw),pitch(_pitch),roll(_roll)
-{
- return;
-};
-
-
-Quaternion3D::Quaternion3D():
- max_storage_time(MAX_STORAGE_TIME),
- first(NULL),
- last(NULL)
-{
-
- pthread_mutex_init( &linked_list_mutex, NULL);
- //fixme Normalize();
- return;
-};
-
-void Quaternion3D::fromQuaternion(double _xt, double _yt, double _zt, double _xr, double _yr, double _zr, double _w, unsigned long long time)
-{
- Quaternion3DStorage temp;
- temp.xt = _xt; temp.yt = _yt; temp.zt = _zt; temp.xr = _xr; temp.yr = _yr; temp.zr = _zr; temp.w = _w; temp.time = time;
-
- add_value(temp);
-
-} ;
-
-
-void Quaternion3D::fromMatrix(const NEWMAT::Matrix& matIn, unsigned long long time)
-{
- // math derived from http://www.j3d.org/matrix_faq/matrfaq_latest.html
- Quaternion3DStorage temp;
- temp.time = time;
-
- const double * mat = matIn.Store();
- //Get the translations
- temp.xt = mat[3];
- temp.yt = mat[7];
- temp.zt = mat[11];
-
- //TODO ASSERT others are zero and one as they should be
-
-
- double T = 1 + mat[0] + mat[5] + mat[10];
-
-
- // If the trace of the matrix is greater than zero, then
- // perform an "instant" calculation.
- // Important note wrt. rouning errors:
-
- if ( T > 0.00000001 ) //to avoid large distortions!
- {
- double S = sqrt(T) * 2;
- temp.xr = ( mat[9] - mat[6] ) / S;
- temp.yr = ( mat[2] - mat[8] ) / S;
- temp.zr = ( mat[4] - mat[1] ) / S;
- temp.w = 0.25 * S;
- }
- //If the trace of the matrix is equal to zero then identify
- // which major diagonal element has the greatest value.
- // Depending on this, calculate the following:
-
- if ( mat[0] > mat[5] && mat[0] > mat[10] ) {// Column 0:
- double S = sqrt( 1.0 + mat[0] - mat[5] - mat[10] ) * 2;
- temp.xr = 0.25 * S;
- temp.yr = (mat[1] + mat[4] ) / S;
- temp.zr = (mat[8] + mat[2] ) / S;
- temp.w = (mat[6] - mat[9] ) / S;
- } else if ( mat[5] > mat[10] ) {// Column 1:
- double S = sqrt( 1.0 + mat[5] - mat[0] - mat[10] ) * 2;
- temp.xr = (mat[1] + mat[4] ) / S;
- temp.yr = 0.25 * S;
- temp.zr = (mat[6] + mat[9] ) / S;
- temp.w = (mat[8] - mat[2] ) / S;
- } else {// Column 2:
- double S = sqrt( 1.0 + mat[10] - mat[0] - mat[5] ) * 2;
- temp.xr = (mat[8] + mat[2] ) / S;
- temp.yr = (mat[6] + mat[9] ) / S;
- temp.zr = 0.25 * S;
- temp.w = (mat[1] - mat[4] ) / S;
- }
- add_value(temp);
-};
-
-void Quaternion3D::fromEuler(double _x, double _y, double _z, double _yaw, double _pitch, double _roll, unsigned long long time)
-{
- fromMatrix(matrixFromEuler(_x,_y,_z,_yaw,_pitch,_roll),time);
-};
-
-void Quaternion3D::fromDH(double length, double alpha, double offset, double theta, unsigned long long time)
-{
- fromMatrix(matrixFromDH(length, alpha, offset, theta),time);
-};
-
-
-NEWMAT::Matrix Quaternion3D::matrixFromEuler(double ax,
- double ay, double az, double yaw,
- double pitch, double roll)
-{
- NEWMAT::Matrix matrix(4,4);
- double ca = cos(yaw);
- double sa = sin(yaw);
- double cb = cos(pitch);
- double sb = sin(pitch);
- double cg = cos(roll);
- double sg = sin(roll);
- double sbsg = sb*sg;
- double sbcg = sb*cg;
-
-
- double* matrix_pointer = matrix.Store();
-
- matrix_pointer[0] = ca*cb;
- matrix_pointer[1] = (ca*sbsg)-(sa*cg);
- matrix_pointer[2] = (ca*sbcg)+(sa*sg);
- matrix_pointer[3] = ax;
- matrix_pointer[4] = sa*cb;
- matrix_pointer[5] = (sa*sbsg)+(ca*cg);
- matrix_pointer[6] = (sa*sbcg)-(ca*sg);
- matrix_pointer[7] = ay;
- matrix_pointer[8] = -sb;
- matrix_pointer[9] = cb*sg;
- matrix_pointer[10] = cb*cg;
- matrix_pointer[11] = az;
- matrix_pointer[12] = 0.0;
- matrix_pointer[13] = 0.0;
- matrix_pointer[14] = 0.0;
- matrix_pointer[15] = 1.0;
-
- return matrix;
-};
-
-
-// Math from http://en.wikipedia.org/wiki/Robotics_conventions
-NEWMAT::Matrix Quaternion3D::matrixFromDH(double length,
- double alpha, double offset, double theta)
-{
- NEWMAT::Matrix matrix(4,4);
-
- double ca = cos(alpha);
- double sa = sin(alpha);
- double ct = cos(theta);
- double st = sin(theta);
-
- double* matrix_pointer = matrix.Store();
-
- matrix_pointer[0] = ct;
- matrix_pointer[1] = -st*ca;
- matrix_pointer[2] = st*sa;
- matrix_pointer[3] = length * ct;
- matrix_pointer[4] = st;
- matrix_pointer[5] = ct*ca;
- matrix_pointer[6] = -ct*sa;
- matrix_pointer[7] = length*st;
- matrix_pointer[8] = 0;
- matrix_pointer[9] = sa;
- matrix_pointer[10] = ca;
- matrix_pointer[11] = offset;
- matrix_pointer[12] = 0.0;
- matrix_pointer[13] = 0.0;
- matrix_pointer[14] = 0.0;
- matrix_pointer[15] = 1.0;
-
- return matrix;
-};
-
-
-Quaternion3D::Quaternion3DStorage& Quaternion3D::Quaternion3DStorage::operator=(const Quaternion3DStorage & input)
-{
- xt = input.xt;
- yt = input.yt;
- zt = input.zt;
- xr = input.xr;
- yr = input.yr;
- zr = input.zr;
- w = input.w ;
- time = input.time;
-
- return *this;
-};
-
-
-
-void Quaternion3D::Quaternion3DStorage::Normalize()
-{
- double mag = getMagnitude();
- xr /= mag;
- yr /= mag;
- zr /= mag;
- w /= mag;
-};
-
-double Quaternion3D::Quaternion3DStorage::getMagnitude()
-{
- return sqrt(xr*xr + yr*yr + zr*zr + w*w);
-};
-
-//Note global scope
-std::ostream & operator<<(std::ostream& mystream, const Quaternion3D::Quaternion3DStorage& storage)
-{
-
- mystream << "Storage: " << storage.xt <<", " << storage.yt <<", " << storage.zt<<", " << storage.xr<<", " << storage.yr <<", " << storage.zr <<", " << storage.w<<std::endl;
- return mystream;
-};
-
-Quaternion3D::Quaternion3DStorage Quaternion3D::getQuaternion(unsigned long long time)
-{
- Quaternion3DStorage temp;
- long long diff_time; //todo Find a way to use this offset. pass storage by reference and return diff_time??
- getValue(temp, time, diff_time);
- return temp;
-};
-
-
-NEWMAT::Matrix Quaternion3D::getMatrix(unsigned long long time)
-{
- Quaternion3DStorage temp;
- long long diff_time;
- getValue(temp, time, diff_time);
-
- std::cout << temp;
- // printStorage(temp);
- // std::cout <<"Locally: "<< xt <<", "<< yt <<", "<< zt <<", "<< xr <<", "<<yr <<", "<<zr <<", "<<w<<std::endl;
- //std::cout << "time Difference: "<< diff_time<<std::endl;
-
- return temp.asMatrix();
-}
-
-NEWMAT::Matrix Quaternion3D::getInverseMatrix(unsigned long long time)
-{
- return getMatrix(time).i();
-
-};
-
-NEWMAT::Matrix Quaternion3D::Quaternion3DStorage::asMatrix()
-{
-
- NEWMAT::Matrix outMat(4,4);
-
- double * mat = outMat.Store();
-
- // math derived from http://www.j3d.org/matrix_faq/matrfaq_latest.html
- double xx = xr * xr;
- double xy = xr * yr;
- double xz = xr * zr;
- double xw = xr * w;
- double yy = yr * yr;
- double yz = yr * zr;
- double yw = yr * w;
- double zz = zr * zr;
- double zw = zr * w;
- mat[0] = 1 - 2 * ( yy + zz );
- mat[4] = 2 * ( xy - zw );
- mat[8] = 2 * ( xz + yw );
- mat[1] = 2 * ( xy + zw );
- mat[5] = 1 - 2 * ( xx + zz );
- mat[9] = 2 * ( yz - xw );
- mat[2] = 2 * ( xz - yw );
- mat[6] = 2 * ( yz + xw );
- mat[10] = 1 - 2 * ( xx + yy );
- mat[12] = mat[13] = mat[14] = 0;
- mat[3] = xt;
- mat[7] = yt;
- mat[11] = zt;
- mat[15] = 1;
-
-
- return outMat;
-};
-
-
-void Quaternion3D::printMatrix(unsigned long long time)
-{
- std::cout << getMatrix(time);
-};
-
-void Quaternion3D::printStorage(const Quaternion3DStorage& storage)
-{
- std::cout << storage;
-};
-
-
-unsigned long long Quaternion3D::Qgettime()
-{
- timeval temp_time_struct;
- gettimeofday(&temp_time_struct,NULL);
- return temp_time_struct.tv_sec * 1000000ULL + (unsigned long long)temp_time_struct.tv_usec;
-}
-
-
-bool Quaternion3D::getValue(Quaternion3DStorage& buff, unsigned long long time, long long &time_diff)
-{
- Quaternion3DStorage p_temp_1;
- Quaternion3DStorage p_temp_2;
- // long long temp_time;
- int num_nodes;
-
- bool retval = false;
-
- pthread_mutex_lock(&linked_list_mutex);
- num_nodes = findClosest(p_temp_1,p_temp_2, time, time_diff);
-
- if (num_nodes == 0)
- retval= false;
- else if (num_nodes == 1)
- {
- memcpy(&buff, &p_temp_1, sizeof(Quaternion3DStorage));
- retval = true;
- }
- else
- {
- interpolate(p_temp_1, p_temp_2, time, buff);
- retval = true;
- }
-
- pthread_mutex_unlock(&linked_list_mutex);
-
-
- return retval;
-
-};
-
-void Quaternion3D::add_value(const Quaternion3DStorage &dataIn)
-{
- pthread_mutex_lock(&linked_list_mutex);
- insertNode(dataIn);
- pruneList();
- pthread_mutex_unlock(&linked_list_mutex);
-};
-
-
-void Quaternion3D::insertNode(const Quaternion3DStorage & new_val)
-{
- data_LL* p_current;
- data_LL* p_old;
-
- // cout << "Inserting Node" << endl;
-
- //Base case empty list
- if (first == NULL)
- {
- //cout << "Base case" << endl;
- first = new data_LL;
- first->data = new_val;
- first->next = NULL;
- first->previous = NULL;
- last = first;
- }
- else
- {
- //Increment through until at the end of the list or in the right spot
- p_current = first;
- while (p_current != NULL && first->data.time > new_val.time)
- {
- //cout << "passed beyond " << p_current->data.time << endl;
- p_current = p_current->next;
- }
-
- //THis means we hit the end of the list so just append the node
- if (p_current == NULL)
- {
- //cout << "Appending node to the end" << endl;
- p_current = new data_LL;
- p_current->data = new_val;
- p_current->previous = last;
- p_current->next = NULL;
-
- last = p_current;
- }
- else
- {
-
- // cout << "Found a place to put data into the list" << endl;
-
- // Insert the new node
- // Record where the old first node was
- p_old = p_current;
- //Fill in the new node
- p_current = new data_LL;
- p_current->data = new_val;
- p_current->next = p_old;
- p_current->previous = p_old->previous;
-
- //point the old to the new
- p_old->previous = p_current;
-
- //If at the top of the list make sure we're not
- if (p_current->previous == NULL)
- first = p_current;
- }
-
-
-
- }
-};
-
-void Quaternion3D::pruneList()
-{
- unsigned long long current_time = Qgettime();
- data_LL* p_current = last;
-
- // cout << "Pruning List" << endl;
-
- //Empty Set
- if (last == NULL) return;
-
- //While time stamps too old
- while (p_current->data.time + max_storage_time < current_time)
- {
- // cout << "Age of node " << (double)(-p_current->data.time + current_time)/1000000.0 << endl;
- // Make sure that there's at least two elements in the list
- if (p_current->previous != NULL)
- {
- if (p_current->previous->previous != NULL)
- {
- // Remove the last node
- p_current->previous->next = NULL;
- last = p_current->previous;
- delete p_current;
- p_current = last;
- // cout << " Pruning Node" << endl;
- }
- else
- break;
- }
- else
- break;
-
- }
-
-};
-
-
-
-int Quaternion3D::findClosest(Quaternion3DStorage& one, Quaternion3DStorage& two, const unsigned long long target_time, long long &time_diff)
-{
-
- data_LL* p_current = first;
-
-
- // Base case no list
- if (first == NULL)
- {
- return 0;
- }
-
- //Case one element list
- else if (first->next == NULL)
- {
- one = first->data;
- time_diff = target_time - first->data.time;
- return 1;
- }
-
- else
- {
- //Two or more elements
- //Find the one that just exceeds the time or hits the end
- //and then take the previous one
- p_current = first->next; //Start on the 2nd element so if we fail we fall back to the first one
- while (p_current->next != NULL && p_current->data.time > target_time)
- {
- p_current = p_current->next;
- }
-
- one = p_current->data;
- two = p_current->previous->data;
-
- //FIXME this should be the min distance not just one random one.
- time_diff = target_time - two.time;
- return 2;
- }
-};
-
-// Quaternion slerp algorithm from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/index.htm
-void Quaternion3D::interpolate(const Quaternion3DStorage &one, const Quaternion3DStorage &two,unsigned long long target_time, Quaternion3DStorage& output)
-{
- output.time = target_time;
-
- // Calculate the ration of time betwen target and the two end points.
- long long total_diff = two.time - one.time;
- long long target_diff = target_time - one.time;
- double t = (double)target_diff / (double) total_diff; //ratio between first and 2nd position interms of time
-
- // Interpolate the translation
- output.xt = one.xt + t * (two.xt - one.xt);
- output.yt = one.yt + t * (two.yt - one.yt);
- output.zt = one.zt + t * (two.zt - one.zt);
-
- // Calculate angle between them.
- double cosHalfTheta = one.w * two.w + one.xr * two.xr + one.yr * two.yr + one.zr * two.zr;
- // if qa=qb or qa=-qb then theta = 0 and we can return qa
- if (cosHalfTheta >= 1.0 || cosHalfTheta <= -1.0){
- output.w = one.w;output.xr = one.xr;output.yr = one.yr;output.zr = one.zr;
- return;
- }
- // Calculate temporary values.
- double halfTheta = acos(cosHalfTheta);
- double sinHalfTheta = sqrt(1.0 - cosHalfTheta*cosHalfTheta);
- // if theta = 180 degrees then result is not fully defined
- // we could rotate around any axis normal to qa or qb
- if (fabs(sinHalfTheta) < 0.001){ // fabs is floating point absolute
- output.w = (one.w * 0.5 + two.w * 0.5);
- output.xr = (one.xr * 0.5 + two.xr * 0.5);
- output.yr = (one.yr * 0.5 + two.yr * 0.5);
- output.zr = (one.zr * 0.5 + two.zr * 0.5);
- return;
- }
-
- double ratioA = sin((1 - t) * halfTheta) / sinHalfTheta;
- double ratioB = sin(t * halfTheta) / sinHalfTheta;
- //calculate Quaternion.
- output.w = (one.w * ratioA + two.w * ratioB);
- output.xr = (one.xr * ratioA + two.xr * ratioB);
- output.yr = (one.yr * ratioA + two.yr * ratioB);
- output.zr = (one.zr * ratioA + two.zr * ratioB);
- return;
-};
-
-double Quaternion3D::interpolateDouble(const double first, const unsigned long long first_time, const double second, const unsigned long long second_time, const unsigned long long target_time)
-{
- if ( first_time == second_time ) {
- return first;
- } else {
- return first + (second-first)* (double)((target_time - first_time)/(second_time - first_time));
- }
-};
Copied: pkg/trunk/libTF/src/simple/Quaternion3D.cpp (from rev 153, pkg/trunk/libTF/src/simple/Quaternion3D.cc)
===================================================================
--- pkg/trunk/libTF/src/simple/Quaternion3D.cpp (rev 0)
+++ pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-22 20:43:16 UTC (rev 155)
@@ -0,0 +1,561 @@
+// Software License Agreement (BSD License)
+//
+// Copyright (c) 2008, Willow Garage, Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of the Willow Garage nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+// POSSIBILITY OF SUCH DAMAGE.
+//
+#include "libTF/Quaternion3D.hh"
+
+Euler3D::Euler3D(double _x, double _y, double _z, double _yaw, double _pitch, double _roll) :
+ x(_x),y(_y),z(_z),yaw(_yaw),pitch(_pitch),roll(_roll)
+{
+ return;
+};
+
+
+Quaternion3D::Quaternion3D():
+ max_storage_time(MAX_STORAGE_TIME),
+ first(NULL),
+ last(NULL)
+{
+
+ pthread_mutex_init( &linked_list_mutex, NULL);
+ //fixme Normalize();
+ return;
+};
+
+void Quaternion3D::fromQuaternion(double _xt, double _yt, double _zt, double _xr, double _yr, double _zr, double _w, unsigned long long time)
+{
+ Quaternion3DStorage temp;
+ temp.xt = _xt; temp.yt = _yt; temp.zt = _zt; temp.xr = _xr; temp.yr = _yr; temp.zr = _zr; temp.w = _w; temp.time = time;
+
+ add_value(temp);
+
+} ;
+
+
+void Quaternion3D::fromMatrix(const NEWMAT::Matrix& matIn, unsigned long long time)
+{
+ // math derived from http://www.j3d.org/matrix_faq/matrfaq_latest.html
+ Quaternion3DStorage temp;
+ temp.time = time;
+
+ const double * mat = matIn.Store();
+ //Get the translations
+ temp.xt = mat[3];
+ temp.yt = mat[7];
+ temp.zt = mat[11];
+
+ //TODO ASSERT others are zero and one as they should be
+
+
+ double T = 1 + mat[0] + mat[5] + mat[10];
+
+
+ // If the trace of the matrix is greater than zero, then
+ // perform an "instant" calculation.
+ // Important note wrt. rouning errors:
+
+ if ( T > 0.00000001 ) //to avoid large distortions!
+ {
+ double S = sqrt(T) * 2;
+ temp.xr = ( mat[9] - mat[6] ) / S;
+ temp.yr = ( mat[2] - mat[8] ) / S;
+ temp.zr = ( mat[4] - mat[1] ) / S;
+ temp.w = 0.25 * S;
+ }
+ //If the trace of the matrix is equal to zero then identify
+ // which major diagonal element has the greatest value.
+ // Depending on this, calculate the following:
+
+ if ( mat[0] > mat[5] && mat[0] > mat[10] ) {// Column 0:
+ double S = sqrt( 1.0 + mat[0] - mat[5] - mat[10] ) * 2;
+ temp.xr = 0.25 * S;
+ temp.yr = (mat[1] + mat[4] ) / S;
+ temp.zr = (mat[8] + mat[2] ) / S;
+ temp.w = (mat[6] - mat[9] ) / S;
+ } else if ( mat[5] > mat[10] ) {// Column 1:
+ double S = sqrt( 1.0 + mat[5] - mat[0] - mat[10] ) * 2;
+ temp.xr = (mat[1] + mat[4] ) / S;
+ temp.yr = 0.25 * S;
+ temp.zr = (mat[6] + mat[9] ) / S;
+ temp.w = (mat[8] - mat[2] ) / S;
+ } else {// Column 2:
+ double S = sqrt( 1.0 + mat[10] - mat[0] - mat[5] ) * 2;
+ temp.xr = (mat[8] + mat[2] ) / S;
+ temp.yr = (mat[6] + mat[9] ) / S;
+ temp.zr = 0.25 * S;
+ temp.w = (mat[1] - mat[4] ) / S;
+ }
+ add_value(temp);
+};
+
+void Quaternion3D::fromEuler(double _x, double _y, double _z, double _yaw, double _pitch, double _roll, unsigned long long time)
+{
+ fromMatrix(matrixFromEuler(_x,_y,_z,_yaw,_pitch,_roll),time);
+};
+
+void Quaternion3D::fromDH(double length, double alpha, double offset, double theta, unsigned long long time)
+{
+ fromMatrix(matrixFromDH(length, alpha, offset, theta),time);
+};
+
+
+NEWMAT::Matrix Quaternion3D::matrixFromEuler(double ax,
+ double ay, double az, double yaw,
+ double pitch, double roll)
+{
+ NEWMAT::Matrix matrix(4,4);
+ double ca = cos(yaw);
+ double sa = sin(yaw);
+ double cb = cos(pitch);
+ double sb = sin(pitch);
+ double cg = cos(roll);
+ double sg = sin(roll);
+ double sbsg = sb*sg;
+ double sbcg = sb*cg;
+
+
+ double* matrix_pointer = matrix.Store();
+
+ matrix_pointer[0] = ca*cb;
+ matrix_pointer[1] = (ca*sbsg)-(sa*cg);
+ matrix_pointer[2] = (ca*sbcg)+(sa*sg);
+ matrix_pointer[3] = ax;
+ matrix_pointer[4] = sa*cb;
+ matrix_pointer[5] = (sa*sbsg)+(ca*cg);
+ matrix_pointer[6] = (sa*sbcg)-(ca*sg);
+ matrix_pointer[7] = ay;
+ matrix_pointer[8] = -sb;
+ matrix_pointer[9] = cb*sg;
+ matrix_pointer[10] = cb*cg;
+ matrix_pointer[11] = az;
+ matrix_pointer[12] = 0.0;
+ matrix_pointer[13] = 0.0;
+ matrix_pointer[14] = 0.0;
+ matrix_pointer[15] = 1.0;
+
+ return matrix;
+};
+
+
+// Math from http://en.wikipedia.org/wiki/Robotics_conventions
+NEWMAT::Matrix Quaternion3D::matrixFromDH(double length,
+ double alpha, double offset, double theta)
+{
+ NEWMAT::Matrix matrix(4,4);
+
+ double ca = cos(alpha);
+ double sa = sin(alpha);
+ double ct = cos(theta);
+ double st = sin(theta);
+
+ double* matrix_pointer = matrix.Store();
+
+ matrix_pointer[0] = ct;
+ matrix_pointer[1] = -st*ca;
+ matrix_pointer[2] = st*sa;
+ matrix_pointer[3] = length * ct;
+ matrix_pointer[4] = st;
+ matrix_pointer[5] = ct*ca;
+ matrix_pointer[6] = -ct*sa;
+ matrix_pointer[7] = length*st;
+ matrix_pointer[8] = 0;
+ matrix_pointer[9] = sa;
+ matrix_pointer[10] = ca;
+ matrix_pointer[11] = offset;
+ matrix_pointer[12] = 0.0;
+ matrix_pointer[13] = 0.0;
+ matrix_pointer[14] = 0.0;
+ matrix_pointer[15] = 1.0;
+
+ return matrix;
+};
+
+
+Quaternion3D::Quaternion3DStorage& Quaternion3D::Quaternion3DStorage::operator=(const Quaternion3DStorage & input)
+{
+ xt = input.xt;
+ yt = input.yt;
+ zt = input.zt;
+ xr = input.xr;
+ yr = input.yr;
+ zr = input.zr;
+ w = input.w ;
+ time = input.time;
+
+ return *this;
+};
+
+
+
+void Quaternion3D::Quaternion3DStorage::Normalize()
+{
+ double mag = getMagnitude();
+ xr /= mag;
+ yr /= mag;
+ zr /= mag;
+ w /= mag;
+};
+
+double Quaternion3D::Quaternion3DStorage::getMagnitude()
+{
+ return sqrt(xr*xr + yr*yr + zr*zr + w*w);
+};
+
+//Note global scope
+std::ostream & operator<<(std::ostream& mystream, const Quaternion3D::Quaternion3DStorage& storage)
+{
+
+ mystream << "Storage: " << storage.xt <<", " << storage.yt <<", " << storage.zt<<", " << storage.xr<<", " << storage.yr <<", " << storage.zr <<", " << storage.w<<std::endl;
+ return mystream;
+};
+
+Quaternion3D::Quaternion3DStorage Quaternion3D::getQuaternion(unsigned long long time)
+{
+ Quaternion3DStorage temp;
+ long long diff_time; //todo Find a way to use this offset. pass storage by reference and return diff_time??
+ getValue(temp, time, diff_time);
+ return temp;
+};
+
+
+NEWMAT::Matrix Quaternion3D::getMatrix(unsigned long long time)
+{
+ Quaternion3DStorage temp;
+ long long diff_time;
+ getValue(temp, time, diff_time);
+
+ std::cout << temp;
+ // printStorage(temp);
+ // std::cout <<"Locally: "<< xt <<", "<< yt <<", "<< zt <<", "<< xr <<", "<<yr <<", "<<zr <<", "<<w<<std::endl;
+ //std::cout << "time Difference: "<< diff_time<<std::endl;
+
+ return temp.asMatrix();
+}
+
+NEWMAT::Matrix Quaternion3D::getInverseMatrix(unsigned long long time)
+{
+ return getMatrix(time).i();
+
+};
+
+NEWMAT::Matrix Quaternion3D::Quaternion3DStorage::asMatrix()
+{
+
+ NEWMAT::Matrix outMat(4,4);
+
+ double * mat = outMat.Store();
+
+ // math derived from http://www.j3d.org/matrix_faq/matrfaq_latest.html
+ double xx = xr * xr;
+ double xy = xr * yr;
+ double xz = xr * zr;
+ double xw = xr * w;
+ double yy = yr * yr;
+ double yz = yr * zr;
+ double yw = yr * w;
+ double zz = zr * zr;
+ double zw = zr * w;
+ mat[0] = 1 - 2 * ( yy + zz );
+ mat[4] = 2 * ( xy - zw );
+ mat[8] = 2 * ( xz + yw );
+ mat[1] = 2 * ( xy + zw );
+ mat[5] = 1 - 2 * ( xx + zz );
+ mat[9] = 2 * ( yz - xw );
+ mat[2] = 2 * ( xz - yw );
+ mat[6] = 2 * ( yz + xw );
+ mat[10] = 1 - 2 * ( xx + yy );
+ mat[12] = mat[13] = mat[14] = 0;
+ mat[3] = xt;
+ mat[7] = yt;
+ mat[11] = zt;
+ mat[15] = 1;
+
+
+ return outMat;
+};
+
+
+void Quaternion3D::printMatrix(unsigned long long time)
+{
+ std::cout << getMatrix(time);
+};
+
+void Quaternion3D::printStorage(const Quaternion3DStorage& storage)
+{
+ std::cout << storage;
+};
+
+
+unsigned long long Quaternion3D::Qgettime()
+{
+ timeval temp_time_struct;
+ gettimeofday(&temp_time_struct,NULL);
+ return temp_time_struct.tv_sec * 1000000ULL + (unsigned long long)temp_time_struct.tv_usec;
+}
+
+
+bool Quaternion3D::getValue(Quaternion3DStorage& buff, unsigned long long time, long long &time_diff)
+{
+ Quaternion3DStorage p_temp_1;
+ Quaternion3DStorage p_temp_2;
+ // long long temp_time;
+ int num_nodes;
+
+ bool retval = false;
+
+ pthread_mutex_lock(&linked_list_mutex);
+ num_nodes = findClosest(p_temp_1,p_temp_2, time, time_diff);
+
+ if (num_nodes == 0)
+ retval= false;
+ else if (num_nodes == 1)
+ {
+ memcpy(&buff, &p_temp_1, sizeof(Quaternion3DStorage));
+ retval = true;
+ }
+ else
+ {
+ interpolate(p_temp_1, p_temp_2, time, buff);
+ retval = true;
+ }
+
+ pthread_mutex_unlock(&linked_list_mutex);
+
+
+ return retval;
+
+};
+
+void Quaternion3D::add_value(const Quaternion3DStorage &dataIn)
+{
+ pthread_mutex_lock(&linked_list_mutex);
+ insertNode(dataIn);
+ pruneList();
+ pthread_mutex_unlock(&linked_list_mutex);
+};
+
+
+void Quaternion3D::insertNode(const Quaternion3DStorage & new_val)
+{
+ data_LL* p_current;
+ data_LL* p_old;
+
+ // cout << "Inserting Node" << endl;
+
+ //Base case empty list
+ if (first == NULL)
+ {
+ //cout << "Base case" << endl;
+ first = new data_LL;
+ first->data = new_val;
+ first->next = NULL;
+ first->previous = NULL;
+ last = first;
+ }
+ else
+ {
+ //Increment through until at the end of the list or in the right spot
+ p_current = first;
+ while (p_current != NULL && first->data.time > new_val.time)
+ {
+ //cout << "passed beyond " << p_current->data.time << endl;
+ p_current = p_current->next;
+ }
+
+ //THis means we hit the end of the list so just append the node
+ if (p_current == NULL)
+ {
+ //cout << "Appending node to the end" << endl;
+ p_current = new data_LL;
+ p_current->data = new_val;
+ p_current->previous = last;
+ p_current->next = NULL;
+
+ last = p_current;
+ }
+ else
+ {
+
+ // cout << "Found a place to put data into the list" << endl;
+
+ // Insert the new node
+ // Record where the old first node was
+ p_old = p_current;
+ //Fill in the new node
+ p_current = new data_LL;
+ p_current->data = new_val;
+ p_current->next = p_old;
+ p_current->previous = p_old->previous;
+
+ //point the old to the new
+ p_old->previous = p_current;
+
+ //If at t...
[truncated message content] |
|
From: <jl...@us...> - 2008-04-22 21:42:45
|
Revision: 156
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=156&view=rev
Author: jleibs
Date: 2008-04-22 14:42:52 -0700 (Tue, 22 Apr 2008)
Log Message:
-----------
Change from .hh to .h. Unclear if this is good convention, but we're going with it for now.
Modified Paths:
--------------
pkg/trunk/libTF/src/simple/Quaternion3D.cpp
pkg/trunk/libTF/src/simple/libTF.cpp
pkg/trunk/libTF/src/test/main.cpp
Added Paths:
-----------
pkg/trunk/libTF/include/libTF/Quaternion3D.h
pkg/trunk/libTF/include/libTF/libTF.h
Removed Paths:
-------------
pkg/trunk/libTF/include/libTF/Quaternion3D.hh
pkg/trunk/libTF/include/libTF/libTF.hh
Copied: pkg/trunk/libTF/include/libTF/Quaternion3D.h (from rev 154, pkg/trunk/libTF/include/libTF/Quaternion3D.hh)
===================================================================
--- pkg/trunk/libTF/include/libTF/Quaternion3D.h (rev 0)
+++ pkg/trunk/libTF/include/libTF/Quaternion3D.h 2008-04-22 21:42:52 UTC (rev 156)
@@ -0,0 +1,174 @@
+// Software License Agreement (BSD License)
+//
+// Copyright (c) 2008, Willow Garage, Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of the Willow Garage nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+// POSSIBILITY OF SUCH DAMAGE.
+//
+#ifndef QUATERNION3D_HH
+#define QUATERNION3D_HH
+
+#include <iostream>
+#include <newmat/newmat.h>
+#include <newmat/newmatio.h>
+#include <math.h>
+#include <pthread.h>
+#include <sys/time.h>
+class Euler3D {
+public:
+ //Constructor
+ Euler3D(double _x, double _y, double _z, double _yaw, double _pitch, double _roll);
+
+ //Storage
+ double x,y,z,yaw,pitch,roll;
+};
+
+
+class Quaternion3D {
+
+public:
+ // Storage class
+ class Quaternion3DStorage
+ {
+ public:
+
+ /** Unary operators preserve timestamps
+ * Binary operators destroy timestamps */
+
+ // Utility functions to normalize and get magnitude.
+ void Normalize();
+ double getMagnitude();
+ Quaternion3DStorage & operator=(const Quaternion3DStorage & input);
+
+
+ /* accessors */
+ NEWMAT::Matrix asMatrix();
+
+ /* Internal Data */
+ double xt, yt, zt, xr, yr, zr, w;
+ unsigned long long time;
+ };
+
+ /** Constructors **/
+ // Standard constructor
+ Quaternion3D();
+
+ /** Mutators **/
+ // Set the values manually
+ void fromQuaternion(double _xt, double _yt, double _zt, double _xr, double _yr, double _zr, double _w, unsigned long long time);
+ //Set the values from a matrix
+ void fromMatrix(const NEWMAT::Matrix& matIn, unsigned long long time);
+ // Set the values using Euler angles
+ void fromEuler(double _x, double _y, double _z, double _yaw, double _pitch, double _roll, unsigned long long time);
+ // Set the values using DH Parameters
+ void fromDH(double length, double alpha, double offset, double theta, unsigned long long time);
+
+
+ /** Interpolated Accessors **/
+ // Return a Quaternion
+ Quaternion3D::Quaternion3DStorage getQuaternion(unsigned long long time);
+ // Return a Matrix
+ NEWMAT::Matrix getMatrix(unsigned long long time);
+ // Return the inverse matrix
+ NEWMAT::Matrix getInverseMatrix(unsigned long long time);
+
+ /**** Utility Functions ****/
+ // this is a function to return the current time in microseconds from the beginning of 1970
+ static unsigned long long Qgettime(void);
+
+ // Convert DH Parameters to a Homogeneous Transformation Matrix
+ static NEWMAT::Matrix matrixFromDH(double length, double alpha, double offset, double theta);
+ // Convert Euler Angles to a Homogeneous Transformation Matrix
+ static NEWMAT::Matrix matrixFromEuler(double ax,
+ double ay, double az, double yaw,
+ double pitch, double roll);
+
+ //Print as a matrix
+ void printMatrix(unsigned long long time); //Not a critical part either
+ void printStorage(const Quaternion3DStorage &storage); //Do i need this now that i've got the ostream method??
+
+
+private:
+ /**** Linked List stuff ****/
+ static const long long MAX_STORAGE_TIME = 1000000000; // max of 100 seconds storage
+
+ struct data_LL{
+ Quaternion3DStorage data;
+ data_LL * next;
+ data_LL * previous;
+ };
+
+ bool getValue(Quaternion3DStorage& buff, unsigned long long time, long long &time_diff);
+ void add_value(const Quaternion3DStorage&);//todo fixme finish implementing this
+
+
+
+ // insert a node into the sorted linked list
+ void insertNode(const Quaternion3DStorage & );
+ // prune data older than max_storage_time from the list
+ void pruneList();
+
+ //Find the closest two points in the list
+ //Return the distance to the closest one
+ int findClosest(Quaternion3DStorage& one, Quaternion3DStorage& two, const unsigned long long target_time, long long &time_diff);
+
+ //Interpolate between two nodes and return the interpolated value
+ // This must always take two valid points!!!!!!
+ // Only Cpose version implemented
+ void interpolate(const Quaternion3DStorage &one, const Quaternion3DStorage &two, const unsigned long long target_time, Quaternion3DStorage& output);
+
+ //Used by interpolate to interpolate between double values
+ double interpolateDouble(const double, const unsigned long long, const double, const unsigned long long, const unsigned long long);
+
+ //How long to cache incoming values
+ unsigned long long max_storage_time;
+
+ //A mutex to prevent linked list collisions
+ pthread_mutex_t linked_list_mutex;
+
+ //Pointers for the start and end of a sorted linked list.
+ data_LL* first;
+ data_LL* last;
+
+
+
+};
+
+
+
+//A global ostream overload for displaying storage
+std::ostream & operator<<(std::ostream& mystream,const Quaternion3D::Quaternion3DStorage & storage);
+
+
+
+
+
+
+
+
+#endif //QUATERNION3D_HH
Deleted: pkg/trunk/libTF/include/libTF/Quaternion3D.hh
===================================================================
--- pkg/trunk/libTF/include/libTF/Quaternion3D.hh 2008-04-22 20:43:16 UTC (rev 155)
+++ pkg/trunk/libTF/include/libTF/Quaternion3D.hh 2008-04-22 21:42:52 UTC (rev 156)
@@ -1,174 +0,0 @@
-// Software License Agreement (BSD License)
-//
-// Copyright (c) 2008, Willow Garage, Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of the Willow Garage nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-// POSSIBILITY OF SUCH DAMAGE.
-//
-#ifndef QUATERNION3D_HH
-#define QUATERNION3D_HH
-
-#include <iostream>
-#include <newmat/newmat.h>
-#include <newmat/newmatio.h>
-#include <math.h>
-#include <pthread.h>
-#include <sys/time.h>
-class Euler3D {
-public:
- //Constructor
- Euler3D(double _x, double _y, double _z, double _yaw, double _pitch, double _roll);
-
- //Storage
- double x,y,z,yaw,pitch,roll;
-};
-
-
-class Quaternion3D {
-
-public:
- // Storage class
- class Quaternion3DStorage
- {
- public:
-
- /** Unary operators preserve timestamps
- * Binary operators destroy timestamps */
-
- // Utility functions to normalize and get magnitude.
- void Normalize();
- double getMagnitude();
- Quaternion3DStorage & operator=(const Quaternion3DStorage & input);
-
-
- /* accessors */
- NEWMAT::Matrix asMatrix();
-
- /* Internal Data */
- double xt, yt, zt, xr, yr, zr, w;
- unsigned long long time;
- };
-
- /** Constructors **/
- // Standard constructor
- Quaternion3D();
-
- /** Mutators **/
- // Set the values manually
- void fromQuaternion(double _xt, double _yt, double _zt, double _xr, double _yr, double _zr, double _w, unsigned long long time);
- //Set the values from a matrix
- void fromMatrix(const NEWMAT::Matrix& matIn, unsigned long long time);
- // Set the values using Euler angles
- void fromEuler(double _x, double _y, double _z, double _yaw, double _pitch, double _roll, unsigned long long time);
- // Set the values using DH Parameters
- void fromDH(double length, double alpha, double offset, double theta, unsigned long long time);
-
-
- /** Interpolated Accessors **/
- // Return a Quaternion
- Quaternion3D::Quaternion3DStorage getQuaternion(unsigned long long time);
- // Return a Matrix
- NEWMAT::Matrix getMatrix(unsigned long long time);
- // Return the inverse matrix
- NEWMAT::Matrix getInverseMatrix(unsigned long long time);
-
- /**** Utility Functions ****/
- // this is a function to return the current time in microseconds from the beginning of 1970
- static unsigned long long Qgettime(void);
-
- // Convert DH Parameters to a Homogeneous Transformation Matrix
- static NEWMAT::Matrix matrixFromDH(double length, double alpha, double offset, double theta);
- // Convert Euler Angles to a Homogeneous Transformation Matrix
- static NEWMAT::Matrix matrixFromEuler(double ax,
- double ay, double az, double yaw,
- double pitch, double roll);
-
- //Print as a matrix
- void printMatrix(unsigned long long time); //Not a critical part either
- void printStorage(const Quaternion3DStorage &storage); //Do i need this now that i've got the ostream method??
-
-
-private:
- /**** Linked List stuff ****/
- static const long long MAX_STORAGE_TIME = 1000000000; // max of 100 seconds storage
-
- struct data_LL{
- Quaternion3DStorage data;
- data_LL * next;
- data_LL * previous;
- };
-
- bool getValue(Quaternion3DStorage& buff, unsigned long long time, long long &time_diff);
- void add_value(const Quaternion3DStorage&);//todo fixme finish implementing this
-
-
-
- // insert a node into the sorted linked list
- void insertNode(const Quaternion3DStorage & );
- // prune data older than max_storage_time from the list
- void pruneList();
-
- //Find the closest two points in the list
- //Return the distance to the closest one
- int findClosest(Quaternion3DStorage& one, Quaternion3DStorage& two, const unsigned long long target_time, long long &time_diff);
-
- //Interpolate between two nodes and return the interpolated value
- // This must always take two valid points!!!!!!
- // Only Cpose version implemented
- void interpolate(const Quaternion3DStorage &one, const Quaternion3DStorage &two, const unsigned long long target_time, Quaternion3DStorage& output);
-
- //Used by interpolate to interpolate between double values
- double interpolateDouble(const double, const unsigned long long, const double, const unsigned long long, const unsigned long long);
-
- //How long to cache incoming values
- unsigned long long max_storage_time;
-
- //A mutex to prevent linked list collisions
- pthread_mutex_t linked_list_mutex;
-
- //Pointers for the start and end of a sorted linked list.
- data_LL* first;
- data_LL* last;
-
-
-
-};
-
-
-
-//A global ostream overload for displaying storage
-std::ostream & operator<<(std::ostream& mystream,const Quaternion3D::Quaternion3DStorage & storage);
-
-
-
-
-
-
-
-
-#endif //QUATERNION3D_HH
Copied: pkg/trunk/libTF/include/libTF/libTF.h (from rev 154, pkg/trunk/libTF/include/libTF/libTF.hh)
===================================================================
--- pkg/trunk/libTF/include/libTF/libTF.h (rev 0)
+++ pkg/trunk/libTF/include/libTF/libTF.h 2008-04-22 21:42:52 UTC (rev 156)
@@ -0,0 +1,172 @@
+//Software License Agreement (BSD License)
+
+//Copyright (c) 2008, Willow Garage, Inc.
+//All rights reserved.
+
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of the Willow Garage nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+//COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+//POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef LIBTF_HH
+#define LIBTF_HH
+#include <iostream>
+#include <iomanip>
+#include <newmat/newmat.h>
+#include <newmat/newmatio.h>
+#include <math.h>
+#include <vector>
+#include <sstream>
+
+#include "Quaternion3D.h"
+
+/** RefFrame *******
+ * An instance of this class is created for each frame in the system.
+ * This class natively handles the relationship between frames.
+ *
+ * The derived class Quaternion3D provides a buffered history of positions
+ * with interpolation.
+ */
+
+class RefFrame: public Quaternion3D
+{
+public:
+
+ /* Constructor */
+ RefFrame();
+
+ /* Get the parent node */
+ inline unsigned int getParent(){return parent;};
+
+ /* Return tha parent node */
+ inline void setParent(unsigned int parentID){parent = parentID;};
+private:
+
+ /* Storage of the parent */
+ unsigned int parent;
+
+};
+
+/*** Transform Reference ***********
+ * This class provides a simple interface to allow recording and lookup of
+ * relationships between arbitrary frames of the system.
+ *
+ * The positions of frames over time must be pushed in.
+ *
+ * It will provide interpolated positions out given a time argument.
+ */
+
+class TransformReference
+{
+public:
+ /************* Constants ***********************/
+ static const unsigned int ROOT_FRAME = 1; //Hard Value for ROOT_FRAME
+ static const unsigned int NO_PARENT = 0; //Value for NO_PARENT
+
+ static const unsigned int MAX_NUM_FRAMES = 100; /* The maximum number of frames possible */
+ static const unsigned int MAX_GRAPH_DEPTH = 100; /* The maximum number of times to descent before determining that graph has a loop. */
+
+ /* Constructor */
+ TransformReference();
+
+ /********** Mutators **************/
+ /* Set a new frame or update an old one. */
+ /* Use Euler Angles. X forward, Y to the left, Z up, Yaw about Z, pitch about new Y, Roll about new X */
+ void setWithEulers(unsigned int framid, unsigned int parentid, double x, double y, double z, double yaw, double pitch, double roll, unsigned long long time);
+ /* Using DH Parameters */
+ // Conventions from http://en.wikipedia.org/wiki/Robotics_conventions
+ void setWithDH(unsigned int framid, unsigned int parentid, double length, double alpha, double offset, double theta, unsigned long long time);
+ // Possible exceptions TransformReference::LookupException
+
+ /*********** Accessors *************/
+
+ /* Get the transform between two frames by frame ID. */
+ NEWMAT::Matrix getMatrix(unsigned int target_frame, unsigned int source_frame, unsigned long long time);
+ // Possible exceptions TransformReference::LookupException, TransformReference::ConnectivityException,
+ // TransformReference::MaxDepthException
+
+ /* Debugging function that will print to std::cout the transformation matrix */
+ std::string viewChain(unsigned int target_frame, unsigned int source_frame);
+ // Possible exceptions TransformReference::LookupException, TransformReference::ConnectivityException,
+ // TransformReference::MaxDepthException
+
+
+
+
+
+
+ /************ Possible Exceptions ****************************/
+
+ /* An exception class to notify of bad frame number */
+ class LookupException : public std::exception
+ {
+ public:
+ virtual const char* what() const throw() { return "InvalidFrame"; }
+ } InvalidFrame;
+
+ /* An exception class to notify of no connection */
+ class ConnectivityException : public std::exception
+ {
+ public:
+ virtual const char* what() const throw() { return "No connection between frames"; }
+ private:
+ } NoFrameConnectivity;
+
+ /* An exception class to notify that the search for connectivity descended too deep. */
+ class MaxDepthException : public std::exception
+ {
+ public:
+ virtual const char* what() const throw() { return "Search exceeded max depth. Probably a loop in the tree."; }
+ private:
+ } MaxSearchDepth;
+
+private:
+ /******************** Internal Storage ****************/
+
+ /* The pointers to potential frames that the tree can be made of.
+ * The frames will be dynamically allocated at run time when set the first time. */
+ RefFrame* frames[MAX_NUM_FRAMES];
+
+
+ /* This struct is how the list of transforms are stored before being passed to computeTransformFromList. */
+ typedef struct
+ {
+ std::vector<unsigned int> inverseTransforms;
+ std::vector<unsigned int> forwardTransforms;
+ } TransformLists;
+
+ /************************* Internal Functions ****************************/
+
+ /* An accessor to get a frame, which will throw an exception if the frame is no there. */
+ inline RefFrame* getFrame(unsigned int frame_number) { if (frames[frame_number] == NULL) throw InvalidFrame; else return frames[frame_number];};
+
+ /* Find the list of connected frames necessary to connect two different frames */
+ TransformLists lookUpList(unsigned int target_frame, unsigned int source_frame);
+
+ /* Compute the transform based on the list of frames */
+ NEWMAT::Matrix computeTransformFromList(TransformLists list, unsigned long long time);
+
+};
+#endif //LIBTF_HH
Deleted: pkg/trunk/libTF/include/libTF/libTF.hh
===================================================================
--- pkg/trunk/libTF/include/libTF/libTF.hh 2008-04-22 20:43:16 UTC (rev 155)
+++ pkg/trunk/libTF/include/libTF/libTF.hh 2008-04-22 21:42:52 UTC (rev 156)
@@ -1,172 +0,0 @@
-//Software License Agreement (BSD License)
-
-//Copyright (c) 2008, Willow Garage, Inc.
-//All rights reserved.
-
-//Redistribution and use in source and binary forms, with or without
-//modification, are permitted provided that the following conditions
-//are met:
-
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of the Willow Garage nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-
-//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-//COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-//POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef LIBTF_HH
-#define LIBTF_HH
-#include <iostream>
-#include <iomanip>
-#include <newmat/newmat.h>
-#include <newmat/newmatio.h>
-#include <math.h>
-#include <vector>
-#include <sstream>
-
-#include "Quaternion3D.hh"
-
-/** RefFrame *******
- * An instance of this class is created for each frame in the system.
- * This class natively handles the relationship between frames.
- *
- * The derived class Quaternion3D provides a buffered history of positions
- * with interpolation.
- */
-
-class RefFrame: public Quaternion3D
-{
-public:
-
- /* Constructor */
- RefFrame();
-
- /* Get the parent node */
- inline unsigned int getParent(){return parent;};
-
- /* Return tha parent node */
- inline void setParent(unsigned int parentID){parent = parentID;};
-private:
-
- /* Storage of the parent */
- unsigned int parent;
-
-};
-
-/*** Transform Reference ***********
- * This class provides a simple interface to allow recording and lookup of
- * relationships between arbitrary frames of the system.
- *
- * The positions of frames over time must be pushed in.
- *
- * It will provide interpolated positions out given a time argument.
- */
-
-class TransformReference
-{
-public:
- /************* Constants ***********************/
- static const unsigned int ROOT_FRAME = 1; //Hard Value for ROOT_FRAME
- static const unsigned int NO_PARENT = 0; //Value for NO_PARENT
-
- static const unsigned int MAX_NUM_FRAMES = 100; /* The maximum number of frames possible */
- static const unsigned int MAX_GRAPH_DEPTH = 100; /* The maximum number of times to descent before determining that graph has a loop. */
-
- /* Constructor */
- TransformReference();
-
- /********** Mutators **************/
- /* Set a new frame or update an old one. */
- /* Use Euler Angles. X forward, Y to the left, Z up, Yaw about Z, pitch about new Y, Roll about new X */
- void setWithEulers(unsigned int framid, unsigned int parentid, double x, double y, double z, double yaw, double pitch, double roll, unsigned long long time);
- /* Using DH Parameters */
- // Conventions from http://en.wikipedia.org/wiki/Robotics_conventions
- void setWithDH(unsigned int framid, unsigned int parentid, double length, double alpha, double offset, double theta, unsigned long long time);
- // Possible exceptions TransformReference::LookupException
-
- /*********** Accessors *************/
-
- /* Get the transform between two frames by frame ID. */
- NEWMAT::Matrix getMatrix(unsigned int target_frame, unsigned int source_frame, unsigned long long time);
- // Possible exceptions TransformReference::LookupException, TransformReference::ConnectivityException,
- // TransformReference::MaxDepthException
-
- /* Debugging function that will print to std::cout the transformation matrix */
- std::string viewChain(unsigned int target_frame, unsigned int source_frame);
- // Possible exceptions TransformReference::LookupException, TransformReference::ConnectivityException,
- // TransformReference::MaxDepthException
-
-
-
-
-
-
- /************ Possible Exceptions ****************************/
-
- /* An exception class to notify of bad frame number */
- class LookupException : public std::exception
- {
- public:
- virtual const char* what() const throw() { return "InvalidFrame"; }
- } InvalidFrame;
-
- /* An exception class to notify of no connection */
- class ConnectivityException : public std::exception
- {
- public:
- virtual const char* what() const throw() { return "No connection between frames"; }
- private:
- } NoFrameConnectivity;
-
- /* An exception class to notify that the search for connectivity descended too deep. */
- class MaxDepthException : public std::exception
- {
- public:
- virtual const char* what() const throw() { return "Search exceeded max depth. Probably a loop in the tree."; }
- private:
- } MaxSearchDepth;
-
-private:
- /******************** Internal Storage ****************/
-
- /* The pointers to potential frames that the tree can be made of.
- * The frames will be dynamically allocated at run time when set the first time. */
- RefFrame* frames[MAX_NUM_FRAMES];
-
-
- /* This struct is how the list of transforms are stored before being passed to computeTransformFromList. */
- typedef struct
- {
- std::vector<unsigned int> inverseTransforms;
- std::vector<unsigned int> forwardTransforms;
- } TransformLists;
-
- /************************* Internal Functions ****************************/
-
- /* An accessor to get a frame, which will throw an exception if the frame is no there. */
- inline RefFrame* getFrame(unsigned int frame_number) { if (frames[frame_number] == NULL) throw InvalidFrame; else return frames[frame_number];};
-
- /* Find the list of connected frames necessary to connect two different frames */
- TransformLists lookUpList(unsigned int target_frame, unsigned int source_frame);
-
- /* Compute the transform based on the list of frames */
- NEWMAT::Matrix computeTransformFromList(TransformLists list, unsigned long long time);
-
-};
-#endif //LIBTF_HH
Modified: pkg/trunk/libTF/src/simple/Quaternion3D.cpp
===================================================================
--- pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-22 20:43:16 UTC (rev 155)
+++ pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-22 21:42:52 UTC (rev 156)
@@ -30,7 +30,7 @@
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
-#include "libTF/Quaternion3D.hh"
+#include "libTF/Quaternion3D.h"
Euler3D::Euler3D(double _x, double _y, double _z, double _yaw, double _pitch, double _roll) :
x(_x),y(_y),z(_z),yaw(_yaw),pitch(_pitch),roll(_roll)
Modified: pkg/trunk/libTF/src/simple/libTF.cpp
===================================================================
--- pkg/trunk/libTF/src/simple/libTF.cpp 2008-04-22 20:43:16 UTC (rev 155)
+++ pkg/trunk/libTF/src/simple/libTF.cpp 2008-04-22 21:42:52 UTC (rev 156)
@@ -30,7 +30,7 @@
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
//POSSIBILITY OF SUCH DAMAGE.
-#include "libTF/libTF.hh"
+#include "libTF/libTF.h"
RefFrame::RefFrame() :
Quaternion3D(),
Modified: pkg/trunk/libTF/src/test/main.cpp
===================================================================
--- pkg/trunk/libTF/src/test/main.cpp 2008-04-22 20:43:16 UTC (rev 155)
+++ pkg/trunk/libTF/src/test/main.cpp 2008-04-22 21:42:52 UTC (rev 156)
@@ -1,5 +1,4 @@
-#include "libTF/Quaternion3D.hh"
-#include "libTF/libTF.hh"
+#include "libTF/libTF.h"
#include <time.h>
using namespace std;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tf...@us...> - 2008-04-22 23:14:16
|
Revision: 157
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=157&view=rev
Author: tfoote
Date: 2008-04-22 16:14:22 -0700 (Tue, 22 Apr 2008)
Log Message:
-----------
getting rid of zero distance interpolation case
Modified Paths:
--------------
pkg/trunk/libTF/include/libTF/Quaternion3D.h
pkg/trunk/libTF/src/simple/Quaternion3D.cpp
pkg/trunk/libTF/src/test/main.cpp
Modified: pkg/trunk/libTF/include/libTF/Quaternion3D.h
===================================================================
--- pkg/trunk/libTF/include/libTF/Quaternion3D.h 2008-04-22 21:42:52 UTC (rev 156)
+++ pkg/trunk/libTF/include/libTF/Quaternion3D.h 2008-04-22 23:14:22 UTC (rev 157)
@@ -52,6 +52,7 @@
class Quaternion3D {
public:
+ static const int MIN_INTERPOLATION_DISTANCE = 5; //Number of micro seconds to not interpolate below.
// Storage class
class Quaternion3DStorage
{
Modified: pkg/trunk/libTF/src/simple/Quaternion3D.cpp
===================================================================
--- pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-22 21:42:52 UTC (rev 156)
+++ pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-22 23:14:22 UTC (rev 157)
@@ -514,6 +514,14 @@
// Calculate the ration of time betwen target and the two end points.
long long total_diff = two.time - one.time;
long long target_diff = target_time - one.time;
+
+ //Check for zero distance case and just return
+ if (total_diff < 10 || target_diff < 10)
+ {
+ output = one;
+ return;
+ }
+
double t = (double)target_diff / (double) total_diff; //ratio between first and 2nd position interms of time
// Interpolate the translation
Modified: pkg/trunk/libTF/src/test/main.cpp
===================================================================
--- pkg/trunk/libTF/src/test/main.cpp 2008-04-22 21:42:52 UTC (rev 156)
+++ pkg/trunk/libTF/src/test/main.cpp 2008-04-22 23:14:22 UTC (rev 157)
@@ -27,6 +27,7 @@
mTR.setWithEulers(3,5,dx,dy,dz,dyaw,dp,dr,atime);
mTR.setWithEulers(5,1,dx,dy,dz,dyaw,dp,dr,atime);
mTR.setWithEulers(6,5,dx,dy,dz,dyaw,dp,dr,atime);
+ mTR.setWithEulers(6,5,dx,dy,dz,dyaw,dp,dr,atime);
mTR.setWithEulers(7,6,1,1,1,dyaw,dp,dr,atime);
mTR.setWithDH(8,7,1.0,1.0,1.0,dyaw,atime);
//mTR.setWithEulers(8,7,1,1,1,dyaw,dp,dr,atime); //Switching out for DH params above
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tf...@us...> - 2008-04-23 01:41:25
|
Revision: 161
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=161&view=rev
Author: tfoote
Date: 2008-04-22 18:41:30 -0700 (Tue, 22 Apr 2008)
Log Message:
-----------
removing zero angle bug in matrix to quaternion. And decreasing to 100 seconds from newest data for interpolation
Modified Paths:
--------------
pkg/trunk/libTF/include/libTF/Quaternion3D.h
pkg/trunk/libTF/src/simple/Quaternion3D.cpp
Modified: pkg/trunk/libTF/include/libTF/Quaternion3D.h
===================================================================
--- pkg/trunk/libTF/include/libTF/Quaternion3D.h 2008-04-22 23:58:24 UTC (rev 160)
+++ pkg/trunk/libTF/include/libTF/Quaternion3D.h 2008-04-23 01:41:30 UTC (rev 161)
@@ -116,7 +116,7 @@
private:
/**** Linked List stuff ****/
- static const long long MAX_STORAGE_TIME = 1000000000; // max of 100 seconds storage
+ static const long long MAX_STORAGE_TIME = 100000000; // max of 100 seconds storage
struct data_LL{
Quaternion3DStorage data;
Modified: pkg/trunk/libTF/src/simple/Quaternion3D.cpp
===================================================================
--- pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-22 23:58:24 UTC (rev 160)
+++ pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-23 01:41:30 UTC (rev 161)
@@ -93,8 +93,7 @@
//If the trace of the matrix is equal to zero then identify
// which major diagonal element has the greatest value.
// Depending on this, calculate the following:
-
- if ( mat[0] > mat[5] && mat[0] > mat[10] ) {// Column 0:
+ else if ( mat[0] > mat[5] && mat[0] > mat[10] ) {// Column 0:
double S = sqrt( 1.0 + mat[0] - mat[5] - mat[10] ) * 2;
temp.xr = 0.25 * S;
temp.yr = (mat[1] + mat[4] ) / S;
@@ -113,6 +112,7 @@
temp.zr = 0.25 * S;
temp.w = (mat[1] - mat[4] ) / S;
}
+
add_value(temp);
};
@@ -363,6 +363,7 @@
void Quaternion3D::insertNode(const Quaternion3DStorage & new_val)
{
+
data_LL* p_current;
data_LL* p_old;
@@ -428,7 +429,6 @@
void Quaternion3D::pruneList()
{
- unsigned long long current_time = Qgettime();
data_LL* p_current = last;
// cout << "Pruning List" << endl;
@@ -436,6 +436,9 @@
//Empty Set
if (last == NULL) return;
+ unsigned long long current_time = first->data.time;;
+
+
//While time stamps too old
while (p_current->data.time + max_storage_time < current_time)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tf...@us...> - 2008-04-23 22:25:41
|
Revision: 170
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=170&view=rev
Author: tfoote
Date: 2008-04-23 15:25:47 -0700 (Wed, 23 Apr 2008)
Log Message:
-----------
the beginning of documentation for libTF
Added Paths:
-----------
pkg/trunk/libTF/doc/
pkg/trunk/libTF/doc/Makefile
pkg/trunk/libTF/doc/README.txt
pkg/trunk/libTF/doc/libTF_Manual.tex
Added: pkg/trunk/libTF/doc/Makefile
===================================================================
--- pkg/trunk/libTF/doc/Makefile (rev 0)
+++ pkg/trunk/libTF/doc/Makefile 2008-04-23 22:25:47 UTC (rev 170)
@@ -0,0 +1,10 @@
+all: manual
+
+
+manual: libTF_Manual.tex
+ pdflatex $^
+ pdflatex $^
+
+clean:
+ rm -f *~ *.aux *.toc *.log
+ rm -f libTF_Manual.pdf
\ No newline at end of file
Added: pkg/trunk/libTF/doc/README.txt
===================================================================
--- pkg/trunk/libTF/doc/README.txt (rev 0)
+++ pkg/trunk/libTF/doc/README.txt 2008-04-23 22:25:47 UTC (rev 170)
@@ -0,0 +1,8 @@
+*************
+*** libTF ***
+*************
+
+
+
+A transform library and ROS wrapper to keep track of coordinate transforms for the whole system.
+
Added: pkg/trunk/libTF/doc/libTF_Manual.tex
===================================================================
--- pkg/trunk/libTF/doc/libTF_Manual.tex (rev 0)
+++ pkg/trunk/libTF/doc/libTF_Manual.tex 2008-04-23 22:25:47 UTC (rev 170)
@@ -0,0 +1,22 @@
+\documentclass[12pt]{article}
+
+
+\begin{document}
+\title{libTF Manual}
+\author{Tully Foote}
+\date{\today}
+\maketitle
+
+\tableofcontents
+\pagebreak
+
+\section{Introduction}
+
+\section{Transform Library}
+
+\section{ROS Integration}
+
+\section{Example Usage}
+
+\end{document}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tf...@us...> - 2008-04-26 00:20:49
|
Revision: 181
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=181&view=rev
Author: tfoote
Date: 2008-04-25 17:20:57 -0700 (Fri, 25 Apr 2008)
Log Message:
-----------
changing to nanoseconds
Modified Paths:
--------------
pkg/trunk/libTF/include/libTF/Quaternion3D.h
pkg/trunk/libTF/src/simple/Quaternion3D.cpp
Modified: pkg/trunk/libTF/include/libTF/Quaternion3D.h
===================================================================
--- pkg/trunk/libTF/include/libTF/Quaternion3D.h 2008-04-25 20:36:20 UTC (rev 180)
+++ pkg/trunk/libTF/include/libTF/Quaternion3D.h 2008-04-26 00:20:57 UTC (rev 181)
@@ -52,7 +52,7 @@
class Quaternion3D {
public:
- static const int MIN_INTERPOLATION_DISTANCE = 5; //Number of micro seconds to not interpolate below.
+ static const int MIN_INTERPOLATION_DISTANCE = 5; //Number of nano-seconds to not interpolate below.
// Storage class
class Quaternion3DStorage
{
@@ -72,7 +72,7 @@
/* Internal Data */
double xt, yt, zt, xr, yr, zr, w;
- unsigned long long time;
+ unsigned long long time; //nanoseconds since 1970
};
/** Constructors **/
@@ -99,7 +99,7 @@
NEWMAT::Matrix getInverseMatrix(unsigned long long time);
/**** Utility Functions ****/
- // this is a function to return the current time in microseconds from the beginning of 1970
+ // this is a function to return the current time in nanooseconds from the beginning of 1970
static unsigned long long Qgettime(void);
// Convert DH Parameters to a Homogeneous Transformation Matrix
@@ -116,7 +116,7 @@
private:
/**** Linked List stuff ****/
- static const long long MAX_STORAGE_TIME = 100000000; // max of 100 seconds storage
+ static const unsigned long long MAX_STORAGE_TIME = 100ULL * 1000000000ULL; // max of 100 seconds storage
struct data_LL{
Quaternion3DStorage data;
Modified: pkg/trunk/libTF/src/simple/Quaternion3D.cpp
===================================================================
--- pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-25 20:36:20 UTC (rev 180)
+++ pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-26 00:20:57 UTC (rev 181)
@@ -316,7 +316,7 @@
{
timeval temp_time_struct;
gettimeofday(&temp_time_struct,NULL);
- return temp_time_struct.tv_sec * 1000000ULL + (unsigned long long)temp_time_struct.tv_usec;
+ return temp_time_struct.tv_sec * 1000000000ULL + (unsigned long long)temp_time_struct.tv_usec * 1000ULL;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tf...@us...> - 2008-04-26 00:37:08
|
Revision: 182
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=182&view=rev
Author: tfoote
Date: 2008-04-25 17:37:15 -0700 (Fri, 25 Apr 2008)
Log Message:
-----------
moving gettime out of quaternion into wrapper as per ticket:19 Also cleaning up things like giving it a datatype ULLtime which is typedefed to ULL, but it makes headers clearer.
Modified Paths:
--------------
pkg/trunk/libTF/doc/libTF_Manual.tex
pkg/trunk/libTF/include/libTF/Quaternion3D.h
pkg/trunk/libTF/include/libTF/libTF.h
pkg/trunk/libTF/src/simple/Quaternion3D.cpp
pkg/trunk/libTF/src/simple/libTF.cpp
pkg/trunk/libTF/src/test/main.cpp
Modified: pkg/trunk/libTF/doc/libTF_Manual.tex
===================================================================
--- pkg/trunk/libTF/doc/libTF_Manual.tex 2008-04-26 00:20:57 UTC (rev 181)
+++ pkg/trunk/libTF/doc/libTF_Manual.tex 2008-04-26 00:37:15 UTC (rev 182)
@@ -191,7 +191,7 @@
dx = dy= dz = 0;
dyaw = dp = dr = 0.1;
- unsigned long long atime = Quaternion3D::Qgettime();
+ unsigned long long atime = mTR.gettime();
//Fill in some transforms
Modified: pkg/trunk/libTF/include/libTF/Quaternion3D.h
===================================================================
--- pkg/trunk/libTF/include/libTF/Quaternion3D.h 2008-04-26 00:20:57 UTC (rev 181)
+++ pkg/trunk/libTF/include/libTF/Quaternion3D.h 2008-04-26 00:37:15 UTC (rev 182)
@@ -98,10 +98,6 @@
// Return the inverse matrix
NEWMAT::Matrix getInverseMatrix(unsigned long long time);
- /**** Utility Functions ****/
- // this is a function to return the current time in nanooseconds from the beginning of 1970
- static unsigned long long Qgettime(void);
-
// Convert DH Parameters to a Homogeneous Transformation Matrix
static NEWMAT::Matrix matrixFromDH(double length, double alpha, double offset, double theta);
// Convert Euler Angles to a Homogeneous Transformation Matrix
Modified: pkg/trunk/libTF/include/libTF/libTF.h
===================================================================
--- pkg/trunk/libTF/include/libTF/libTF.h 2008-04-26 00:20:57 UTC (rev 181)
+++ pkg/trunk/libTF/include/libTF/libTF.h 2008-04-26 00:37:15 UTC (rev 182)
@@ -88,22 +88,24 @@
static const unsigned int MAX_NUM_FRAMES = 100; /* The maximum number of frames possible */
static const unsigned int MAX_GRAPH_DEPTH = 100; /* The maximum number of times to descent before determining that graph has a loop. */
+ typedef unsigned long long ULLtime;
+
/* Constructor */
TransformReference();
/********** Mutators **************/
/* Set a new frame or update an old one. */
/* Use Euler Angles. X forward, Y to the left, Z up, Yaw about Z, pitch about new Y, Roll about new X */
- void setWithEulers(unsigned int framid, unsigned int parentid, double x, double y, double z, double yaw, double pitch, double roll, unsigned long long time);
+ void setWithEulers(unsigned int framid, unsigned int parentid, double x, double y, double z, double yaw, double pitch, double roll, ULLtime time);
/* Using DH Parameters */
// Conventions from http://en.wikipedia.org/wiki/Robotics_conventions
- void setWithDH(unsigned int framid, unsigned int parentid, double length, double alpha, double offset, double theta, unsigned long long time);
+ void setWithDH(unsigned int framid, unsigned int parentid, double length, double alpha, double offset, double theta, ULLtime time);
// Possible exceptions TransformReference::LookupException
/*********** Accessors *************/
/* Get the transform between two frames by frame ID. */
- NEWMAT::Matrix getMatrix(unsigned int target_frame, unsigned int source_frame, unsigned long long time);
+ NEWMAT::Matrix getMatrix(unsigned int target_frame, unsigned int source_frame, ULLtime time);
// Possible exceptions TransformReference::LookupException, TransformReference::ConnectivityException,
// TransformReference::MaxDepthException
@@ -114,9 +116,13 @@
+ /**** Utility Functions ****/
+ // this is a function to return the current time in nanooseconds from the beginning of 1970
+ static ULLtime gettime(void);
+
/************ Possible Exceptions ****************************/
/* An exception class to notify of bad frame number */
@@ -166,7 +172,7 @@
TransformLists lookUpList(unsigned int target_frame, unsigned int source_frame);
/* Compute the transform based on the list of frames */
- NEWMAT::Matrix computeTransformFromList(TransformLists list, unsigned long long time);
+ NEWMAT::Matrix computeTransformFromList(TransformLists list, ULLtime time);
};
#endif //LIBTF_HH
Modified: pkg/trunk/libTF/src/simple/Quaternion3D.cpp
===================================================================
--- pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-26 00:20:57 UTC (rev 181)
+++ pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-26 00:37:15 UTC (rev 182)
@@ -312,14 +312,6 @@
};
-unsigned long long Quaternion3D::Qgettime()
-{
- timeval temp_time_struct;
- gettimeofday(&temp_time_struct,NULL);
- return temp_time_struct.tv_sec * 1000000000ULL + (unsigned long long)temp_time_struct.tv_usec * 1000ULL;
-}
-
-
bool Quaternion3D::getValue(Quaternion3DStorage& buff, unsigned long long time, long long &time_diff)
{
Quaternion3DStorage p_temp_1;
Modified: pkg/trunk/libTF/src/simple/libTF.cpp
===================================================================
--- pkg/trunk/libTF/src/simple/libTF.cpp 2008-04-26 00:20:57 UTC (rev 181)
+++ pkg/trunk/libTF/src/simple/libTF.cpp 2008-04-26 00:37:15 UTC (rev 182)
@@ -51,7 +51,7 @@
}
-void TransformReference::setWithEulers(unsigned int frameID, unsigned int parentID, double a,double b,double c,double d,double e,double f, unsigned long long time)
+void TransformReference::setWithEulers(unsigned int frameID, unsigned int parentID, double a,double b,double c,double d,double e,double f, ULLtime time)
{
if (frameID > MAX_NUM_FRAMES || parentID > MAX_NUM_FRAMES || frameID == NO_PARENT || frameID == ROOT_FRAME)
throw InvalidFrame;
@@ -63,7 +63,7 @@
getFrame(frameID)->fromEuler(a,b,c,d,e,f,time);
}
-void TransformReference::setWithDH(unsigned int frameID, unsigned int parentID, double a,double b,double c,double d, unsigned long long time)
+void TransformReference::setWithDH(unsigned int frameID, unsigned int parentID, double a,double b,double c,double d, ULLtime time)
{
if (frameID > MAX_NUM_FRAMES || parentID > MAX_NUM_FRAMES || frameID == NO_PARENT || frameID == ROOT_FRAME)
throw InvalidFrame;
@@ -76,7 +76,7 @@
}
-NEWMAT::Matrix TransformReference::getMatrix(unsigned int target_frame, unsigned int source_frame, unsigned long long time)
+NEWMAT::Matrix TransformReference::getMatrix(unsigned int target_frame, unsigned int source_frame, ULLtime time)
{
NEWMAT::Matrix myMat(4,4);
TransformLists lists = lookUpList(target_frame, source_frame);
@@ -149,7 +149,7 @@
}
-NEWMAT::Matrix TransformReference::computeTransformFromList(TransformLists lists, unsigned long long time)
+NEWMAT::Matrix TransformReference::computeTransformFromList(TransformLists lists, ULLtime time)
{
NEWMAT::Matrix retMat(4,4);
retMat << 1 << 0 << 0 << 0
@@ -194,3 +194,11 @@
mstream << std::endl;
return mstream.str();
}
+
+TransformReference::ULLtime TransformReference::gettime()
+{
+ timeval temp_time_struct;
+ gettimeofday(&temp_time_struct,NULL);
+ return temp_time_struct.tv_sec * 1000000000ULL + (unsigned long long)temp_time_struct.tv_usec * 1000ULL;
+}
+
Modified: pkg/trunk/libTF/src/test/main.cpp
===================================================================
--- pkg/trunk/libTF/src/test/main.cpp 2008-04-26 00:20:57 UTC (rev 181)
+++ pkg/trunk/libTF/src/test/main.cpp 2008-04-26 00:37:15 UTC (rev 182)
@@ -13,7 +13,7 @@
dx = dy= dz = 0;
dyaw = dp = dr = 0.1;
- unsigned long long atime = Quaternion3D::Qgettime();
+ unsigned long long atime = mTR.gettime();
//Fill in some transforms
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tf...@us...> - 2008-04-26 01:06:00
|
Revision: 186
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=186&view=rev
Author: tfoote
Date: 2008-04-25 18:06:06 -0700 (Fri, 25 Apr 2008)
Log Message:
-----------
adding default argument for cacheing as per ticket:21
Modified Paths:
--------------
pkg/trunk/libTF/include/libTF/Quaternion3D.h
pkg/trunk/libTF/src/simple/Quaternion3D.cpp
Modified: pkg/trunk/libTF/include/libTF/Quaternion3D.h
===================================================================
--- pkg/trunk/libTF/include/libTF/Quaternion3D.h 2008-04-26 01:05:46 UTC (rev 185)
+++ pkg/trunk/libTF/include/libTF/Quaternion3D.h 2008-04-26 01:06:06 UTC (rev 186)
@@ -76,8 +76,8 @@
};
/** Constructors **/
- // Standard constructor
- Quaternion3D();
+ // Standard constructor max_cache_time is how long to cache transform data
+ Quaternion3D(unsigned long long max_cache_time = DEFAULT_MAX_STORAGE_TIME);
/** Mutators **/
// Set the values manually
@@ -112,7 +112,7 @@
private:
/**** Linked List stuff ****/
- static const unsigned long long MAX_STORAGE_TIME = 100ULL * 1000000000ULL; // max of 100 seconds storage
+ static const unsigned long long DEFAULT_MAX_STORAGE_TIME = 10ULL * 1000000000ULL; // default value of 10 seconds storage
struct data_LL{
Quaternion3DStorage data;
Modified: pkg/trunk/libTF/src/simple/Quaternion3D.cpp
===================================================================
--- pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-26 01:05:46 UTC (rev 185)
+++ pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-26 01:06:06 UTC (rev 186)
@@ -39,8 +39,8 @@
};
-Quaternion3D::Quaternion3D():
- max_storage_time(MAX_STORAGE_TIME),
+Quaternion3D::Quaternion3D(unsigned long long max_cache_time):
+ max_storage_time(max_cache_time),
first(NULL),
last(NULL)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tf...@us...> - 2008-04-28 14:06:08
|
Revision: 209
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=209&view=rev
Author: tfoote
Date: 2008-04-28 07:05:55 -0700 (Mon, 28 Apr 2008)
Log Message:
-----------
history of transforms destroyed when parent frame is changes ticket:18.
Modified Paths:
--------------
pkg/trunk/libTF/include/libTF/Quaternion3D.h
pkg/trunk/libTF/include/libTF/libTF.h
pkg/trunk/libTF/src/simple/Quaternion3D.cpp
pkg/trunk/libTF/src/test/main.cpp
Modified: pkg/trunk/libTF/include/libTF/Quaternion3D.h
===================================================================
--- pkg/trunk/libTF/include/libTF/Quaternion3D.h 2008-04-28 04:57:01 UTC (rev 208)
+++ pkg/trunk/libTF/include/libTF/Quaternion3D.h 2008-04-28 14:05:55 UTC (rev 209)
@@ -108,6 +108,9 @@
//Print as a matrix
void printMatrix(unsigned long long time); //Not a critical part either
void printStorage(const Quaternion3DStorage &storage); //Do i need this now that i've got the ostream method??
+
+ // Remove all nodes from the list
+ void clearList();
private:
Modified: pkg/trunk/libTF/include/libTF/libTF.h
===================================================================
--- pkg/trunk/libTF/include/libTF/libTF.h 2008-04-28 04:57:01 UTC (rev 208)
+++ pkg/trunk/libTF/include/libTF/libTF.h 2008-04-28 14:05:55 UTC (rev 209)
@@ -60,8 +60,10 @@
/* Get the parent node */
inline unsigned int getParent(){return parent;};
- /* Return tha parent node */
- inline void setParent(unsigned int parentID){parent = parentID;};
+ /* Set the parent node
+ * return: false => change of parent, cleared history
+ * return: true => no change of parent */
+ inline bool setParent(unsigned int parentID){if (parent != parentID){parent = parentID; clearList(); return false;} return true;};
private:
/* Storage of the parent */
Modified: pkg/trunk/libTF/src/simple/Quaternion3D.cpp
===================================================================
--- pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-28 04:57:01 UTC (rev 208)
+++ pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-28 14:05:55 UTC (rev 209)
@@ -457,8 +457,26 @@
};
+void Quaternion3D::clearList()
+{
+ data_LL * p_current = first;
+ data_LL * p_last = NULL;
+ // Delete all nodes in list
+ while (p_current != NULL)
+ {
+ p_last = p_current;
+ p_current = p_current->next;
+ delete p_last;
+ }
+ //Clean up pointers
+ first = NULL;
+ last = NULL;
+
+};
+
+
int Quaternion3D::findClosest(Quaternion3DStorage& one, Quaternion3DStorage& two, const unsigned long long target_time, long long &time_diff)
{
Modified: pkg/trunk/libTF/src/test/main.cpp
===================================================================
--- pkg/trunk/libTF/src/test/main.cpp 2008-04-28 04:57:01 UTC (rev 208)
+++ pkg/trunk/libTF/src/test/main.cpp 2008-04-28 14:05:55 UTC (rev 209)
@@ -79,6 +79,9 @@
{
std::cout <<"caught unconnected frame"<<std::endl;
}
+
+ //Testing clearing the history with parent change
+ mTR.setWithEulers(7,5,1,1,1,dyaw,dp,dr,atime);
return 0;
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tf...@us...> - 2008-04-28 15:46:23
|
Revision: 210
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=210&view=rev
Author: tfoote
Date: 2008-04-28 08:46:01 -0700 (Mon, 28 Apr 2008)
Log Message:
-----------
adding time to constructor and documenting. ticket:21
Modified Paths:
--------------
pkg/trunk/libTF/doc/libTF_Manual.tex
pkg/trunk/libTF/include/libTF/libTF.h
pkg/trunk/libTF/src/simple/libTF.cpp
Modified: pkg/trunk/libTF/doc/libTF_Manual.tex
===================================================================
--- pkg/trunk/libTF/doc/libTF_Manual.tex 2008-04-28 14:05:55 UTC (rev 209)
+++ pkg/trunk/libTF/doc/libTF_Manual.tex 2008-04-28 15:46:01 UTC (rev 210)
@@ -108,6 +108,26 @@
\subsection{libTF API}
\index{libTF API}
+The class which provides external functionality is named TransformReference.
+
+\subsubsection{Data Types}
+\begin{verbatim}
+typedef unsigned long long ULLtime;
+\end{verbatim}
+
+\texttt{ULLtime} provides a simple typedef for the timestamp used in this library.
+\texttt{ULLtime} is the number of nanoseconds since the epoch(1970) expressed as
+an unsigned long long, which should be equivilant to a \texttt{uint64\_t}.
+
+\subsubsection{Constructor}
+\index{libTF API!Constructor}
+\begin{verbatim}
+TransformReference(ULLtime cache_time = DEFAULT_CACHE_TIME);
+\end{verbatim}
+This is the constructor for the class. It's optional argument is
+how long to keep a history of the transforms. It is expressed in
+\texttt{ULLtime}, nanoseconds since the epoch(1970).
+
\subsubsection{Mutators}
\paragraph{setWithEulers}
@@ -159,14 +179,6 @@
unsigned int source_frame);
\end{verbatim}
-\subsubsection{Constructor}
-\index{libTF API!Constructor}
-\begin{verbatim}
-TransformReference();
-\end{verbatim}
-\todo{add max time default argument}
-
-
\section{ROS Integration}
unimplemented
Modified: pkg/trunk/libTF/include/libTF/libTF.h
===================================================================
--- pkg/trunk/libTF/include/libTF/libTF.h 2008-04-28 14:05:55 UTC (rev 209)
+++ pkg/trunk/libTF/include/libTF/libTF.h 2008-04-28 15:46:01 UTC (rev 210)
@@ -83,6 +83,9 @@
class TransformReference
{
public:
+ // A typedef for clarity
+ typedef unsigned long long ULLtime;
+
/************* Constants ***********************/
static const unsigned int ROOT_FRAME = 1; //Hard Value for ROOT_FRAME
static const unsigned int NO_PARENT = 0; //Value for NO_PARENT
@@ -90,10 +93,11 @@
static const unsigned int MAX_NUM_FRAMES = 100; /* The maximum number of frames possible */
static const unsigned int MAX_GRAPH_DEPTH = 100; /* The maximum number of times to descent before determining that graph has a loop. */
- typedef unsigned long long ULLtime;
+ static const ULLtime DEFAULT_CACHE_TIME = 10 * 1000000000ULL; //10 seconds in nanoseconds
+
/* Constructor */
- TransformReference();
+ TransformReference(ULLtime cache_time = DEFAULT_CACHE_TIME);
/********** Mutators **************/
/* Set a new frame or update an old one. */
@@ -157,6 +161,8 @@
* The frames will be dynamically allocated at run time when set the first time. */
RefFrame* frames[MAX_NUM_FRAMES];
+ // How long to cache transform history
+ ULLtime cache_time;
/* This struct is how the list of transforms are stored before being passed to computeTransformFromList. */
typedef struct
Modified: pkg/trunk/libTF/src/simple/libTF.cpp
===================================================================
--- pkg/trunk/libTF/src/simple/libTF.cpp 2008-04-28 14:05:55 UTC (rev 209)
+++ pkg/trunk/libTF/src/simple/libTF.cpp 2008-04-28 15:46:01 UTC (rev 210)
@@ -40,7 +40,8 @@
}
-TransformReference::TransformReference()
+TransformReference::TransformReference(ULLtime cache_time):
+ cache_time(cache_time)
{
/* initialize pointers to NULL */
for (unsigned int i = 0; i < MAX_NUM_FRAMES; i++)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tf...@us...> - 2008-04-29 23:41:39
|
Revision: 239
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=239&view=rev
Author: tfoote
Date: 2008-04-29 16:41:43 -0700 (Tue, 29 Apr 2008)
Log Message:
-----------
adding a point method ticket:22, and fixing zero distance bug
Modified Paths:
--------------
pkg/trunk/libTF/doc/libTF_Manual.tex
pkg/trunk/libTF/include/libTF/libTF.h
pkg/trunk/libTF/src/simple/libTF.cpp
pkg/trunk/libTF/src/test/main.cpp
Modified: pkg/trunk/libTF/doc/libTF_Manual.tex
===================================================================
--- pkg/trunk/libTF/doc/libTF_Manual.tex 2008-04-29 23:24:20 UTC (rev 238)
+++ pkg/trunk/libTF/doc/libTF_Manual.tex 2008-04-29 23:41:43 UTC (rev 239)
@@ -17,7 +17,9 @@
\newfloat{struct}{thp}{lop}
\floatname{struct}{Data Structure}
+\setcounter{tocdepth}{4}
+
\begin{document}
\title{libTF Manual}
\author{Tully Foote\\
@@ -119,6 +121,16 @@
\texttt{ULLtime} is the number of nanoseconds since the epoch(1970) expressed as
an unsigned long long, which should be equivilant to a \texttt{uint64\_t}.
+\begin{verbatim}
+struct TFPoint
+{
+ double x,y,z;
+ unsigned long long time;
+ unsigned int frame;
+};
+\end{verbatim}
+
+
\subsubsection{Constructor}
\index{libTF API!Constructor}
\begin{verbatim}
@@ -172,6 +184,14 @@
unsigned long long time);
\end{verbatim}
+\paragraph{transformPoint}
+\begin{verbatim}
+/* Transform a point to a different frame */
+TFPoint transformPoint(unsigned int target_frame, const TFPoint & point_in);
+\end{verbatim}
+Point $P_0 = (x,y,z,1)^T$ will be transformed into the target frame
+using the time and source frame embedded in the point struct.
+
\paragraph{viewChain}
\index{libTF API!viewChain}
\begin{verbatim}
@@ -179,6 +199,22 @@
unsigned int source_frame);
\end{verbatim}
+\subsubsection{Constants}
+\begin{verbatim}
+static const unsigned int ROOT_FRAME = 1; //Hard Value for ROOT_FRAME
+static const unsigned int NO_PARENT = 0; //Value for NO_PARENT
+
+/* The maximum number of frames possible */
+static const unsigned int MAX_NUM_FRAMES = 100;
+/* The maximum number of times to descent before
+ * determining that graph has a loop. */
+static const unsigned int MAX_GRAPH_DEPTH = 100;
+
+//10 seconds in nanoseconds
+static const ULLtime DEFAULT_CACHE_TIME = 10 * 1000000000ULL;
+
+\end{verbatim}
+
\section{ROS Integration}
unimplemented
Modified: pkg/trunk/libTF/include/libTF/libTF.h
===================================================================
--- pkg/trunk/libTF/include/libTF/libTF.h 2008-04-29 23:24:20 UTC (rev 238)
+++ pkg/trunk/libTF/include/libTF/libTF.h 2008-04-29 23:41:43 UTC (rev 239)
@@ -42,6 +42,20 @@
#include "Quaternion3D.h"
+
+
+
+
+/**** Point ****
+ */
+struct TFPoint
+{
+ double x,y,z;
+ unsigned long long time;
+ unsigned int frame;
+};
+
+
/** RefFrame *******
* An instance of this class is created for each frame in the system.
* This class natively handles the relationship between frames.
@@ -106,6 +120,10 @@
/* Using DH Parameters */
// Conventions from http://en.wikipedia.org/wiki/Robotics_conventions
void setWithDH(unsigned int framid, unsigned int parentid, double length, double alpha, double offset, double theta, ULLtime time);
+ /* Set the transform using a matrix */
+ void setWithMatrix(unsigned int framid, unsigned int parentid, const NEWMAT::Matrix & matrix_in, ULLtime time);
+ /* Set the transform using quaternions natively */
+ void setWithQuaternion(unsigned int framid, unsigned int parentid, double xt, double yt, double zt, double xr, double yr, double zr, double w, ULLtime time);
// Possible exceptions TransformReference::LookupException
/*********** Accessors *************/
@@ -115,6 +133,10 @@
// Possible exceptions TransformReference::LookupException, TransformReference::ConnectivityException,
// TransformReference::MaxDepthException
+
+ /* Transform a point to a different frame */
+ TFPoint transformPoint(unsigned int target_frame, const TFPoint & point_in);
+
/* Debugging function that will print to std::cout the transformation matrix */
std::string viewChain(unsigned int target_frame, unsigned int source_frame);
// Possible exceptions TransformReference::LookupException, TransformReference::ConnectivityException,
@@ -164,6 +186,7 @@
// How long to cache transform history
ULLtime cache_time;
+ public:
/* This struct is how the list of transforms are stored before being passed to computeTransformFromList. */
typedef struct
{
@@ -171,6 +194,7 @@
std::vector<unsigned int> forwardTransforms;
} TransformLists;
+ // private:
/************************* Internal Functions ****************************/
/* An accessor to get a frame, which will throw an exception if the frame is no there. */
@@ -180,7 +204,7 @@
TransformLists lookUpList(unsigned int target_frame, unsigned int source_frame);
/* Compute the transform based on the list of frames */
- NEWMAT::Matrix computeTransformFromList(TransformLists list, ULLtime time);
+ NEWMAT::Matrix computeTransformFromList(const TransformLists & list, ULLtime time);
};
#endif //LIBTF_HH
Modified: pkg/trunk/libTF/src/simple/libTF.cpp
===================================================================
--- pkg/trunk/libTF/src/simple/libTF.cpp 2008-04-29 23:24:20 UTC (rev 238)
+++ pkg/trunk/libTF/src/simple/libTF.cpp 2008-04-29 23:41:43 UTC (rev 239)
@@ -77,6 +77,35 @@
}
+void TransformReference::setWithMatrix(unsigned int frameID, unsigned int parentID, const NEWMAT::Matrix & matrix_in, ULLtime time)
+{
+ if (frameID > MAX_NUM_FRAMES || parentID > MAX_NUM_FRAMES || frameID == NO_PARENT || frameID == ROOT_FRAME)
+ throw InvalidFrame;
+
+ //TODO check and throw exception if matrix wrong size
+ if (frames[frameID] == NULL)
+ frames[frameID] = new RefFrame();
+
+ getFrame(frameID)->setParent(parentID);
+ getFrame(frameID)->fromMatrix(matrix_in,time);
+}
+
+
+void TransformReference::setWithQuaternion(unsigned int frameID, unsigned int parentID, double xt, double yt, double zt, double xr, double yr, double zr, double w, ULLtime time)
+{
+ if (frameID > MAX_NUM_FRAMES || parentID > MAX_NUM_FRAMES || frameID == NO_PARENT || frameID == ROOT_FRAME)
+ throw InvalidFrame;
+
+ if (frames[frameID] == NULL)
+ frames[frameID] = new RefFrame();
+
+ getFrame(frameID)->setParent(parentID);
+ getFrame(frameID)->fromQuaternion(xt, yt, zt, xr, yr, zr, w,time);
+}
+
+
+
+
NEWMAT::Matrix TransformReference::getMatrix(unsigned int target_frame, unsigned int source_frame, ULLtime time)
{
NEWMAT::Matrix myMat(4,4);
@@ -86,6 +115,28 @@
}
+
+
+TFPoint TransformReference::transformPoint(unsigned int target_frame, const TFPoint & point_in)
+{
+ //Create a vector
+ NEWMAT::Matrix pointMat(4,1);
+ pointMat << point_in.x << point_in.y << point_in.z << 1;
+
+ NEWMAT::Matrix myMat = getMatrix(target_frame, point_in.frame, point_in.time);
+
+
+ pointMat = myMat * pointMat;
+ TFPoint retPoint;
+ retPoint.x = pointMat(1,1);
+ retPoint.y = pointMat(2,1);
+ retPoint.z = pointMat(3,1);
+ retPoint.frame = target_frame;
+ retPoint.time = point_in.time;
+ return retPoint;
+}
+
+
TransformReference::TransformLists TransformReference::lookUpList(unsigned int target_frame, unsigned int source_frame)
{
TransformLists mTfLs;
@@ -140,17 +191,24 @@
if (mTfLs.inverseTransforms.back() == NO_PARENT || mTfLs.forwardTransforms.back() == NO_PARENT)
throw(NoFrameConnectivity);
+ bool imdone = false;
while (mTfLs.inverseTransforms.back() == mTfLs.forwardTransforms.back())
{
mTfLs.inverseTransforms.pop_back();
mTfLs.forwardTransforms.pop_back();
+
+ // Make sure we don't go beyond the beginning of the list.
+ // (The while statement above doesn't fail if you hit the beginning of the list,
+ // which happens in the zero distance case.)
+ if (mTfLs.inverseTransforms.size() == 0 || mTfLs.forwardTransforms.size() == 0)
+ break;
}
return mTfLs;
}
-NEWMAT::Matrix TransformReference::computeTransformFromList(TransformLists lists, ULLtime time)
+NEWMAT::Matrix TransformReference::computeTransformFromList(const TransformLists & lists, ULLtime time)
{
NEWMAT::Matrix retMat(4,4);
retMat << 1 << 0 << 0 << 0
@@ -158,17 +216,14 @@
<< 0 << 0 << 1 << 0
<< 0 << 0 << 0 << 1;
+
for (unsigned int i = 0; i < lists.inverseTransforms.size(); i++)
{
retMat *= getFrame(lists.inverseTransforms[i])->getMatrix(time);
- // std::cout <<"Multiplying by " << std::endl << frames[lists.inverseTransforms[i]].getInverseMatrix() << std::endl;
- //std::cout <<"Result "<<std::endl << retMat << std::endl;
}
for (unsigned int i = 0; i < lists.forwardTransforms.size(); i++)
{
retMat *= getFrame(lists.forwardTransforms[lists.forwardTransforms.size() -1 - i])->getInverseMatrix(time); //Do this list backwards for it was generated traveling the wrong way
- // std::cout <<"Multiplying by "<<std::endl << frames[lists.forwardTransforms[i]].getMatrix() << std::endl;
- //std::cout <<"Result "<<std::endl << retMat << std::endl;
}
return retMat;
Modified: pkg/trunk/libTF/src/test/main.cpp
===================================================================
--- pkg/trunk/libTF/src/test/main.cpp 2008-04-29 23:24:20 UTC (rev 238)
+++ pkg/trunk/libTF/src/test/main.cpp 2008-04-29 23:41:43 UTC (rev 239)
@@ -56,8 +56,31 @@
std::cout << "Result of getMatrix(10,8,atime):" << std::endl << mat<< std::endl;
-
-
+ TFPoint mPoint;
+ mPoint.x = 1;
+ mPoint.y = 1;
+ mPoint.z = 1;
+ mPoint.frame = 10;
+
+ TFPoint nPoint = mPoint;
+
+ std::cout <<"Point 1,1,1 goes like this:" <<std::endl;
+ std::cout << "(" << mPoint.x <<","<< mPoint.y << "," << mPoint.z << ") in frame " << mPoint.frame << std::endl;
+ mPoint = mTR.transformPoint(2, mPoint);
+ std::cout << "(" << mPoint.x <<","<< mPoint.y << "," << mPoint.z << ") in frame " << mPoint.frame << std::endl;
+ mPoint = mTR.transformPoint(3, mPoint);
+ std::cout << "(" << mPoint.x <<","<< mPoint.y << "," << mPoint.z << ") in frame " << mPoint.frame << std::endl;
+ mPoint = mTR.transformPoint(5, mPoint);
+ std::cout << "(" << mPoint.x <<","<< mPoint.y << "," << mPoint.z << ") in frame " << mPoint.frame << std::endl;
+ mPoint = mTR.transformPoint(6, mPoint);
+ std::cout << "(" << mPoint.x <<","<< mPoint.y << "," << mPoint.z << ") in frame " << mPoint.frame << std::endl;
+ mPoint = mTR.transformPoint(7, mPoint);
+ std::cout << "(" << mPoint.x <<","<< mPoint.y << "," << mPoint.z << ") in frame " << mPoint.frame << std::endl;
+ mPoint = mTR.transformPoint(8, mPoint);
+ std::cout << "(" << mPoint.x <<","<< mPoint.y << "," << mPoint.z << ") in frame " << mPoint.frame << std::endl;
+ mPoint = mTR.transformPoint(10, mPoint);
+ std::cout << "(" << mPoint.x <<","<< mPoint.y << "," << mPoint.z << ") in frame " << mPoint.frame << std::endl;
+
//Break the graph, making it loop and demonstrate catching MaxDepthException
mTR.setWithEulers(6,7,dx,dy,dz,dyaw,dp,dr,atime);
@@ -82,6 +105,7 @@
//Testing clearing the history with parent change
mTR.setWithEulers(7,5,1,1,1,dyaw,dp,dr,atime);
+ //todo display this somehow
return 0;
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tf...@us...> - 2008-04-30 01:17:52
|
Revision: 243
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=243&view=rev
Author: tfoote
Date: 2008-04-29 18:17:58 -0700 (Tue, 29 Apr 2008)
Log Message:
-----------
adding a max length to the linked list to prevent unbounded memory usage
Modified Paths:
--------------
pkg/trunk/libTF/include/libTF/Quaternion3D.h
pkg/trunk/libTF/src/simple/Quaternion3D.cpp
Modified: pkg/trunk/libTF/include/libTF/Quaternion3D.h
===================================================================
--- pkg/trunk/libTF/include/libTF/Quaternion3D.h 2008-04-30 00:56:19 UTC (rev 242)
+++ pkg/trunk/libTF/include/libTF/Quaternion3D.h 2008-04-30 01:17:58 UTC (rev 243)
@@ -53,6 +53,7 @@
public:
static const int MIN_INTERPOLATION_DISTANCE = 5; //Number of nano-seconds to not interpolate below.
+ static const unsigned int MAX_LENGTH_LINKED_LIST = 1000000; // Maximum length of linked list, to make sure not to be able to use unlimited memory.
// Storage class
class Quaternion3DStorage
{
@@ -155,8 +156,8 @@
data_LL* first;
data_LL* last;
+ unsigned int list_length;
-
};
Modified: pkg/trunk/libTF/src/simple/Quaternion3D.cpp
===================================================================
--- pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-30 00:56:19 UTC (rev 242)
+++ pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-30 01:17:58 UTC (rev 243)
@@ -42,7 +42,8 @@
Quaternion3D::Quaternion3D(unsigned long long max_cache_time):
max_storage_time(max_cache_time),
first(NULL),
- last(NULL)
+ last(NULL),
+ list_length(0)
{
pthread_mutex_init( &linked_list_mutex, NULL);
@@ -355,7 +356,6 @@
void Quaternion3D::insertNode(const Quaternion3DStorage & new_val)
{
-
data_LL* p_current;
data_LL* p_old;
@@ -417,6 +417,10 @@
}
+
+ // Record that we have increased the length of th elist
+ list_length ++;
+
};
void Quaternion3D::pruneList()
@@ -432,7 +436,7 @@
//While time stamps too old
- while (p_current->data.time + max_storage_time < current_time)
+ while (p_current->data.time + max_storage_time < current_time || list_length > MAX_LENGTH_LINKED_LIST)
{
// cout << "Age of node " << (double)(-p_current->data.time + current_time)/1000000.0 << endl;
// Make sure that there's at least two elements in the list
@@ -446,6 +450,7 @@
delete p_current;
p_current = last;
// cout << " Pruning Node" << endl;
+ list_length--;
}
else
break;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|