EV3 motor regulation troubles

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

Moderators: roger, gloomyandy, skoehler

EV3 motor regulation troubles

Postby pepijndevos » Tue Oct 08, 2013 11:22 am

I'm working on a program to parallel-park the RAC3TRUCK, but I'm running into trouble with motor regulation.

http://www.youtube.com/watch?v=h9_pNfebQf4

Sometimes the second motor gets all nervous, overshooting like it has P*10. I tried switching the cables, and then the other motor starts jiggling. Sometimes they both work fine.

At 1:03 you can see a violent outbreak, ramming the other car for no good reason. WTF... But sometimes it's like that all the time.

I can't figure out why this is happening to one motor, sometimes. Maybe some weird thread-scheduling issue? Or maybe this is the "undefined" behaviour you get, because once upon a time I set a negative power.
pepijndevos
New User
 
Posts: 24
Joined: Fri May 14, 2010 8:56 am

Re: EV3 motor regulation troubles

Postby gloomyandy » Tue Oct 08, 2013 11:44 am

How are you actually controlling the motors?
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3642
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: EV3 motor regulation troubles

Postby pepijndevos » Tue Oct 08, 2013 4:28 pm

I'm using Clojure, but I hope you can pick out the LejOS API functions

Code: Select all
(def left    (lejos.robotics.MirrorMotor/invertMotor lejos.nxt.Motor/D))
(def right   (lejos.robotics.MirrorMotor/invertMotor lejos.nxt.Motor/B))

(defn move [angle speed distance]
  (let [deg (* (/ distance wheel-circumference) 360)
        radius (trailing-radius truck-length angle)
        [outer-ratio inner-ratio] (speed-ratio width radius)
        [outer inner] (if (> angle 0) [left right] [right left])]
    (.setSpeed outer (int (* speed outer-ratio)))
    (.setSpeed inner (int (* speed inner-ratio)))
    (.rotate outer (int (* deg outer-ratio)) true)
    (.rotate inner (int (* deg inner-ratio)) true)))


The weird thing is that it does it just to one motor...

(not sure why the EV3 stuff is in the NXT namespace)
pepijndevos
New User
 
Posts: 24
Joined: Fri May 14, 2010 8:56 am

Re: EV3 motor regulation troubles

Postby gloomyandy » Tue Oct 08, 2013 4:59 pm

No idea what is causing the problem, it may be threading (after all all of the motor control stuff is running in Java). But all of the motors are using the same thread, so I would have expected the problem to impact all of them. I've not seen any problems when running other programs. The only small issues I've seen is when the JIT compiler runs that may cause small amounts of jitter. Do you have a simple reproducible case? It may be that some of the clojure features/implementation are causing problems (high use of GC, lots of class loading?).

How sure are you that this is a motor control problem rather than your program requesting that operation, have you tried logging the motor requests?

I'm not sure what you mean by setting a negative power. The regulated motor class does not have any notion of power settings.

The EV3 stuff is in the NXT name space because we are still working on it. This is an Alpha release, if you want everything to be perfect them feel free to wait until we have finished.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3642
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: EV3 motor regulation troubles

Postby pepijndevos » Tue Oct 08, 2013 5:19 pm

I'm pretty sure it's a control problem. It keeps jiggling after the program is done, until I flt it.

I don't have a simple reproducible program. That's the thing with problems that happen sometimes. But I'm not doing much more than

Code: Select all
(def steer   lejos.nxt.Motor/A)
(def left    (lejos.robotics.MirrorMotor/invertMotor lejos.nxt.Motor/D))
(def right   (lejos.robotics.MirrorMotor/invertMotor lejos.nxt.Motor/B))
(.rotateTo steer 100)
(.setSpeed right 110)
(.setSpeed left 90)
(.rotate right 200 true)
(.rotate left 180 true)


The outbreaks seem to happen after I stop, reset the tacho count and reverse. Maybe the thread that is holding the motors in position sees this huge jump in tacho count and tries to correct it? Should I flt all motors before resetting the tacho count?

