Problem on physical limit detection with RegulatedMotor

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

Moderators: 99jonathan, roger, imaqine

Problem on physical limit detection with RegulatedMotor

Postby cracky^^ » Sun Oct 09, 2011 6:19 pm

Hi lejos community,

This is my first post and i'm still new in lejos and NXT.
I use the 0.9.0 release version of lejos and so far it works fine. I love to be able to use OOP on a NXT!

But now i'm facing a problem:
My robot project includes several Motors, some are directly connected to NXT, others throw a multiplexer(mindsensors).
I need a solution to detect two physical/hard-limits (positiveLimit and negativeLimit for each motor), get the center(middle) position and store the values.
I'm looking forward to use ONE implementation for both motor types: NXTRegulated and MMXRegulatedMotor.
I've tried to use the RegulatedMotor interface and came up with this solution:

Code: Select all
public class MotorAdjustor {
   
   private RegulatedMotor _motor;
   private boolean _isAdjusted;
   private int _positiveLimit;
   private int _negativeLimit;
   private int _middle;

   public MotorAdjustor(RegulatedMotor motor)
   {
      _motor = motor;
   }
   
   public void Adjust(int positiveLimitMaxSpeedDivider, int negativeLimitMaxSpeedDivider) throws Exception
   {
      _motor.resetTachoCount();
      _motor.setSpeed((int)_motor.getMaxSpeed()/positiveLimitMaxSpeedDivider);      
      _motor.rotate(360,false);   
      Thread.sleep(150);   
      _positiveLimit = _motor.getLimitAngle();
      
      Thread.sleep(1000);
      
      _motor.setSpeed((int)_motor.getMaxSpeed()/negativeLimitMaxSpeedDivider);   
      Thread.sleep(150);
      _motor.rotate(-360,false);
      Thread.sleep(150);   
      _negativeLimit = _motor.getLimitAngle();
            
      _middle = (_negativeLimit + _positiveLimit) / 2;
      _motor.rotateTo(_middle);
      
      LCD.drawString("p:" + _positiveLimit, 0, 3);
      LCD.drawString("n:" + _negativeLimit, 0, 4);
      LCD.drawString("m:" + _middle, 0, 5);

      _motor.flt();
      Thread.sleep(10000);
   }
   
   public boolean isAdjustd()
   {
      return _isAdjusted;
   }
   
   public int getPositiveLimit()
   {
      return _positiveLimit;
   }
   
   public int getMiddle()
   {
      return _middle;
   }
   
   public int getNegativeLimit()
   {
      return _negativeLimit;
   }
}



It works in general but one of the motors are heavier to move and stops before reaching the limit.
I tried different speed and acceleration settings but always get simular results.

Questions:
Is it possible at all to change the sensivity of the Motors with RegulatedMotor class?
If not, which implementation can i use to complete the task?
Is the sensivity of motors influenced by speed or accelaration at all?
Have someone do simular stuff with lejos or have sources with further information on this?

As you can see, i'm a little stuck with this and looking forward to get some advises.

best regards,
cracky^^
cracky^^
New User
 
Posts: 4
Joined: Sun Oct 09, 2011 5:11 pm

Re: Problem on physical limit detection with RegulatedMotor

Postby gloomyandy » Sun Oct 09, 2011 7:19 pm

Hi,
I think you need to explain a little more about:
a) How do you expect this to work. So for instance to you have some sort of physical stop that you are moving the motors to and expecting them to stall when they hit the stop?
b) what is going wrong. what motors are "failing to reach the stop", what controller are you using for those motors, what do you mean by the term "motor sensitivity"?

Also I don't really see how your code can work. The value returned by calls to getLimitAngle are defined as the current target angle for a rotate request. You are making calls to getLimitAngle after the rotate has completed, the return value for getLimitAngle is not defined in this case. You seem to actually want the current position of the motor (presumably after is has stalled), in which case I would suggest that getTachoCount should give you the actual position. Is there some reason why you are using getLimitAngle?

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

Re: Problem on physical limit detection with RegulatedMotor

Postby cracky^^ » Sun Oct 09, 2011 8:46 pm

Hi gloomyandy,

thanks for you reply!

to a) Yes exactly, i expect the motor to stall and then i want to read the position. if i have the two limits i calculate the mid-position.

to b)
The failing motor is a normal NXT-Motor connectet to a Mindsensors NXTMMX-v2 Multiplexer like two other motors on which the adjustment works fine but it is mouted with axis vertical (the other motors axis are horizontal mounted) and drives a turntable-gear which seems to be a little sluggish(???) maybe becouse it has to carry more weight then the horizontal ones.
The adjustment first works fine in most test cases, motor reaches first limit(sometimes when the robot is moving it also fails on this) moves in other direction and then it reaches somethink like a critical point and stops.

