Home→Forums→MonoBrick EV3 Firmware→Stop motor at mechanical end position?
- This topic has 5 replies, 2 voices, and was last updated 9 years, 8 months ago by Anders Søborg.
-
AuthorPosts
-
March 10, 2015 at 14:32 #5301
Kristofer JaxneParticipantI’m about to program a robot that have a grip arm that I don’t know how to program functionality for. The easy way to program the grip arm is to run the controlling motor for a specified time for open and close, but then I get no control if the grip have stopped earlier because it have grab something, and I need to know from start which position the grip is in.
I want to start by letting the grip close until the mechanical end position so I have a known position from the beginning and then I know how long time to run until open grip. If there is any method of checking if the motor is moving this would be able to do, and also check when closing how fast the grip stops moving and see if anything is in grabbed.
How does GetSpeed() work? Can I use it to check if actual speed is the same as the speed that is set? Or will it always be the same value? GetTachoCount() maybe is a better function to use, but how does the TachoCount work? I haven’t understand that yet.
March 10, 2015 at 19:20 #5303
Anders SøborgKeymasterHi there
Thanks for using monobrick firmware.How does GetSpeed() work?
It simply returns the current speed.
GetTachoCount()
Returns the position in degrees.
Writing a function like the one you describe depends on what approach you use. If you have some feedback that tells you when to stop simply move the motor until this requirement is meet. But just from your description it is hard to tell how to write the code. If you need input try possting the code you have.
/Anders
March 16, 2015 at 15:17 #5310
Kristofer JaxneParticipantI 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.
March 16, 2015 at 18:41 #5311
Anders SøborgKeymasterHi
That is great.
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.
Since the program programs execute so fast the while loop will be skipped since in reality your motor is not moving.
/Anders
March 17, 2015 at 14:52 #5316
Kristofer JaxneParticipantI think I solve that problem with the waiting time inside the while loop? It works anyway.
March 21, 2015 at 22:19 #5330
Anders SøborgKeymasterHi there
I think I solve that problem with the waiting time inside the while loop?
That code is never executed since the motor has not yet started moving 🙂
/Anders
-
AuthorPosts
You must be logged in to reply to this topic.
Follow