The negative power was a bit of a joke. I did that a few days ago, and read it causes undefined behaviour. The jiggling and violence seems pretty undefined...

I'm not waiting for a perfect release. LejOS is the best and most complete EV3 API out there that I'm aware of.
pepijndevos
New User
 
Posts: 24
Joined: Fri May 14, 2010 8:56 am

Re: EV3 motor regulation troubles

Postby gloomyandy » Tue Oct 08, 2013 6:12 pm

Hi,
you will get more help if you use Java rather than other languages that run on the JVM. I don't think any of the devs have the time at the moment to look into issues that are not easy to reproduce. Resetting the tacho counts may be causing the problem but I would doubt that. I assume you are resetting them via the regulated motor class and not directly to the motor port or by some other means. Have you tried the test code you just posted do you ever see the problem when running it? I'm not sure what you mean by jigging, the motors may move a little as they try to maintain position but they should not move more than a few degrees either side of the position they are trying to hold.

The only issue I'm aware of with the motor control is that with the 0.4.0 version you may need to reset the tacho counts before you do anything else in your program as they will pick up an initial value from previous program runs. But I don't thinkt hat would explain what happens in your video.

If you can get a reproducible case then I'l try and work out what is going on...
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3642
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: EV3 motor regulation troubles

Postby pepijndevos » Tue Oct 08, 2013 6:37 pm

Ok, this reproduces the problem for me, sometimes:

Code: Select all
import lejos.robotics.RegulatedMotor;

public class HelloWorld {
  public static void main (String[] args) {
    RegulatedMotor steer = lejos.nxt.Motor.A;
    RegulatedMotor left = lejos.robotics.MirrorMotor.invertMotor(lejos.nxt.Motor.D);
    RegulatedMotor right = lejos.robotics.MirrorMotor.invertMotor(lejos.nxt.Motor.B);
    steer.rotateTo(100);
    right.setSpeed(110);
    left.setSpeed(90);
    right.rotate(2000, true);
    left.rotate(1800, true);
    System.out.println("got here");
    while (left.isMoving() || right.isMoving());

    System.out.println("got here");
    left.resetTachoCount();
    right.resetTachoCount();
    right.rotate(-2000, true);
    left.rotate(-1800, true);
    System.out.println("got here");
    while (left.isMoving() || right.isMoving());
    System.out.println("got here");
  }
}


[edit] video of above code: http://www.youtube.com/watch?v=h5ZnbSdAtBI It's not usually that bad, but it illustrates the problem well :)
pepijndevos
New User
 
Posts: 24
Joined: Fri May 14, 2010 8:56 am

Re: EV3 motor regulation troubles

Postby gloomyandy » Tue Oct 08, 2013 7:06 pm

Please describe what exactly happens when it goes wrong, what output do you see and at what point does the motor go wrong, which one goes wrong and how does it go wrong? How often is "sometimes" 1 in 10 1 in 100? What motors are you using in the various ports?
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3642
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: EV3 motor regulation troubles

Postby pepijndevos » Tue Oct 08, 2013 7:38 pm

In case you missed my edit: http://www.youtube.com/watch?v=h5ZnbSdAtBI

Ok, so I have a medium motor on A and two large motors on B and D. In this case it was D that went crazy, but it differs. It is always only ONE of them that goes crazy. I never had the medium motor do this so far.

What happens is that it's just turning, until it suddenly starts overreacting, and overreacting and overreacting. As you see in the video it's never really smooth to begin with, but acceptable. And then at some random point(not even at the reset part yet), it starts to get really bad, doing full-power oscillations of like 45 degrees on the D motor. at this point it just printed "got here" once, and is still doing the first leg.

I'd say something like 1 in 10 over today, but it just did it pretty consistently. Also, once it gets i this mode, it never gets out. Only after a clean reboot would it behave sometimes.
pepijndevos
New User
 
