I’m having problems figuring out an override logic for the Ventilation Challenge. My problem is that one of the latches seems to work differently with the boolean input from a boolean writable and the boolean input from a boolean switch. I’ll try to explain with some screen shots:
First screen shot: when the latch is driven from a Boolean Writable when the clock is ‘true’ and the “Boolean In” is ‘true’ it outputs the expected “Out” ‘true’ It makes sense.
I’m passing this through the Boolean Writable to isolate any effect from the Boolean Switch. It happens exactly the same when I pass the output directly from the switch.
What am I not understanding here? Thanks for any input all. And Happy New Years!
I had the same feeling so I increased the length of the One Shots to ten seconds and also tried to run it through the Boolean Writable to isolate. This is the bog for my whole solution (still a work in progress so mind the mess!) You’ll find this piece in the Override Logic Folder (still learning how to organize and make this mess prettier). Thank you in advance for looking!!
Thank you, I did select that pin and was trying it out, but didn’t work with it enough to understand it. I will lean into it then! I want to get this right this time, as I believe it was the same problem I had with the override in the LUX lighting challenge! Hoping to learn on this one and kill both birds with this one stone! Thank you again!
The Clock is difficult for people to really understand. The function of the Clock property is to trigger the component to capture and send the In value to the Out value at the moment the property changes from false to true. Nothing happens when it changes from true to false. Basically it’s only latching on the rising edge.
In practice, it is best to just set the clock property to false then ignore the CLOCK input.
Link your latch command to the object’s Latch Action instead. You can expose the Latch Action using the composite feature. When the Latch command goes from false to true, the value of the In slot will be passed to the Out slot, where it will remain until another Latch false-true cycle repeats.
Be sure to add a short boolean time delay for the Latch command (1 second?) to assure proper timing in algorithms where any input logic change and latch actions occur at (nearly) the same instant. This assures the In property has the correct value before the Latching occurs
@ControlFreak the latch is working as it should. The issue is that your in value and clock are changing at the same time (timing issue). I added a 3 second on delay to allow the in value to first change before being clocked by the one shot.
Looking at the code there is a very distinct difference between using clock and the latch action. I have to say I disagree with @Charles_Johnson’s comment.
These are the two methods in question:
public void changed(Property property, Context context) {
if (this.isRunning() && property == clock) {
this.currentClock = this.getClock().getValue();
if (this.getClock().getStatus().isValid()) {
if (this.currentClock && !this.lastClock) {
this.setOutStatusValue(this.getInStatusValue());
}
this.lastClock = this.currentClock;
}
}
}
public void doLatch() {
this.setOutStatusValue(this.getInStatusValue());
}
changed Method (for clock)
Triggered by Property Change: The changed method is automatically triggered whenever the clock property changes value. This is reactive and depends on the clock property update.
Edge Detection: It implements edge detection logic:
If the clock transitions from false to true (rising edge), it sets the output status value to the input status value.
This is based on the currentClock and lastClock boolean flags to detect a rising edge (true now but was false previously).
Additionally: It verifies that the clock status is valid before performing the action. This avoids and rouge values triggering change.
doLatch Action
Explicit Invocation: The doLatch method is invoked explicitly on rising or falling edge when linked by wire. In my opinion the latch action should only be invoked by user action as a means to expedite the current in value, to the out value.
This becomes an issue when for example when you’re in value is true and you invoke latch with a oneshot. The latch is triggerd twice during the lifecycle of the oneshot, once on the rising edge, and once on the falling edge. If your in value changes from true to false during the rise and fall, then you will not capture the intended value (captured true but then changed back to false on falling).
Functionality: It directly sets the output status value to match the input status value. This is a straightforward, one-off action, where no additional conditions are checked. You can think of it like a “force action”.
The take away from this @ControlFreak is that when you invoke an action it doesn’t care if the value that invoked it is true or false, it is invoked on rise or fall (true to false or false to true). The Clock is only triggered on a rise from false to true.
You can use the latch either way, to the same effect however when using the latch action to set the out value you need to be absolutely sure that your in slot is long lived and will not change value. I would never use the latch action to capture a momentary value, rather, you should use the Clock as intended.
Wow! This is next level discussion! I’m pretty sure banging my head against the wall like I do would never have gotten this. What this tells me is I should really understand both methods! I get parts of this but will have to spend more time till I really understand and can use it in the wild. I have been warned about using latches and it always makes me nervous, but my skills are limited at this point, so I use what is on hand in my brain! This is all so brilliant and gives me my next step so I can proceed forward. I truly appreciate all the help.
100% agree! Nothing good comes without pain! It amazes me how much else I learn along the way, by banging my head on every wall. But sometimes it’s nice to be shone the window. Cheers my great teachers.