Potentiometer Autonomous selector

Good afternoon ladies and gentlemen,
I just wanted to make known to the VEX community, last season, my team and I stumbled upon a video on YouTube that explained how to make an autonomous selector switch out of a potentiometer, some screws, and a few other items. I made several of them and made a program in EasyC that allowed us to have over 14 different autonomous programs. It worked every time and was a very easy, low budget way to get multiple programs.

That being said, I was wondering if any teams would be interested in getting a link to the video, a picture of our setup, or the code that I wrote to go along with it. I can also explain/ teach the code as it can be extremely confusing when you first see it. I know I was very confused when I first began coding (even on EasyC).

I got various requests this last year while in competition for different aspects of the switch and I wanted to see if anyone else wanted it as well. I will be out of town the next few days but if anyone wants the information, you can PM me or just comment on this post. There are also pictures on our instagram of the switch if you want to see pictures before I post some here.

Cheers and good luck to all this year

Yes, please post a link to the video. Something as basic and useful as this can greatly help new teams.

I’d definitely love to know how to make one of these. I’ve always wanted to learn how to make a clicky autonomous switch. I have a program that goes with my potentiometer that also shows the program to be run on my lcd screen when it’s at a position, and this would definitely help it.

E: Looked at the instagram: shoot, looks like it was something different from what I was expecting. Oh well, still pretty neat.

Ok I apoligize for the late post if anyone was waiting to see this.

This is a link to the video:

All credit goes to CSM for this. We merely stumbled upon it and felt others could benefit from it.

As for the code, would anyone want the basic code posted here? I don’t have access to it at this point but if someone truly wanted it, I could provide it.

I got you covered. (Bad pseudocode inbound)

void Autonomous(){

int armPot = PotentiometerRead(whatever the pot’s analog port is)

if (armPot >= 0 && armPot <= 800){
firstAutonomous()
}

else if (armPot >= 801 && armPot <= 1200) {
secondAutonomous()
}

else if (armPot >= 1201 && armPot <= 1900) {
thirdAutonomous()
}

else{
fourthAutonomous()
}

}

For each respective autonomous (you can have as many as can fit on the selector) you’d write the actions of each routine in their own separate function (firstAutonomous, secondAutonomous, etc) and have the cortex poll the potentiometer value at the beginning of autonomous to determine which one to run, based on the if statements. To get a little fancy, you could do something similar in Teleoperated mode with an LCD Display, to make sure you have the right program running when Autonomous begins: (More bad pseudocode inbound)

void Teleop(){

While(1){

lcdSetText (uart1,1, “Current Autonomous”)

int armPot = PotentiometerRead(whatever the pot’s analog port is)

if (armPot >= 0 && armPot <= 800){
lcdSetText (uart1,2, “Program 1”)
}

else if (armPot >= 801 && armPot <= 1200) {
lcdSetText (uart1,2, “Program 2”)
}

else if (armPot >= 1201 && armPot <= 1900) {
lcdSetText (uart1,2, “Program 3”)
}

else{
lcdSetText (uart1,2, “Program 4”)
}
…rest of Teleoperated code…
}
}

Thanks. I didn’t want to have to find my old flash drive, dig out a computer that had the code, etc.

For anyone wondering, you can have seven programs using just one of these selectors.

One side note for range values, I believe the maximum value that a potentiometer can have is something like 1024. I’m not positive on this number but the way I did the math was simple. I divided whatever the maximum number of values on the potentiometer was by six. You might expect to divide by seven. However, programs one and seven are both at the very outside values of the potentiometer. Therefore, if I were to divide by seven, program two would most likely have still been in program ones range. Anyways, long story short, I counted programs one and seven as half a value. That puts you at six different sections.

That might’ve been confusing so here is how I broke down the ranges using 1024 as the highest number a potentiometer can get.
0-85= program one (it is 85 and not 170 because it is only half)
Greater than 85-255= program two
Greater than 255-425= program three
Greater than 425-595= program four
Greater than 595-765= program five
Greater than 765-935= program six
Greater than 935-1024= program seven

I’m not positive on these values being correct though. If you use these values, please make sure you do your own calculations.

If there are any problems with any of this or you want more info, you can always PM me or comment on this.

Cheers

