Programming Optical shaft encoders for the lift to go to a certain height.

Hello there,

This will be our first time using optical shaft encoders on a lift using easyC.

What we want to do is press a button on the joystick and then the lift goes up to a certain height…

I have tried doing this on easyC but I am unsure on what to do as it is my first time…

Also how would I use Optical Shaft Encoders in autonomous?

I hope you can help me !

I’d recommend using a potentiometer instead.

But regardless, encoders just count ticks. Part of this will be figuring out how to setup the sensor and use it with easyC (which I don’t use so I don’t know), the other part will be some basic math which will be dependent on how your lift is setup.

In general you’ll want to figure out how many ticks per degree of travel, or inches in height, or w/e and use that to determine when to stop motors.

If you need two sets of motors to synchronize, things get more complicated.

-Cody

Hello there,

Firstly thanks for the quick reply !

I would rather program it so I can count the rotations of the dial inside the shaft encoder instead or degrees.

Thanks

However, what would be great is if someone has a sample program of how it works because I can’t seem to find one on the VEX Forum example programs…

I don’t know easyC, but perhaps if you make your way through the following:
https://vexforum.com/t/optical-shaft-encoder-programming/23063/1

By reading through how people worked their way through the aforementioned problem in the link above, and see how they developed and improved it, maybe you can get some idea of how to use encoders.

Hope that helps.

EDIT: be aware that in the thread I posted, near the end they start talking about how to hook up wires to the PIC. If you have the newer Cortex, then their talk about the PIC probably won’t apply. Their concepts in the code, however, should help you somewhat. I hope.

Here’s an old thread to get you started, this question is asked every year so search back through the forum archives.

https://vexforum.com/t/preset-arm-heights-in-easyc-v4/20223/1

For a lift, an encoder is probably better as the motors/gears will generally be making more than one revolution. They do need to use a limit switch or similar as safety measures to detect the end of travel, IMEs are good but do expect issues with them reseting to 0 when you don’t want them to (sad but unfortunate truth).

jPearman - So what sensor are you suggesting that I should use?

Pots can turn only about 260 degrees, which might be good for a shoulder-like movement. Encoders can rotate an “infinite” number of times, so it depends on how your system is geared and maybe what sort of resolution you need.

But I’m not jpearman. :slight_smile:

We want to use this encoder on a linear lift.

Do you have a sample code?

I was simply saying that the mechanical design will usually dictate the type of sensor you can use. A pot can only rotate about 220 degrees as others have said, that’s fine for something like a 4-bar but may not be appropriate for a lift. I use IMEs and accept the fact that sometimes I have to do tricky things in the code to work around the limitations. If the old school quad encoder can fit then use that.