Summary
It's all about the bookkeeping.
Details
Does click plc have a bit-shift-left (BSL) or bit-shift-right (BSR) instruction, and can that instruction span multiple words?
Say it does and can, and you have
- a sprocket wheel on the conveyor roller
- such that some number, say 91, of teeth are equivalent to two feet of conveyor movement,
- and a prox detecting each sprocket tooth that goes near the fixed prox position
- If you don't have sprocket teeth and/or a prox, then
- say the conveyor moves at a constant rate,
- say two feet in 9.1s,
- which is 91 100ms periods
Either way you should be able to generate 91 pulses over two feet of conveyor movment.
Allocate a shift register for each lane that is an array of six 16-bit words (96 bit; 96 >- 91).
At each pulse (tooth prox or 100ms pulse), push (shift) a 0 bit onto the shift register, using the BSL instruction. That represents the new quantum of product that has just been placed onto the beginning of the conveyor, and the BSL instruction that does the shift also shifts all other bits one to the left, representing the movement since the previous pulse.
If that new quantum of product is bad, the PLC model does not know it yet, and it assumes the product is good, which is why it pushed a 0, but it will need to know if the product is bad before that bit moves 91 times from the start and gets to bit position 91 (bit 11 out of [0..15], in word 5 out of [0..5]).
So at some point, the image is taken, and say X represents the lane (cross-conveyor) position, and Y represents the location of a bad product in the along-conveyor position. You might need to scale Y to figure out which bit, [0..91], it represents, but that should be straightforward; let's say Y in the image converts to YbitImage
at the time the image was taken.
If you know
- the image was taken some Tdelay seconds ago, i.e. between the time of the image and the time of the current scan, and
- the conveyor moves 91 pulses in Tperiod seconds,
Then that means the bad product at YbitImage has moved another Tdelay * (91/Tperiod) pulses between the time of the image and the time of the current scan.
- So on the scan when receive you the image and convert Y to YbitImage, you calculate the current position of the bad product as
- YbitNow = YbitImage + (Tdelay * 91 / Tperiod)
- Obviously you will want to be careful with rounding and such;
- a much higher number of pulses per foot will improve the accuracy.
Still on the current scan when the image was received, the PLC model knows that bit YbitNow out of [0..91], in lane X, represents a bad product, so it needs to change the 0 at that location, YbitNow, to a 1. I don't know how click PLCs address bits using indirect addressing, but you will need to convert YbitNow into a [word,bit_in_word] pair:
- Ybit_in_wordNow = YbitNow AND 15 ### Assumes AND is a bit-wise instruction
- YwordNow = (YbitNow - Ybit_in_wordNow) / 16
Then all that is left is to set bit [Ybit_in_wordNow] of word [YwordNow], using the set/latch instruction. When that bit gets to bit position 91, it will cause the diverter paddles to activate.
Caveats
- It would probably work best to add a small offset, as a number of bits, to the Y-to-Ybit conversion to extend the "bad" bit designation beyond (downstream-conveyor) the nominal Ybit result, and to set several contiguous bits from that location back (upstream-conveyor) towards the beginning of the conveyor to ensure the paddles divert the bad product.
- How much of an offset and how many contiguous bits will depend on the process, how big the products are in units of bit position, and how much, or little, of a gap there may between products.
- The [91/Tperiod] ratio represents the speed of the conveyor in pulses per second.
- if the conveyor speed may change, then it may make sense to make that (91/Tperiod) speed a variable i.e. measured and calculated quantity*, so the system will continue to work even if the conveyor speed changes.
- * that calculated quantity may be scaled from a speed reference, or from a continually measured number of pulses per so many seconds.
- This is a problem if the pulses are not based on a prox detecting sprocket teeth, and will require a somewhat different approach.
- If click plc does not have a multi-word capable BSL instruction, you will have to build one capable of handling multiple shift registers (lanes).