Ev3 Motors in lejos 0.5.0

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

Moderators: roger, gloomyandy, skoehler

Re: Ev3 Motors in lejos 0.5.0

Postby jorrge » Fri Apr 04, 2014 9:39 pm

when i try to rotate two motors as well as you write the code one line is first and the the other, on my EV3 the first line moves one motor and the second motor starts after the first one finish. I hope this show's you my problem
here is may code:
Code: Select all
 
izq = new EV3LargeRegulatedMotor(MotorPort.A);
der = new EV3LargeRegulatedMotor(MotorPort.B);   
izq.rotate(grados);
der.rotate(grados);   

i think my problem has to be with the immediateReturn variable, but I cant figure out the solution, Thanks again
jorrge
New User
 
Posts: 14
Joined: Wed Mar 19, 2014 9:19 pm

Re: Ev3 Motors in lejos 0.5.0

Postby jorrge » Fri Apr 04, 2014 9:45 pm

In fact just to complet the information, when I used the forward() method both motors starts at the same time.
jorrge
New User
 
Posts: 14
Joined: Wed Mar 19, 2014 9:19 pm

Re: Ev3 Motors in lejos 0.5.0

Postby jorrge » Fri Apr 04, 2014 9:50 pm

In fact just to completed the information, when I used the forward() method both motors starts at the same time, which is the result I espected, so what happend with the rotate() method when I used two motors?
jorrge
New User
 
Posts: 14
Joined: Wed Mar 19, 2014 9:19 pm

Re: Ev3 Motors in lejos 0.5.0

Postby gloomyandy » Fri Apr 04, 2014 10:05 pm

It is always worth spending a little bit of time studying the API documentation for the class you are using. In this case:
http://www.lejos.org/ev3/docs/lejos/rob ... rotate(int)
states clearly that "This method does not return until the rotation is completed.". So the motors are doing exactly what you have asked them to do.

However if you look at the same class there is a second rotate method:
http://www.lejos.org/ev3/docs/lejos/rob ... rotate(int, boolean)
Which states "iff immediateReturn is true, method returns immediately and the motor stops by itself ", which is probably what you want to happen.

If you need to wait for the motors to complete the requested operation you may need to use waitComplete:
http://www.lejos.org/ev3/docs/lejos/rob ... tComplete()
or isMoving:
http://www.lejos.org/ev3/docs/lejos/rob ... #isMoving()
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4240
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Ev3 Motors in lejos 0.5.0

Postby jorrge » Sat Apr 05, 2014 2:44 am

completly agree, but I think i didn't give more information, the problem is that I try the other method that you explain, just like you explain
here is my code
Code: Select all
izq.rotate(grados,true);
der.rotate(grados,true);

and my EV3 just make a little movement of the motors ( i would say that one degree) and finished, my question is why after I used that method it didn't work.
In the API says :
"If any motor method is called before the limit is reached, the rotation is canceled."
So another question is if this is happening?
jorrge
New User
 
Posts: 14
Joined: Wed Mar 19, 2014 9:19 pm

Re: Ev3 Motors in lejos 0.5.0

Postby gloomyandy » Sat Apr 05, 2014 7:10 am

You need to show us the rest of your code. Perhaps if you actually told us the entire story you would get a better answer?
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4240
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Ev3 Motors in lejos 0.5.0

Postby jorrge » Mon Apr 07, 2014 2:11 pm

Hi, well I intend to move the EV3 a determined distance, in this case 50 cm, that's why i made all this, do you know another way, here is the code a used, of course is just the first attempt.

Code: Select all
public static void main(String[] args) {
      
      RegulatedMotor izq;
      RegulatedMotor der;
      
      izq = new EV3LargeRegulatedMotor(MotorPort.A);
      der = new EV3LargeRegulatedMotor(MotorPort.B);
      izq.forward();
      der.forward();
      //move the EV3 for 1 second
      Delay.msDelay(1000);
      izq.stop();
      der.stop();
      
      double distance=50;//cm
      double diam=5.5;//cm
      double giros= distance/(diam*Math.PI);
      
      int contador=0;
      int total=(int)(giros*360);
      //move the EV3 50 cm forward
      izq.rotate(total);
      der.rotate(total);
      izq.close();
      der.close();
      
      
   }

Thanks in regards.
jorrge
New User
 
Posts: 14
Joined: Wed Mar 19, 2014 9:19 pm

Re: Ev3 Motors in lejos 0.5.0

Postby gloomyandy » Mon Apr 07, 2014 2:38 pm

I assume it is the second example that you have been having problems with?

If so then when you use the version of rotate that returns immediately then as I hinted at above you will need to follow the two rotate calls with calls to wait (the waitComplete method)for the operation to complete...
Code: Select all
  izq.rotate(grados,true);
  der.rotate(grados,true);
  izq.waitComplete();
  der.waitComplete();


Another hint when trying to write code like this, there is a lot of code that already exists in both the leJOS class files and in the samples, it is always worth looking at that to see how to do things.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4240
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Previous

Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 3 guests

more stuff