Go to Post In the encyclopedia of FIRST under the term Encyclopedia it says - See Joe Ross. - rees2001 [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 07-03-2003, 23:03
GrahamS314's Avatar
GrahamS314 GrahamS314 is offline
Registered User
FRC #0314 (Megatron Oracles)
Team Role: College Student
 
Join Date: Dec 2002
Rookie Year: 2002
Location: Flint, MI
Posts: 8
GrahamS314 is an unknown quantity at this point
Send a message via AIM to GrahamS314
Question Programming Optical Encoders

We ordered some Digi-Key optical encoders for use on our robot's stacking mechanism (for automatic positions). However, we have run into a snag in programming these little buggers. We have hooked the power up to the +5V for Potentiometers on the Analog Inputs, and the ground wire to this port as well. Then, we hooked Inputs A and B onto digital inputs 15 and 16, respectively. Our problem is that all the readings we get on a debug are zeros. Any ideas? Thanks.
  #2   Spotlight this post!  
Unread 07-03-2003, 23:43
MikeDubreuil's Avatar
MikeDubreuil MikeDubreuil is offline
Carpe diem
FRC #0125 (Nu-Trons)
Team Role: Engineer
 
Join Date: Jan 2003
Rookie Year: 1999
Location: Boston, MA
Posts: 967
MikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond repute
Send a message via AIM to MikeDubreuil
Check your documentation. You most likely are missing a resistor. There should be two voltages, cmos and ttl, you want to use a correct resistor value for TTL voltage levels.
  #3   Spotlight this post!  
Unread 08-03-2003, 00:20
randomperson's Avatar
randomperson randomperson is offline
Assembler Freak
#0904
Team Role: College Student
 
Join Date: Dec 2002
Rookie Year: 2003
Location: Wyoming,MI
Posts: 100
randomperson is an unknown quantity at this point
Send a message via AIM to randomperson Send a message via MSN to randomperson
now correct me if im wrong but..

It won't work the way you have it connected.

I believe that the only items you are allowed to connect to the analog ports are the pots and other analog related stuff, all other items requiring power must be hooked up into the main circuit breakers. For 5V power, what you need to do is get a 7805 voltage regulator and connect:

pin1: 12V (to fuse)
pin2: GND (to ground)
pin3: 5V (to the 5V power on encoder)

With the power connected as explained above, the encoder *should* function properly.. and really this is something for the electrical forums anyway..
__________________
main() {
srandom(time(0));
while(1) {
int pid=random()%30000;
if (pid>1 && pid!=getpid()){
kill(pid, random()&1 ? SIGSTOP : SIGBUS);
sleep(10); }}}

Visit my completely useless website! http://randomperson.cjb.net
  #4   Spotlight this post!  
Unread 08-03-2003, 01:36
GrahamS314's Avatar
GrahamS314 GrahamS314 is offline
Registered User
FRC #0314 (Megatron Oracles)
Team Role: College Student
 
Join Date: Dec 2002
Rookie Year: 2002
Location: Flint, MI
Posts: 8
GrahamS314 is an unknown quantity at this point
Send a message via AIM to GrahamS314
Success . . . Sort of

We have now gotten readouts from the first sensor using Gyro power, but the second input reads a constant 1. We tried changing the variable to another digital input, but to no avail. Help!!! Also, our counts using the first input to determine position are very inaccurate. They are:
if sw_stacker >= 136 then stack_up
if sw_stacker <= 122 then stack_down
stack_up:
stack_pos = stack_pos + A_out
arm_out = sw_stacker
goto done_stack
stack_down:
stack_pos = stack_pos - A_out
arm_out = sw_stacker
done_stack:

in the above, sw_stacker is a pot on the OI control system, stack_pos is a counter for postion (=0 at the beginning of the loop), A_out is the first input from the encoder (0 or 1), and arm_out is the variable sent to the van door motor running our stacker.
  #5   Spotlight this post!  
Unread 08-03-2003, 07:32
Lloyd Burns Lloyd Burns is offline
Registered User
FRC #1246 (Agincourt Robotics)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Toronto
Posts: 292
Lloyd Burns is an unknown quantity at this point
How do these "encoders" of yours work ?

With the encoders that look like pots, that I just found on pages 830-831 of the DigiKey catalog, you have two "quadrature" outputs that you have to use to determine the direction, and also count one of them (or count all the transitions on both, for more resolution). The duration of the pulses is dependent on the speed of rotation, and the RC cannot be programmed to read them reliably if the pulses don't last exactly 26 ms. To be better than a pot, you would want 128+ bits / rev, which would make the motion awfully slow. If in quadrature, you would need 52 ms x 128 = 6.6 seconds to turn one rev.

They have open collector outputs, and so they will need pull-up resistors, as mentioned in another reply, above. 10k from +5V to the encoder output ought to be ok.

=-=-=-=-=-=-=-=-=-=

A PIC operating on an interrupt-on-change is a real nice thing to have with these, because it can keep up with the pulses (it notices things every microsecond) and it could count the pulses, as does a mouse. Reporting back to the RC is possible too, possibly using the programming port of the RC.

Any other way for a PIC to talk to the RC via an analog input reduces the data to 8 bits anyway, so why not use a pot ?

Last edited by Lloyd Burns : 08-03-2003 at 08:08.
  #6   Spotlight this post!  
Unread 09-03-2003, 08:16
dave_l dave_l is offline
Registered User
#1038
 
Join Date: Feb 2003
Location: Lakota East HS
Posts: 10
dave_l is an unknown quantity at this point
For simplicity and cost reasons, we chose to use mechanical rather than optical encoders. These are basically rotary switches in quadrature; common to ground, A and B outputs to two digital inputs.

Timing is something you have to think about. Determine your maximum revolutions per second at the encoder, invert to get time per revolution, then divide by the number of encoder states to get time per state. Each state should last at least 26 milliseconds (longer is better - ours worked out to 55ms).

If you are trying to track absolute position, you will need to establish a reference point.

(In our implimentation, we attached the encoder to an earlier stage on the gearbox, which acts as a multiplier on the encoder - [N encoder states] times [gearing ratio] = #Effective states)

Given the above, the following code works great for us...

'table lookup using current and previous encoder state
temp.bit3 = fng_sensorA
temp.bit2 = fng_sensorB
temp.bit1 = fng_sns_lstA
temp.bit0 = fng_sns_lstB
read graydcd+temp.lownib, temp

'update current position with change in position (mod 256)
fng_sns_pos = fng_sns_pos + temp

'save current encoder bits for next time around
fng_sns_lstA = fng_sensorA
fng_sns_lstB = fng_sensorB

'finger zero established as 6 o'clock, +=ccw
fng_inp = (fng_inp */ fng_inp2sns_m) + fng_inp2sns_b 'scale OI control input to sensor units
if fng_sns_calib then fng_sns_pos = fng_inp 'reset calib
temp = (fng_sns_pos - fng_inp) */ fng_sns2mtr_scl 'to +-127
fng_motor = 254 - (127 + temp)

graydcd data 0,255,1,-0, 1,0,-0,255, 255,-0,0,1, -0,1,255,0 'state table for finger position decode

(The '-0' entries are the cases where somehow you missed an encoder state change)
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming Compatition Angela06 Programming 30 08-04-2005 23:12
Q&A Discuss: optical sensors CD47-Bot Extra Discussion 0 15-02-2003 22:58
Pneumatics electrical wiring and programming archiver 2001 1 23-06-2002 23:10
Error found in programming for the pump and pressure switch sjharobotics Programming 4 06-02-2002 17:46
pbasic programming punarhero Programming 4 21-01-2002 23:32


All times are GMT -5. The time now is 04:00.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi