c0pperdragon/EV3Basic

Working with stalled motors

ddstarkey opened this issue · 6 comments

Great work on EV3Basic!
Is it possible to add a routine to handle stalled motors? When I want to "Home" a motor, I want to run the motor until it hits a hard physical stop. In the LEGO environment, I could turn it on for a period of time then shut it off, assuming it reached the limit of its travel. In EV3Basic, I don't see a way to handle the stalled motor. Is there a way to do this? Thanks

I hope these help.
If you do not wish to regulate your speed, but want the motor to push as hard as it can, you can use:

Motor.StartPower("B", 100)
Program.Delay(1000)
Motor.Stop("B", "True")

If you wish to regulate your rotation speed,

Motor.Start("B", 100)
Program.Delay(1000)
Motor.Stop("B", "True")

Both programs stop program execution for 1000ms = 1s.
Take note that at the end you might want to coast your motor for a while first (~0.2s) before braking it. This is because your motor may force its way and compress the surrounding parts, so if you spin it out and back again to the hard limit, all the while using degrees to monitor and control its motion, it may have problems reaching the hard limit again. It won't be a problem if you use time to control though.

You could otherwise use Motor.GetSpeed(port) (BTW I haven't used that before, so I'm not sure, but you can try...) for a few times per second. You can also query the current milliseconds since the start of program execution by using EV3.Time. You could also, for a few times per second, use the Motor.GetCount(port) (degrees of motor) method to see if the previous GetCount is the same as the current GetCount, so if they are the same your motor has stalled.

I think that if the limit can be broken so quickly, then it is likely that you should reinforce your limit. In case you are unable to, it could be better if you use Motor.StartPower(), because the motor would not increase its force while trying to overcome your limit as it does not try to regulate its speed. Either way, the limit must be strong enough to stop the motor even at low power.

The coasting is used after a certain amount of time, so with a strong power the motor can still break your limit. It is only useful if you want to revert to that position in the future if you use degrees to monitor your subsequent motions.

Good luck!!

If I remember correctly, I have once used the Motor.StartPower command with a very low power value (10 or less) to calibrate the mechanics so it knows where the hard stop is. This needs some fine-tuning but it should allow you to make a kind of soft landing without breaking anything.

Motor.Start will not work because it is a regulated mode that will cause the motor to keep the speed, no matter what power it takes to overcome the resistance. This will break something for sure.