Significant delay in motor response

This is where you talk about the NXJ hardware related topics such as the brick, sensors, LEGO pieces, etc

Moderators: roger, 99jonathan, imaqine

Significant delay in motor response

Postby Doug Fane » Mon Dec 05, 2011 1:46 pm

I looked through the forum and couldn't find anything about this, but I am having problems controlling my motor. I am trying to make the NXT drive forward until it gets within about 8cm of a wall, and then turn around. My problem is that when I make a call to stop the motors, there is about a 2 second delay before they respond. I have also tried just switching the direction of the motors, which reduces the delay, but the delay is still significant (about .75 seconds) Is this a hardware issue or something wrong with my code?

Code: Select all
while (!Button.ESCAPE.isPressed()){
          i = sonic.getDistance();
         if (i < 38){
                     Motor.A.setSpeed(3000f);
                     Motor.B.setSpeed(3000f);
                     Motor.A.backward();
                     Motor.B.backward();
                     Thread.sleep(800);
                     Motor.A.setSpeed(3000f);
                     Motor.B.setSpeed(1500f);
                     Motor.A.backward();
                     Motor.B.backward();
                     Thread.sleep(700);
            Motor.B.setSpeed(3000f);
            Motor.A.forward();
            Motor.B.forward();
         }
         }
    }



NOTE: The sensor is defined outside the loop and is working properly, I know there is no delay in the sensor. Also, as of right now the code is working, but not the way I want it to. I had to slow down the NXT and increase the distance of detection from 8cm to 38cm to avoid hitting the wall
Doug Fane
New User
 
Posts: 9
Joined: Sun Dec 04, 2011 11:20 pm

Re: Significant delay in motor response

Postby skoehler » Mon Dec 05, 2011 3:17 pm

It might be related to the insanely high speed value of 3000 degrees per second. The motors can handle about 700 degrees per sec.
Use 700 instead of 3000.
skoehler
leJOS Team Member
 
Posts: 1114
Joined: Thu Oct 30, 2008 4:54 pm

Re: Significant delay in motor response

Postby gloomyandy » Mon Dec 05, 2011 3:37 pm

Hi,
There is a method getMaxSpeed which will return an estimate of the maximum speed for a motor based upon the current battery voltage... But as Sven says 700 is probably a pretty safe value...

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

Re: Significant delay in motor response

Postby Doug Fane » Mon Dec 05, 2011 4:07 pm

Ok, so I was just trying to make it go to fast. Originally it was set at 7200, but I stepped it back to 3000.
Doug Fane
New User
 
Posts: 9
Joined: Sun Dec 04, 2011 11:20 pm

Re: Significant delay in motor response

Postby gloomyandy » Mon Dec 05, 2011 5:31 pm

Well neither 7200 or 3000 make any sense as Sven said the realistic maximum is nearer to 700 (not 7000)... If you ask the motor regulator to go too fast you will basically place it outside of usable regulation...

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

Re: Significant delay in motor response

Postby Doug Fane » Tue Dec 06, 2011 12:59 pm

I guess I don't understand. Do you mean that the motor itself can't turn that fast, or that it just can't be regulated at that speed?

The original turning method worked (motor A at 7200 and motor B at 3500), so the maximum must lie somewhere above 3500 or there wouldn't be any difference in the speed of the motors and the vehicle wouldn't be able to turn.

Finally, how do the motor stop and motor flt methods work? I think this may help me understand the issue, as this is the method call that is causing the lag.
Doug Fane
New User
 
Posts: 9
Joined: Sun Dec 04, 2011 11:20 pm

Re: Significant delay in motor response

Postby skoehler » Tue Dec 06, 2011 1:08 pm

Doug Fane wrote:I guess I don't understand. Do you mean that the motor itself can't turn that fast, or that it just can't be regulated at that speed?


At full power, the motors rotate at 700 (maybe 800) degrees per sec. That is the physical maximum of the motors.
Regulation for values close to the maximum will not be optimal.

Doug Fane wrote:The original turning method worked (motor A at 7200 and motor B at 3500), so the maximum must lie somewhere above 3500 or there wouldn't be any difference in the speed of the motors and the vehicle wouldn't be able to turn.


I haven't tested it, but I'm extremely skeptic that it worked. As we have repeatedly said, the maximum is at about 700. And I wonder why you haven't tested with sane speed values yet.

Doug Fane wrote:Finally, how do the motor stop and motor flt methods work? I think this may help me understand the issue, as this is the method call that is causing the lag.


I suspect, that the stop() method will try to make the motor stop at a certain tacho count, which is equal to the tacho count that the motor should have been at the desired speed.
However, since your desired speed is so high, the motor hasn't reached this tachocount yet, and it takes ages until it actually reaches the desired tacho count value. Hence the lag.
skoehler
leJOS Team Member
 
Posts: 1114
Joined: Thu Oct 30, 2008 4:54 pm

Re: Significant delay in motor response

Postby Doug Fane » Wed Dec 07, 2011 1:28 pm

I have since tested with the "sane" values and the program has significantly less lag, but the vehicle moves much slower than before. I am using the slower speeds for programs where a quicker reaction time is needed, and the faster speeds for programs where the speed is preferable to accuracy.
Doug Fane
New User
 
Posts: 9
Joined: Sun Dec 04, 2011 11:20 pm


Return to NXJ Hardware

Who is online

Users browsing this forum: No registered users and 0 guests

more stuff