Skip to content
Snippets Groups Projects
Commit 3194b1a6 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

Format

parent 1508cbb9
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
*/ */
#include "gazebo/physics/physics.hh" #include "gazebo/physics/physics.hh"
#include "SpringPlugin.hh" #include "SpringPlugin.hh"
...@@ -24,19 +24,15 @@ using namespace gazebo; ...@@ -24,19 +24,15 @@ using namespace gazebo;
GZ_REGISTER_MODEL_PLUGIN(SpringPlugin) GZ_REGISTER_MODEL_PLUGIN(SpringPlugin)
///////////////////////////////////////////////// /////////////////////////////////////////////////
SpringPlugin::SpringPlugin() SpringPlugin::SpringPlugin() {}
{
}
///////////////////////////////////////////////// /////////////////////////////////////////////////
void SpringPlugin::Load(physics::ModelPtr lmodel, void SpringPlugin::Load(physics::ModelPtr lmodel, sdf::ElementPtr lsdf) {
sdf::ElementPtr lsdf)
{
this->model = lmodel; this->model = lmodel;
// hardcoded params for this test // hardcoded params for this test
if (!lsdf->HasElement("joint_spring")) if (!lsdf->HasElement("joint_spring"))
ROS_ERROR_NAMED("SpringPlugin","No field joint_spring for SpringPlugin"); ROS_ERROR_NAMED("SpringPlugin", "No field joint_spring for SpringPlugin");
else else
this->jointExplicitName = lsdf->Get<std::string>("joint_spring"); this->jointExplicitName = lsdf->Get<std::string>("joint_spring");
...@@ -44,30 +40,22 @@ void SpringPlugin::Load(physics::ModelPtr lmodel, ...@@ -44,30 +40,22 @@ void SpringPlugin::Load(physics::ModelPtr lmodel,
this->kdExplicit = lsdf->Get<double>("kd"); this->kdExplicit = lsdf->Get<double>("kd");
ROS_INFO_NAMED("SpringPlugin", ROS_INFO_NAMED("SpringPlugin", "Loading joint : %s kp: %f kd: %f", this->jointExplicitName.c_str(), this->kpExplicit,
"Loading joint : %s kp: %f kd: %f",
this->jointExplicitName.c_str(),
this->kpExplicit,
this->kdExplicit); this->kdExplicit);
} }
///////////////////////////////////////////////// /////////////////////////////////////////////////
void SpringPlugin::Init() void SpringPlugin::Init() {
{
this->jointExplicit = this->model->GetJoint(this->jointExplicitName); this->jointExplicit = this->model->GetJoint(this->jointExplicitName);
/* this->jointImplicit->SetStiffnessDamping(0, this->kpImplicit, /* this->jointImplicit->SetStiffnessDamping(0, this->kpImplicit,
this->kdImplicit); */ this->kdImplicit); */
this->updateConnection = event::Events::ConnectWorldUpdateBegin( this->updateConnection = event::Events::ConnectWorldUpdateBegin(boost::bind(&SpringPlugin::ExplicitUpdate, this));
boost::bind(&SpringPlugin::ExplicitUpdate, this));
} }
///////////////////////////////////////////////// /////////////////////////////////////////////////
void SpringPlugin::ExplicitUpdate() void SpringPlugin::ExplicitUpdate() {
{
#if GAZEBO_MAJOR_VERSION < 9 #if GAZEBO_MAJOR_VERSION < 9
common::Time currTime = this->model->GetWorld()->GetSimTime(); common::Time currTime = this->model->GetWorld()->GetSimTime();
#else #else
...@@ -79,7 +67,6 @@ void SpringPlugin::ExplicitUpdate() ...@@ -79,7 +67,6 @@ void SpringPlugin::ExplicitUpdate()
double pos = this->jointExplicit->GetAngle(0).Radian(); double pos = this->jointExplicit->GetAngle(0).Radian();
double vel = this->jointExplicit->GetVelocity(0); double vel = this->jointExplicit->GetVelocity(0);
double force = -this->kpExplicit * pos double force = -this->kpExplicit * pos - this->kdExplicit * vel;
-this->kdExplicit * vel;
this->jointExplicit->SetForce(0, force); this->jointExplicit->SetForce(0, force);
} }
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
*/ */
#ifndef __GAZEBO_SPRING_TEST_PLUGIN_HH__ #ifndef __GAZEBO_SPRING_TEST_PLUGIN_HH__
#define __GAZEBO_SPRING_TEST_PLUGIN_HH__ #define __GAZEBO_SPRING_TEST_PLUGIN_HH__
...@@ -23,31 +23,42 @@ ...@@ -23,31 +23,42 @@
#include "gazebo/physics/physics.hh" #include "gazebo/physics/physics.hh"
#include "gazebo/util/system.hh" #include "gazebo/util/system.hh"
namespace gazebo namespace gazebo {
{ class GAZEBO_VISIBLE SpringPlugin : public ModelPlugin {
class GAZEBO_VISIBLE SpringPlugin : public ModelPlugin public:
{ SpringPlugin();
public: SpringPlugin();
public: virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf);
public: virtual void Init();
private: void ExplicitUpdate(); public:
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf);
private: event::ConnectionPtr updateConnection; public:
virtual void Init();
private: physics::ModelPtr model; private:
void ExplicitUpdate();
private: common::Time prevUpdateTime; private:
event::ConnectionPtr updateConnection;
private: physics::JointPtr jointExplicit; private:
private: std::string jointExplicitName; physics::ModelPtr model;
/// \brief simulate spring/damper with ExplicitUpdate function private:
private: double kpExplicit; common::Time prevUpdateTime;
/// \brief simulate spring/damper with ExplicitUpdate function private:
private: double kdExplicit; physics::JointPtr jointExplicit;
}; private:
} std::string jointExplicitName;
/// \brief simulate spring/damper with ExplicitUpdate function
private:
double kpExplicit;
/// \brief simulate spring/damper with ExplicitUpdate function
private:
double kdExplicit;
};
} // namespace gazebo
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment