Problem with motors on 0.6.0

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

Moderators: roger, gloomyandy, skoehler

Problem with motors on 0.6.0

Postby daspfanni2000 » Wed Feb 12, 2014 9:48 pm

Hi all,

I am experiencing a problem that I did not have bevor (with 0.5.0)

I have trouble in the code that should home my robots arm.

The motor is set to forward() until the touch sensor is pressed. Then it should rotate to a certain number of degrees.

The problem is the latter part, rotating a certain number of degrees: Sometimes it rotates much less degrees than it should, sometimes it rotates in the wrong direction (causing sever damage...) right through the sensor...

Here is the relevance parts of my code

Code: Select all
public class TRAC3RsArm {
   
   private final double gearRatio1 = 56.0;
   
   private final String touchSensorPortName1 = "S1";
   
   private final Port motorPort1 = MotorPort.B;
   
   private SampleProvider touchSensor1; // sensor for initializing the shoulder
   
   private EV3LargeRegulatedMotor motor1; // the base or "shoulder" motor
   
   public TRAC3RsArm() {
      System.out.println("Setting up Touch Sensor 1...");
      touchSensor1 = new EV3TouchSensor(LocalEV3.get().getPort(touchSensorPortName1));
   
   
      System.out.println("Setting up Motor 1...");
      motor1 = new EV3LargeRegulatedMotor(motorPort1);
      motor1.rotateTo(0);

   
   System.out.println("Motor 1 speed: " + motor1.getSpeed() + " acceleration: " + motor1.getAcceleration());
   }
   
   public void setBothJointsSpeed(int speed){
      //set motor speed
      //the faster motor should be set according to defined default
      double jointRatio = this.gearRatio1 / this.gearRatio2;
      if (jointRatio > 1) {
         // joint1 motor needs to be faster (and default) than joint2 to turn arm as fast
         motor1.setSpeed(speed);
         motor2.setSpeed((int) (speed / jointRatio));
      } else {
         //joint2 needs to be faster (and default!) than joint1
         motor1.setSpeed((int) (speed * jointRatio));
         motor2.setSpeed(speed );
      }
   }
   
   public void setBothJointsAcceleration(int acceleration){
      //set motor acceleration
      //the faster motor should be set according to defined default
      double jointRatio = this.gearRatio1 / this.gearRatio2;
      if (jointRatio > 1) {
         // joint1 motor needs to be faster (and default) than joint2 to turn arm as fast
         motor1.setAcceleration(acceleration);
         motor2.setAcceleration((int) (acceleration / jointRatio));
      } else {
         //joint2 needs to be faster (and default!) than joint1
         motor1.setAcceleration((int) (acceleration * jointRatio));
         motor2.setAcceleration(acceleration);
      }
   }
   
   public void initialize()
   {
      System.out.println("Initializing arm positon...");
      
      Sound.twoBeeps();
      Button.LEDPattern(9);
      
      setBothJointsSpeed(500);
      
      // Find home for motor 1
      System.out.println("Homing motor1...");
      
      float[] sample = new float[touchSensor1.sampleSize()];
      
      motor1.forward();
      
      do {
         touchSensor1.fetchSample(sample, 0);
         Delay.msDelay(10);
      } while (sample[0] == 0.0);
      
      motor1.stop();
      motor1.resetTachoCount();
      System.out.println("... motor1 reached home.");
      
      rotateJoint1(-115, false);
   }
   
        void rotateJoint1(double limitAngle, boolean immediateReturn)
   {
      motor1.rotate((int) (limitAngle * gearRatio1), immediateReturn);
   }



The hurting part is: rotateJoint1()...

As mention before: with lejos 0.5.0 a very similar code ran without any problem (well the jittery motors aside:-))

Thanks so much in advance for your help!


EDIT: I took last evenings version which ran on 0.5.0. Here too the same error occurs: the Movement for -115 Degress (times the gear ratio) has stopped after ca -20 degrees. If I run it again, chances are that it will drive in the + direction again right through the touch sensor. Ouch, help, please!
daspfanni2000
New User
 
Posts: 19
Joined: Sun Dec 22, 2013 5:34 pm

Re: Problem with motors on 0.6.0

Postby gloomyandy » Thu Feb 13, 2014 12:21 am

Hi,
What happens if you do not reset the tacho count (after all you are using relative moves so the reset dos not have any effect)?

If the above does not make any difference then please try and reproduce the problem in a simple test program (so for instance does the problem happen with just a single motor?).

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

Re: Problem with motors on 0.6.0

