mikeexplorer
Supporting Member
I would like some feedback on this program I wrote. As some of may know, I am developing a model railroad layout using a Micrologix 1400 PLC to control the trains as a means of learning how to program. (unusual I admit, but it is working)
I have already written several of the supporting subroutines needed in the programs (not shown in attachment due to size limits) that handle things like the remote switches, track power, and so forth.
The next step is building the routine selection system where options are presented on the HMI screen (sample attached) which are various operations to do with the trains. I have looked at several ways to do this, several other websites call it "mission" but at this time it is not known how many routines I will have and probably will never know as I am sure I will think of new things to do with the trains. So I came up with this idea of selecting a routine to run and having the ability to select the next routine I want to run while the current one is running.
I wrote this program and use the RSLogix emulator to run it and it works. Some of the routines can run endless (such as interchanging the main and side track train and running it around the track X number of times) and it will just do that endless. Other routines planned would do an operation and end. (such as take the running train and park it in the side track)
So this routine selection has to have a flag that the endless subroutines would see to tell it that a different routine wants to run and to end its cycle at a proper point.
The subroutines here are just timer cycles, the first two will run endless, once the third timer expires, it resets the sequence steps and restarts the second timer. The other routines will go through the three timer cycles and just end.
Each routine will also set a flag to indicate that its "done" with what it has to do, whether it was a routine that did an operation and ended, or an endless routine that was flagged to end and its now finished with its cycle.
Here is information on the data used for the program:
N7:0 HMI choice for next routine to run
When one of the desired options is pressed, this integer will be set to a number for the desired next routine but no action is taken until a "confirm" flag is set, in case it was accidentally pressed.
N7:1 Next routine to run
N7:2 Current routine running
N7:4 Current routine end flag (non-zero value indicates current routine has ended)
(I am thinking to change this to a bit value and latch/unlatch it)
B3:0/3 HMI Confirm flag for selection of next routine. When this goes high via the HMI this means the user is "confirming" the choice for the next routine to run.
B3:0/1 "End request" flag. When next routine is confirmed, this bit goes high. This will tell the current running routine to end when it completes a cycle. This is set automatically once the "next routine" is selected.
B3:0/0 This is the "OK to run" flag, conditions that have to be met for this flag to be high
(No E-stop, automatic mode, no alarms, etc...)
Each subroutine uses an integer as a sequence step which I do rely on for this project in many of the programs written so far.
The idea of this program is I can expand it as I think of new routines to develop and would require little modification to this program. The only thing missing is maybe a check for the next routine to be out of bounds (a number higher then the number of available routines) but the HMI would be the source for this integer value.
I am just looking for thoughts and feedback on this approach since I have not seen anything similar on other websites.
Mike
I have already written several of the supporting subroutines needed in the programs (not shown in attachment due to size limits) that handle things like the remote switches, track power, and so forth.
The next step is building the routine selection system where options are presented on the HMI screen (sample attached) which are various operations to do with the trains. I have looked at several ways to do this, several other websites call it "mission" but at this time it is not known how many routines I will have and probably will never know as I am sure I will think of new things to do with the trains. So I came up with this idea of selecting a routine to run and having the ability to select the next routine I want to run while the current one is running.
I wrote this program and use the RSLogix emulator to run it and it works. Some of the routines can run endless (such as interchanging the main and side track train and running it around the track X number of times) and it will just do that endless. Other routines planned would do an operation and end. (such as take the running train and park it in the side track)
So this routine selection has to have a flag that the endless subroutines would see to tell it that a different routine wants to run and to end its cycle at a proper point.
The subroutines here are just timer cycles, the first two will run endless, once the third timer expires, it resets the sequence steps and restarts the second timer. The other routines will go through the three timer cycles and just end.
Each routine will also set a flag to indicate that its "done" with what it has to do, whether it was a routine that did an operation and ended, or an endless routine that was flagged to end and its now finished with its cycle.
Here is information on the data used for the program:
N7:0 HMI choice for next routine to run
When one of the desired options is pressed, this integer will be set to a number for the desired next routine but no action is taken until a "confirm" flag is set, in case it was accidentally pressed.
N7:1 Next routine to run
N7:2 Current routine running
N7:4 Current routine end flag (non-zero value indicates current routine has ended)
(I am thinking to change this to a bit value and latch/unlatch it)
B3:0/3 HMI Confirm flag for selection of next routine. When this goes high via the HMI this means the user is "confirming" the choice for the next routine to run.
B3:0/1 "End request" flag. When next routine is confirmed, this bit goes high. This will tell the current running routine to end when it completes a cycle. This is set automatically once the "next routine" is selected.
B3:0/0 This is the "OK to run" flag, conditions that have to be met for this flag to be high
(No E-stop, automatic mode, no alarms, etc...)
Each subroutine uses an integer as a sequence step which I do rely on for this project in many of the programs written so far.
The idea of this program is I can expand it as I think of new routines to develop and would require little modification to this program. The only thing missing is maybe a check for the next routine to be out of bounds (a number higher then the number of available routines) but the HMI would be the source for this integer value.
I am just looking for thoughts and feedback on this approach since I have not seen anything similar on other websites.
Mike