What causes the GyroBoy motor malfunction limit?

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

Moderators: roger, gloomyandy, skoehler

clplaneguy
Novice
Posts: 29
Joined: Sat Feb 18, 2017 3:44 pm

What causes the GyroBoy motor malfunction limit?

Postby clplaneguy » Mon Apr 23, 2018 3:31 pm

leJOS:0.9.1-beta
Menu: 0.9.1


I have implemented GyroBoy from leJOS News. Slow and easy works fine. The robot balances, moves forward and steers left and right. I can drive it around the room. It seems to use the PID concept. Actually, it uses a double PD controller. (vertical and speed) However, if I push the robot to the limit, it fails/falls. It would be easy to just claim that in general the robot has been pushed past its physical limit.

There are several false software limits in the code to create a small operational envelope that will hopefully keep the robot within its physical limit.

Code: Select all

public void setSpeed (double s) {
      if (s>10)  s =  10;         // Limit speed
      if (s<-10) s = -10;
      speed = s;
   }


Code: Select all

public void turn (double d) {
      if (d> 50) d =  50;
      if (d<-50) d = -50;
      direction = d;
   }


Code: Select all

if (pwr >  100) pwr =  100;
if (pwr < -100) pwr = -100;


But, the real problem is specific. There is a motor malfunction at high speed/power/acceleration. When GyroBoy fails/falls, it falls hard and fast because the motors have reversed. The problem is even worse in reverse. This happens so fast that it is hard to see/notice and it does not show up in the math/output data.

More useful questions are
What is the physical limit.
What causes the hardware fault?


This reminds me of the problem of large numbers in an integer. And, in fact, the motors are receiving a product as an integer. However, the largest value of an integer is quite high and the error occurs at a motor power of around 200. 200 should be quite far from the limit of an integer.

I have gutted the GyroBoy code down to the smallest program that reproduces the fault. The problem is not(?) with the code. All of the output data looks fine. The problem only shows up in the actual function of the motors. It is not necessary to build the whole robot to watch the motors. All that is needed is a gyro and one motor. To observe the fault, it is necessary to actually monitor the rotation of the motor. Manipulating the gyro makes the motor reverse in places that it should NOT.

Does anyone have an idea what might cause this?

My test code in its entirety follows . . .

Code: Select all

import lejos.hardware.Button;
import lejos.hardware.Sound;
import lejos.hardware.motor.UnregulatedMotor;
import lejos.hardware.port.MotorPort;
import lejos.hardware.port.SensorPort;
import lejos.hardware.sensor.EV3GyroSensor;
import lejos.robotics.SampleProvider;


public class TEST {
   private static UnregulatedMotor leftMotor = new UnregulatedMotor(MotorPort.D);       
   private static EV3GyroSensor gyroSensor = new EV3GyroSensor(SensorPort.S2);               
   public static void main(String[] args) {
      double gAng = 0; // gyro angle in degrees                                               
      double gSpd = 0; // gyro angle speed in degrees/sec                         
      double pwr  = 0; // motor power in [-100,100]                   
      leftMotor.resetTachoCount();                                                               
      gyroSensor.reset();                                                                   
      SampleProvider gyroReader = gyroSensor.getRateMode();                             
      float[] sample = new float[gyroReader.sampleSize()];                                 
      long lastTimeStep = System.nanoTime();                                                   
      System.out.println("GyroBoy.run");                                       
       gAng = -0.25;                // Start angle when sitting on support           
      Sound.beepSequenceUp();                                                                                                   
      // feed back loop                   
      while (Button.ESCAPE.isUp()) {                         
         if (gAng > 30) {                                 
         System.out.println("gAnd > 30");                         
            System.exit(-1);                                         
         }                                                         
         if (gAng < -30) {                                     
            System.out.println("gAnd < -30");                           
            System.exit(-1);                           
         }                                           
         // Get time in seconds since last step               
         long now = System.nanoTime();                           
         double dt = (now - lastTimeStep) / 1000000000.0;   // Time step in seconds           
         lastTimeStep = now;                                                           
         // Get gyro angle and speed                                   
         gyroSensor.fetchSample(sample, 0);                                       
         gSpd = -sample[0]; // invert sign to undo negation in class EV3GyroSensor         
         gAng = gAng + (gSpd * dt); // integrate angle speed to get angle                 
         // Get motor rotation angle and rotational angle speed             
         pwr = 15*gAng ;                                               
         if (pwr >  200) pwr =  200;                                       
         if (pwr < -200) pwr = -200;                                       
         System.out.printf("Power %3.0f\tgAng  %5.0f\t15*gAng %5.0f\t\t(int)15*gAng %5.0f\tDiff %5.0f\n", pwr, gAng, 15*gAng, (int) 15*gAng, 15*gAng-(int) 15*gAng);             
            leftMotor.setPower((int) (pwr));                                                                           
         }                   
       leftMotor .close();                                             
      gyroSensor.close();                                                                                           
   }                                                             
}

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

Re: What causes the GyroBoy motor malfunction limit?

Postby gloomyandy » Mon Apr 23, 2018 7:03 pm

Why are you limiting the motor power to +/-200? The power setting range is +/-100 (it is a percentage). Using values that can go beyond 127 is almost certainly a bad idea as the power value is passed into the kernel as a byte. There is no point in setting the power higher then 100% as it will not achieve anything, the motor will be running as fast as it can when set to 100.
leJOS news https://lejosnews.wordpress.com/

clplaneguy
Novice
Posts: 29
Joined: Sat Feb 18, 2017 3:44 pm

Re: What causes the GyroBoy motor malfunction limit?

Postby clplaneguy » Mon Apr 23, 2018 8:18 pm

YES! I understand. 100% is the maximum. 101% is undefined.

(Stupid me)

THANK YOU

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

Re: What causes the GyroBoy motor malfunction limit?

Postby gloomyandy » Mon Apr 23, 2018 11:51 pm

Oh and another thing you will see is if you drive the motors rapidly forwards and backwards with high power settings (which can happen when trying to balance a robot like this), then eventually the motors will just turn off. They will come back on again in a few seconds (but the robot will have fallen by then). This is the EV3 hardware thermal cutout operating because the motor drivers have got too hot.
leJOS news https://lejosnews.wordpress.com/


Return to “EV3 Software”

Who is online

Users browsing this forum: No registered users and 1 guest