views:

98

answers:

2

What type of machine you ask? A machine that measures wedge and roundness of lenses.

I've already written software for the machine and it is in production, but it is brittle and prone to lock ups when they dont do things in the right order. I'm trying to come up with the best way to architect it so that its stable and maintainable.

Here's the quick twenty second run down. There are two modes, setup and run. In setup mode the operator can manually move any of the 6 different motors using one of the 6 different momentary toggle switches on the control panel. They get everything homed in, then they turn it to run mode, load a lense, and press go. The machine will automatically bring in the three indicators, find the edge of the lense, and then rotate the spindle and measure all the way around the wedge.

I ended with a very poor non-design of having a class that raised an event that says when a switch has changed state, which switch it was, and what its new state is. Then I do a lot of ifs and stuff to determine what the machine can do. As you can imagine, this is very very bad.

Does anyone have any good ideas on how to structure this? I have some of my own, but I want to hear some from those that may be a little more experienced with this type of application development.

A: 

I wouldn't even worry about figuring out what the system can do until the operator starts the machine.

Event listeners are fine, but just have them update a memory model of the switches with the current information. Make sure you catch all the events, IN ORDER....if there's a way to query the current state of the switches, that's even better - ignore all switching until the operator starts the machine, then query.

Either way, determine the operational mode at start time, based on the memory model of the switches. Make a copy of the memory model for operation to avoid any chance of it changing during operation.

sangretu
+2  A: 

What you need is build a finite-state machine, that's the best way to model a problem like the one you have:

http://en.wikipedia.org/wiki/Finite_state_machine

tekBlues