Skip to content

Commit

Permalink
Add parameter for adjust current sign in battery plugin (#2696)
Browse files Browse the repository at this point in the history
Signed-off-by: Tatsuro Sakaguchi <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
(cherry picked from commit dd3e241)
  • Loading branch information
Tacha-S authored and iche033 committed Dec 17, 2024
1 parent 779b009 commit 500fe86
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/systems/battery_plugin/LinearBatteryPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ class gz::sim::systems::LinearBatteryPluginPrivate

/// \brief Initial power load set trough config
public: double initialPowerLoad = 0.0;

/// \brief Flag to invert the current sign
public: bool invertCurrentSign{false};
};

/////////////////////////////////////////////////
Expand Down Expand Up @@ -273,6 +276,10 @@ void LinearBatteryPlugin::Configure(const Entity &_entity,
if (_sdf->HasElement("fix_issue_225"))
this->dataPtr->fixIssue225 = _sdf->Get<bool>("fix_issue_225");

if (_sdf->HasElement("invert_current_sign"))
this->dataPtr->invertCurrentSign =
_sdf->Get<bool>("invert_current_sign");

if (_sdf->HasElement("battery_name") && _sdf->HasElement("voltage"))
{
this->dataPtr->batteryName = _sdf->Get<std::string>("battery_name");
Expand Down Expand Up @@ -624,7 +631,10 @@ void LinearBatteryPlugin::PostUpdate(const UpdateInfo &_info,
msg.mutable_header()->mutable_stamp()->CopyFrom(
convert<msgs::Time>(_info.simTime));
msg.set_voltage(this->dataPtr->battery->Voltage());
msg.set_current(this->dataPtr->ismooth);
if (this->dataPtr->invertCurrentSign)
msg.set_current(-this->dataPtr->ismooth);
else
msg.set_current(this->dataPtr->ismooth);
msg.set_charge(this->dataPtr->q);
msg.set_capacity(this->dataPtr->c);

Expand Down

0 comments on commit 500fe86

Please sign in to comment.