Reply To: Stop motor at mechanical end position?

HomeForumsMonoBrick EV3 FirmwareStop motor at mechanical end position?Reply To: Stop motor at mechanical end position?

#5310
Author Image
Kristofer Jaxne
Participant

I solved the problem using the function IsRunning, I had not noticed it before.

Motor motorA = new Motor (MotorPort.OutA);
motorA.ResetTacho ();
motorA.SetSpeed (50);
int deg1, deg2, diff;
while (motorA.IsRunning ()) 
{
	Thread.Sleep (100);
}
motorA.Off ();
deg1 = motorA.GetTachoCount ();
motorA.ResetTacho ();

Thred.Sleep (1000);
motorA.SetSpeed (-50);
Thread.Sleep (50);
while (motorA.IsRunning ()) 
{
      Thread.Sleep (100);
}
motorA.Off ();
Thread.Sleep (500);
deg2 = motorA.GetTachoCount ();
diff = Math.Abs (deg1 - deg2);

LcdConsole.WriteLine ("Diff deg: " + diff);

This way I get the total degrees between the two end positions. But it seems like the motor won’t run the second time more than a very short moment. The waiting time between the two directions seem to solve this.

Posted in

Make a donation