Stop motor at mechanical end position?

HomeForumsMonoBrick EV3 FirmwareStop motor at mechanical end position?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #5301
    Author Image
    Kristofer Jaxne
    Participant

    I’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.

    #5303
    Author Image
    Anders Søborg
    Keymaster

    Hi 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

    #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.

    #5311
    Author Image
    Anders Søborg
    Keymaster

    Hi

    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

    #5316
    Author Image
    Kristofer Jaxne
    Participant

    I think I solve that problem with the waiting time inside the while loop? It works anyway.

    #5330
    Author Image
    Anders Søborg
    Keymaster

    Hi 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

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Posted in

Make a donation