Quote:
Originally Posted by adciv
Option A: Use an encoder to convert a given value to binary and read the buttons as a binary input.
Option B: Use analog input on "joystick" and just break it up into ranges.
Option C: Put the control in software on the Driver Station Dashboard and the robot doesn't start auto until it receives its directions.
We typically use Option C, particularly as we had at least three different settings to configure each match (goal, position, defense).
|
Option B works really well. Wire GND to the left most position and 5V to the right most position. Put resistors in series between each post of the other positions. It'll make it like a potentiometer, but with low resolution.
Say you have a 6 position switch, you would wire it like:
GND-> Position 0 - 2kOhm - Position 1 - 2kOhm - Position 3 - 2kOhm - Position 4 - 2kOhm - Position 5 <- +5V
Then connect it to the joystick input. I guess it goes from -1 to 1, like shown below:
Pos 0 -> ~-1
Pos 1 -> ~-0.6
Pos 2 -> ~-0.2
Pos 3 -> ~0.2
Pos 4 -> ~0.6
Pos 5 -> ~1
You'll want to factor in some tolerance. It won't be exactly -1, -0.6, etc. In this case, you have 0.4 units between each measurement. You can test between the cases.
if ana < -0.8
pos = 0;
else if ana >= -0.8 and ana < -0.4
pos = 1;
else ifana >= -0.4 and ana < 0
pos = 2;
else ifana >= 0 and ana < 0.4
pos = 3;
else if ana >= 0.4 and ana < 0.8
pos = 4;
else // in this case, this has to be true: ana >= 0.8
pos = 5;