Skip to content

Commit daa8b15

Browse files
committed
ArduPilotPlugin: add distributed sim support
- Check if simulation is distributed. - Use DEBUG_JSON_IO macro. Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
1 parent ea9b15f commit daa8b15

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

src/ArduPilotPlugin.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ class gz::sim::systems::ArduPilotPluginPrivate
388388
// >>>>> DISTRIBUTED <<<<<
389389
public: sdf::ElementPtr sdfClone;
390390
public: bool isSocketInitialised{false};
391-
public: bool isDistributed{false};
392391
public: Entity performerEntity{kNullEntity};
393392
// >>>>> DISTRIBUTED <<<<<
394393
};
@@ -1077,7 +1076,8 @@ void gz::sim::systems::ArduPilotPlugin::PreUpdate(
10771076
auto performerAffinity = _ecm.Component<components::PerformerAffinity>(
10781077
this->dataPtr->performerEntity);
10791078

1080-
if (this->dataPtr->performerEntity != kNullEntity &&
1079+
if (_info.isDistributed &&
1080+
this->dataPtr->performerEntity != kNullEntity &&
10811081
(performerAffinity == nullptr ||
10821082
performerAffinity->Data() != _info.secondaryNamespace))
10831083
{
@@ -1090,10 +1090,6 @@ void gz::sim::systems::ArduPilotPlugin::PreUpdate(
10901090
{
10911091
this->dataPtr->isSocketInitialised = InitSockets(this->dataPtr->sdfClone);
10921092
return;
1093-
// if (!InitSockets(this->dataPtr->sdfClone))
1094-
// {
1095-
// return;
1096-
// }
10971093
}
10981094

10991095
static bool calledInitAnemometerOnce{false};
@@ -1321,7 +1317,8 @@ void gz::sim::systems::ArduPilotPlugin::PostUpdate(
13211317
auto performerAffinity = _ecm.Component<components::PerformerAffinity>(
13221318
this->dataPtr->performerEntity);
13231319

1324-
if (this->dataPtr->performerEntity != kNullEntity &&
1320+
if (_info.isDistributed &&
1321+
this->dataPtr->performerEntity != kNullEntity &&
13251322
(performerAffinity == nullptr ||
13261323
performerAffinity->Data() != _info.secondaryNamespace))
13271324
{
@@ -1411,7 +1408,8 @@ void gz::sim::systems::ArduPilotPlugin::ApplyMotorForces(
14111408
if (this->dataPtr->controls[i].type == "COMMAND")
14121409
{
14131410
msgs::Double cmd;
1414-
cmd.set_data(this->dataPtr->controls[i].cmd);
1411+
double cmdData = this->dataPtr->controls[i].cmd;
1412+
cmd.set_data(cmdData);
14151413
this->dataPtr->controls[i].pub.Publish(cmd);
14161414
continue;
14171415
}
@@ -1754,7 +1752,7 @@ void gz::sim::systems::ArduPilotPlugin::UpdateMotorCommands(
17541752
{
17551753
this->dataPtr->controls[i].outputReady = false;
17561754
this->dataPtr->controls[i].cmd = 0.0;
1757-
#if 0
1755+
#if DEBUG_JSON_IO
17581756
gzdbg << "apply input chan["
17591757
<< this->dataPtr->controls[i].channel
17601758
<< "] to control chan[" << i
@@ -1772,7 +1770,7 @@ void gz::sim::systems::ArduPilotPlugin::UpdateMotorCommands(
17721770
raw_cmd = gz::math::clamp(raw_cmd, 0.0, 1.0);
17731771
this->dataPtr->controls[i].cmd =
17741772
multiplier * (raw_cmd + offset);
1775-
#if 0
1773+
#if DEBUG_JSON_IO
17761774
gzdbg << "apply input chan["
17771775
<< this->dataPtr->controls[i].channel
17781776
<< "] to control chan[" << i
@@ -2105,7 +2103,9 @@ void gz::sim::systems::ArduPilotPlugin::CreateStateJSON(
21052103

21062104
// get JSON
21072105
this->dataPtr->json_str = "\n" + std::string(s.GetString()) + "\n";
2108-
// gzdbg << this->dataPtr->json_str << "\n";
2106+
#if DEBUG_JSON_IO
2107+
gzdbg << this->dataPtr->json_str << "\n";
2108+
#endif
21092109
}
21102110

21112111
/////////////////////////////////////////////////

0 commit comments

Comments
 (0)