How would you design an application to run a machine?

喜欢而已 提交于 2019-12-24 20:14:14

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/998079/how-would-you-design-an-application-to-run-a-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!