View unanswered posts | View active topics It is currently Tue Oct 21, 2014 2:05 am






Reply to topic  [ 7 posts ] 
nMotorEncoderTarget 
Author Message
Rookie

Joined: Tue Jul 03, 2012 5:16 am
Posts: 43
Post nMotorEncoderTarget
Hi,
I'm experiencing issues when nMotorEncoderTarget is set to 0, the motor simply continues in one direction when it is obvious that it has gone past the limit. NOTE: I do not want to reset the motors anywhere in the program.

Code:
task main()
{
   nMotorEncoder[motorB] = 0;
   nMotorEncoder[motorC] = 0;
   
   nMotorEncoderTarget[motorB] = -100;        // set the  target for Motor Encoder of Motor B
   nMotorEncoderTarget[motorC] = 10;        // set the  target for Motor Encoder of Motor C
   motor[motorB] = -50;
   motor[motorC] = -50;

   while(nMotorRunState[motorB] != runStateIdle || nMotorRunState[motorC] != runStateIdle){}
   motor[motorB] = 0;                       // motor B is stopped at a power level of 0
   motor[motorC] = 0;                       // motor C is stopped at a power level of 0
   
   nxtDisplayTextLine(3,"%d",nMotorEncoder[motorB]);
   
   nMotorEncoderTarget[motorB] = 0;        // set the  target for Motor Encoder of Motor B
   nMotorEncoderTarget[motorC] = 0;        // set the  target for Motor Encoder of Motor C
   motor[motorB] = 50;
   motor[motorC] = 50;

   while(nMotorRunState[motorB] != runStateIdle || nMotorRunState[motorC] != runStateIdle){}
   motor[motorB] = 0;                       // motor B is stopped at a power level of 0
   motor[motorC] = 0;                       // motor C is stopped at a power level of 0
   
   nxtDisplayTextLine(3,"%d",nMotorEncoder[motorB]);
   
   while(true){}
}


Fri Sep 21, 2012 7:37 pm
Profile
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 195
Post Re: nMotorEncoderTarget
from the help file;
"A target value of 0 (zero) means run forever."

so you can not use 0 as a target and if it comes up mathematically you have to deal with it.

_________________
Mike aka Spiked3
http://www.spiked3.com


Fri Sep 21, 2012 10:08 pm
Profile
Rookie

Joined: Tue Jul 03, 2012 5:16 am
Posts: 43
Post Re: nMotorEncoderTarget
I will need the encoders to be accurate as possible. I tried resetting them but then it makes it very unaccurate especially when it is resetted many times in a short period of time. What other methods can I use?


Sat Sep 22, 2012 2:46 am
Profile
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 195
Post Re: nMotorEncoderTarget
That is by definition, "as accurate as possible".

If you are looking for 100% accuracy, LEGO is probably not an appropriate platform. Even if 0 worked as you hoped, you will find that a) the final position is +/- a couple of degrees (encoder ticks) and b) the gear slop is +/- a couple of degrees.

In robotics, uncertainty is always the case and should be dealt with to some extent. There are entire college courses on the subject. The most expensive robots made, have uncertainty.

At the beginner level, I have never encountered a LEGO situation where a small bit of inaccuracy was a fail / no fail proposition. For example, when moving a distance of exactly 100mm, if it comes up at 102mm, the next time I simply move 2mm less. Very easy, works every time. Remember that you can also mechanically improve some by gear reduction, so the 2 degree inaccuracy becomes a 1/2 degree inaccuracy (or some gear multiple).

_________________
Mike aka Spiked3
http://www.spiked3.com


Sat Sep 22, 2012 8:39 am
Profile
Rookie

Joined: Tue Jul 03, 2012 5:16 am
Posts: 43
Post Re: nMotorEncoderTarget
The thing is, I have to use nMotorEncoderTarget in a loop and after hundreds of loops, +-1 degree results in quite a large difference. I am working on a printing device with an arm and the angles have to be precise. I have already geared the motors quite high, but I guess I'll have to gear it higher. Thanks.

If there is a way to use nMotorEncoderTarget without resetting it, please reply.
At the moment, without resetting the motors, when the target is 0, it will simply go forever.


Sun Sep 23, 2012 3:31 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: nMotorEncoderTarget
Actually, I am not sure I understand what you want but just answering the face question you have. In theory, there is no reason to reset the encoder targets. You can keep the encoders running. Let's say the encoders are cleared to begin with. Then you set the encoder targets to some distance ahead. When the motors get there, they will stop (with some small amount of error). Then if you want to set another target some distance ahead again, you can read the current encoder value, add the delta distance to it and set it as your new encoder target. Since you did not clear the encoders, the previous error will be accounted for when setting your next target. Am I answering your question, or am I way off?


Sun Sep 23, 2012 4:25 am
Profile
Rookie

Joined: Tue Jul 03, 2012 5:16 am
Posts: 43
Post Re: nMotorEncoderTarget
That would work so I'll put that into the program.
I had that idea a long time ago, but I was afraid of the target being 0. I guess I'll just put an if else statement if the target is 0:
if(target==0){
//don't set target and don't run motor
}
Don't worry about this anymore. It's just a tiny issue.


Sun Sep 23, 2012 8:05 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.