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.

nMotorEncoder[motorB] = 0; // reset the Motor Encoder of Motor BnMotorEncoderTarget[motorB] = 360; // set the target for Motor Encoder of Motor B to 360motor[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.

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

tom.jakowenko

Rookie

Joined: Wed Jan 23, 2013 6:16 pmPosts: 7

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.

Who is online

Users browsing this forum: No registered users and 2 guests

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