|
|||||||
| UNOFFICIAL Answers - Ask the Community! Community Members can provide UNOFFICIAL answers to the questions from the "locked" forum above. |
![]() |
|
|
Thread Tools |
|
#1
|
|||
|
|||
|
Hi, I recently started using sensors on my robot and i'm having some problems on programing the shaft encoder
Here are my questions: (ps. I am using easy C for programing (V2)) 1. I only know that 1 wire goes to interrupts, but how about the other one? 2. please correct me if i misunderstand the commands for shaft encoder. "start" means to start the sensor "get" means to get value from the sensor "preset" means to set a specific value for the sensor "stop" means to stop it 3. last question, I have no idea how to use those commands.I don't really understand the samples on the vex official website. can some1 show me some other samples of using all 4 commands? thanks |
|
#2
|
|||
|
|||
|
Re: syntax for shaft encoder?
|
|
#3
|
||||
|
||||
|
Re: syntax for shaft encoder?
Quote:
![]() Quote:
Since the Vex Controller is related to the FRC Controller, take a look at this document about using the Timers, Using Polled or Interrupt-driven Timers which are closely related to Sensors that use Interrupts verses Digital Input.. Quote:
Quote:
Optical Encoders are used to detect Rotation, and Quad Encoders to detect Rotation and Direction. Indirectly, this can be used to Calculate Rotational Speed (RPM), and/or a Distance Traveled, and with the Quad Encoder, which Direction was Traveled. |
|
#4
|
|||
|
|||
|
Re: syntax for shaft encoder?
Quote:
I only know that this sensor can measure the distance that a robot travels and also limit the distance. But how can this quad encoder tell u the direction/rotation? besides, which port in the interrupts does it go to? |
|
#5
|
||||
|
||||
|
Re: syntax for shaft encoder?
Yes, see the Incremental Rotary Encoder section of Encoders on Wikipedia.
Quote:
For Example, if the Optical Encoder is on the same metal shaft as the Wheel, every revolution of the Wheel is a revolution for the Optical Encoder. The Optical Encoder is 90 Counts per Revolution, so 90 Counts is also One Revolution of the Wheel, a 2" Wheel is 6.2831852" around (2" * Pi [3.1415926]). So, 90 Counts of the Optical Encoder is 6.2831852" of Travel, if there is no slippage. It does not mater if you go slow or fast, the counter only counts revolutions.. So lets say you drive your robot above, 790 Counts. How far did you go?? 790 Counts / 90 Counts per Revolution = 8.778 Revolutions. 8.778 Revolutions Times 6.2831852" = 55.152", or 140.086 centimeters If you decide that 55.152" is enough, you stop moving, and have just limited your distance... If you have a different size wheel, or if the Encoder is on a Gear that is not a 1:1 Ratio with the Wheel, you will need to perform additional calculations to get the proper conversion of Optical Encoder counts to Wheel Revolutions, and thus Distance Traveled. A lot of this is also documented in the Inventor's Guide - Optical Shaft Encoder download. But, sometimes that can be hard to follow, so keep asking questions.... Quote:
|
|
#6
|
|||
|
|||
|
Re: syntax for shaft encoder?
thanks, MarkO, ur explanation really helps me understanding how encoders work
![]() but i still have some questions on how to programing it. 1. what is the purpose of presetting the encoder? so it doesn't start at negative value (or any other unknown value?) 2.when u preset the encoder, can u preset the same encoder later on in the same program flow under the same condition? ex: while (1==1), if (a==0)....etc? 3. when u preset the value for an encoder and then start it, does it mean the encoder starts to count distance from the set value? (preset it to 0 and start it will that mean start counting from 0?) 4.when using the syntax, "start", what does that mean to invert the direction? so it can measure it in counter-clockwise or clockwise? Does it always measure in clockwise? |
|
#7
|
|||||
|
|||||
|
Re: syntax for shaft encoder?
Quote:
Quote:
It saves you some calculations... If you want to travel 450 Clicks, Start the Encoder at Zero, and then as you move, you check the current value on the Encoder until you reach or exceed 450. If the Encoder is not Zero, you need to Save the Value of the Encoder in another Variable (maybe called Encoder_Start_Value, since I prefer descriptive variable names), then as you move, you check the current value on the Encoder, subtract the Encoder_Start_Value and see if it is 450 Clicks or more. Quote:
Quote:
Quote:
This line is from the EasyC v2 Help. "Use Invert Direction reverse the positive direction of rotation." Read through the Help in EasyC. When you have a Quad Encoder Dialog Box up, click the Help Button to bring up the Help on the subject. Note the EasyC v2 document states that Vex Labs does not provide a Quad Encoder, which was originally true, but is no longer. I would suggest that you "Try it and find out." (A line from a former College Instructor) There is Four Basic things to test. Inverted and Non-Inverted in the Code, and Input A and Input B. If the Encode Wires are not labeled (I think mine are), use a Sharpe (TM) or Fingernail Polish and Mark one 'A' and the other 'B'. Make a little table. Setup a simple program that displays the Value of the Counter. For each Basic Test: Turn the Quad Encoder Clockwise, then Counter-Clockwise. Set the Invert Flag. Turn the Quad Encoder Clockwise, then Counter-Clockwise. Switch the A and B Encoder lines. Turn the Quad Encoder Clockwise, then Counter-Clockwise. Set the Invert Flag. Turn the Quad Encoder Clockwise, then Counter-Clockwise. Note which way the Counter Increments and Decrements. Record your results in the Table. |
|
#8
|
|||
|
|||
|
Re: syntax for shaft encoder?
thanks MarkO, now i can program it w/o any problems
but, i still have one more question though, can I just plug in one of wires of the Quad Encoder and so maybe it will work like a normal shaft encoder? or it doesn't matter? |
|
#9
|
||||
|
||||
|
Re: syntax for shaft encoder?
Quote:
Quote:
Yes, you can plug in just one of the Wires, and Program just like a Single Optical Encoder. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|