Skip to content

StuyPulse/NewbieBot

Repository files navigation

NewbieBot

In this lab, you'll be learning about common robot hardware, subsystems, and how to write robot code!

Robot Hardware


Motors

Motors are one of the most common components on the robot. They turn voltage into a rotation on an output shaft.

NEO

NEO Motor

We use NEOs everywhere on our robot, so its good to be familiar with how to use them in code.

Motor Controllers

Motor controllers are how robot code interfaces with motors. They're the middleman between you and the motor, translating your instructions into voltages for the motors.

CANSparkMax

CANSparkMax

CANSparkMax is the class/type in java used to control NEO motors.

Solenoids

Solenoids are electronic components that control the air pressure in a piston, causing it to extend or retract.

There are two types of solenoids: normal solenoids and double solenoids. Double solenoids can force the piston to be extended, retracted, or do nothing. Normal solenoids can only force the solenoid to be extended or retracted.

piston

Subsystems

Subsystems represent and control mechanisms on the robot like the drivetrain, intake, and shooter. Subsystems are some of the most important parts of our robot code.

In code, a subsystem is a class that has fields for hardware that is physically on the mechanism, including motors, solenoids (pistons), and encoders. The subsystem's methods represent the behaviors that we want the real mechanism to have.

In this lab you'll be coding your own subsystems!

Intake


First, we're going to be coding an intake, which brings balls into the robot. The intake is has an arm that hangs in front of the robot with spinning wheels to force balls inwards, and this arm can retract to perpendicular.

The intake has one NEO to drive the wheels on the arm and a double solenoid that controls it extending or retracting.

Intake.java Template

Here is your intake file.

Challenge: fill in the empty methods in Intake.java with the functionality that the comments talk about using hardware class tables below.

public class Intake extends SubsystemBase {

    CANSparkMax motor;
    DoubleSolenoid piston;
    
    // initialize your motor and piston in here!
    public Intake() {}
    
    // puts the intake down by extending the piston
    public void extend() {}
    // brings the intake up by retracting the piston
    public void retract() {}
    // runs the motor at full speed to spin wheels that bring balls in the robot
    public void acquire() {}
    // runs the motor backwards spin wheels that spit balls out of the robot
    public void deacquire() {}
    // stop the drive motor so that balls are not brought in or out
    public void stop() {}
    
}

Shooter and Feedforward


The shooter is another important mechanism on the robot, and controlling it requires some new algorithms compared to our intake code. The shooter has a flywheel that speeds balls up and ejects them out of the robot. It also has a feeder wheel that pushes balls up towards the flywheel and a solenoid that extends to change the shooting angle. The last piece of hardware it has is a solenoid (piston) that changes the angle of the shooter.

The shooter has 3 NEOs and a normal solenoid (not DoubleSolenoid, just Solenoid). One of these motors spins the feeder wheel, which pushes balls up towards the shooter flywheel, while the other two motors work together to spin the shooter flywheel. Last, the solenoid controls extending the hood, which changes the shooting angle.

With the tools we have right now, keeping a flywheel at a certain RPM isn't possible. The first tool we'll need is Feedforward.

Controlling the RPM with Feedforward

We're going to be using the Feedforward algorithm which calculates the voltage that the motor should run at given the target RPM. In the future we're going to use another class that calculates this for us, but today we're going to implement the algorithm on our own.

The feedforward equation

V: output voltage to feed to the motor
kS, kV, kA: constant values (we will give you these)
sgn: the sign function (-1 if negative, 1 if positive)
d with one dot: the target rpm of the motor
d with two dots: the target acceleration of the motor (we'll ignore this)

Encoders

In the intake, we didn't need to know the speed that the motor was running at - we just wanted to run it at full speed. But in the shooter, we might want to know if the RPM is what we're expecting it to be to be. We can do this with Encoders. As the motor turns, the encoder reads pulses and can calculate the number of rotations the motor has gone.

Shooter.java

Here is your shooter file.

Challenge: fill in the empty methods in Shooter.java with the functionality that the comments talk about using hardware class tables below.

public class Shooter extends SubsystemBase {

    double shooterKs = 0.17118;
    double shooterKv = 0.0020763;
    double shooterKa = 0.00011861;

    double feederKs = 0.16971;
    double feederKv = 0.0021435;
    double feederKa = 0.00012423;

    CANSparkMax shooterA;
    CANSparkMax shooterB;
    CANSparkMax feeder;

    RelativeEncoder shooterEncoder;
    RelativeEncoder feederEncoder;
    
    double targetShooterRPM;
    double targetFeederRPM;

    Solenoid hoodPiston;

    public Shooter() {}

    // sets the RPM that the shooter is trying to reach
    public void setShooterRPM(double rpm) {}
    
    // sets the RPM that the feeder is trying to reach
    public void setFeederRPM(double rpm) {}

    // extend the hood solenoid to increase the shooter angle
    public void extendHood() {}

    // retract the hood solenoid to decrease the shooter angle
    public void retractHood() {}

    // a special method that's run by the robot every 0.02 seconds
    // set the voltage of the motors in here using the feedforward equation!
    public void periodic() {}
}

Ports

Mechanism Hardware Port
Intake Motor (CANSparkMax) 40
Intake DoubleSolenoid extend port 2
Intake DoubleSolenoid retract port 3
Shooter Motor A 20
Shooter Motor B 21
Shooter Feeder motor 22
Shooter Hood solenoid (piston) 5

Hardware Classes

CANSparkMax

Method Description Returns
CANSparkMax(int port, type) Constructor, takes in a port and a type. Type is normally MotorType.kBrushless. void
get() Returns the set speed of the motor from -1.0 to 1.0. double
set(double speed) Sets the speed of the motor from -1.0 to 1.0. void
setInverted(boolean inverted) Inverts the direction of the motor spinning, takes in a true/false inverted value. void
setVoltage(volts) Sets the voltage of the motor directly, usually between -12.0 and 12.0 volts. void
stopMotor() Stops the motor. void
getEncoder() Gets the encoder attached to the motor RelativeEncoder

DoubleSolenoid

Method Description Returns
DoubleSolenoid(type, int extendPort, int retractPort) Constructor, takes in a type which is normally PneumaticsModuleType.CTREPCM and two ports. void
get() Returns which state the solenoid is in (extended or retracted). If it is extended, the return value will be Value.kForward, Value.kReverse, or Value.kOff. Value
set(value) Sets the solenoid to be either Value.kForward, Value.kReverse, or Value.kOff void

Solenoid

Method Description Returns
Solenoid(type, int port) Constructor, takes in a type which is normally PneumaticsModuleType.CTREPCM and a port. void
get() Returns a boolean if the solenoid is extended or not. boolean
set(boolean on) Sets the solenoid to extended if true or off if false. void

RelativeEncoder

Method Description Returns
getVelocity() Returns the motor's velcotity in RPM. double

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages