1

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.

joen
  • 634
  • 2
  • 5
  • 14

3 Answers3

2

This is probably what you're looking for:

isStalled()

NXTRegulatedMotor.isStalled() - Return true if the motor is currently stalled. (i.e. move count shows less rotation degrees than expected) http://www.lejos.org/nxt/nxj/api/lejos/nxt/NXTRegulatedMotor.html#isStalled()

Another method you should be aware of is this:

setStalledThreshold()

NXTRegulatedMotor.setStallThreshold() - Set the parameters for detecting a stalled motor. A motor will be recognised as stalled if the movement error (the amount the motor lags the regulated position) is greater than error for a period longer than time. http://www.lejos.org/nxt/nxj/api/lejos/nxt/NXTRegulatedMotor.html#setStallThreshold(int, int)

And finally here's an example of how to put it all together:

public static void main(String[] args) 
{
    boolean stalled = false;
    NXTRegulatedMotor motor_arm = Motor.A;
    motor_arm.setStallThreshold(1, 100);

    motor_arm.setSpeed(400);
    motor_arm.backward();

    while (! stalled)
    {
        LCD.drawString("Motor is rotating", 0, 0);
        if(motor_arm.isStalled())
        {
           motor_arm.stop();
           stalled=true;
           LCD.drawString("Motor is stalled", 0, 0);
           Delay.msDelay(3000);
        }

        Delay.msDelay(100);
    }

}

Notice: The values for setStalledThreshold() are likely to be mechanically-dependent, if you use gears to connect the motor to the stalling mechanism the values for correct stall detection may vary according to the design of your robot.

Good luck! :)

RazK
  • 45
  • 8
0

According to the documentation, the motor.getPosition() should be the same as motor.getTachoCount(). If it is not, then you can assume that the motor is stalled.

public float getPosition()

Returns the current position that the motor regulator is trying to maintain. Normally this will be the actual position of the motor and will be the same as the value returned by getTachoCount(). However in some circumstances (activeMotors that are in the process of stalling, or activeMotors that have been forced out of position), the two values may differ. Note that if regulation has been suspended calling this method will restart it.

So you just need to check whether the two values equal or not:

public boolean isStealed() {
    motor.getPosition() == motor.getTachoCount();
}
Ambrus Tóth
  • 552
  • 6
  • 14
0

I think checking whether the position changes is the only way. Send the move command, wait, check the position, see if it's what you asked for.

Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186
  • Thanks, but the API has functions called isStalled() and setStallThreshold. Anybody know, how does it works? Ive tried some implementations but no of them works. How must or can i use these functions? – joen Dec 22 '11 at 21:46