ScrewJoint.hh
00001 /*
00002  *  Gazebo - Outdoor Multi-Robot Simulator
00003  *  Copyright (C) 2003  
00004  *     Nate Koenig & Andrew Howard
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 /* Desc: A screw or primastic/rotational joint
00022  * Author: Nate Keonig, Andrew Howard
00023  * Date: 21 May 2003
00024  * CVS: $Id$
00025  */
00026 
00027 #ifndef SCREWJOINT_HH
00028 #define SCREWJOINT_HH
00029 
00030 #include <float.h>
00031 #include "physics/Joint.hh"
00032 
00033 namespace gazebo
00034 {
00035   namespace physics
00036   {
00037 
00040 
00042     template<class T>
00043     class ScrewJoint : public T
00044     {
00046       public: ScrewJoint( ) : T()
00047               { this->AddType(Base::SCREW_JOINT); }
00048 
00050       public: virtual ~ScrewJoint()
00051               { }
00052 
00054       protected: virtual void Load( sdf::ElementPtr &_sdf )
00055                  {
00056                    T::Load(_sdf);
00057   
00058                    if (_sdf->HasElement("thread_pitch"))
00059                      this->threadPitch = _sdf->GetElement("thread_pitch")->GetValueDouble();
00060                    else
00061                    {
00062                      gzerr << "should not see this\n";
00063                      this->threadPitch = 1.0;
00064                    }
00065 
00066                    if (_sdf->HasElement("axis"))
00067                    {
00068                      sdf::ElementPtr axisElem = _sdf->GetElement("axis");
00069                      this->SetAxis(0, axisElem->GetValueVector3("xyz"));
00070                      if (axisElem->HasElement("limit"))
00071                      {
00072                        sdf::ElementPtr limitElem = _sdf->GetElement("axis")->GetElement("limit");
00073                        // Perform this three step ordering to ensure the parameters 
00074                        // are set properly. This is taken from the ODE wiki.
00075                        this->SetHighStop(0,limitElem->GetValueDouble("upper"));
00076                        this->SetLowStop( 0,limitElem->GetValueDouble("lower"));
00077                        this->SetHighStop(0,limitElem->GetValueDouble("upper"));
00078                      }
00079                    }
00080                  }
00081 
00083       public: virtual void SetAnchor( int /*_index */, const math::Vector3 &anchor)
00084                 {fakeAnchor = anchor;}
00085 
00087       public: virtual math::Vector3 GetAnchor(int /*_index*/) const
00088                {return fakeAnchor;}
00089    
00090       protected: math::Vector3 fakeAnchor;
00091       protected: double threadPitch; 
00092     };
00094   }
00095 }
00096 #endif