##

GearboxJoint.hh
Go to the documentation of this file.
/*
* Copyright (C) 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef _GEARBOXJOINT_HH_
#define _GEARBOXJOINT_HH_
#include <string>
#include "gazebo/msgs/msgs.hh"
#include "gazebo/util/system.hh"
namespace gazebo
{
namespace physics
{
template<class T>
class GZ_PHYSICS_VISIBLE GearboxJoint : public T
{
public: explicit GearboxJoint(BasePtr _parent)
: T(_parent), gearRatio(1.0)
{ this->AddType(Base::GEARBOX_JOINT); }
public: virtual ~GearboxJoint()
{ }
// Documentation inherited.
public: virtual unsigned int DOF() const
{return 2;}
public: virtual void Load(sdf::ElementPtr _sdf)
{
T::Load(_sdf);
if (_sdf->HasElement("gearbox_ratio"))
{
this->gearRatio =
_sdf->Get<double>("gearbox_ratio");
}
else
{
gzerr << "gearbox_ratio_not_specified, set to 1.\n";
this->gearRatio = 1.0;
/* below should bring in default values for sdf 1.4+
this->gearRatio =
_sdf->Get<double>("gearbox_ratio");
*/
}
if (_sdf->HasElement("gearbox_reference_body"))
{
this->referenceBody =
_sdf->Get<std::string>("gearbox_reference_body");
}
else
{
gzerr << "Gearbox joint missing reference body.\n";
}
}
protected: virtual void Init()
{
T::Init();
}
public: virtual double GetGearboxRatio() const
{ return this->gearRatio; }
public: virtual void SetGearboxRatio(double _gearRatio) = 0;
// Documentation inherited
public: virtual void FillMsg(msgs::Joint &_msg)
{
Joint::FillMsg(_msg);
msgs::Joint::Gearbox *gearboxMsg = _msg.mutable_gearbox();
gearboxMsg->set_gearbox_reference_body(this->referenceBody);
gearboxMsg->set_gearbox_ratio(this->gearRatio);
}
protected: double gearRatio;
protected: std::string referenceBody;
};
}
}
#endif
gazebo::physics::Joint::FillMsg
virtual void FillMsg(msgs::Joint &_msg)
Fill a joint message.
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
gazebo::physics::Base::GEARBOX_JOINT
GearboxJoint type.
Definition: Base.hh:106
gazebo::physics::GearboxJoint::FillMsg
virtual void FillMsg(msgs::Joint &_msg)
Definition: GearboxJoint.hh:101
system.hh
msgs.hh
gazebo::physics::GearboxJoint
A double axis gearbox joint.
Definition: GearboxJoint.hh:36
gazebo::physics::GearboxJoint::Init
virtual void Init()
Initialize joint.
Definition: GearboxJoint.hh:83
gazebo::physics::GearboxJoint::Load
virtual void Load(sdf::ElementPtr _sdf)
Load joint.
Definition: GearboxJoint.hh:53
gazebo::physics::GearboxJoint::GearboxJoint
GearboxJoint(BasePtr _parent)
Constructor.
Definition: GearboxJoint.hh:40
gzerr
#define gzerr
Output an error message.
Definition: Console.hh:50
gazebo::physics::GearboxJoint::SetGearboxRatio
virtual void SetGearboxRatio(double _gearRatio)=0
Set gearbox joint gear ratio.
gazebo::physics::GearboxJoint::DOF
virtual unsigned int DOF() const
Definition: GearboxJoint.hh:48
gazebo::physics::BasePtr
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:77
gazebo::msgs::Init
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
gazebo::physics::GearboxJoint::referenceBody
std::string referenceBody
reference link/body for computing joint angles
Definition: GearboxJoint.hh:113
gazebo::physics::GearboxJoint::~GearboxJoint
virtual ~GearboxJoint()
Destructor.
Definition: GearboxJoint.hh:44
gazebo::physics::GearboxJoint::gearRatio
double gearRatio
Gearbox gearRatio.
Definition: GearboxJoint.hh:110
gazebo::physics::GearboxJoint::GetGearboxRatio
virtual double GetGearboxRatio() const
Get gearbox joint gear ratio.
Definition: GearboxJoint.hh:90