... I understand how to get the traffic lights to work, but the cross walks and car sensors throw me off.
Can you show us how you get the traffic lights to work (e.g. post a screenshot of the logic), and we can go from there?
The way to solve this kind of problem is to break it into separate pieces, or states of the system at any given time. How a PLC program controls a system on each scan cycle is determined by two thing, and two things
only:
- the state of the system i.e. how the PLC program left the system at the end of the previous scan cycle, and
- the state of the system inputs on the current scan cycle.
PLC programming is primarily about time, and the scan cycle is the clock. A scan cycle can be considered as a discrete period in time where the PLC
- reads the inputs, and considers the state of the system (as noted above),
- determines if the combination of the state of the system from the previous scan cycle coupled with the new states of inputs on the current scan cycle should cause a change the state of the system, and
- and finally write that new state; writing the new may involve
- EITHER external outputs, such as the various lights,
- OR state information stored in the bits of the PLC memory, such as booleans and timers
E.g. if the green 1/3 light is on (output state information from
previous scan cycle) and the green 1/3 light's two-minite timer expires (internal state information from the
current scan cycle), then the PLC will change from a state we might call "green 1/3 light is on" to a state we might call "yellow 1/3 light is on."
So the first thing you need to determine, once you have identified all of the inputs and outputs, is how many states there are in this assignments' system, and what those states are. Can you identify all the states of the system? Ignore the crosswalk for now, because the crosswalk does not override the main traffic lights.
Defining the states, determining which state the system is in, determining which transitions are allowed*, and identifying the events that cause transitions between states is about 90% of the problem.
The other 10% is what to do in each state. For example, whenever the system gets into the state "yellow 1/3 light is on," then I hope it is obvious that the PLC will run a timer, and the expiry of that yellow 1/3 timer is the trigger for the transition out of state "yellow 1/3 light is on."
You see, the best way to solve this kind of problem is to apply a software principle called "separation of concerns." In this traffic light problem, there are two concerns
- managing the state of system and the transitions between states,
- managing the output image* and internal state entities (e.g. timers) depending on the current state of the system.
To do this, the PLC program maintains a
model of the state of the system in the PLC memory; PLC memory comprises bits, and any bit can have a value of either 1 or 0. The unique combination of the 1 or 0 values of all the bits in the system
model are what define the state of the system.
The PLC program comprises instructions. In the simplest concept of a PLC program, each PLC Instruction does either, or both, of two things: examine the state of one or more memory bits' states before the instruction is evaluated; manipulate memory bits based on that examination. Also, in Ladder Logic, there is also the state of the input and output rungs of each instruction; these can be though of as transient memory bits that are created, written, and evaluated on the fly as the PLC program scan evaluates each instruction on each rung.
The point I am getting at is that, to write this program, you need to narrow your focus to how you will
model the traffic light system in PLC memory. Because the PLC
program you write will only interact with the memory bits of the PLC model you design, and it is unlikely that you will be connecting the PLC's output or input channels to physical lights and sensors.
* Note that the PLC
program does
not manipulate the
physical output channels or examine the
physical input channels. The only data the PLC
program can manipulate or examine are bits in PLC memory. The physical input channels are examined by the PLC I/O scan and the results are written to an "image" in PLC of those channels states. Likewise, the PLC I/O scan examines the output "image" in PLC memory, written by the PLC
program, and writes the values from that image to the physical output channels.