Log in

View Full Version : Encoders


Ctx32
07-05-2006, 12:25
I got the Ultrasonics working, But can someone help me with programming encoders.
I understand how they work, But I don't understand how to program them so they will track the motor to a certain spot then return to the starting spot.
Calvin

Francis-134
07-05-2006, 17:20
What you need to do is to make a program that makes the robot go in whatever direction you wish UNTIL a certian number of encoder clicks is reached. For example, if you wanted to go five rotations of the wheel forward, then you would tell the robot to go forward until the encoder count reached 450 clicks (90 clicks per rotation * 5 rotations). In order to go back the same ammount, you have to preset the encoder to zero (the Vex encoders don't know whether you are going backwards or forwards) and set the motor to go backwards until it reads another 450 clicks (using the example above).

If you want to see how many clicks it is to a certian spot, download the "ENCODERTEST" program from the test code folder. Then, bring up the terminal window and see what the reading is once you reach a certian spot. If you need help specificaly about the encoder blocks, take a look in the help file which explains them very nicely. I hope this helps you, but if it dosen't, come on back and I'm sure someonw can help you. :)

Ctx32
07-05-2006, 19:25
What you need to do is to make a program that makes the robot go in whatever direction you wish UNTIL a certian number of encoder clicks is reached. For example, if you wanted to go five rotations of the wheel forward, then you would tell the robot to go forward until the encoder count reached 450 clicks (90 clicks per rotation * 5 rotations). In order to go back the same ammount, you have to preset the encoder to zero (the Vex encoders don't know whether you are going backwards or forwards) and set the motor to go backwards until it reads another 450 clicks (using the example above).

If you want to see how many clicks it is to a certian spot, download the "ENCODERTEST" program from the test code folder. Then, bring up the terminal window and see what the reading is once you reach a certian spot. If you need help specificaly about the encoder blocks, take a look in the help file which explains them very nicely. I hope this helps you, but if it dosen't, come on back and I'm sure someonw can help you. :)


Thats my problem, How do you tell the motor to go forward say 90 clicks?
Is this how: Begin - Start Encoder - Get encoder - motor module clockwise
If -encoder ==90 - stop motor.

Is this correct?
and how do you reverse it?
I'm sorry I'm really lost.
Thanks for your help.
Calvin

Andrew Schreiber
11-05-2006, 13:02
On the topic of Encoders, would it be possible to use a grayhill op encoder on a vex system? If i recall correctly the grayhills run on 5v and just use an interupt port on the full size controller.

As the ports are the same (i believe but i have not found a pin out or anything to tell me if they are exactly alike) so i think it is possible. The reason is our team has several older grayhills around and none of the vex encoders. As i am doing vex as a class and focusing on the programming aspect i would like to know if the sensors could be made to work for vex as well.

The same question also goes for pots.

As for easyC im not very sure. I prefer to write the code by hand as i find it faster and more open ended.

Kingofl337
11-05-2006, 13:32
The Greyhills encoders would work with easyC but would only count up and not up and down.

Ctx32
13-05-2006, 21:33
How do you tell an encoder, How many clicks you want the motor to turn?

Andrew Schreiber
13-05-2006, 21:45
Since they would work in easyC it is valid to assume that it would also work in normal C. correct?

Tristan Lall
13-05-2006, 22:42
How do you tell an encoder, How many clicks you want the motor to turn?With programming. If you work in C (for the Microchip C18 compiler), check out Kevin Watson's site (http://www.kevin.org/frc/), and download the FRC encoder module.

Really, this is a job that is better suited for a stepper motor (which are currently illegal in FIRST). The Grayhills and Kevin's code can be made to simulate this sort of behaviour quite effectively, though.

GeorgeTheEng
13-05-2006, 23:54
Thats my problem, How do you tell the motor to go forward say 90 clicks?
Is this how: Begin - Start Encoder - Get encoder - motor module clockwise
If -encoder ==90 - stop motor.

Is this correct?
and how do you reverse it?
I'm sorry I'm really lost.
Thanks for your help.
Calvin

That is basically correct. Start the encoder when you want it to start. Inside some sort of loop, get the encoder value. Compare that to 90. If it's less, drive the motor forward. Stop it when it gets to 90 or above.

The encoders do not detect direction. So no matter what way it moves, the value will increase. Depending on how your code is set up, to reverse it, you have two choices. 1) reverse the motor direction and keep counting the encoder until it hits 180. Then stop. 2) reset the encoder and in a separate loop, do the same thing as forward, except you need to reverse the motor direction.

Try this...
create a variable, count = 0
Start Encoder
While (count <= 90)
Set motor forward
Set motor to neutral
Stop Encoder
Start Encoder
While (count <= 90)
Set motor reverse
Set motor to neutral