NXTRegulatedMotor builds up

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

Moderators: roger, gloomyandy, skoehler

NXTRegulatedMotor builds up

Postby saturn_at_sky » Sat Jan 18, 2014 12:25 pm

In my next program, I use the NXTRegulatedMotor class. After

Code: Select all
motorLeft.setSpeed(200);
motorRight.setSpeed(200);
motorLeft.forward();
motorRight.forward();
while(Button.ESCAPE.isUp()) {}

the motors oscillates a bit. After

Code: Select all
while(Button.ESCAPE.isUp()) {
   motorLeft.setSpeed(200);
   motorRight.setSpeed(200);
   motorLeft.forward();
   motorRight.forward();
}

the motors builds up (I hope this is the correct description in English). The motors turns forward fast and slow and this with increasing power. After a while, the motors calm down. Do I make a mistake?
User avatar
saturn_at_sky
New User
 
Posts: 22
Joined: Wed Jan 08, 2014 1:55 pm
Location: Germany

Re: NXTRegulatedMotor builds up

Postby Aswin » Sat Jan 18, 2014 2:24 pm

Hi,

You do not make a mistake but you can make the problem smaller.

There are several reasons for your problem. One is that the regulater code competes with user code for CPU time. As a result is executed at irregular intervals. This problem can be minimised by putting a delay within your while loop. Use the Delay class for this. A delay gives the regulater code more time to execute.
A second problem is that your program is being compiled while it runs (LeJOS uses a JIT compiler). This consumes even more CPU time. There is not much you can do about it, but it explaines why the motors stabilise over time. When the program is compiled more CPU time comes available to the regulater code.

Andy is currently working very hard to move the regulater code to a device driver. Problems like this will disappear when LeJOS for the EV3 evolves.
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 199
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: NXTRegulatedMotor builds up

Postby skoehler » Sat Jan 18, 2014 9:33 pm

The first variant (setting the speed and telling the motor to rotate) is better than the second one. As far as I know, the second will currently confuse the regulation code and while this is being fixed, it doesn't make any sense to repeatedly call setSpeed() or forward(). They need to be called exactly once. Then let the motors rotate.
As Aswin mentions, the code that waits for the button to go down does waste CPU. A delay of say 10ms inside the loop may reduce the CPU time consumed by the loop. However, the higher the delay the more likely that a button press is not registered.
skoehler
leJOS Team Member
 
Posts: 1406
Joined: Thu Oct 30, 2008 4:54 pm

Re: NXTRegulatedMotor builds up

Postby gloomyandy » Sat Jan 18, 2014 10:15 pm

Add the following lines to the start of your program:
motorRight.rotateTo(0);
motorLeft.rotateTo(0);
Delay.msDelay(8000);

This will allow the jit compiler to compile the motor control code before you start using it and will remove the bad oscillation at start up. As others have said try and avoid very tight loops without a slep/delay, also try and avoid code that constantly sets the motor speed or sets the direction (forwards/backwards), there is no real need to do this. Only make these calls when the direction of speed actually needs to be changed.

We are working on a new motor controller but it is not yet ready for general use.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3967
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: NXTRegulatedMotor builds up

Postby saturn_at_sky » Sun Jan 19, 2014 4:07 pm

Aswin, skoehler and gloomyandy thank you for your hints. My program processes better now.
User avatar
saturn_at_sky
New User
 
Posts: 22
Joined: Wed Jan 08, 2014 1:55 pm
Location: Germany


Return to EV3 Software

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

more stuff