Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
nim65s committed Sep 2, 2020
1 parent d24f733 commit 4c71012
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 34 deletions.
22 changes: 6 additions & 16 deletions src/SpringPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "SpringPlugin.hh"


using namespace gazebo;

GZ_REGISTER_MODEL_PLUGIN(SpringPlugin)
Expand All @@ -26,9 +25,7 @@ GZ_REGISTER_MODEL_PLUGIN(SpringPlugin)
SpringPlugin::SpringPlugin() {}

/////////////////////////////////////////////////
void SpringPlugin::Load(physics::ModelPtr lmodel,
sdf::ElementPtr lsdf)
{
void SpringPlugin::Load(physics::ModelPtr lmodel, sdf::ElementPtr lsdf) {
model_ = lmodel;

// hardcoded params for this test
Expand All @@ -43,24 +40,18 @@ void SpringPlugin::Load(physics::ModelPtr lmodel,

axisExplicit_ = lsdf->Get<int>("axis");

ROS_INFO_NAMED("SpringPlugin",
"Loading joint : %s kp: %f kd: %f alongs %d axis",
jointExplicitName_.c_str(),
kpExplicit_,
kdExplicit_,
axisExplicit_);
ROS_INFO_NAMED("SpringPlugin", "Loading joint : %s kp: %f kd: %f alongs %d axis", jointExplicitName_.c_str(),
kpExplicit_, kdExplicit_, axisExplicit_);
}

/////////////////////////////////////////////////
void SpringPlugin::Init()
{
void SpringPlugin::Init() {
jointExplicit_ = model_->GetJoint(jointExplicitName_);

/* jointImplicit->SetStiffnessDamping(0, kpImplicit,
kdImplicit); */

updateConnection_ = event::Events::ConnectWorldUpdateBegin(
boost::bind(&SpringPlugin::ExplicitUpdate, this));
updateConnection_ = event::Events::ConnectWorldUpdateBegin(boost::bind(&SpringPlugin::ExplicitUpdate, this));
}

/////////////////////////////////////////////////
Expand All @@ -80,7 +71,6 @@ void SpringPlugin::ExplicitUpdate() {
double pos = jointExplicit_->Position(axisExplicit_);
#endif
double vel = jointExplicit_->GetVelocity(axisExplicit_);
double force = -kpExplicit_ * pos
-kdExplicit_ * vel;
double force = -kpExplicit_ * pos - kdExplicit_ * vel;
jointExplicit_->SetForce(axisExplicit_, force);
}
49 changes: 31 additions & 18 deletions src/SpringPlugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,46 @@

#pragma GCC diagnostic pop

namespace gazebo
{
class GAZEBO_VISIBLE SpringPlugin : public ModelPlugin
{
public: SpringPlugin();
public: virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf);
public: virtual void Init();
namespace gazebo {
class GAZEBO_VISIBLE SpringPlugin : public ModelPlugin {
public:
SpringPlugin();

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: std::string jointExplicitName_;
private:
physics::ModelPtr model_;

private:
common::Time prevUpdateTime_;

private:
physics::JointPtr jointExplicit_;

private:
std::string jointExplicitName_;

/// \brief simulate spring/damper with ExplicitUpdate function
private: double kpExplicit_;
private:
double kpExplicit_;

/// \brief simulate spring/damper with ExplicitUpdate function
private: double kdExplicit_;

private:
double kdExplicit_;

/// \brief Specify on which axis the spring is applied.
private: int axisExplicit_;
private:
int axisExplicit_;
};
}
} // namespace gazebo
#endif

0 comments on commit 4c71012

Please sign in to comment.