A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
generic-battery-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Tokushima University, Japan
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Alberto Gallegos Ramonet <alramonet@is.tokushima-u.ac.jp>
7 * Based on the works of Andrea Sacco (2010)
8 */
9
10#include "ns3/core-module.h"
11#include "ns3/energy-module.h"
12
13using namespace ns3;
14using namespace ns3::energy;
15
16/**
17 * @ingroup energy-tests
18 *
19 * @brief Discharge a battery test
20 */
22{
23 public:
25
26 void DoRun() override;
27
28 Ptr<Node> m_node; //!< Node to aggregate the source to.
29};
30
32 : TestCase("Discharge a Li-Ion Panasonic CGR18650DA battery")
33{
34}
35
36void
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
45 GenericBatteryModelHelper batteryHelper;
46 Ptr<GenericBatteryModel> batteryModel =
48
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
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 */
73{
74 public:
76};
77
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
Discharge a battery test.
void DoRun() override
Implementation to actually run this TestCase.
Ptr< Node > m_node
Node to aggregate the source to.
Generic battery TestSuite.
Creates and assign an assortment of BatteryModels to Nodes.
Ptr< energy::EnergySourceContainer > Install(NodeContainer c) const
This function installs energy sources in a group of nodes in a node container.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static GenericBatteryTestSuite g_genericBatteryTestSuite
create an instance of the test suite
@ PANASONIC_CGR18650DA_LION
Panasonic CGR18650DA Li-Ion battery.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Definition test.h:327
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1345
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:585