I've got a BX-DM1-18ED2-D and BX-08AD-2B. I'm using an accelerometer to measure both shock amplitude and to estimate position.
First, the accelerometer is a little jittery and has a small offset. It's a 5V device, with a separate grounded supply, putting out a 2.5V nominal at rest with deflection responding linearly to encountered acceleration to +/- 20G. I've got that compensated, but if there's a built-in function to redo my hand-rolled function, groovy. From what I can tell, I'm getting the right acceleration out via the RX1 conversion and setting the range to +/- 20 via System Configuration.
The major issue I'm having right now is I can't get a reliable sampling period to estimate the instantaneous velocity. I understand there are drift issues with inertia-based navigation but I'll worry about that later. For now, I'm using Euler's approximation (and if it's reliable but flakey I'll move to a Runge Kutta but that's cart before horse.) which is
vel = vel + accel * timeslice
pos = pos + vel * timeslice
But I can't get timeslice to be reliable, so the calculations are all erratic. The tutorial suggests using an ISR with an OUTI or a SETI instruction, but
those only work with pins, not with C values. I can't use those to measure a consistent time
internally. (Do-More is restricting my output choices to ones that physically exist; I can't run the ISR to, say, Y1023 or something like that.)
I've tried:
- timers to measure the ms since the last iteration
- ISR with a repeated interval
- ENTASK triggers
- Tickms() with modulo in a math operation
- TMR with 5ms periods, both accumulating and individual, with flags, control blocks, etc.
- possibly others, I've become a little lost in the weeds.
Nothing seems to give a reliable time period. I understand how the PLC cycles and iterations work and how the cycle length is indeterminate depending on what other things are being done in that particular iteration. i.e. Cycle time will vary between less than a millisecond and (in this case) 5ms.
I've got to be missing something obvious; what did I get wrong?