Home→Forums→MonoBrick EV3 Firmware→Stop motor at mechanical end position?→Reply To: Stop motor at mechanical end position?
March 16, 2015 at 15:17
#5310
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.
Follow