My motors doesn't stop at the same time [SOLVED]

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

My motors doesn't stop at the same time [SOLVED]

Postby esmetaman » Sat Sep 28, 2013 11:37 am

Hi,

This morning I was testing a new Robot. The robot had 2 NXT motors and when i tried to stop both motors, it was impossible. One motor wait a bit until stop and I am not understand the reason, because I am using latest EV3 release (0.4) and this behaviour is classic in NXT. I thought that the reason was the motors and I replaced them. I changed the chassis using 2 EV3 motors and the behaviour was the same.

What is the problem?

Code: Select all
package jab.lejos.liverobots;

import lejos.nxt.Motor;
import lejos.nxt.Sound;
import lejos.robotics.RegulatedMotor;

public class BrityPOC {   

   private static RegulatedMotor leftMotor;
   private static RegulatedMotor rightMotor;
   private final static int speedMotor = 720;
   private final static int accelerationMotor = 800;
   
   public static void main(String[] args){

      leftMotor = Motor.A;
      rightMotor = Motor.C;
      leftMotor.setSpeed(speedMotor);
      rightMotor.setSpeed(speedMotor);
      leftMotor.setAcceleration(accelerationMotor);
      rightMotor.setAcceleration(accelerationMotor);
      leftMotor.resetTachoCount();
      rightMotor.resetTachoCount();
      leftMotor.rotateTo(0);
      rightMotor.rotateTo(0);

      int iterationCounter = 0;
      
      while (!(iterationCounter >= 5)) {   

         leftMotor.forward();
         rightMotor.forward();
         try { Thread.sleep(1000); } catch (InterruptedException e) {}
         leftMotor.stop();
         rightMotor.stop();

         iterationCounter++;
         
         try { Thread.sleep(1000); } catch (InterruptedException e) {};
       }
      
      Sound.beepSequence();

      System.out.println("EXIT");      
      System.exit(0);
   }
   
}

Last edited by esmetaman on Sat Sep 28, 2013 4:12 pm, edited 1 time in total.
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 236
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: My motors doesn't stop at the same time

Postby gloomyandy » Sat Sep 28, 2013 11:45 am

If you want both motors to stop at the same time then just like on the nxt you have to use the version of stop that returns immediately for the first motor. If you don't do that stop will wait until the first motor has stopped before it returns. This is exactly the same as what happens on the NXT and is not unique to the EV3.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3635
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: My motors doesn't stop at the same time

Postby esmetaman » Sat Sep 28, 2013 11:50 am

Sorry Andy,

I don't remember that way.
What is the right way?

Cheers
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 236
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: My motors doesn't stop at the same time

Postby gloomyandy » Sat Sep 28, 2013 11:59 am

The right way is as I've described above. If what I'm saying does not make sense just look at the pilot source code to see how it does it...
https://sourceforge.net/p/lejos/code/HE ... Pilot.java
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3635
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: My motors doesn't stop at the same time

Postby esmetaman » Sat Sep 28, 2013 4:09 pm

Hi Andy,

yes, I didn't use the right method.

Now, the example runs nice.

Code: Select all
package jab.lejos.liverobots;

import lejos.nxt.Motor;
import lejos.nxt.Sound;
import lejos.robotics.RegulatedMotor;

public class BrityPOC {   

   private static RegulatedMotor leftMotor;
   private static RegulatedMotor rightMotor;
   private final static int speedMotor = 720;
   private final static int accelerationMotor = 800;
   
   public static void main(String[] args){

      leftMotor = Motor.A;
      rightMotor = Motor.C;
      leftMotor.setSpeed(speedMotor);
      rightMotor.setSpeed(speedMotor);
      leftMotor.setAcceleration(accelerationMotor);
      rightMotor.setAcceleration(accelerationMotor);
      leftMotor.resetTachoCount();
      rightMotor.resetTachoCount();
      leftMotor.rotateTo(0);
      rightMotor.rotateTo(0);

      int iterationCounter = 0;
      
      while (!(iterationCounter >= 5)) {   

         leftMotor.forward();
         rightMotor.forward();
         try { Thread.sleep(1000); } catch (InterruptedException e) {}
         leftMotor.stop(true);
         rightMotor.stop(true);

         iterationCounter++;
         
         try { Thread.sleep(1000); } catch (InterruptedException e) {};
       }
      
      Sound.beepSequence();

      
      System.out.println("EXIT");      
      System.exit(0);
   }
   
}
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 236
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain


Return to EV3 Software

Who is online

Users browsing this forum: krchilders, Yahoo [Bot] and 0 guests

more stuff