Skip to content

Commit c4e82ce

Browse files
committed
Orbit: add rover model
- Use Imu sensors with custom gravity - Adjust earth mass to give surface accel of 10 m/s^2 - Add rover model Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
1 parent 60a109a commit c4e82ce

2 files changed

Lines changed: 77 additions & 18 deletions

File tree

src/GravityPlugin.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class GravityPlugin::Impl
6363
/// \brief Flag set to true if the plugin is initialised.
6464
public: bool initialised{false};
6565

66+
/// \brief Power law exponent. Default is inverse square.
67+
public: double gravity_expo{-2.0};
68+
6669
/// \brief Universal gravitational constant (N m^2 / kg^2).
6770
public: static constexpr double G{6.67430E-11};
6871
};
@@ -98,9 +101,9 @@ void GravityPlugin::Configure(
98101
}
99102

100103
// parameters
101-
if (_sdf->HasElement("source"))
104+
if (_sdf->HasElement("gravity_source"))
102105
{
103-
this->impl->sourceName = _sdf->Get<std::string>("source");
106+
this->impl->sourceName = _sdf->Get<std::string>("gravity_source");
104107
}
105108
else
106109
{
@@ -109,6 +112,11 @@ void GravityPlugin::Configure(
109112
return;
110113
}
111114

115+
if (_sdf->HasElement("gravity_expo"))
116+
{
117+
this->impl->gravity_expo = _sdf->Get<double>("gravity_expo");
118+
}
119+
112120
if (_sdf->HasElement("debug"))
113121
{
114122
this->impl->debug = _sdf->Get<bool>("debug");
@@ -207,10 +215,10 @@ void GravityPlugin::PreUpdate(
207215

208216
// inverse radius
209217
double one_over_r = 1.0 / r;
210-
double one_over_r2 = 1.0 / (r * r);
218+
double r_expo = pow(r, this->impl->gravity_expo);
211219

212220
// magnitude of force
213-
auto f = 1.0 * this->impl->G * mass_C * mass_B * one_over_r2;
221+
auto f = 1.0 * this->impl->G * mass_C * mass_B * r_expo;
214222

215223
// direction of force
216224
auto direction = -1.0 * one_over_r * p_CB_W;

worlds/earth.sdf

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@
2222
</plugin>
2323
<plugin filename="gz-sim-imu-system"
2424
name="gz::sim::systems::Imu">
25+
<gravity_source>earth</gravity_source>
26+
<gravity_expo>-2.0</gravity_expo>
2527
</plugin>
2628

2729
<plugin filename="GravityPlugin"
2830
name="GravityPlugin">
2931
<debug>0</debug>
30-
<source>earth</source>
32+
<gravity_source>earth</gravity_source>
33+
<gravity_expo>-2.0</gravity_expo>
3134
</plugin>
3235

3336
<!-- disable planar gravity -->
@@ -53,7 +56,7 @@
5356
<direction>-0.5 0.1 -0.9</direction>
5457
</light>
5558

56-
<model name="enu_axes">
59+
<!-- <model name="enu_axes">
5760
<static>1</static>
5861
<link name="link">
5962
<visual name="r">
@@ -105,34 +108,55 @@
105108
</material>
106109
</visual>
107110
</link>
108-
</model>
111+
</model> -->
109112

110113
<!-- source of gravity -->
111114
<model name="earth">
112115
<static>0</static>
113116
<link name="earth">
114117
<gravity>0</gravity>
118+
<!-- expo = -2.0 -->
115119
<inertial>
116-
<mass>5.972E14</mass>
120+
<mass>1.50E+13</mass>
117121
<inertia>
118-
<ixx>2.38880E+16</ixx>
122+
<ixx>5.99314E+14</ixx>
119123
<ixy>0</ixy>
120124
<ixz>0</ixz>
121-
<iyy>2.38880E+16</iyy>
125+
<iyy>5.99314E+14</iyy>
122126
<iyz>0</iyz>
123-
<izz>2.38880E+16</izz>
127+
<izz>5.99314E+14</izz>
124128
</inertia>
125129
</inertial>
130+
<!-- expo = -0.5 -->
131+
<!-- <inertial>
132+
<mass>4.74E+11</mass>
133+
<inertia>
134+
<ixx>1.89520E+13</ixx>
135+
<ixy>0</ixy>
136+
<ixz>0</ixz>
137+
<iyy>1.89520E+13</iyy>
138+
<iyz>0</iyz>
139+
<izz>1.89520E+13</izz>
140+
</inertia>
141+
</inertial> -->
126142
<collision name="collision">
127-
<pose degrees="true">0 0 0 90 0 0</pose>
143+
<pose degrees="true">0 0 0 90 0 -90</pose>
128144
<geometry>
129145
<sphere>
130146
<radius>10</radius>
131147
</sphere>
132148
</geometry>
133-
</collision>
149+
<surface>
150+
<friction>
151+
<ode>
152+
<mu>1.0</mu>
153+
<mu2>1.0</mu2>
154+
</ode>
155+
</friction>
156+
</surface>
157+
</collision>
134158
<visual name="visual">
135-
<pose degrees="true">0 0 0 90 0 0</pose>
159+
<pose degrees="true">0 0 0 90 0 -90</pose>
136160
<geometry>
137161
<sphere>
138162
<radius>10</radius>
@@ -154,7 +178,7 @@
154178

155179
<plugin filename="gz-sim-velocity-control-system"
156180
name="gz::sim::systems::VelocityControl">
157-
<initial_angular>0 0 0.1</initial_angular>
181+
<initial_angular>0 0 0.0</initial_angular>
158182
</plugin>
159183

160184
</model>
@@ -201,7 +225,7 @@
201225
<plugin filename="InitialVelocityPlugin"
202226
name="InitialVelocityPlugin">
203227
<debug>0</debug>
204-
<linear>0 51.55 0</linear>
228+
<linear>0 8.164965809 0</linear>
205229
<link>base_link</link>
206230
<p_gain>50</p_gain>
207231
<i_gain>1</i_gain>
@@ -255,7 +279,7 @@
255279
<plugin filename="InitialVelocityPlugin"
256280
name="InitialVelocityPlugin">
257281
<debug>0</debug>
258-
<linear>-44.64 0 0</linear>
282+
<linear>-7.071067812 0 0</linear>
259283
<link>base_link</link>
260284
<p_gain>50</p_gain>
261285
<i_gain>1</i_gain>
@@ -309,7 +333,7 @@
309333
<plugin filename="InitialVelocityPlugin"
310334
name="InitialVelocityPlugin">
311335
<debug>0</debug>
312-
<linear>0 65.0 0</linear>
336+
<linear>0 10.0 0</linear>
313337
<link>base_link</link>
314338
<p_gain>50</p_gain>
315339
<i_gain>1</i_gain>
@@ -321,5 +345,32 @@
321345
</plugin>
322346
</model>
323347

348+
<!-- <include>
349+
<uri>model://iris_with_gimbal</uri>
350+
<pose degrees="true">0 0 10.3 0 0 90</pose>
351+
</include> -->
352+
353+
354+
<!--
355+
Earth uses ECEF frame
356+
X - in plane of equator through centre and meridian 0
357+
Y - in plane of equator through centre and meridian 90
358+
Z - through centre and north pole
359+
360+
Transforms to local NED for different starting positions
361+
<10 0 0 90 0 90>
362+
lat 0, lon 0, hdg 90
363+
NED
364+
X_ned = Z_ecef
365+
Y_ned = Y_ecef
366+
Z_ned = -X_ecef
367+
<gazeboXYZToNED degrees="true">10 0 0 0 -90 0</gazeboXYZToNED>
368+
-->
369+
370+
<include>
371+
<uri>model://omni4rover</uri>
372+
<pose degrees="true">10.3 0 0 90 -90 90</pose>
373+
</include>
374+
324375
</world>
325376
</sdf>

0 commit comments

Comments
 (0)