Ball Shifter Programming

Our captain just announced the team bough the 3 CIM Ball Shifter from vex pro, and wants the programmers (keep in mind its literally just me and one other person who hasn’t written a line of code yet), to add manual and automatic shifting to the robot between a low gear and high gear. I have almost no idea how to implement this, or where to even start. Does anybody have any example code from previous years or any resources I could use to get started? Any help is appreciated, thank you!

1 Like

What do you mean by automatic shifting and manual shifting? The coding in a sense is pretty easy. You just need to declare a Solenoid/Double Solenoid object which is attached to the piston of your gearbox. To shift you need need use the set() method

import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class ExampleDrive extends SubsystemBase {
        private DoubleSolenoid shifter;

        public ExampleDrive() {
            shifter = new DoubleSolenoid(0, 1); // (forward channel, reverse channel)
        }

        public void shiftIn() {
            shifter.set(DoubleSolenoid.Value.kReverse);
        }

        public void shiftOut() {
            shifter.set(DoubleSolenoid.Value.kForward);
        }
}

(assuming you are using java)

I understand the code, just what is the difference between a solenoid and a double solenoid? When I say automatic I mean the robot will detect the speed/acceleration of the robot and shift accordingly to the right gear. Manual is the same thing but using a button on the controller.

A double solenoid controls a piston that has an air extend and an air retract. A single solenoid controls a piston that has air retract and spring extend or air extend and spring retract. For a shifter, you definitely want a double solenoid. Doing manual shifting is just as a easy as mapping two buttons to shift a double solenoid. Automatic shifting on the other hand is much more difficult to pull off, but it can be done…

2 Likes

Thank you! Yeah, I figured automatic wasn’t going to be a piece of cake, so we’ll see how it goes. Thanks again!

In general you want to be in the low gear during high acceleration and high gear during high speed.

1 Like

In order to program the automatic shifting you need to know what the end user wants or needs. It not really the programmers job to define this. (If the programmers are doing it they are stepping outside their function as coders. Multitasking is not necessarily a bad thing.) So your captain needs to do his job and define the goals of automatic shifting.

Due to the way DC motors work (Hi Torque at low RPMs) you really don’t gain that much in acceleration with automatic shifting. One benefit would to be sure you are in low gear when being defended or defending. Unexpected shifting can be distracting to the drivers so you need to develop the shifting strategy by working closely with them.

2 Likes

The replies already are sufficient, but if you want a full implementation of how we use automatic and manual shifting here is our last year’s code:

Shifting is all done in the DriveTrain subsystem. You’ll notice that all you need to get the pneumatics going is to instantiate your DoubleSolenoid object. That will start the compressor running in a closed-loop way (stop running when full, start running when the psi is below 100).

Then the shifting into gear is just a matter of understanding which gear is the forward solenoid and which is reverse.

1 Like

So true. So few folks in the world who get this…

If they’re looking for ideas, here’s a good one for FRC: Max torque to the ground at all times.

Efficiency of motor operation could be another option.

Assuming you want max torque: You’ll need to be measuring (directly or indirectly) speeds, since motor torque is proportional to applied voltage and speed. Here’s a theoretical spreadsheet doing the calculation of what that “crossover” point is where you should perform the shift. The punchline is, depending on your motors, gear ratios, etc… you can pick the wheel output speed at which it makes sense to change gears.

Key context to remember: This is theory. Real world signals have noise. Intuitive systems account not just for current system state, but also operator intent for future state. Pneumatic systems can only shift so many times before they run out of air. Gear “hunting” is a very real thing, where your system oscillates between the two gears and doesn’t stabilize in one of them.

Some level of hysteresis or debounceing is usually required to prevent rapid shifting near your shift-point RPM. A more detailed analysis could re-work that initial requirement of “max torque at all times” to be a bit more nuanced.

1 Like

Sorry. But I want to correct this a bit. What you are talking about are single acting vs double acting CYLINDERS. Single and double solenoids are different:

A single solenoid has one electrical input. When the input is off it outputs from the A port, when it is on it outputs from the B port. When the robot is disabled it will return to the A port.

A double solenoid has two electrical inputs. When only input A is powered it will switch to the A port. When only input B is powered it will switch to the B port. When both or neither are powered it will stay in it’s last position.

You can use a double or single solenoids with double or single cylinders. It’s just that single solenoids use half the channels at the expense of having a home position.

2 Likes

Yes. You beat me to this, but this is correct. @Varun_Rajesh @runtime_terror this is the difference between a single and double solenoid.

1 Like

Thank you for the correction!

Good thing. we have run single solenoids our shifters with a pancake double acting cylinder. :slight_smile:

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.