allwpilib icon indicating copy to clipboard operation
allwpilib copied to clipboard

AsynchronousInterrupt class seems to have rising and falling edges reversed in simulation

Open sjcbulldog opened this issue 4 months ago • 0 comments

Describe the bug We have a sensor that detects a note and the path sometimes allows a note to clear completely within a single robot loop. This means sampling the state of the sensor each robot loop will cause us to miss notes. Therefore we use the AsynchronousInterrupt so we can know if a falling or rising edge on the sensor occurred since the last robot loop. This works great for the actual robot hardware, but the values returned for simulation seem to be reversed.

To Reproduce Steps to reproduce the behavior:

  1. See the attached project. Run the simuliation and note the rising edge followed by falling edge. Expected the opposite.

Expected behavior Digital input gets initialized high, transitions to low and back to high. Expect to see a falling edge followed by a rising edge.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows 11

Additional context From digging through this via code review, note that ProcessInterruptDigitalSynchronous() in the file hal/src/main/native/sim/Interrupt.cpp sets the interrupt->previousState value. This is line 125 in v2024.2.1. In Interrupt::WaitForInterruptDigital at line 256 the conditional seems to set the rising an falling edge based on the previous state value being the previous state. But because of the ProcessInterruptDigitalSynchronous() code, it is not the current value. I suspect just reversing this conditional fixes the problem, but I don't feel comfortable enough with the code to say for sure.

sjcbulldog avatar Apr 15 '24 16:04 sjcbulldog