I agree with this. It's another reason that I favour a simpler more robust sensor system. A real time based OS or non-OS system (as I know them) isn't really practical with an Arduino or one or two sensors. It might get close with the system that
@whydontu proposed or maybe with a rotary encoder.
But still, I prefer kiss. Therefore I'm now leaning more toward the light based IR sensor system. I'd bet (but have not checked) that they can be had in very precise versions over the counter. But if not, some attention to shielding from ambient light and shuttering for precision would make such a system plenty effective enough even over a very short distance for this application.
If I were doing it, I'd put two sender receiver pairs into opposite sides of a piece of rectangular aluminium (or plastic) attached to the base and an internal slider screen with narrow vertical slots in it that moves with the ram. The width of the slots would set the precision. A little calibration would be required to determine the appropriate correction factor for the Arduino. It would be a pretty bullet proof system that would as close to real-time as needed for great results on a machine of this type. Best of all, it could easily display feet per minute or whatever scale is desirable for the operation.
Considering that it is easy to make a chart with the length of the cut on the X axis, and the speed of the cut on the why axis and then plot a line that will give you all the surface fpm possibilities of the shaper based on just one calculation it becomes hard to justify overly complex solutions that rely of twitchy sensors and more complex code.
See link at end of this post for a good video explanation of how the above chart is made and the best practice sensing methodology based on Arduino controller and the maths I am referring to below.
Programming and Hardware
Start with a sound tachometer sketch. Most sketches take about a second to calculate and display data because they elect to count the pulses in a set timeframe and then use that to calculate the resultant RPM which is the same as our strokes per minute here. In fact we want to sense the bull gear rpms to derive spm.
This is the tachometer sketch I prefer because instead the sketch measures only the time between pulses and then calculates the result. This requires only a single revolution of the bull gear.
drive.google.com
Then your sketch should require the entry of the total stroke length in your Arduino sketch. This value is the sum of the length of the workpiece plus the small distances before and after the cutter engages the work.
It is my understanding that this value is easily obtained in the set-up of the shaper when preparing to cut the piece and trying to ascertain this from a sensor is less than ideal. I just don't know why you'd not want to enter this manually. Maybe I dont understand shapers well enough?I'm old but not that old where I got to work with a shaper.
If electing the manual entry you will need an LCD shield and keypad combination BUT again this is also well established code with standard libraries so you don't need to write anything new here either.
The same for having the Arduino sketch only count every complete revolution of the bull gear as your data. This is easy task for the Arduino with little to no chance of dropping a count. Hall Effect sensor and magnet only required.
Then you'd only need to write the calculation portion of the sketch. You could use simplified and inaccurate method or the more accurate but to Arduino neither task is difficult to perform very quickly and accurately.
The simple calculation most often employed is:
V = L x 2 x N,
where L = the total length of the forward stroke
2 is the multiplier to account for the backstroke,
and N is the number of strokes per minute.
The above is not the most accurate calculation however because the backstroke is much faster than the forward stroke due to the linkages on the bull gear.
The forward stroke accounts for about 2/3rd of the gear revolution, while the back stroke is about 1/3. Any calculation seeking to provide accuracy should account for this. BUT you don't need a hardware solution like an ultrasonic sensor. You just need maths.
So in 1 minute of operation there will be 40 seconds of forward stroke, and 20 of back stroke. Lets ignore the backstroke since it is meaningless to the result and we use a 40 second denominator for our calculation instead of using length x 2.
The calculation then becomes:
L x 60 x spm / divided by 40 = the mm per minute cutting speed
Where L is the total length of the stroke the user enters
60 is the number of seconds in a minute
spm (strokes per minute) is the calculated rpm output.
40 is the number of seconds in a minute that the shaper is taking the forward stroke.
With the Arduino running you'd only need to adjust your stroke speed until your output displayed hit your target millimeters per minute cutting speed.
Now if I am incorrect in my assumption that you can't easily ascertain the length of stroke during the set-up with a simple measuring device please let me know.
Personally for simple matters like this I prefer a chart.