Postby daspfanni2000 » Thu Feb 13, 2014 6:44 am

Hi Andy,

I will come back to you and this thread in approx. 13h.

Of course, the code I showed was only the code used for homing. After that I make extensive use if rotateTo method calls. So the goal in the end will be to reset the Tacho counts:-)

But I will try and report back to both your suggestions! Can I create some kind of logging that would be interesting to you?

Best regards
daspfanni2000
New User
 
Posts: 19
Joined: Sun Dec 22, 2013 5:34 pm

Re: Problem with motors on 0.6.0

Postby gloomyandy » Thu Feb 13, 2014 7:56 am

Please try your homing code without the tacho reset, and/or change the code to keep the reset and use an absolute rotateTo command. I think there may be a problem with relative moves after a reset.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3645
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Problem with motors on 0.6.0

Postby fuzzycow » Thu Feb 13, 2014 5:10 pm

In case this could be helpful:

I have tested the following calibration methods:
1) Homing of a complex geared mechanism via touch sensor in 0.5.0
2) Homing of motor + basic limiter via stall detection in 0.6.0

In each case I used resetTachoCount, and then movement based on rotateTo methods. It seems to work ok.
Some in-exact-ness in rotation forward vs back in case (2), hard to tell yet if its mechanics or the code.
For (1) - couldn't get stall detection to stop motors in time when driving a complex mechanism with high gear reduction.

I'll post some examples when I get home.

Some advice from personal struggles (sorry if this seems like trivial stuff to all but me ;) ):
* Try to work out stall detection threshold - see if it can be effective in your case
* Add isStalled checks to your calibration loop
* Don't use "forward" method to begin rotation during calibration. Use rotate(angle, true) - this way your motor will stop before it does too much damage
* Do initial tests at low motor speed, and via ssh - you will have enough time to kill/ctrl-c the program, before it does too much damage.

P.S.: You may want to check the speed .. I think max speed is voltage * 100. What's the actual calculated motor speed in your case ?
fuzzycow
New User
 
Posts: 20
Joined: Sun Sep 08, 2013 4:33 pm

Re: Problem with motors on 0.6.0

Postby daspfanni2000 » Thu Feb 13, 2014 6:31 pm

Hi you two,;-)

this code - if I did nothing wrong (and I am a beginner here) seems to totally show, that something is wrong.
Code: Select all
public class MotorBugTester {
   
   public static void main(String[] args) {
      EV3TouchSensor touchSensor1 = new EV3TouchSensor(LocalEV3.get().getPort("S1"));
      EV3LargeRegulatedMotor motor1 = new EV3LargeRegulatedMotor(MotorPort.B);
      motor1.rotateTo(0);
      
      float[] sample = new float[touchSensor1.sampleSize()];
      
      while(true){
         motor1.forward();
         
         do {
            touchSensor1.fetchSample(sample, 0);
            Delay.msDelay(10);
         } while (sample[0] == 0.0);
         
         motor1.stop();
         motor1.resetTachoCount();
         motor1.rotate(-720, false);
      }
      

   }

}


When run, the touch sensor stops having any effect after a few touches. The motor NEVER rewinds for -720. But stops shortly and then turns forward again (sometimes stopping after a few turns and restarting).

And Andy, yes, switching to rotateTo instead of rotate totally solves the issue!

And also not resetting tacho when using rotate also seems to work! Like in here:

Code: Select all
import lejos.hardware.ev3.LocalEV3;
import lejos.hardware.motor.EV3LargeRegulatedMotor;
import lejos.hardware.port.MotorPort;
import lejos.hardware.sensor.EV3TouchSensor;
import lejos.utility.Delay;


public class MotorBugTester {
   
   public static void main(String[] args) {
      EV3TouchSensor touchSensor1 = new EV3TouchSensor(LocalEV3.get().getPort("S1"));
      EV3LargeRegulatedMotor motor1 = new EV3LargeRegulatedMotor(MotorPort.B);
      motor1.rotateTo(0);
      
      float[] sample = new float[touchSensor1.sampleSize()];
      
      while(true){
         motor1.forward();
         
         do {
            touchSensor1.fetchSample(sample, 0);
            Delay.msDelay(10);
         } while (sample[0] == 0.0);
         
         motor1.stop();
         motor1.rotate(-720, false);
      }
      

   }

}


So yup, that seems to be buggy:-)

@fuzzycow:

Using stall detection seems to be truly awesome way of homing a robot! Trust me - for me it is more like rocket science than being trivial!:-)