Posts: 24
Joined: Fri May 14, 2010 8:56 am

Re: EV3 motor regulation troubles

Postby gloomyandy » Tue Oct 08, 2013 7:50 pm

Please try adding a resetTachoCount for each motor before you do anything with any of them. Does the problem still happen then?
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3642
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: EV3 motor regulation troubles

Postby pepijndevos » Tue Oct 08, 2013 8:27 pm

The code below reproduce BOTH problems.

First run it went pretty fine, but did a wild overshoot at the second reset.
The second and third runs it just went completely out of control on D.

I also noticed that at times when the D motors was sort of doing fine, it seemed to move at ~100ms intervals, with the other motor moving more constant.

Code: Select all
import lejos.robotics.RegulatedMotor;

public class HelloWorld {
  public static void main (String[] args) {
    RegulatedMotor steer = lejos.nxt.Motor.A;
    RegulatedMotor left = lejos.robotics.MirrorMotor.invertMotor(lejos.nxt.Motor.D);
    RegulatedMotor right = lejos.robotics.MirrorMotor.invertMotor(lejos.nxt.Motor.B);
    left.resetTachoCount();
    right.resetTachoCount();
    steer.rotateTo(100);
    right.setSpeed(110);
    left.setSpeed(90);
    right.rotate(2000, true);
    left.rotate(1800, true);
    System.out.println("got here");
    while (left.isMoving() || right.isMoving());

    System.out.println("got here");
    left.resetTachoCount();
    right.resetTachoCount();
    right.rotate(-2000, true);
    left.rotate(-1800, true);
    System.out.println("got here");
    while (left.isMoving() || right.isMoving());
    System.out.println("got here");
  }
}
pepijndevos
New User
 
Posts: 24
Joined: Fri May 14, 2010 8:56 am

Re: EV3 motor regulation troubles

Postby gloomyandy » Tue Oct 08, 2013 10:47 pm

I've managed to reproduce the problem but a fix will not be very easy. The jitter problem is caused by the PID control loop being starved of cpu. This is partly caused by the way you are using a busy wait loop to test for the motors to complete a movement. You can help this problem a lot by changing your code to either include a sleep/delay of 1ms inside the two while loops or better still switch to using the waitComplete method. Clearly this is not a long term solution, but it is all I can suggest for now.

The second problem seems to be some sort of race condition when resetting the tachometers. I'm still not sure exactly where this problem is. The best way to avoid this problem is not to reset them. I don't really understand why you are doing that as your code seems to use relative moves and a tacho reset should not make any difference to those. If you do need to absolute moves you can simply record the tacho value at the same point you would have reset it and use this saved value as a base to calculate the absolute move value.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3642
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: EV3 motor regulation troubles

Postby pepijndevos » Wed Oct 09, 2013 7:28 am

In my actual code I have a 100ms sleep in the loop, but Java complained about interruptexceptions, so I skipped that part. I'll try waitComplete, and see what is using resources. Maybe it IS Clojure after all.

I'm using the tacho to measure my distance after the fact. I could store it and do more maths, but it's maybe easier to flt the motors before resetting.
pepijndevos
New User
 
Posts: 24
Joined: Fri May 14, 2010 8:56 am

Re: EV3 motor regulation troubles

Postby gloomyandy » Wed Oct 09, 2013 1:32 pm

Not sure if flt will help. The race condition is inside the Lego kernel module and is down to timing not if the motors are turning. It may make some difference but mainly because leJOS will re-read the tacho count after a float.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3642
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: EV3 motor regulation troubles

Postby skoehler » Wed Oct 09, 2013 3:07 pm

pepijndevos wrote:I'm using the tacho to measure my distance after the fact. I could store it and do more maths, but it's maybe easier to flt the motors before resetting.

By "more maths" you mean the subtraction of two tacho count values, right?
skoehler
leJOS Team Member
 
Posts: 1350
Joined: Thu Oct 30, 2008 4:54 pm

Next

Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff