How to detect all stalled motor

Discussion specific to projects ideas and support.
doc222
Posts: 117
Joined: 29 Sep 2010, 03:02
Contact:

Re: How to detect all stalled motor

Post by doc222 »

My trouble too, might be my age or perhaps the eyes going as well. Some days we win the battle of brain malfunction others not so well.

My solution is to make X's rotational joint now stronger than the motor is. This helps when say I tell one of them to rotate say 99 revolutions at the motor , when they can only go 9! What happens is the motor stalls dead in it tracks and the thermal kicks in about every 1.5 seconds it trys to finish the count, thermal kicks in again and so on untill i cancle the command or pull a wire to the power(NXTmx). Or tell it go the wrong way or even a wrong port all can lead to trouble. The good thing now is wont tear its self apart like x2 would, that sound is something you wont forget.
"Anyone who has never made a mistake has never tried anything new."
Albert Einstein
markcrosbie
Posts: 34
Joined: 30 Sep 2010, 09:56
Location: Ireland
Contact:

Re: How to detect all stalled motor

Post by markcrosbie »

Here's a little NXC program I wrote up to detect a stall by running a watchdog task in the background to monitor the delta change in rotation encoder values. The assumption is that if you are moving then you will see a change in these values. In practice I have found that the NXT motors have such a high torque that you are more likely to see wheel-slippage than a full halt of your robot, unless you have an exceptionally heavy robot.

Let me know if this helps you out.
Mark

Code: Select all

//
// Watchdog timer example program
//
// Watchdog runs in the background and will sound an alarm if the motor
// rotation encoder values don't constantly change
// 
// Assumes a robot with two drive motors A and C
// Ignores wheel slippage - assumes that the wheels will stop rotating
// if the robot becomes stuck

bool driving;	// indicates we are driving
#define DELTA 30 // minimum value we need to see a change

task watchdog() {
	
	int prevLeftEncoder;
	int prevRightEncoder;
	
	int currentLeftEncoder;
	int currentRightEncoder;

	prevLeftEncoder = MotorTachoCount(OUT_A);
	prevRightEncoder = MotorTachoCount(OUT_C);
	
	Wait(1000);
	
	while(true) {
	
		if(driving) {
			currentLeftEncoder = MotorTachoCount(OUT_A);
			currentRightEncoder = MotorTachoCount(OUT_C);
						
			if( (abs(prevLeftEncoder - currentLeftEncoder) <= DELTA ) ||
				(abs(prevRightEncoder - currentRightEncoder) <= DELTA ) ) {
					// we're stalled
					Off(OUT_AC);
					driving = false;
					PlayTone(500, 1000);
			}
			
			prevRightEncoder = currentRightEncoder;
			prevLeftEncoder = currentLeftEncoder;
		} else {
			// we're not driving so just keep the values current
			prevLeftEncoder = MotorTachoCount(OUT_A);
			prevRightEncoder = MotorTachoCount(OUT_C);
		}	
		
		Wait(250);

}


task main() {

	driving = false;
	StartTask(watchdog);
	
	ResetTachoCount(OUT_AC);
	ResetRotationCount(OUT_AC);


	driving = true;
	while(driving) {
		Wait(250);

	
	StopAllTasks();
}
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests