If the motor is running at 100% of max speed from empty bag (0% bag full) to 90% bag full, and you also measure the time that it took to go from 0% to 90%, then you know the approximate rate.
E.g. say the empty bag's tare weight is taken at time 0s, and it gets to 9kg = 9000g, i.e. 90% full, at time 18s; the average rate over that time is 0.5kg/s = 500g/s.
Since the bag fill takes only 20s-30s, that 500g/s might -
might - provide a reasonable estimate - i.e.
prediction - of the ratio of the motor speed to the fill rate (g/s) for the rest of the bag.
Using @PeterN's approach, say you want do a linear ramp reducing motor speed from 100% to 30%, and the code will stop the motor when the measured weight exceeds 10000g. So, being engineers means we assume everything is linear at some scale, we make the assumption that the fill rate will be linear with motor speed, and we estimate 5(g/s)/%. So now the fill rate, which is also the change in weight with respect to time, is estimated as
dW/dt, g/s = 5(g/s)/% * (MotorSpeed, %)
W100% - W90% = DEFINITE_INTEGRAL||MotorSpeed=100% to MotorSpeed=30%||(5*MotorSpeed dt)
Let's shift the timeframe to make the math easier:
τ = t - 19
dt/dτ = 1
dW/dτ, g/s = 5(g/s)/% * (MotorSpeed, %)
W100% - W90% = DEFINITE_INTEGRAL||τ=0 to τ=τEnd||(5*MotorSpeed dτ)
Where
MotorSpeed = 100 - (100-30)*τ/τEnd = 100 - τ * (70/τEnd)
N.B. -70/τEnd is the ramp rate, %/s, of the motor, so we need to solve for τEnd
W100% - W90% = DEFINITE_INTEGRAL||τ=0 to τ=τEnd||(5*(100 - τ * 70/τEnd) dτ)
10000-9000 = (100*τ - 1/2 τ**2 70/τEnd)||τ=0 to τ=τEnd||
1000 = 5 * [ (100*τEnd - 1/2 τEnd**2 70/τEnd) - (100*0 - 1/2 0**2 70/τEnd) ]
1000 = 5 * τEnd * (100 - 1/2 * 70) = 5 * τEnd * 65 = 325 * τEnd
τEnd = 1000 / 325 ~ 3.08s
Ramp rate = -70 / τEnd = -22.75%/s
So the question is, can you ramp the % signal to the motor at a rate of 22.75%/s, for the given case?
The only thing that is going to change from bag to bag is the calculated fill rate, i.e. the 5(g/s)/% value above; the 100 and 30 and -70 and 65 will always be the same, so you can calculate the ramp rate at 90% from the t90, i.e. the time measured get from empty to 90% full (0g to 9000g):
RampRate, %/s =-70 / τEnd = -70 / (1000 / (((9000 / t90) / 100) * 65)) = -70 / (1000 / ((90 / t90) * 65)) = -70 / (1000 / (90 * 65 / t90)) = (-70 * 90 * 65) / (1000 * t90)
RampRate = -409.5 / t90
Checking the test case: -409.5 / 18 = 22.75, good.
Again, this
is a model that assumes the empty-to-90%-based rate
predicts the future rate. And the
critical part of any model is its
level of fidelity. Who knows, maybe measuring from 40% to 90%, which discards data 10s and older, would be a better
predictor?
I still think the time would be better spent figuring out how to accumulate strawberries at the feed to the motorized system so the rate is more consistent.