Log in

View Full Version : Digital I/O Dilemma


comwiz7
19-01-2009, 17:09
We attempted to wire the encoder but have not been able to get any feedback from it using the dashboard.

I split two PWM cables and connected the two power wires to the power wire on the encoder and the same with the ground. I connected the Channel A wire on the encoder to the white wire on one PWM and the Channel B wire to the white wire on the other PWM.

http://farm4.static.flickr.com/3315/3210177185_780a121d52.jpg?v=0

I connected one PWM to Digital I/O 3 and the other to Digital I/O 4.

I initialized it in the programming like this:
Encoder encoder1;
encoder1(4, 3, 4, 4, 0);


The SLOT 4 spot on the dashboard (picture linked below) sporadically changes colors and I'm not sure if it is even supposed to do that but we can't get any feedback on the ports of the encoder. I'm sure I've done something wrong as I have never worked with an encoder before. However, I can't get it to react to something as simple as a limit switch either.

http://farm4.static.flickr.com/3521/3210177155_b35ab122de.jpg?v=0

jee7s
19-01-2009, 18:26
Well, I wouldn't be all that surprised by that flickering.

Since your dashboard is updating pretty fast (as fast as you get packets) and the encoder state changes once per 'tick', the value of the encoder ports should change state quickly enough to make the dashboard display a flickering or "both 0 and 1" state on the GPIO port. That's a matter of how slowly your eyes and monitor react.

The information you are really after is the number of ticks that have occurred, which is in the FPGA. To get this value, you first have to set the distance per tick, then call Encoder::GetDistance(). The distance per tick defaults to 1.0, so without modification, Encoder::GetDistance returns number of ticks.

Your call would look like this:
float dist = encoder1.GetDistance();

Then, to view this on your dashboard, add the distance to the user bytes of the packet, and parse them out in LabVIEW. This takes a bit of inspection, but is possible. Alternately, use dprintf to display the distance, and open a console to the cRIO to monitor the count.

-Jeff Erickson, FRC 41

comwiz7
19-01-2009, 23:22
Well, I wouldn't be all that surprised by that flickering.

It would make sense for the inputs of the encoders to flicker, but every single input flickers, even if nothing is plugged into it. It is seemingly random. I couldn't even get a limit switch to work properly.

I added this line of code to the teleoperated loop:
dashboard.Printf("Distance: %f\n", encoder1.GetDistance());
On the dashboard it always says "Distance: 0.0000000" no matter what I do with the encoder.

Jared Russell
20-01-2009, 08:01
The initialization code you posted will not work.

Either do:


Encoder encoder1(4, 3, 4, 4, 0);


or do:


Encoder *encoder1;
encoder1 = new Encoder(4, 3, 4, 4, 0);

JDNovak
20-01-2009, 08:18
Be sure to start the encoder or it won't count. I spent an hour remembering this last night. . .

Encoder1->Start();

I test them by getting the value and printing to the console.

signed mouseXPosition = Encoder1->Get();

printf("MouseX %d\r\n", mouseXPosition);

You can view the console output by right right clicking on the connection to the cRIO and selecting Target Tools / Target Console. This will display all printed data until a reboot.