View unanswered posts | View active topics It is currently Fri Sep 19, 2014 3:51 pm






Reply to topic  [ 6 posts ] 
Help understanding nMotorEncoderTarget[motor] command 
Author Message
Rookie

Joined: Wed Jan 23, 2013 6:16 pm
Posts: 7
Post Help understanding nMotorEncoderTarget[motor] command
Is the nMotorEncoderTarget[motor] command an absolutea or reletive based command? For example, if I want to make the 3 following moves based on joy1Btn() commands:

From 0 to 10000
From 10000 to 2500
From 2500 to 8000

It doesn't seem that I can simply use the following commands (along with the additional waiting commands for the motion to complete:

nMotorEncoder[motor] = 0
nMotorEncoderTarget[motor] = 10000
nMotorEncoderTarget[motor] = 2500
nMotorEncoderTarget[motor] = 8000

Is this true, or am I missing something? Note: I'm using Tetrix motors with rotory encoders and the PID attribute.

Thank you in advance for any insight.......


~TJ


Mon Feb 04, 2013 11:59 am
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 578
Post Re: Help understanding nMotorEncoderTarget[motor] command
Would you be able to post the code segments in question in their entirety using the [code] tags? This way we will be able to make sure that there aren't any programming logic errors.

In the meanwhile, take a look at our nMotorEncoderTarget wiki page and the Video Trainer Curriculum video dealing with nMotorEncoder commands (under the Movement -> Improved Movement -> Target Distances video). The video trainer can walk you through how each command works, and the wiki page can show you code samples of how to use them in a program.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Mon Feb 04, 2013 5:43 pm
Profile
Rookie

Joined: Wed Jan 23, 2013 6:16 pm
Posts: 7
Post Re: Help understanding nMotorEncoderTarget[motor] command
Thank you for your reply. I'm trying to see the video, but in the mean-time attached is the code. I tried copying it into the body of this message, but I'm having trouble with the formatting.

This code seems to work, but intermittently, the motor will blow past the setpoint. I beleive it is tied to the PID_DELAY and I'm working to find the best wait time to give time to both the joystick driving and tower motor. The examples "block" in a while() loop waiting for the nMotorRunState to be idle, but then we would have no response from the joystick.


Thank you for the help.......


Attachments:
5521ModifiedTeleopPID_relative.c [8.94 KiB]
Downloaded 302 times
Mon Feb 04, 2013 8:38 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 578
Post Re: Help understanding nMotorEncoderTarget[motor] command
According to the code you have posted, there is one instance of the nMotorEncoderTarget command (please correct me if I am wrong):

Code:
 wait1Msec(25);

            // set the encoder target
            nMotorEncoderTarget[Tower] = reletiveDestination;

            // give time to process the target command
            wait1Msec(25);


Generally, the nMotorEncoderTarget uses the following format:

Code:

nMotorEncoder[motorB] = 0;                // reset the Motor Encoder of Motor B
nMotorEncoderTarget[motorB] = 360;        // set the  target for Motor Encoder of Motor B to 360
motor[motorB] = 75;                       // motor B is run at a power level of 75
 
while(nMotorRunState[motorB] != runStateIdle)  // while Motor B is still running (hasn't reached target yet):
{
  // do not continue
}
motor[motorB] = 0;                       // motor B is stopped at a power level of 0
 


The key lines are setting the encoder target, setting a power speed, and creating a while loop that keeps the motor power level the same until the target is reached and the nMotorRunState command returns a runStateIdle. We usually advise clearing the encoder counts to 0 before using the nMotorEncoderTarget command, unless you are keeping track of where you are at versus where you want to be (it appears in your code that you are doing so).

The best way to explain this is actually found in the linked Video Curriculum Trainer video; it goes over the three run states, the nMotorEncoderTarget command, and how to use them correctly in a program.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Fri Feb 08, 2013 4:19 pm
Profile
Rookie

Joined: Tue Nov 20, 2012 8:09 pm
Posts: 35
Post Re: Help understanding nMotorEncoderTarget[motor] command
If you want to have the motor go to a specific encoder position (in other words, to use it like a servo) see this thread: http://robotc.net/forums/viewtopic.php?f=52&t=5399. I don't think that's what you want exactly, but you might find something there helpful anyways. Also, its helpful code to have for the future.


Sat Feb 09, 2013 8:48 pm
Profile
Rookie

Joined: Wed Jan 23, 2013 6:16 pm
Posts: 7
Post Re: Help understanding nMotorEncoderTarget[motor] command
Thank you both for your input. I finally was able to see the video and it confirmed reletive (incrimental) moves. I think we're going to settle on our current implimentation for now. It seems to work.

Thank you again...

~TJ


Tue Feb 12, 2013 12:02 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 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.