Help understanding nMotorEncoderTarget[motor] command
Page 1 of 1

Author:  tom.jakowenko [ Mon Feb 04, 2013 11:59 am ]
Post subject:  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.......


Author:  JohnWatson [ Mon Feb 04, 2013 5:43 pm ]
Post subject:  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.

Author:  tom.jakowenko [ Mon Feb 04, 2013 8:38 pm ]
Post subject:  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.......

5521ModifiedTeleopPID_relative.c [8.94 KiB]
Downloaded 661 times

Author:  JohnWatson [ Fri Feb 08, 2013 4:19 pm ]
Post subject:  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):


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

            // give time to process the target command

Generally, the nMotorEncoderTarget uses the following format:


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.

Author:  SergeantFTC [ Sat Feb 09, 2013 8:48 pm ]
Post subject:  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: 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.

Author:  tom.jakowenko [ Tue Feb 12, 2013 12:02 pm ]
Post subject:  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...


Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group