2008-03-12

HOWTWO - When Polling Becomes an Issue.

Upplagd av Mneme

This is just a short description of a problem we had, and wheren't really able to solve due to time-constraints, but it is a pitfall that you can avoid pretty easily.

We where building an interactive boxing-bag, where the user would hit a the bag and trigger home-made buttons. Our buttons worked well in the early tests but when we put them in the bag we ended up with large issues in getting the SunSPOT to register a pressed button. We thought that this was an issue with the buttons never making contact. We spend a lot of time and effort on fixing the buttons, and of course it turned out that the buttons where the issue at all.

We where registering hits on the SunSPOT in a polling loop, ie the main program-loop read the inputs on the spot, processed it and sent data on a hit. Due to the polling nature of the program and the fact that the time our buttons got pressed where really short they never registered on the spot. Ie. in our bag the time the buttons made contact (ie. closing the circuit) was a lot shorter than the loop that ran on the spot making us miss a large proportion of triggers.

We never really solved this issue but ended up using the Phidget (it's event-nature was a lot easier to work with), so I can't really present a solution to you but keep in mind that this CAN be an issue in applications with very low time-constraints.

3 kommentarer:

Joakim Bergman sa...

We solved that problem by using the waitForChange() method. It uses interrupts instead of polling. Then you need to start a new thread for each input.

More thorough HOWTO coming soon.

Mneme sa...

Now that sure does make me feel silly. Whe where using the D/A converters, does it work for thoose too?

cristi sa...

I don't think waitForChange is supported for ADC (scalar) pins in the stable (Orange) SunSPOT version. As mentioned at the lecture, the new SunSPOT API (Purple) supports events just as the Phidgets do.

I was unfortunately not aware of your difficulty until after you switched to phidgets. I think it's still good that you got things working in the end somehow.