I personally think that screws or push in/out method to hold the selector aren’t fully necessary.

Because the potentiometer has a decent amount of friction, you can just set it when the robot is placed on the field, and it will stay at the position without a problem. It is only read by the program at the very beginning of autonomous, so it won’t matter if it moves afterwards, although still unlikely.

This is true. They aren’t fully necessary. You could just rotate the center piece. However, having screws or something to lock the center piece in place removes some chance for error. The problem with just rotating it before a match is that you may not know which program you are on. Things can get confusing. When you have a million things going on with goggles, flags, missing alliance members, air tanks, positioning your bot, etc., its one less thing you have to worry about. The screws simply make it so you can find the correct program more reliably. Our team ran into plenty of setbacks throughout the year and having this as one sure fire thing was helpful.

If you want to set up the selector to be even cooler you can do this

Here is some very modular code for selecting autonomous programs. Adding a section is as easy as changing a single number.


// The number of different autonomous programs that you want to run.
const unsigned int numberOfSections = 7;
// Actual max value is 1023, but we use 1024 so that there aren't any off by one errors
const unsigned int maxPotReading = 1024;

// Returns true if the potentiometer is within the specified section
bool isSectionSelected(unsigned int section) {

    // Just some error checking so that we don't accidentally choose a section that doesn't exist
    if (section >= numberOfSections) {
        writeDebugStreamLine("Section: %u does not exist! Try changing the number of sections!", section);
        return false;
    }

    // Gets the value of the potentiometer
    unsigned int potReading = SensorValue[pot];
    // Determines a section size based off the number of sections
    unsigned int sectionSize = maxPotReading / (numberOfSections + 1);

    // Determines if the potentiometer reading is between the start value for the section, and the end value
    return (potReading >= section * sectionSize && potReading < (section + 1) * sectionSize);

}

task autonomous() {
    // Just some example code
    if (isSectionSelected(0))
        runAutonRedAutoloader();
    else if (isSectionSelected(1))
        runAutonRedPost1();
    else if (isSectionSelected(2))
        runAutonRedPost2();
    else if (isSectionSelected(3))
        runAutonBlueAutoloader();
    else if (isSectionSelected(4))
        runAutonBluePost1();
    else if (isSectionSelected(5))
        runAutonBluePost2();
    else if (isSectionSelected(6))
        runProgrammingSkills();
}

My team used a potentiometer as an autonomous selector for the Toss Up season. It works very well for choosing different autonomous selections. It is pretty much a gear with eight screw holes in it. You attach a potentiometer on the bottom and place long screws through each hole as a place for the potentiometer to stay. Place an axle through the middle of the gear (making sure it can spin smoothly) and on the end of the axle place a piece of steel/aluminum on it, so when you turn the metal it turns the axle. The axle should be long enough to move up, spin and land on a screw end. You then pull up the debugger window and test each value. In programming set the values so that if the value of the first screw is 10, make it >0 and <15 to start autonomous one. The only downfalls to them is that if you have eight autonomous selections you can only have seven choices because you need to leave the last space open to switch it to if you don’t need to use your autonomous, which can be helpful sometimes with testing. Also sometimes the potentiometer can move when the screws become loose changing the values, so tighten them down tightly. The pros to them is that they are very simple and easy to change at the last minute. I would definitely recommend using them.

Max value is 4095…

PIC has 10 bit analog inputs (0-1023) and Cortex has 12 bit analog (0-4095) which is probably where the confusion comes from

EasyC returns maximum of 1023 when using GetAnalogInput(), use GetAnalogInputHR() to get values in the range 0-4095

I recently built the potentiometer autonomous selector with the gear, and I want to know what values to use for the program (Using EasyC). The selector has 7 screws, so I want 7 different programs.

Well I don’t know anything about easyc or if its that much different from robotc, but in robotc, you would pull up the debugger window and move the potentiometer to each place and record the general values for each.

I don’t have EAsyC either (or a pot for that matter), so I’m just going off of the above posts regarding the range of analog input.

If you use GetAnalogInput() then apparently you get a value in the range of 0-1023. So divide this by 7 (1023/7 = 146.1 . . .). The first autonomous position would be anything in the range of 0-146, the 2nd autonomous would be 147-292, and so on.