Hi,
I am new to the Gazebo. I have made a model plugin (based on the [Animated Box ](http://gazebosim.org/tutorials?tut=animated_box) example. My model has two `revolute` joints (each are limited to the 15°). When I add an angular velocity to the model by
this->model->SetAngularVel(math::Vector3(0, 0, LinearSpeed));
The `revolute` joints stop moving. Can any one help me how I can make the joints moving in the moment of the rotation of the model?
Thanks ,
You can find below my source files.
## World's SDF File ##
> Blockquotemodel://ground_plane model://sun 1 0.01 0.05 0 0 0 100 8,3341 0 0 8,3341 0 16,666 1 1 0.01 1 1 0.01 1 0.01 0.8 0 0 0 0.1868 0 0 0.1867 0 0.0000415 0.01 0.02 1.5 heavy_base01 revolute_base01 1 -0.01 0.8 0 0 0 0.1868 0 0 0.1867 0 0.0000415 0.01 0.02 1.5 heavy_base01 revolute_base02 1 0.1 0.85 0 0 0 0.16351 0 0 0.16351 0 0.00166 0.1 0.1 1.4 0.1 0.1 1.4 revolute_base01 revolute_arm01 0 1 0 0 0.06 0 0 0 0 1 -0.1 0.85 0 0 0 0.16351 0 0 0.16351 0 0.00166 0.1 0.1 1.4 0.1 0.1 1.4 revolute_base01 revolute_arm02 0 1 0 0 -0.1 0.0 0 0 0
## Plugin Source File ##
#include
#include
#include
#include
#include
#include
static const double AngularLegSpeed = 1; // rad/s
static const double LinearSpeed = 0.1; // m/s
static const double LegAngle = 15; // degre
namespace gazebo
{
class AnimatedBox : public ModelPlugin
{
bool m_isInitialised;
public: AnimatedBox():m_isInitialised(false){}
public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/)
{
// Store the pointer to the model
this->model = _parent;
// Listen to the update
this->updateConnection = event::Events::ConnectWorldUpdateBegin(boost::bind(&AnimatedBox::OnUpdate, this));
}
public: void OnUpdate()
{
// Apply a small linear velocity to the model.
this->model->SetAngularVel(math::Vector3(0, 0, LinearSpeed));
//this->model->SetLinearVel(math::Vector3(LinearSpeed, 0, 0));
if(!m_isInitialised)
{
this->model->GetJoint("revolute_demo01")->SetVelocity(0, AngularLegSpeed);
this->model->GetJoint("revolute_demo02")->SetVelocity(0, -AngularLegSpeed);
m_isInitialised = true;
}
else
{
angle01 = this->model->GetJoint("revolute_demo01")->GetAngle(0);
angle02 = this->model->GetJoint("revolute_demo02")->GetAngle(0);
if (angle01.Degree() > LegAngle)
{
this->model->GetJoint("revolute_demo01")->SetVelocity(0, -AngularLegSpeed);
}
else if (angle01.Degree() < -LegAngle)
{
this->model->GetJoint("revolute_demo01")->SetVelocity(0, AngularLegSpeed);
}
if (angle02.Degree() < -LegAngle)
{
this->model->GetJoint("revolute_demo02")->SetVelocity(0, AngularLegSpeed);
}
else if (angle02.Degree() > LegAngle)
{
this->model->GetJoint("revolute_demo02")->SetVelocity(0, -AngularLegSpeed);
}
}
}
// Pointer to the model
private: physics::ModelPtr model;
physics::JointPtr joint;
math::Angle angle01;
math::Angle angle02;
// Pointer to the update event connection
private: event::ConnectionPtr updateConnection;
};
// Register this plugin with the simulator
GZ_REGISTER_MODEL_PLUGIN(AnimatedBox)
}
↧