Problem with suspendRegulation() 0.9.1

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

Moderators: roger, 99jonathan, imaqine

Problem with suspendRegulation() 0.9.1

Postby iran » Tue Dec 11, 2012 11:10 am

Hi friends,
This is my first post on Lejos forum, I apologise in advance for poor English.
I'm working on smoothing of NXT moves and I think I found two bugs in the NXTRegulatedMotor class.
1. In my opinion, motor should suspend regulation without breaking.
I mean suspending regulation shouldn't have any impact on current move. Reality shows something different.
So this is the first bug.
2. Also, this motor should know actual current position, instead of remember the last one from regulated mode.
And this is the second bug.

On the short movie we can see violent break after calling suspendRegulation(). In addition, method rotate() doesn't refresh its data.
That is why it rotates circa 270 deg, instead of 360.
A link to movie with described test is here:
http://youtu.be/8u6T623lROc
I attach source code at the botom:
Code: Select all
import lejos.nxt.LCD;
import lejos.nxt.Button;
import lejos.nxt.MotorPort;
import lejos.nxt.NXTRegulatedMotor;
import lejos.util.Delay;

public class Parametr {
  public static void main(String[] args){

     NXTRegulatedMotor right = new NXTRegulatedMotor(MotorPort.A);
     right.forward();
     //rotate until tire has max momentum (inertia plus gravity)
     while( right.getTachoCount() < 360 * 0.75 ){
        Thread.yield();
     }
     //save position, where you want to give up regulation
     LCD.drawInt(right.getTachoCount(), 0,0);
     right.suspendRegulation();
     // allow the motor to move freely for 2 seconds
     Delay.msDelay(2000);
     //get the position, where it actually is
     LCD.drawInt(right.getTachoCount(), 0,1);
     //and make one more round
     right.rotate(360);
     LCD.drawInt(right.getTachoCount(), 0,2);
    
     Button.waitForAnyPress();
     System.exit(0);
  }
}

Values on LCD were: 270, 372, 640. So "rotate(360)" moved motor only by: 640 - 372 = 268 degrees.
I hope my test will help leJOS team to improve next release :wink:

ps.
This isn't new issue, I read connected thread "0.9.0 resetTachoCount()" here:
http://lejos.sourceforge.net/forum/viewtopic.php?f=7&t=2735&hilit=resetTachoCount
iran
New User
 
Posts: 2
Joined: Mon Dec 10, 2012 7:21 pm

Re: Problem with suspendRegulation() 0.9.1

Postby gloomyandy » Tue Dec 11, 2012 3:16 pm

Hi and welcome to the forum.

I'm sorry I don't agree with your first point. SuspendRegulation does exactly what it is intended to do and is documented to do. After a call to this method the motor will have stopped and will be in float mode. It simply does not make sense to leave it running, doing so would result in the current power being set to a value which would be unpredictable which does not make much sense. If you want to perform your own low level motor control then you need to replace the entire regulator it does not make sense to try and mix the two.

Point 2 is a bug but you can easily work around it. The current code makes use of the current position which is not valid if regulation has been disabled. This value will get reset as part of regulation being enabled, but by this time it is too late. To work around it try enabling motor regulation via a call to stop before making any move requests. Again it does not make any sense to try and enable the regulator while the motor is moving either the motor needs to be under control of the regulator or it does not, it is not designed to allow you to switch between regulated and none regulated operation while the motor is running.

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3004
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Problem with suspendRegulation() 0.9.1

Postby iran » Tue Dec 11, 2012 4:48 pm

Hi, thank you for your detailed answer.
You are right, SuspendRegulation does exactly what it is intended to do and is documented to do. Sorry for my mistake :oops: I studied a little source code of NXTRegulatedMotor and assumed that methods flt() and suspendRegulation() are the same. Obviously my assumption was incorrect.
However, I tested flt() now - inserted flt() instead of suspendRegulation(). Unfortunately visual result didn't change, despite the fact that documentary claims it should.
public void flt()
Set the motor into float mode. This will stop the motor without braking and the position of the motor will not be maintained.

I don't want to perform my own low level motor control. Even if I wanted to, I don't think I talented enough to do so. I like, even love, the way leJOS controls NXT motors. It was the main reason I have chosen leJOS. Even RobotC can't offer such a function as setAcceleration().

Speaking of point 2, your trick with calling stop() to refresh current position works :D Thank you Andy!
iran
New User
 
Posts: 2
Joined: Mon Dec 10, 2012 7:21 pm

Re: Problem with suspendRegulation() 0.9.1

Postby gloomyandy » Tue Dec 11, 2012 10:58 pm

Hi,
I think you misunderstand what flt is intended to do. flt will stop the motor (as stated in the description), however after the motor has been stopped the regulator will no longer attempt to maintain the position of the motor. In contrast stop will both stop the motor and will then attempt to maintain the position of the motor even if other forces are acting on the motor. So for instance a robot on a slope will that is being driven up the slope will stop and stay in position if stop is used, but will stop and then roll back down the slope if flt is used.

What are you trying to do exactly? If you tell us we may be able to suggest a way forward.

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3004
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff