|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Tokushima University, Japan |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: GPL-2.0-only |
| 5 | + * |
| 6 | + * Author: Alberto Gallegos Ramonet <[email protected]> |
| 7 | + * Based on the works of Andrea Sacco (2010) |
| 8 | + */ |
| 9 | + |
| 10 | +#include "ns3/core-module.h" |
| 11 | +#include "ns3/energy-module.h" |
| 12 | + |
| 13 | +using namespace ns3; |
| 14 | +using namespace ns3::energy; |
| 15 | + |
| 16 | +/** |
| 17 | + * @ingroup energy-tests |
| 18 | + * |
| 19 | + * @brief Discharge a battery test |
| 20 | + */ |
| 21 | +class DischargeBatteryTestCase : public TestCase |
| 22 | +{ |
| 23 | + public: |
| 24 | + DischargeBatteryTestCase(); |
| 25 | + |
| 26 | + void DoRun() override; |
| 27 | + |
| 28 | + Ptr<Node> m_node; //!< Node to aggregate the source to. |
| 29 | +}; |
| 30 | + |
| 31 | +DischargeBatteryTestCase::DischargeBatteryTestCase() |
| 32 | + : TestCase("Discharge a Li-Ion Panasonic CGR18650DA battery") |
| 33 | +{ |
| 34 | +} |
| 35 | + |
| 36 | +void |
| 37 | +DischargeBatteryTestCase::DoRun() |
| 38 | +{ |
| 39 | + // This test demonstrates that the battery reach its cutoff voltage in a little less than 1 |
| 40 | + // hour. When discharged with a constant current of 2.33 A (Equivalent to 1C). |
| 41 | + // Note: The cutoff voltage is only reached within this time for the specified battery |
| 42 | + // (PANASONIC CGR18650DA Li-Ion). |
| 43 | + |
| 44 | + Ptr<Node> node = CreateObject<Node>(); |
| 45 | + GenericBatteryModelHelper batteryHelper; |
| 46 | + Ptr<GenericBatteryModel> batteryModel = |
| 47 | + DynamicCast<GenericBatteryModel>(batteryHelper.Install(node, PANASONIC_CGR18650DA_LION)); |
| 48 | + |
| 49 | + Ptr<SimpleDeviceEnergyModel> consumptionEnergyModel = CreateObject<SimpleDeviceEnergyModel>(); |
| 50 | + consumptionEnergyModel->SetEnergySource(batteryModel); |
| 51 | + batteryModel->AppendDeviceEnergyModel(consumptionEnergyModel); |
| 52 | + consumptionEnergyModel->SetNode(node); |
| 53 | + |
| 54 | + // Discharge the battery with a constant current of 2.33 A (1C) |
| 55 | + consumptionEnergyModel->SetCurrentA(2.33); |
| 56 | + |
| 57 | + Simulator::Stop(Seconds(3459)); |
| 58 | + Simulator::Run(); |
| 59 | + Simulator::Destroy(); |
| 60 | + |
| 61 | + NS_TEST_ASSERT_MSG_EQ_TOL(batteryModel->GetSupplyVoltage(), |
| 62 | + 3.0, |
| 63 | + 1.0e-2, |
| 64 | + "Cutoff voltage not reached"); |
| 65 | +} |
| 66 | + |
| 67 | +/** |
| 68 | + * @ingroup energy-tests |
| 69 | + * |
| 70 | + * @brief Generic battery TestSuite |
| 71 | + */ |
| 72 | +class GenericBatteryTestSuite : public TestSuite |
| 73 | +{ |
| 74 | + public: |
| 75 | + GenericBatteryTestSuite(); |
| 76 | +}; |
| 77 | + |
| 78 | +GenericBatteryTestSuite::GenericBatteryTestSuite() |
| 79 | + : TestSuite("generic-battery-test", Type::UNIT) |
| 80 | +{ |
| 81 | + AddTestCase(new DischargeBatteryTestCase, TestCase::Duration::QUICK); |
| 82 | +} |
| 83 | + |
| 84 | +/// create an instance of the test suite |
| 85 | +static GenericBatteryTestSuite g_genericBatteryTestSuite; |
0 commit comments