Joint.hh
00001 /*
00002  * Copyright 2011 Nate Koenig & Andrew Howard
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  *
00016 */
00017 /* Desc: The base joint class
00018  * Author: Nate Keonig, Andrew Howard
00019  * Date: 21 May 2003
00020  */
00021 
00022 #ifndef JOINT_HH
00023 #define JOINT_HH
00024 
00025 #include "common/Event.hh"
00026 #include "math/Angle.hh"
00027 #include "math/Vector3.hh"
00028 #include "transport/TransportTypes.hh"
00029 #include "msgs/MessageTypes.hh"
00030 
00031 #include "physics/Base.hh"
00032 
00033 namespace gazebo
00034 {
00035     namespace physics
00036   {
00039 
00041     class Joint : public Base
00042     {
00044       public: enum Attribute {FUDGE_FACTOR, 
00045                               SUSPENSION_ERP, 
00046                               SUSPENSION_CFM, 
00047                               STOP_ERP,
00048                               STOP_CFM,
00049                               ERP,
00050                               CFM,
00051                               FMAX,
00052                               VEL,
00053                               HI_STOP,
00054                               LO_STOP};
00055   
00057       public: Joint();
00058   
00060       public: virtual ~Joint();
00061   
00063       public: virtual void Load( sdf::ElementPtr &_sdf );
00064 
00066       public: virtual void Init();
00067   
00069       public: void Update();
00070   
00072       public: virtual void UpdateParameters( sdf::ElementPtr &_sdf );
00073 
00075       public: void ShowJoints(const bool &s);
00076   
00078       public: virtual void Reset();
00079   
00081       public: void SetModel(ModelPtr model);
00082   
00084       public: virtual LinkPtr GetJointLink( int index ) const = 0;
00085   
00087       public: virtual bool AreConnected( LinkPtr one, LinkPtr two ) const = 0;
00088   
00090       public: virtual void Attach( LinkPtr parent, LinkPtr child );
00091   
00093       public: virtual void Detach() = 0;
00094   
00096       public: virtual void SetAxis(int index, const math::Vector3 &axis) = 0;
00097   
00099       public: virtual void SetDamping(int index, const double damping) = 0;
00100   
00102       public: template<typename T>
00103               event::ConnectionPtr ConnectJointUpdate(T subscriber)
00104               { return jointUpdate.Connect(subscriber); }
00106       public: void DisconnectJointUpdate( event::ConnectionPtr &c )
00107               { jointUpdate.Disconnect(c); }
00108   
00110       public: math::Vector3 GetLocalAxis(int _index) const;
00111       public: virtual math::Vector3 GetGlobalAxis(int _index) const = 0;
00112   
00114       public: virtual void SetAnchor( int index, const math::Vector3 &anchor ) = 0;
00115   
00117       public: virtual math::Vector3 GetAnchor(int index) const = 0;
00118   
00120       public: virtual void SetHighStop(int index, math::Angle angle) = 0;
00121   
00123       public: virtual void SetLowStop(int index, math::Angle angle) = 0;
00124    
00126       public: virtual math::Angle GetHighStop(int index) = 0;
00127   
00129       public: virtual math::Angle GetLowStop(int index) = 0;
00130   
00132       public: virtual void SetVelocity(int index, double v) = 0;
00133   
00135       public: virtual double GetVelocity(int index) const = 0;
00136   
00138       public: virtual void SetForce(int /*index*/, double /*f*/) {}
00139   
00141       public: virtual double GetForce(int /*index*/) {return 0;}
00142    
00144       public: virtual void SetMaxForce(int index, double t) = 0;
00145   
00147       public: virtual double GetMaxForce(int index) = 0;
00148   
00150       public: math::Angle GetAngle(int index) const;
00151 
00155       public: void SetAngle(int _index, math::Angle _angle);
00156   
00159       public: virtual math::Vector3 GetLinkForce(unsigned int index) const = 0;
00160   
00163       public: virtual math::Vector3 GetLinkTorque(unsigned int index) const = 0;
00164   
00166       public: virtual void SetAttribute( Attribute, int index, double value) = 0;
00167 
00169       public: LinkPtr GetChild() const;
00170 
00172       public: LinkPtr GetParent() const;
00173 
00175       public: void FillJointMsg( msgs::Joint &_msg );
00176 
00177       protected: virtual math::Angle GetAngleImpl(int _index) const = 0;
00178 
00180       protected: LinkPtr childLink;
00181   
00183       protected: LinkPtr parentLink;
00184   
00185       protected: std::string visual;
00186       protected: std::string line1;
00187       protected: std::string line2;
00188       protected: bool showJoints;
00189   
00190       protected: ModelPtr model;
00191   
00192       protected: math::Vector3 anchorPos;
00193       protected: LinkPtr anchorLink;
00194   
00195       private: event::EventT<void ()> jointUpdate;
00196       private: event::ConnectionPtr showJointsConnection;
00197   
00198       // joint damping_coefficient
00199       protected: double damping_coefficient;
00200       protected: transport::PublisherPtr vis_pub;
00201       private: math::Angle staticAngle;
00202     };
00204   }
00205 }
00206 #endif
00207