[FTC]: Motor Encoders

We are atempting to create a code for motor encoders, but we can not find a VI that does this or any place to tell us how to do this. Can anybody give us some directions or sample code?

Can this be in robotC or can it only be for labview?

Alyssa,

I can’t help with LabView, but in general, I’d say look for a variable/attribute in the motor block with ‘Encoder’ or ‘Count’ in the name.

Jason,

How are you trying to use them? Through the standard HiTechnic interface, you can access a variable in RobotC named ‘nMotorEncoder]’…

Find a file in your (this was RobotC 2.xx) distribution of sample programs:

C:\Program Files (x86)\Robotics Academy\ROBOTC for MINDSTORMS\Sample Programs\NXT\TETRIX Motors\TETRIX nMotorEncoders Example.c

and see this code:


task main()
{

  nMotorEncoder[motorE] = 0;  //clear the TETRIX encoders in motors D and E
  nMotorEncoder[motorD] = 0;

  while (nMotorEncoder[motorE] < 1440) //while the encoder wheel turns one revolution
  {
    motor[motorE] = 30; //turn both motors on at 30 percent power
    motor[motorD] = 30;
  }

  motor[motorE] = 0; //turn both motors off
  motor[motorD] = 0;

  wait1Msec(3000); // wait 3 seconds to see feedback from the debugger screens
                    // open the "NXT Devices" window to see the distance the encoder
                    //spins. The robot will coast a little bit.
}

Hi,
Yes, that is what I was going to suggest for her to do - I actually was asking her if she would be allowed to use robotC and then was going to tell her that, I did already know how to do that :slight_smile:

But you just made my life easier and told her. And yes, that is exactly what to do.

If you need help with labview, I can ask someone else on my team who uses it sometimes, and will try to get you an answer by tuesday

We use Labview.

DC Motors with encoders can be used in LabVIEW through three VIs on the “NXT Robotics >> TETRIX” palette.

Move a Fixed Distance : Starts motors running at constant speed with a target encoder count. You can also specify timeout conditions.

Motor Status: Returns the current encoder count and whether the DC controller is in the middle of a move to position command.

Reset Encoders: this ones pretty simple.

Team #116 is using a torque-limiting clutch (FTC Robotics: Tips, Tricks, Strategies & Secrets, Teams #247 & 248) and would like to install an encoder after the clutch on a standard Tetrix 3/16" shaft. Can we use a US Digital E4P-360-188-D-H-D-2 encoder on a shaft instead of a standard Tetrix motor encoder? The only difference is the shaft size and mounting screws.

Better ask this question on the official game Q&A before you purchase anything.

It’s also very easy to use the encoders to regulate the motor speed (vs the motor power)

eg: On the driving portion of the code, on the move motors VI, change the Polymorphic selector (small oprion box under the move motor VI) from Power to Speed.

Assuming you have the encoder and motors wired correctly, this will enable you to get MUCH finer control of the driving. eg: with constant power, it’s hard to get a slow move. You always need to have a certain amount of power just to get the motors to overcome friction (eg 20%). However if you use Constant Speed, (with encoders) you can get the speed as low as you want (eg: 5%) and it ALWAYS runs at that speed, regardless of friction. It’s great for slow turns etc.

If you try using encoders and you always seem to go at 100% speed, then you have a wiring problem… Could be your encoders and motors are switched, A-B and B-A or mayve your motors are wired in reverse (red -ve, black +ve)