PLEASE share your code for homing your robot using this technique!

My robot is a 2dof robot arm using the large technic turntable and a worm gear - with the high gear ratio I wonder if the stall technique is applicable without destroying the robot:-)


I use a poor man's battery to power the ev3, so there is plenty of voltage. I set the motor speed to 700 for the faster turning motor:-) http://www.thingiverse.com/thing:122810
daspfanni2000
New User
 
Posts: 19
Joined: Sun Dec 22, 2013 5:34 pm

Re: Problem with motors on 0.6.0

Postby fuzzycow » Thu Feb 13, 2014 11:30 pm

Code: Select all
public void touchCalibrate() {
      gripMotor.setStallThreshold(10, 100);
      gripMotor.stop();
      gripMotor.resetTachoCount();

      Screen.print("Calibration starting");

                // already touching sensor, but could be "over-pressing" due to previous run not stopping in time and having been aborted
                // first get lost, and then do calibration anyway      
      if ( readTouchBoolean() ) {
         gripMotor.rotateTo(ROTATE_GRIP_MIDWAY);
      }

                // rotate to maximum angle of grip's movement arc, plus a bit - ~minumum angle which guarantees that sensor will be touched
      gripMotor.rotateTo(- ROTATE_GRIP_FULL_OPEN + ROTATE_GRIP_STEP, true);      
      
      while(! readTouchBoolean() ) {
         Delay.msDelay(50);

      }
      gripMotor.stop();
      gripMotor.resetTachoCount();
   }   


Code: Select all
public boolean readTouchBoolean() {
      float[] sample = new float[1];
      touchSampleProvider.fetchSample(sample, 0);
      if ( sample[0] == 1)
         return true;
      else
         return false;
   }
   
fuzzycow
New User
 
Posts: 20
Joined: Sun Sep 08, 2013 4:33 pm

Re: Problem with motors on 0.6.0

Postby daspfanni2000 » Fri Feb 14, 2014 5:29 pm

Hi,

so you are not calling "isStalled" but wait for the motor to stop because it IS stalled, right?

Will isStalled be true if the motor is not stalled entirely but is just going against hard resistance?

For Homing the "hand" of my robot i simply use a technical solution by using a gear with clutch (http://www.bricklink.com/catalogItem.asp?P=60c01). I wonder if I can also replace it by code that uses stall detection. But I fear slipping of gears or breaking stuff.

So is it possible to stop the motor as soon it goes "very hard" but not 100% stalled?

I would be happy to learn more. I think the docs do not completely introduce the concepts here;-)
daspfanni2000
New User
 
Posts: 19
Joined: Sun Dec 22, 2013 5:34 pm

Re: Problem with motors on 0.6.0

Postby fuzzycow » Sat Feb 15, 2014 11:57 pm

From my understanding isStalled() works by comparing the lag between actual position and intended position of the motor.
If difference persists too long - isStalled is set. You can try to fine tune it to minimum workable values for your mechanism.
I thought of using getPosition vs getTachoCount and writing my own function to detect various degrees of motor being "stalled", but I don't think you can at getPosition via public API yet.

Clutch gear didn't work for my grip due to high torque, and for radar looked like it would "loose" calibration after a while :(

Previous example was from my grip mechanism, where stall detection didn't fire most of the time (with 0.5.0)
Will have to go back and try to fine-tune it again.

Here's a draft of calibration via stall detection, I've been using for a basic radar (ultrasonic sensor directly connected to ev3 large motor).
From my testing this approach is far less scary then it looks. From appearances doesn't seem to take any longer then touch-sensor based calibration.

Code: Select all
public void calibrate() {
      Screen.print("Radar Motor Calibration Start");
      
      motor.setStallThreshold(5, 30);
      motor.setAcceleration(100);
      motor.setSpeed(100);

      //Logger.info("Radar rotating to max");
      motor.rotate(360, true);
      waitWhileMoving();
      
      //Logger.info("Radar centering");
      motor.rotate(-90 - 45);
      
      //Logger.info("Radar zero-ing position to center");
      motor.resetTachoCount();
   }


Code: Select all
   public void waitWhileMoving() {
      while (true) {
         if (motor.isStalled()) {
            //Logger.error("Stalled !");
            motor.stop();
            break;
         }
         if (!motor.isMoving()) {
            //Logger.info("Not moving");
            break;
         }
      
         Thread.yield();
      }
   }
fuzzycow
New User
 
Posts: 20
Joined: Sun Sep 08, 2013 4:33 pm


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff