-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/877 add battery capacity fault capability #879
base: develop
Are you sure you want to change the base?
Conversation
@@ -59,6 +59,16 @@ void SimpleBattery::evaluateBatteryModel(PowerStorageStatusMsgPayload *msg) { | |||
this->storedCharge = 0; | |||
} | |||
|
|||
if(this->fault == true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some value to making these fault
and faultCapacityRatio
input messages instead of class variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mm, you are thinking like a battery configuration message? I'm not sure I can think of an associated scenario that would need this. I'll think on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about a separate model that would produce output messages that reduce the effective capacity of the battery. For example, a slow, continuous BatteryDegradationModel or a model that randomly produces an output message that lowers the capacity to simulate discrete random faults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mm, interesting. I could see value in that. @Yume27 , what you can do is move the fault state to a message. Then, in simpleBattery
you check if this optional message is connected. If yes, you read in the values and use them? In your event handler you would just change the value of this input message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, couldn't this fault feature be added to the powerStorageBase()
base class? This way all batteries based on this parent class would get this capability?
if(this->faultCapacityRatio < 0) | ||
{ | ||
this->faultCapacityRatio = 1.0; | ||
} | ||
if(this->storedCharge > this->storageCapacity * this->faultCapacityRatio) { | ||
this->storedCharge = this->storageCapacity * this->faultCapacityRatio; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be simplified and made more strict regarding acceptable values of faultCapacityRatio
?
if (this->faultCapacityRatio < 0 || this->faultCapacityRatio > 1)
bskLogger.bskLog(BSK_ERROR, "faultCapacityRatio should be between 0 and 1!");
else
this->storedCharge = this->storageCapacity * this->faultCapacityRatio;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Right now this code silently changes the value if <0 and the user is not notified. I like the more compact version that doesn't silently change values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@juan-g-bonilla , your code actually always set the stored charge to the max value. I think the code should be:
if (this->faultCapacityRatio < 0 || this->faultCapacityRatio > 1) {
bskLogger.bskLog(BSK_ERROR, "faultCapacityRatio should be between 0 and 1!");
} else if(this->storedCharge > this->storageCapacity * this->faultCapacityRatio) {
this->storedCharge = this->storageCapacity * this->faultCapacityRatio;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sorry I misread something about that line when writing the comment!
@@ -39,6 +39,8 @@ class SimpleBattery: public PowerStorageBase { | |||
|
|||
public: | |||
double storageCapacity; //!< [W-s] Battery capacity in Watt-seconds (Joules). | |||
bool fault = false; //!< Fault flag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These variables should be private variables, and then we need associated setter and getter functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you’re using setters, then i would move the check 0<=faultCapacityRatio<=1
to the setter of faultCapacityRatio
instead of every time the model is run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But, if we are reading in the value from a message, then we don't have that control. I like the idea of moving the fault info to a battery fault message. I think it will provide a more elegant solution.
@@ -39,6 +39,8 @@ class SimpleBattery: public PowerStorageBase { | |||
|
|||
public: | |||
double storageCapacity; //!< [W-s] Battery capacity in Watt-seconds (Joules). | |||
bool fault = false; //!< Fault flag | |||
double faultCapacityRatio = 1.0; //!< Fault capacity ratio |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explain what 1.0 default value means here. This means by default we have full capacity, correct?
if(this->faultCapacityRatio < 0) | ||
{ | ||
this->faultCapacityRatio = 1.0; | ||
} | ||
if(this->storedCharge > this->storageCapacity * this->faultCapacityRatio) { | ||
this->storedCharge = this->storageCapacity * this->faultCapacityRatio; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Right now this code silently changes the value if <0 and the user is not notified. I like the more compact version that doesn't silently change values.
# | ||
# ISC License | ||
# | ||
# Copyright (c) 2016, Autonomous Vehicle Systems Lab, University of Colorado at Boulder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update copyright year to 2024
test_battery = simpleBattery.SimpleBattery() | ||
test_battery.storedCharge_Init = storedChargeInit | ||
test_battery.storageCapacity = batteryCapacity | ||
test_battery.fault = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now you are only testing the functionality if there is a fault. You should include a trivial test that checks that the default behavior is no fault.
@@ -36,3 +36,8 @@ The next step is to attach one or more :ref:`PowerNodeUsageMsgPayload` instances | |||
|
|||
|
|||
For more information on how to set up and use this module, see the simple power system example :ref:`scenarioPowerDemo`. | |||
|
|||
To simulate a battery capacity fault that reduces the actual storage capacity (without directly altering the stated capacity), users must set up the fault flag:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not very clear what we are doing here. Can you please be more explicit on what is done when a fault is modeled?
|
||
To simulate a battery capacity fault that reduces the actual storage capacity (without directly altering the stated capacity), users must set up the fault flag:: | ||
|
||
battery.fault = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be updated to use the private class setter function. Check out
https://avslab.github.io/basilisk/Documentation/moduleTemplates/cppModuleTemplate/cppModuleTemplate.html
to see how to name and document the setter and getter functions.
if(this->faultCapacityRatio < 0) | ||
{ | ||
this->faultCapacityRatio = 1.0; | ||
} | ||
if(this->storedCharge > this->storageCapacity * this->faultCapacityRatio) { | ||
this->storedCharge = this->storageCapacity * this->faultCapacityRatio; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@juan-g-bonilla , your code actually always set the stored charge to the max value. I think the code should be:
if (this->faultCapacityRatio < 0 || this->faultCapacityRatio > 1) {
bskLogger.bskLog(BSK_ERROR, "faultCapacityRatio should be between 0 and 1!");
} else if(this->storedCharge > this->storageCapacity * this->faultCapacityRatio) {
this->storedCharge = this->storageCapacity * this->faultCapacityRatio;
}
}
@Yume27 , your pre-commit test failed. Be sure to install the pre-commit support by reading https://avslab.github.io/basilisk/Support/Developer/CodingGuidlines.html. Look near the bottom for the link to CONTRIBUTING.md. It talks about how to include the checks, and how to many force check specific files if needed. |
@@ -59,6 +59,16 @@ void SimpleBattery::evaluateBatteryModel(PowerStorageStatusMsgPayload *msg) { | |||
this->storedCharge = 0; | |||
} | |||
|
|||
if(this->fault == true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, is there a reason to have both fault
AND faultCapacityRatio
? Doesn’t faultCapacityRatio==1
imply no fault in the capacity and anything below 1 implies a fault?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also do if(this->fault)
instead of if(this->fault == true)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. If the fault info is coming from an optional input message, we don't need fault
at all. Rather, if a fault message is connected, then the fault is read in and applied. If we temporarily don't want a fault, then the message value of faultCapacityRatio
would just be set to 1?
Description
This added the capability to simulate a fault in the
simpleBattery
module that reduces the actual storage capacity without directly altering the stated capacity.Verification
Added unit test to verify that
Documentation
Updated rst file associated with simpleBattery module.
Future work
None