View unanswered posts | View active topics It is currently Thu Aug 21, 2014 10:19 pm






Reply to topic  [ 5 posts ] 
Shaft Encoders 
Author Message
Rookie
User avatar

Joined: Wed Feb 25, 2009 7:00 pm
Posts: 10
Post Shaft Encoders
After a fair bit of googling and searching the forums, I have been unable to find out how to set up/use the Tetrix Motor encoders. Can anyone provide basic setup/test code?

Thanks,
--Nathan

P.S. Sorry if this is a redundant post.

_________________
--Nathan


Wed Mar 04, 2009 9:38 pm
Profile
Novice

Joined: Fri Oct 24, 2008 8:58 am
Posts: 87
Post Re: Shaft Encoders
Okay, so I'm assuming all the mechanical stuff is done and the encoders are mounted properly to the motor with the included cable going from the encoder to the Hitechnic motor controller.

Don't forget to double check that you have the encoders plugged into the right port for the motor they are attached to.

After that using the encoders is pretty much automatic (which is partly the reason for lack of discussion about them)

Say you've got a motor named LeftDrive and RightDrive (assigned up in the #pragma section)

you can access the motor encoder value using nMotorEncoder[LeftDrive] and nMotorEncoder[RightDrive].
you can assign a value to them also which is usefull for resetting to zero.

nMotorEncoder[LeftDrive] = nMotorEncoder[RightDrive] = 0;

You can test they are working using the NXT Devices debug window. That's about it for encoders unless you have a more specific question.
Good Luck.


Wed Mar 04, 2009 9:55 pm
Profile
Rookie
User avatar

Joined: Sat Feb 14, 2009 5:59 pm
Posts: 22
Post Re: Shaft Encoders
how do you set the DC motors to be used as a servo? I know it uses the motor encoder to read the position but I don't know what the code actually is.

_________________
Lead Programmer for Team COV-0651.


Thu Mar 05, 2009 10:08 pm
Profile
Novice

Joined: Fri Oct 24, 2008 8:58 am
Posts: 87
Post Re: Shaft Encoders
sorry, I wish there was an easy answer to that one, but unfortunately thats a tough one.

If the PID control works then you should be able to:
1. Turn PID control on for the motor in question
Code:
nMotorPIDSpeedCtrl[motorF] = mtrSpeedReg;

2. Set the target position for the encoder
Code:
nMotorEncoderTarget[motorF] = 1000; // move 1000 encoder counts and stop

3. Start the motor by setting a speed value.
Code:
motor[motorF] = 50;


So try this out. But bewarned, I feel the PID control for the 12V motors is somewhere between useless and broken.
I tried for weeks to get this to work and was never happy with it. It sometimes goes completely screwy. Be careful and test it out thoroughly before you rely on it. Also try at various battery levels.

And try not to set power levels > 75%.

If this doesn't work then you have to write the PID controller yourself or use some other control technique. Because the built in PID controller parameters can't be tuned.

Another suggestion...before you try to use the PID controller. Run the sample program "NXT Motor Consistency vs Time" its under Sample Programs/Motor directory. This will help you know that everything is working okay before pulling your hair out with the flaky PID stuff.


Fri Mar 06, 2009 2:02 pm
Profile
Rookie
User avatar

Joined: Wed Feb 25, 2009 7:00 pm
Posts: 10
Post Re: Shaft Encoders
Thanks for the responses! It turned out that our problem was accidentally reading nMotorEndcoderTarget[leftMotor] rather than nMotorEncoder[leftMotor] :oops: . I hate typo programming errors.

_________________
--Nathan


Fri Mar 06, 2009 7:53 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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.