Quantcast
Channel: Gazebo: Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 7017

revolute joint dos not work when adding an angular velocity to the model

$
0
0
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_planemodel://sun1 0.01 0.05 0 0 01008,3341008,3341016,6661 1 0.011 1 0.011 0.01 0.8 0 0 00.1868000.186700.00004150.01 0.02 1.5heavy_base01revolute_base011 -0.01 0.8 0 0 00.1868000.186700.00004150.01 0.02 1.5heavy_base01revolute_base021 0.1 0.85 0 0 00.16351000.1635100.001660.1 0.1 1.40.1 0.1 1.4revolute_base01revolute_arm010 1 00 0.06 0 0 0 01 -0.1 0.85 0 0 00.16351000.1635100.001660.1 0.1 1.40.1 0.1 1.4revolute_base01revolute_arm020 1 00 -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) }

Viewing all articles
Browse latest Browse all 7017