-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added linear battery plugin and msg integration Signed-off-by: Aditya <[email protected]> Co-authored-by: braanan <[email protected]>
- Loading branch information
1 parent
fdb0322
commit 7efbba3
Showing
11 changed files
with
1,137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
lrauv_system_tests/test/vehicle/test_battery_full_charge.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (C) 2022 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
/* | ||
* Development of this module has been funded by the Monterey Bay Aquarium | ||
* Research Institute (MBARI) and the David and Lucile Packard Foundation | ||
*/ | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <gz/msgs/battery_state.pb.h> | ||
|
||
#include <chrono> | ||
|
||
#include "lrauv_system_tests/TestFixture.hh" | ||
|
||
using namespace gz; | ||
using namespace std::literals::chrono_literals; | ||
|
||
////////////////////////////////////////////////// | ||
/// Test if the battery discharges with time with the specified | ||
/// disacharge power rate, when starting with full charge. | ||
TEST(BatteryTest, TestDischargeFullCharged) | ||
{ | ||
using TestFixture = lrauv_system_tests::TestFixtureWithVehicle; | ||
TestFixture fixture("buoyant_tethys.sdf", "tethys"); | ||
uint64_t iterations = fixture.Step(100u); | ||
|
||
transport::Node node; | ||
lrauv_system_tests::Subscription<msgs::BatteryState> batterySubscription; | ||
batterySubscription.Subscribe(node, "/model/tethys/battery/linear_battery/state"); | ||
|
||
fixture.Step(1000u); | ||
|
||
ASSERT_TRUE(batterySubscription.WaitForMessages(5, 10s)); | ||
int n = batterySubscription.MessageHistorySize() - 1; | ||
auto initialMessage = batterySubscription.GetMessageByIndex(0); | ||
double initialCharge = initialMessage.charge(); | ||
double initialVoltage = initialMessage.voltage(); | ||
double initialTime = initialMessage.header().stamp().sec() + | ||
initialMessage.header().stamp().nsec()/1000000000.0; | ||
|
||
/* Plugin started with 100% charge */ | ||
EXPECT_NEAR(initialCharge, 400, 0.2); | ||
|
||
auto finalMessage = batterySubscription.GetMessageByIndex(n); | ||
double finalCharge = finalMessage.charge(); | ||
double finalVoltage = finalMessage.voltage(); | ||
double finalTime = finalMessage.header().stamp().sec() + | ||
finalMessage.header().stamp().nsec()/1000000000.0; | ||
|
||
double dischargePower = (finalVoltage + initialVoltage) * 0.5 * | ||
(finalCharge - initialCharge) * 3600 / (finalTime - initialTime); | ||
EXPECT_NEAR(dischargePower, -28.8, 0.5); | ||
} |
97 changes: 97 additions & 0 deletions
97
lrauv_system_tests/test/vehicle/test_battery_half_charge.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright (C) 2022 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
/* | ||
* Development of this module has been funded by the Monterey Bay Aquarium | ||
* Research Institute (MBARI) and the David and Lucile Packard Foundation | ||
*/ | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <gz/msgs/battery_state.pb.h> | ||
|
||
#include <chrono> | ||
|
||
#include "lrauv_system_tests/TestFixture.hh" | ||
|
||
using namespace gz; | ||
using namespace std::literals::chrono_literals; | ||
|
||
////////////////////////////////////////////////// | ||
/// Test if the battery discharges with time with the specified | ||
/// disacharge power rate, when starting with half charge. | ||
/// Send recharge start/stop commands and verify the battery behaves | ||
/// accordingly. | ||
TEST(BatteryTest, TestDischargeHalfCharged) | ||
{ | ||
using TestFixture = lrauv_system_tests::TestFixtureWithVehicle; | ||
TestFixture fixture("buoyant_tethys_half_battery.sdf", "tethys"); | ||
uint64_t iterations = fixture.Step(100u); | ||
|
||
transport::Node node; | ||
lrauv_system_tests::Subscription<msgs::BatteryState> batterySubscription; | ||
batterySubscription.Subscribe(node, "/model/tethys/battery/linear_battery/state"); | ||
|
||
fixture.Step(1000u); | ||
|
||
ASSERT_TRUE(batterySubscription.WaitForMessages(5, 10s)); | ||
int n = batterySubscription.MessageHistorySize() - 1; | ||
auto initialMessage = batterySubscription.GetMessageByIndex(0); | ||
double initialCharge = initialMessage.charge(); | ||
double initialVoltage = initialMessage.voltage(); | ||
double initialTime = initialMessage.header().stamp().sec() + | ||
initialMessage.header().stamp().nsec()/1000000000.0; | ||
|
||
/* Plugin started wiht 50% charge */ | ||
EXPECT_NEAR(initialCharge, 200, 0.2); | ||
|
||
auto finalMessage = batterySubscription.GetMessageByIndex(n); | ||
double finalCharge = finalMessage.charge(); | ||
double finalVoltage = finalMessage.voltage(); | ||
double finalTime = finalMessage.header().stamp().sec() + | ||
finalMessage.header().stamp().nsec()/1000000000.0; | ||
|
||
/* Check discharge rate when battery is 50% discharged */ | ||
double dischargePower = (finalVoltage + initialVoltage) * 0.5 * | ||
(finalCharge - initialCharge) * 3600 / (finalTime - initialTime); | ||
EXPECT_NEAR(dischargePower, -28.8, 0.5); | ||
|
||
batterySubscription.ResetMessageHistory(); | ||
|
||
/* Test battery recharge command */ | ||
/* Start charging and check if charge increases with time */ | ||
const unsigned int timeout{5000}; | ||
bool result; | ||
msgs::Boolean req; | ||
msgs::Empty rep; | ||
EXPECT_TRUE(node.Request("/model/tethys/battery/linear_battery/recharge/start", req, timeout, rep, result)); | ||
|
||
fixture.Step(1000u); | ||
|
||
ASSERT_TRUE(batterySubscription.WaitForMessages(5, 10s)); | ||
n = batterySubscription.MessageHistorySize() - 1; | ||
EXPECT_GT(batterySubscription.GetMessageByIndex(n).charge(), finalCharge); | ||
batterySubscription.ResetMessageHistory(); | ||
|
||
/* Stop charging, charge should decrease with time */ | ||
EXPECT_TRUE(node.Request("/model/tethys/battery/linear_battery/recharge/stop", req, timeout, rep, result)); | ||
fixture.Step(1000u); | ||
ASSERT_TRUE(batterySubscription.WaitForMessages(5, 10s)); | ||
n = batterySubscription.MessageHistorySize() - 1; | ||
EXPECT_LT(batterySubscription.GetMessageByIndex(n).charge(), | ||
batterySubscription.GetMessageByIndex(0).charge()); | ||
} |
Oops, something went wrong.