View Single Post
Old 01-29-2016, 03:30 PM   #27067
Katsunami
Grand Sorcerer
Katsunami ought to be getting tired of karma fortunes by now.Katsunami ought to be getting tired of karma fortunes by now.Katsunami ought to be getting tired of karma fortunes by now.Katsunami ought to be getting tired of karma fortunes by now.Katsunami ought to be getting tired of karma fortunes by now.Katsunami ought to be getting tired of karma fortunes by now.Katsunami ought to be getting tired of karma fortunes by now.Katsunami ought to be getting tired of karma fortunes by now.Katsunami ought to be getting tired of karma fortunes by now.Katsunami ought to be getting tired of karma fortunes by now.Katsunami ought to be getting tired of karma fortunes by now.
 
Katsunami's Avatar
 
Posts: 6,111
Karma: 34000001
Join Date: Mar 2008
Device: KPW1, KA1
Quote:
Originally Posted by Freeshadow View Post
@Katsunami:... Is this somehow along with what you had in mind?
Yeah, it is. The procedure to get this machine to do what it needs to do is somewhere around 75 to 100 lines or so. It has code like this (not actual code, but to give an idea):

Code:
(* This task will keep running, even if boxes are being placed and filled *)
IF (InputBuffer.Count < (NUMBER_OF_JARS_SET_BY_UI + EXTRA_BUFFER))
    AND (JarInputTrack.Status = STATUS_READY)
    AND (TASK_Get_Batch_Of_Jars = TASK_IDLE)
THEN
    TASK_Get_Batch_Of_Jars := TASK_RUN;
END_IF

IF (BoxPickupArm.Status = STATUS_READY)
    AND (BoxPlatform.Status = STATUS_EMPTY)
THEN
    TASK_Place_Box := TASK_RUN;
END_IF

IF (BoxPlatforum.Status = STATUS_BOX_PLACED)
    AND (JarPusher.Status = STATUS_READY)
    AND (InputBuffer.Count >= NUMBER_OF_JARS_SET_BY_UI)
THEN
    TASK_Fill_Box := TASK_RUN;
END_IF
Rinse/repeat conditions and kicking tasks on and off. At some point, the full box will be moved off the platform, so it becomes empty, and the placement task will start again. Everybody understands this and it's easy to write (I prefer to use types and/or enumerations where-ever possible, to avoid magic numbers and strings scattered through the code.)

Then you start to read the tasks themselves, which have a fairly simple code as well; it's comparable to the code above, but only for one part of the machine. Each task also detects errors, which is fairly obvious code as well.

Then you start reading the error handling, (re)initialization procedures and communication with the main user interface to disable/enable buttons while the program runs.... and you'll probably want to kill yourself before you finish, because in there, you'll find stuff describing what needs to happen if handling the fail actually fails itself.

** ERROR **
*box was crushed*
Action: Retract box placement arm, then remove crushed b....
** ERROR **
*Retract of box placement arm failed*
Action: Shutdown this part of the machine, wait for manual removal of the box, restart, re-initialize box placement arm....

Then try to place a new box... while the REST of the machine (input of jars, output of already finished boxes) keeps running.

You not fast enough removing that box?

** ERROR **
*Input buffer overflow*
Action: Stop input track.
Result: Preceding machine will be stopped as well.
* chain reaction of stopped machines *

Have a nice day reading code if you didn't write such a program yourself.

Last edited by Katsunami; 01-29-2016 at 05:53 PM.
Katsunami is offline   Reply With Quote