The NXTRegulatedMotor class has a Method called setStallThreshold() and in past tests i used it to adjust the sensivity of stall control. This seems to work but it is neither within the RegulatedMotor interface nor within MMXRegulatedMotor class. So i'm searching for a alternative solution.

to getLimitAngle()
The getLimitAngle() returns obviously correct angles so i just considered it to be fine. I will run some test with getTachoCount() to figure out if there are differences. Thanks for the advice!

Sorry if my messages sound a little messed up... I'm not fluent in English :/

cracky^^
cracky^^
New User
 
Posts: 4
Joined: Sun Oct 09, 2011 5:11 pm

Re: Problem on physical limit detection with RegulatedMotor

Postby cracky^^ » Mon Oct 10, 2011 7:05 pm

Hi its me again,

So here is my new test code with getTachoCount:

Code: Select all
public class MotorAdjustor {
   
   private RegulatedMotor _motor;
   private boolean _isAdjusted;
   private int _positiveLimit;
   private int _negativeLimit;
   private int _middle;

   public MotorAdjustor(RegulatedMotor motor)
   {
      _motor = motor;
   }
   
   public void Adjust(int positiveLimitMaxSpeedDivider, int negativeLimitMaxSpeedDivider) throws Exception
   {
      _motor.resetTachoCount();
      
      _motor.setSpeed((int)_motor.getMaxSpeed()/positiveLimitMaxSpeedDivider);      
      _motor.rotate(660, false);   
      _motor.flt();
      _positiveLimit = _motor.getTachoCount();
      
      Thread.sleep(2000);
      
      _motor.setSpeed((int)_motor.getMaxSpeed()/negativeLimitMaxSpeedDivider);   
      _motor.rotate(-660, false);
      _motor.flt();
      _negativeLimit = _motor.getTachoCount();
               
      _middle = (_negativeLimit + _positiveLimit) / 2;
      _motor.rotateTo(_middle);
      
      LCD.drawString("p:" + _positiveLimit, 0, 3);
      LCD.drawString("n:" + _negativeLimit, 0, 4);
      LCD.drawString("m:" + _middle, 0, 5);

      Thread.sleep(10000);
   }
   
   public boolean isAdjustd()
   {
      return _isAdjusted;
   }
   
   public int getPositiveLimit()
   {
      return _positiveLimit;
   }
   
   public int getMiddle()
   {
      return _middle;
   }
   
   public int getNegativeLimit()
   {
      return _negativeLimit;
   }   
}


The values are smaller now, so maybe it was part of the problem, thanks again!
The term "Limit" in the Method name was a little misleading to me.

But in 1 out of 2 tests the adjustment still fails: The motor stops if the turntable reachs a point where it gets a little bit harder to turn it.
So, is it possible to set the threshold on which the motor stops without using the NXTRegulatedMotor class?
If not, is is hard to implement a method like the setStallThreshold from NXTRegulatedMotor in MMXRegulatedMotor, so i could use a custom interface instead of RegulatedMotor to adjust MMXRegulatedMotor and NXTRegulatedMotor?

best regards,
cracky^^
cracky^^
New User
 
Posts: 4
Joined: Sun Oct 09, 2011 5:11 pm

Re: Problem on physical limit detection with RegulatedMotor

Postby kirkpthompson » Mon Oct 10, 2011 7:27 pm

Hi.
is is hard to implement a method like the setStallThreshold from NXTRegulatedMotor in MMXRegulatedMotor,

Since the NXTMMX handles all the motor functionality in its firmware and the LeJOS classes really just provide a wrapper to expose that functionality, I would say the answer is yes, it is very hard since that would require the NXTMMX firmware to be changed. Well, let me qualify: at least for us since we don't "own" the firmware code, etc.

Best,
-K
Leg Godt!
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Re: Problem on physical limit detection with RegulatedMotor

Postby cracky^^ » Mon Oct 10, 2011 9:14 pm

Hi K,
Thank you for that hint, I wasn't aware that the stall control is handled by the motor!
You see, I'm still a beginner :roll:
So, I will change my pin configuation and use the NXTRegulatetMotor class to accomplish the adjustment of this particular motor.

Thank you both for the quick help!

best,
cracky^^
cracky^^
New User
 
Posts: 4
Joined: Sun Oct 09, 2011 5:11 pm

Re: Problem on physical limit detection with RegulatedMotor

Postby kirkpthompson » Mon Oct 10, 2011 9:49 pm

Hi.
Just to clarify, the stall detection in the NXTMMX is in the NXTMMX firmware, not the motor itself. Also, this has nothing to do with the NXTRegulatedMotor class. If I remember right, it only works on rotate commands and I don't remember if the stall status is exposed by the LeJOS API.

Best,
-K
Leg Godt!
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff