Download presentation
Presentation is loading. Please wait.
1
Fe Maidens Programming 2017-2018
Mechanism Coding Fe Maidens Programming
2
Agenda Lift Review Shooters and Hitters Grippers
Writing Code for a spring-style hitter Grippers Writing code for a roller arm
3
Lift Review Last time, you wrote code for lifts. There are 3 major types- do you know what they are?
4
Lift Review Last time, you wrote code for lifts. There are 3 major types- do you know what they are? Power Up/Down: Single stage lifts - simple but big. Cascade: Multi stage lift, all stages move at once. Smaller, but often only has an up and a down. Continuous: Multi stage lift, stages move consecutively. Sort of a cross between power and cascade, but slower than either. Telescopic and scissor lifts are also sometimes used, but rarely due to their complexity and relative structural weakness.
5
Lift Review Look over your code from last Monday on lifts- any lingering questions? This is an example of a power up/down lift.
6
package org.usfirst.frc.team2265.robot.subsystems;
import edu.wpi.first.wpilibj.command.Subsystem; import edu.wpi.first.wpilibj.CANTalon; import edu.wpi.first.wpilibj.Joystick; public class Forklift extends Subsystem { //creates CANTalons for the lift CANTalon topMotor = new CANTalon(1); CANTalon bottomMotor = new CANTalon(2); //defines the speeds that the motors turn at as variables private final static double UP = 0.5; private final static double DOWN = -0.5; private final static double STOP = 0.0; private final int axis = 1; //creates the Joystick that controls the lift’s movement public atkJoy = new Joystick(1); /*the methods that move the lift up or down This method moves the lift up at a constant speed*/ public static void up() { topMotor.set(UP); bottomMotor.set(UP); } //makes the lift go down at a constant speed public static void down() { topMotor.set(DOWN); bottomMotor.set(DOWN); //stops the lift from moving public static void stop() { topMotor.set(STOP); bottomMotor.set(STOP); // tell forklift to move up, down or stop moving based on joystick position //if joystick is in the up position, move lift up //if joystick is in its default position, stop // if joystick is in the down position, move down public void helper() { private double Val = atkJoy.getRawAxis(axis) if (Val > 0) { up(); else if (Val < 0){ down(); else { stop(); public void initDefaultCommand(){ setDefaultCommand(new MoveForkLift());
7
package org.usfirst.frc.team2265.robot.commands;
import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2265.robot.Robot; Import org.usfirst.frc.team2265.robot.subsystems.ForkLift; public class MoveForkLift extends Command { public MoveForkLift(Robot.ForkLift) { // Use requires() here to declare subsystem dependencies requires(Robot.ForkLift); } // Called just before this Command runs the first time protected void initialize() { // Called repeatedly when this Command is scheduled to run protected void execute(){ Robot.ForkLift.helper(); // Make this return true when this Command no longer needs to run execute() protected boolean isFinished() { return false; // Called once after isFinished returns true protected void end() { // Called when another command which requires one or more of the same // subsystems is scheduled to run protected void interrupted() {
8
Shooters/Hitters These mechanisms are used to eject game pieces from the robot. Types of Shooters: Turret: Wheel(s), and often an aiming chute Roller: Sets of parallel powered rollers Types of Hitter: Catapult: Uses a turning motion like a throw to launch the piece Piston: “punches” the game piece (best for light objects) Spring: Uses spring force pulled back and released via a (can also use surgical tubing)
9
Code the Piston Hitter A piston releases, and then after a moment the gate- latch piston also releases. Write a subsystem to control both, and a command that will allow for us to test for the optimal time delay later on. What are the advantages and disadvantages of using this method?
10
package org.usfirst.frc.team2265.robot.subsystems;
import edu.wpi.first.wpilibj.command.Subsystem; import edu.wpi.first.wpilibj.DoubleSolenoid; import edu.wpi.first.wpilibj.DoubleSolenoid.Value; import edu.wpi.first.wpilibj.Timer; public class PistonHitter extends Subsystem { // Put methods for controlling this subs ystem // here. Call these from Commands. // Instances of the double solenoids and the timer DoubleSolenoid bigPiston; DoubleSolenoid gatelatchPiston; static Timer t = new Timer(); Public pistonHitter(int BigOutport, int BigInport, int SmallOutport, int SmallInport) { bigPiston = new DoubleSolenoid(BigOutport,BigInport); gatelatchPiston = new DoubleSolenoid(SmallOutport,SmallInport); } public void firePiston { bigPiston.set(DoubleSolenoid.Value.kForward); t.delay(3.0); gatelatchPiston.set (DoubleSolenoid.Value.kReverse);
11
package org.usfirst.frc.team2265.robot.commands;
import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2265.robot.Robot; Import org.usfirst.frc.team2265.robot.subsystems.PistonHitter; public class shootPiston extends Command { public shootPiston(Robot.PistonHitter) { // Use requires() here to declare subsystem dependencies requires(Robot.PistonHitter); } // Called just before this Command runs the first time protected void initialize() { // Called repeatedly when this Command is scheduled to run protected void execute() { Robot.ph.firePiston(); // Make this return true when this Command no longer needs to run execute() protected boolean isFinished() { return false; // Called once after isFinished returns true protected void end() { // Called when another command which requires one or more of the same // subsystems is scheduled to run protected void interrupted() {
12
Grippers Most grippers are rollers. Some move on manipulatable arms, to go down over a game piece.
13
Coding a Roller Arm A motor manipulates the arm, moving it up and down. Then, a second motor spins a roller to bring in the game piece. After, the arm moves back up to complete the movement. Write a subsystem to control the motors and a command that will retrieve a game piece from the field.
14
package org.usfirst.frc.team2265.robot.subsystems;
import edu.wpi.first.wpilibj.command.Subsystem; import edu.wpi.first.wpilibj.CANTalon; import edu.wpi.first.wpilibj.Timer; public class RollerArm extends Subsystem { public CANTalon armMover; public CANTalon spinMotor; public static Timer t = new Timer(); public RollerArm (int armMoverPort, int spinMotorPort) { armMover = new CANTalon(1); spinMotor = new CANTalon(2); } /*Put methods for controlling this subsystem here. Call these from Commands. */ public void initDefaultCommand() { // Set the default command for a subsystem here. //setDefaultCommand(new MySpecialCommand()); public void up(){ armMover.set(-1.0); t.delay(0.1); armMover.set(0); public void down(){ armMover.set(1.0); // speed has a sign public void spin(double speed){ //think: what do you need to make this spin different speeds? spinMotor.set(speed);
15
Gear Chute:
16
package org. usfirst. frc. team2265. robot
package org.usfirst.frc.team2265.robot.subsystems; //creates imports import org.usfirst.frc.team2265.robot.RobotMap; import edu.wpi.first.wpilibj.command.Subsystem; import edu.wpi.first.wpilibj.DoubleSolenoid.Value; import edu.wpi.first.wpilibj.DoubleSolenoid; /** * */ // makes gear chute subsystem// public class GearChute extends Subsystem { // intializes doubleSolenoid for the gearChute public static DoubleSolenoid gearPistons = new DoubleSolenoid(RobotMap.gearPort1, RobotMap.gearPort2); public static DoubleSolenoid basePistons = new DoubleSolenoid(RobotMap.basePort1, RobotMap.basePort2); // Extends the piston public static void extend() { gearPistons.set(DoubleSolenoid.Value.kForward); basePistons.set(DoubleSolenoid.Value.kForward); } // Retracts the piston public static void retract() { gearPistons.set(DoubleSolenoid.Value.kReverse); basePistons.set(DoubleSolenoid.Value.kReverse); } // Put methods for controlling this subsystem // here. Call these from Commands. public void initDefaultCommand() { // Set the default command for a subsystem here. // setDefaultCommand(new MySpecialCommand()); } }
17
package org. usfirst. frc. team2265. robot. commands; import org
package org.usfirst.frc.team2265.robot.commands; import org.usfirst.frc.team2265.robot.subsystems.GearChute; import edu.wpi.first.wpilibj.command.Command; /** * */ public class ShiftChute extends Command { boolean down; public ShiftChute(boolean u) { // Use requires() here to declare subsystem dependencies // eg. requires(chassis); down = u; } // Called just before this Command runs the first time protected void initialize() { } // Called repeatedly when this Command is scheduled to run protected void execute() { // retract if piston off/extended // if (GearChute.gearPiston.get().equals(Value.kForward) || // GearChute.gearPiston.get().equals(Value.kOff)) { if (down) { GearChute.extend(); return; } // extend if piston is retracted // if (GearChute.gearPiston.get().equals(Value.kReverse)) { if (!down) { GearChute.retract(); return; } } // Make this return true when this Command no longer needs to run execute() protected boolean isFinished() { // return true means the clause is now true, so the command will stop // executing return true; } // Called once after isFinished returns true protected void end() { } // Called when another command which requires one or more of the same // subsystems is scheduled to run protected void interrupted() { } }
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.