Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

physics/ODEUniversalJoint.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002   Copyright (C)1996 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: ODEUniversalJoint.cpp 1031 2004-02-11 20:46:36Z jungd $
00019   $Revision: 1.2 $
00020   $Date: 2004-02-11 15:46:36 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #include <physics/ODEUniversalJoint>
00026 #include <physics/ODEConstraintGroup>
00027 
00028 using physics::ODEUniversalJoint;
00029 using physics::ODEConstraintGroup;
00030 
00031 
00032 ODEUniversalJoint::ODEUniversalJoint()
00033 {
00034 }
00035 
00036 ODEUniversalJoint::~ODEUniversalJoint() 
00037 {
00038 }
00039 
00040 void ODEUniversalJoint::onConstraintGroupAdd(ref<ConstraintGroup> g)
00041 {
00042   Assert(g != 0);
00043   Assert(instanceof(*g,ODEConstraintGroup));
00044   group = g;
00045 
00046   ref<ODEConstraintGroup> ogroup = narrow_ref<ODEConstraintGroup>(group);
00047   setJointID( dJointCreateUniversal(ogroup->getWorldID(), ogroup->getJointGroupID()) );
00048 }
00049 
00050 
00051 void ODEUniversalJoint::setAnchor(const Point3& p)
00052 {
00053   checkAddedAndAttached();
00054   Point3 gp( body1->getRelPointPos(p) ); // to global frame
00055   dJointSetUniversalAnchor(jointID, gp.x, gp.y, gp.z);
00056 }
00057 
00058 base::Point3 ODEUniversalJoint::getAnchor() const
00059 {
00060   checkAddedAndAttached();
00061   dVector3 ogp;
00062   dJointGetUniversalAnchor(jointID, ogp);
00063   Point3 gp(ogp[0], ogp[1], ogp[2]);
00064   return body1->getGlobalPointRelPos(gp);
00065 }
00066 
00067 void ODEUniversalJoint::setAxis1(const Vector3& v)
00068 {
00069   checkAddedAndAttached();
00070   // transform direction vector to global frame for ODE
00071   Vector3 g(v);
00072   body1->getOrientation().rotatePoint(g);
00073   dJointSetUniversalAxis1(jointID, g.x, g.y, g.z);
00074 }
00075 
00076 base::Vector3 ODEUniversalJoint::getAxis1() const
00077 {
00078   checkAddedAndAttached();
00079   dVector3 gaxis;
00080   dJointGetUniversalAxis1(jointID, gaxis);
00081   // transform into body1 frame
00082   Vector3 l(gaxis[0], gaxis[1], gaxis[2]);
00083   body1->getOrientation().invert().rotatePoint(l);
00084   return l;
00085 }
00086   
00087 void ODEUniversalJoint::setAxis2(const Vector3& v)
00088 {
00089   checkAddedAndAttached();
00090   // transform direction vector to global frame for ODE
00091   Vector3 g(v);
00092   body1->getOrientation().rotatePoint(g);
00093   dJointSetUniversalAxis2(jointID, g.x, g.y, g.z);
00094 }
00095 
00096 base::Vector3 ODEUniversalJoint::getAxis2() const
00097 {
00098   checkAddedAndAttached();
00099   dVector3 gaxis;
00100   dJointGetUniversalAxis2(jointID, gaxis);
00101   // transform into body1 frame
00102   Vector3 l(gaxis[0], gaxis[1], gaxis[2]);
00103   body1->getOrientation().invert().rotatePoint(l);
00104   return l;
00105 }
00106 
00107 
00108 // Don't think ODE Universal Joint supports a joint motor
00109 // perhaps use an AMotor instead??? !!!
00110 bool ODEUniversalJoint::hasMotor(Int dof) const
00111 {
00112   return false;
00113   //return ((dof==1)||(dof==2));
00114 }
00115 
00116 void ODEUniversalJoint::setMotorTargetVel(Int dof, Real vel)
00117 {
00118   Assert(false);
00119   /*
00120   Assert((dof==1)||(dof==2));
00121   if (dof==1)
00122     dJointSetUniversalParam(jointID, dParamVel, vel);
00123   else
00124     dJointSetUniversalParam(jointID, dParamVel2, vel);
00125   */
00126 }
00127 
00128 void ODEUniversalJoint::setMotorMaxForce(Int dof, Real force)
00129 {
00130   Assert(false);
00131   /*
00132   Assert((dof==1)||(dof==2));
00133   if (dof==1)
00134     dJointSetUniversalParam(jointID, dParamFMax, force); 
00135   else
00136     dJointSetUniversalParam(jointID, dParamFMax2, force); 
00137   */
00138 }

Generated on Thu Jul 29 15:56:28 2004 for OpenSim by doxygen 1.3.6