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))
I only know that 1 wire goes to interrupts, but how about the other one?
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
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?
You have the newer Quad Optical Encoders with the Two Connectors. That means that you can use one or the other, or Both, if you want to be able to determine the Direction of the Rotation. Ideally, if you are using both they should both go the the Interrupts. EasyC v2 supports the Quad Encoders with the [FONT=Courier New]StartQuadEncoder()[/FONT] function, which use One Interrupt and One Digital Input.
Since the Vex Controller is related to the FRC Controller, take a look at this document about using the Timers, -driven Interrupt**Timers which are closely related to Sensors that use Interrupts verses Digital Input…
Yes, that is correct. The reason for Start and Stop is so that Processor time is only dedicated when you want to use the Optical Encoder.
Sure… But the examples are quite straight forward… Maybe I should start with, what do you understand about the Optical Encoder and its Intended Purpose??
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.
Umm… so its a Quad Encoder
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?
Actually, you calculate the Distance, and then you decide if you want to limit the distance.
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.
Two different Optical Encoders that are Out of Phase. I would think that the A Encoder goes in the Interrupt and the B Encoder goes to the Digital Input, because depending on the Direction, the Encoders will Trigger in a different order. Get them backwards, the Direction will report backwards. (I must note that my Optical Encoders are mis-placed, and I can not plug them in and try them this minute, so I am replying of the Top of My Head)
OK… I am quite limited on trying things these next few days… I have a Chemistry Final on Monday, my Optical Quad Encoders and Programming Dongal is misplaced…
Note that you are doing nothing to the Encoder itself, you are Setting the Value of the Variable that holds the number of Clicks of the Encoder.
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 [FONT=Courier New]Encoder_Start_Value[/FONT], since I prefer descriptive variable names), then as you move, you check the current value on the Encoder, subtract the [FONT=Courier New]Encoder_Start_Value[/FONT] and see if it is 450 Clicks or more.
AFAIK, you can reset the Preset any time. A limit might be that you need to Stop the Encoder, Preset the Encoder, then Start the Encoder, but that can be done any time…
Yes, or set it to 1000, and it will count from 1000.
I think it will depend on which Input is A and which Input is B to determine Clockwise and Counter-Clockwise…
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 ™ or Fingernail Polish and Mark one ‘A’ and the other ‘B’.