Go Back   VEX Forum > Official VEX Technical Support > UNOFFICIAL Answers - Ask the Community!

UNOFFICIAL Answers - Ask the Community! Community Members can provide UNOFFICIAL answers to the questions from the "locked" forum above.

Reply
 
Thread Tools
  #1  
Old 03-10-2010, 11:43 PM
allenh allenh is offline
Junior Member
 
Join Date: Apr 2009
Posts: 6
Question syntax for shaft encoder?

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
Reply With Quote
  #2  
Old 03-11-2010, 01:32 PM
LegoMindstormsmaniac LegoMindstormsmaniac is offline
Senior Member
VEX # 24(C)
 
Join Date: May 2009
Location: Owings Mills, Maryland
Posts: 215
Images: 4
Re: syntax for shaft encoder?

Quote:
Originally Posted by allenh View Post
...I only know that 1 wire goes to interrupts, but how about the other one?...
Yes, 1 wire goes into the Interrupt (Int) port, and the other goes into the Analog/Digital (A/D) Port. Sorry that I cannot help you with much else, because I do not use EasyC, instead I use RobotC.
__________________
Team 24C Super Sonic Sparks (S^3)______Team 24A Super Sonic Sparks (S^3)______Team 24B Super Sonic Sparks (S^3)
1/23/10: Tournament Champion___________________10/31/09: Energy Award_________________________10/31/09: Create Award
1/23/10: Community Award______________________ 1/23/10: Tournament Finalist_____________________ 1/23/10: Tournament Finalist
1/23/10: Innovate Award________________________ 1/23/10: Community Award______________________ 1/23/10: Amaze Award
2/20/10: Amaze Award__________________________ 1/23/10: Create Award__________________________1/23/10: Community Award
2/26-27/10: Tournament Finalist (Alliance Captain)___2/26-27/10: Tournament Champion________________2/20/10: Excellence Award
2/26-27/10: Innovate Award_____________________ 2/26-27/10: Create Award_______________________4/10/10: Energy Award
4/10/10: Tournament Champion (Alliance Captain)____4/10/10: Robot Skills____________________________4/22-24/10: 13th After Qualifying In Science
4/10/10: Think Award___________________________ 4/10/10: Programming Skills
4/22-24/10: 9th After Qualifying In Technology______ 4/22-24/10: 18th After Qualifying In Science
4/22-24/10: Tournament Quarter-Finalist (Alliance Captain)

4/22-24/10: 9th Robot Skills (3-way tie)
Reply With Quote
  #3  
Old 03-12-2010, 01:35 PM
MarkO's Avatar
MarkO MarkO is offline
Senior Member
 
Join Date: Aug 2006
Location: Albany, Oregon, USA, North Western Hemisphere, Planet Tera
Posts: 1,577
Images: 10
Re: syntax for shaft encoder?

Quote:
Originally Posted by allenh View Post
Hi, I recently started using sensors on my robot and i'm having some problems on programing the shaft encoder
This is a good place to ask questions...

Quote:
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?
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 StartQuadEncoder() 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, Using Polled or Interrupt-driven Timers which are closely related to Sensors that use Interrupts verses Digital Input..

Quote:
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
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.

Quote:
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
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.
__________________
MarkO


See Linn-Benton CC's, 2010 MATE Qualification Video.

THANKS for Rating my ROV Team's Video, From Dyno... to DyKnow.
There were 117 redirects from http://www.vexforum.com.


Tech Support Notice and Disclaimer

My "emerging" Vex Site
My Tech Site
Reply With Quote
  #4  
Old 03-12-2010, 03:06 PM
allenh allenh is offline
Junior Member
 
Join Date: Apr 2009
Posts: 6
Re: syntax for shaft encoder?

Quote:
Originally Posted by MarkO View Post
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?
Reply With Quote
  #5  
Old 03-13-2010, 02:20 PM
MarkO's Avatar
MarkO MarkO is offline
Senior Member
 
Join Date: Aug 2006
Location: Albany, Oregon, USA, North Western Hemisphere, Planet Tera
Posts: 1,577
Images: 10
Re: syntax for shaft encoder?

Quote:
Originally Posted by allenh View Post
Umm... so its a Quad Encoder
Yes, see the Incremental Rotary Encoder section of Encoders on Wikipedia.

Quote:
I only know that this sensor can measure the distance that a robot travels and also limit the distance.
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.

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:
But how can this quad encoder tell u the direction/rotation?
besides, which port in the interrupts does it go to?
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)
__________________
MarkO


See Linn-Benton CC's, 2010 MATE Qualification Video.

THANKS for Rating my ROV Team's Video, From Dyno... to DyKnow.
There were 117 redirects from http://www.vexforum.com.


Tech Support Notice and Disclaimer

My "emerging" Vex Site
My Tech Site
Reply With Quote
  #6  
Old 03-13-2010, 07:01 PM
allenh allenh is offline
Junior Member
 
Join Date: Apr 2009
Posts: 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?
Reply With Quote
  #7  
Old 03-14-2010, 05:19 PM
MarkO's Avatar
MarkO MarkO is offline
Senior Member
 
Join Date: Aug 2006
Location: Albany, Oregon, USA, North Western Hemisphere, Planet Tera
Posts: 1,577
Images: 10
Re: syntax for shaft encoder?

Quote:
Originally Posted by allenh View Post
thanks, MarkO, ur explanation really helps me understanding how encoders work
but i still have some questions on how to programing it.
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..

Quote:
1. what is the purpose of presetting the encoder? so it doesn't start at negative value (or any other unknown value?)
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 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:
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?
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...

Quote:
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?)
Yes, or set it to 1000, and it will count from 1000.

Quote:
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?
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 (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.
Attached Files
File Type: pdf 20100314-002.pdf (64.2 KB, 26 views)
File Type: doc 20100314-002.doc (11.5 KB, 11 views)
__________________
MarkO


See Linn-Benton CC's, 2010 MATE Qualification Video.

THANKS for Rating my ROV Team's Video, From Dyno... to DyKnow.
There were 117 redirects from http://www.vexforum.com.


Tech Support Notice and Disclaimer

My "emerging" Vex Site
My Tech Site
Reply With Quote
  #8  
Old 03-17-2010, 12:24 AM
allenh allenh is offline
Junior Member
 
Join Date: Apr 2009
Posts: 6
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?
Reply With Quote
  #9  
Old 03-17-2010, 02:50 AM
MarkO's Avatar
MarkO MarkO is offline
Senior Member
 
Join Date: Aug 2006
Location: Albany, Oregon, USA, North Western Hemisphere, Planet Tera
Posts: 1,577
Images: 10
Re: syntax for shaft encoder?

Quote:
Originally Posted by allenh View Post
thanks MarkO, now i can program it w/o any problems
Did the Table I uploaded help with the Programming??? I was curious to see what you (or anyone else) though of it...

Quote:
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?

Yes, you can plug in just one of the Wires, and Program just like a Single Optical Encoder.
__________________
MarkO


See Linn-Benton CC's, 2010 MATE Qualification Video.

THANKS for Rating my ROV Team's Video, From Dyno... to DyKnow.
There were 117 redirects from http://www.vexforum.com.


Tech Support Notice and Disclaimer

My "emerging" Vex Site
My Tech Site
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -6. The time now is 11:46 AM.