Make use of polling functionality in 16-ev3dev kernel#241
Conversation
|
Tested with 16th kernel. It turns out |
Introduces the following functions:
* Motor.wait(condition),
* Motor.wait_while(state, timeout=None)
* Motor.wait_until(state, timeout=None)
Make the following possible:
m.wait_while('running')
m.wait_until('stalled')
Closes #230
|
Looks good, however I think you should add a note in the documentation for these functions that there may be a momentary delay and that it should be taken into account. |
|
I could also put a sleep(0.1) in the beginning of the 'wait()' method. What
do you think?
|
Normally, I would discount that possibility as a hack 😆. However, in this case we're working with "real-time" interfaces, in the sense that many functions are doing things which take time in the real world. So I think this is at least worth considering. One alternative I could think of would be to add some sort of logic specifically for the "stalled" case; maybe it would require that the motor stays Or, similarly, it could enact that delay condition only if you are waiting on a state that the motor is already in when the function is called. Neither of these are perfect, but they're all worth considering I think. We should keep in mind that simplicity and predictability are important, so maybe in the end an unconditional |
poll() is not a generator function, as I thought initially
|
I have some similar functions in helper.py (I'll remove these in the future infavor of the patch above). I had to jump through some small hoops to work around how the initial states are set. I forget exactly what I did and am on my phone right now but maybe take a quick look at that to see what things I had to look out for. Mindcuber is a great test case for this because if anything is off at all it will be very obvious :) |
|
I've added |
|
@dwalton76, thanks, will check |
|
@dwalton76, it looks like wait functions in your |
|
Ah good point. We should think about what to name these so that the differences are clear. Maybe the helper.py ones could be wait_pos_* and the PR ones could be wait_state_* ? |
|
From your experience, does wait for position works better than running motor to relative/absolute position and waiting for its state to change? |
|
Yeah the only way I could make it 100% reliable was to use the motor position |
|
This smells both like a possible bug in drivers and a functionality duplication. It may be confusing for the users if we provide both |
|
One scenario I remember was the state of the motor would read running before the motor actually started moving so I started using pos to work around that. I want to say I had the same problem with stopping a motor in that the state would read stopped when the motor was in fact still moving (although not for long). There were some other problems but my memory is fuzzy. Agreed though that we don't want multiple ways to do the same thing. I still have mindcuber assembled so I'll give it a try using the functions you are adding here and try to pinpoint the scenarios where using state alone wasn't reliable. |
dwalton76
left a comment
There was a problem hiding this comment.
Maybe have it return True if the condition is met and False if we hit the timeout
Good idea! Implemented in 30e4da4 |
Or you could fix the motor driver itself. It should not be reporting stalled unless it is really stalled. |
For future reference: https://github.com/ev3dev/lego-linux-drivers/blob/master/ev3/legoev3_motor.c#L637 |
|
It looks like 'stalled' flag is set whenever more time has passed between samples (are those position clicks?) than a predefined constant, max_us_per_sample. With this in mind, it seems logical that motor is considered stalled in the beginning of the run, when it has not yet gained speed. How would you fix this? Would simple increase of |
I think we could just increase the time before we set the stalled flag. In the code that you linked, we are setting speed = 0 and stalled = true at the same time. We could modify this to just set the speed to 0 and start a stall timer. If the speed does not change for 0.1 seconds, then set the stalled flag. |
May help with sporadic misreports. See discussion in ev3dev/ev3dev-lang-python#241
|
We can probably drop the |
Should not be needed with ev3dev/lego-linux-drivers#57.
|
I'm working on a new rubiks cube robot and the ability to do is golden...thank you @ddemidov for implementing this |
|
Do you need to do those two in sequence, or is calling just the second reliable? I'm thinking we should document how we recommend that you use these methods with a sample like this. |
|
I think you are correct that only the wait_while() is typically needed...I'll verify tonight. |
|
I got distracted....just verified that the |
Introduces the following functions:
Motor.wait(condition),Motor.wait_while(state, timeout=None)Motor.wait_until(state, timeout=None)Make the following possible:
Closes #230