How can i detect a stalled motor?

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

How can i detect a stalled motor?

Postby manjan4487 » Thu Dec 22, 2011 7:05 pm

Hello,

I try to build a Rubiks Cube Solver with 4 arms to grab the cube.
I am using the lejos firmware version 0.9.0. My problem is how can i detect that a motor is stalled?

For example:
Motor.A rotates forward while the motor will be blocked/stalled,
then Motor.A should stop.

I hope anyone can help me, because iam looking for a solution a long time ago before.
manjan4487
New User
 
Posts: 2
Joined: Thu Dec 22, 2011 6:51 pm

Re: How can i detect a stalled motor?

Postby kirkpthompson » Thu Dec 22, 2011 9:59 pm

Check out the lejos.nxt.NXTRegulatedMotor class, isStalled() method.

-K
Leg Godt!
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Re: How can i detect a stalled motor?

Postby manjan4487 » Thu Dec 22, 2011 10:39 pm

Hi and thanks.

I did try it. but it doesn t work correct.

Here is an example code:

Code: Select all
boolean stalled=false;
NXTRegulatedMotor m = new NXTRegulatedMotor (MotorPort.A)
m.setSpeed(400);
m.forward();

while (! stalled){
    if(m.isStalled()){
       m.stop();
       stalled=true;   
    }
}



When i block the Motor and release it the motor continues rotating forward. The function isStalled always returns false.
manjan4487
New User
 
Posts: 2
Joined: Thu Dec 22, 2011 6:51 pm

Re: How can i detect a stalled motor?

Postby kirkpthompson » Thu Dec 22, 2011 11:31 pm

Try slowing down the motor to see how the behavior changes. It is going to work as hard as it can to rotate at the speed you specify and higher speeds=higher power=resistance is overcome=stalls are less likely for a given resistance.

Also, you may want to put a delay in the loop as it is checking isStalled() as fast as possible which is a bad design because the CPU is being hogged by your loop

Code: Select all
while (!m.isStalled()){
   Delay.msDelay(100);
}
m.stop();


-K
Leg Godt!
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Re: How can i detect a stalled motor?

Postby gloomyandy » Fri Dec 23, 2011 10:37 am

Hi,
Detecting a stalled motor is actually a tricky thing to do. The default settings in the regulated motor class are pretty conservative and will take a short while before the motor is considered stalled. This will also mean that considerable power can be applied in an attempt to keep the motor moving. It is possible to adjust the parameters controlling the stall detection logic using the setStallThreshold method
http://lejos.sourceforge.net/nxt/nxj/api/lejos/nxt/NXTRegulatedMotor.html#setStallThreshold(int,%20int)
But adjusting these values may result in a stall being detected when the motor has not in fact hit the limit, you will need to experiment with the settings to find ones that work for you. Note though that even with these settings the motor can still apply full power to attempt to overcome the stall and this may break some models. If what you are trying to do is to calibrate the end stops of movement, then you may wish to consider using the unregulated motor interface (which allows you to set the power levels), and to use this to apply a low power level for some fixed period of time and then assume that after this the motor will have hit the end stop and use the tachometer reading for this point a as limit in later operations using NXTRegulatedMotor. Note that if you want to mix regulated and unregulated control of the same motor in this way you will have to disable motor regulation when using the unregulated commands by calling the suspendRegulation method:
http://lejos.sourceforge.net/nxt/nxj/api/lejos/nxt/NXTRegulatedMotor.html#suspendRegulation()

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3996
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: How can i detect a stalled motor?

Postby s.frings » Sun Dec 25, 2011 6:51 pm

I like to repeat what gllomyandy write in other ords, because it is so important.

It's basically not a good idea to drive the motor against a hard end point using maximum power as the regulated motor class does. Because the NXT motor is quite powerful and may break your parts in half when you do that. The motor has a thermal protection that protectes the electric parts, but there is no protection for the plastic parts.

So better use the unregulated motor class (or motor port) and drive the motor with only as much power as really necessary (e.g. 70%). You can poll the tacho counter every 200 or 500 milliseconds to see whether it changes. If it does not change or changes only a very little, then the motor is stalled.
s.frings
Active User
 
Posts: 131
Joined: Tue Jul 20, 2010 2:01 pm


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff