Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
talos-data
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stack Of Tasks
talos-data
Commits
3194b1a6
Commit
3194b1a6
authored
5 years ago
by
Guilhem Saurel
Browse files
Options
Downloads
Patches
Plain Diff
Format
parent
1508cbb9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/SpringPlugin.cc
+9
-22
9 additions, 22 deletions
src/SpringPlugin.cc
src/SpringPlugin.hh
+31
-20
31 additions, 20 deletions
src/SpringPlugin.hh
with
40 additions
and
42 deletions
src/SpringPlugin.cc
+
9
−
22
View file @
3194b1a6
...
@@ -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
);
}
}
This diff is collapsed.
Click to expand it.
src/SpringPlugin.hh
+
31
−
20
View file @
3194b1a6
...
@@ -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:
p
rivate:
std
::
string
jointExplicitName
;
p
hysics
::
ModelPtr
model
;
/// \brief simulate spring/damper with ExplicitUpdate function
private:
private:
double
kpExplicit
;
common
::
Time
prevUpdateTime
;
/// \brief simulate spring/damper with ExplicitUpdate function
private:
p
rivate:
double
kd
Explicit
;
p
hysics
::
JointPtr
joint
Explicit
;
};
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment