DQMH Consortium Toolkits Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

DQMH Helper Loop Class Update

Solved!
Go to solution

Hello,

 

I have set up a HAL for my power supplies and wrapped that into a clone-able DQMH module. Works pretty good, however I have two pain points with my helper loop. I use the helper loop to continuously monitor the power supply output and OVP/OCP. I personally don't like my current solutions for them so want to ask the community for guidance here, so I can continue to code better with best practices going forward. 

 

1. Starting the helper loop. 

  •  Currently I use an event to make it easy to use in the tester API/placing it in other code that uses this module. Clicking this button/triggering this event then runs a property node of a start helper loop boolean inside my MHL which writes into value signaling, thus triggering my helper loop to start which is waiting for a change on that start helper loop flag/boolean. I do the same to stop the helper loop with a separate stop helper loop flag and event that go through the MHL.

2. Passing updates to the class from MHL to Helper Loop.

  • I'm currently passing updates to the class object by using local variable between MHL and helper loop.
  • This was giving me an issue until I found my bug which was that I was using a local variable which was only called once the power supply was connected to and the correct child class was being used from the factory pattern. I have some dynamic accessors stored in the class which weren't being updated since I only updated this class once to the helper loop after the communication was confirmed. Now that I solved that issue by adding a local variable of the class to every event/MHL that changes the configuration of the power supply the helper loop works as intended. 
    • Example of issue I had originally was that some power supplies that I have at home don't have a OCP so I decided to store it in my class, but since the class was never updated outside of the initial communication the default value of 0 was kept for OCP and whenever it read any current it would stop as intended if over current was detected from a measurement. However, the wrong OCP was being referenced since it would never update. 
0 Kudos
Message 1 of 4
(608 Views)
Solution
Accepted by topic author VInoob

The thing that jumps out at me is that you are sharing state data between loops with local variables.  That is a method very prone to problems, as you are finding.  It can also become a performance issue, as every local variable causes a data copy.  Consider two other options:

1) Don't have the helper loop actually read your power supply.  Have it send "Time to read power supply" events to your main loop. Having the helper just be a timing source means there is no reason to share your HAL Object between loops.

2) Use a DVR to hold the Object and share access between loops.

Message 2 of 4
(599 Views)

Thank you for the advice. I like solution 1 and I will try that out now as I still have a constant bug I am seeing. In an application I set up I have a loop that updates the voltage level by a certain increment every 2 seconds and eventually the module times out possibly due to the helper loop running trying to poll the power supply measurements every second. 

 

I think this solution should solve my issue. Seems pretty straightforward will report in a day or 2. It's my bed time and have a long day tomorrow away from my desk, need to touch grass to clear the mind.😀

 

Update: Was pretty straight forward to implement ended up doing it before going to bed. I have tested it twice so far and it seems to be working now! Before my program would crash around the second or third test, but when I disabled the helper loop it worked. Now I get to go to bed in a good mood and a working helper loop in my application. Thank you so much for the suggestions!

 

Another Update: Was able to get through my whole range without a problem. That solution is solid! Before I was only testing a small sample of the range. Now to figure out how to start and stop the helper loop is there a better way?

0 Kudos
Message 3 of 4
(585 Views)

Found the answer to pain point one if anyone else in the future needs help with this. I did end up leaving my public events to start and stop the helper loops, but replaced the flags and property nodes inside the MHL with private events that are tied to the helper loops. Below is a link to why and how I figured out to do this. 

https://documentation.dqmh.org/dqmh/7.1/PublicandPrivateRequests.html

 

 

0 Kudos
Message 4 of 4
(421 Views)