View Single Post
  #1   Spotlight this post!  
Unread 19-11-2015, 19:06
Bernstern Bernstern is offline
Registered User
FRC #2141 (Spartonics)
Team Role: Programmer
 
Join Date: Nov 2015
Rookie Year: 2015
Location: Clayton
Posts: 30
Bernstern is an unknown quantity at this point
Newbie How to control a spike

In our code for a tshirt cannon (Im a freshman and get all the bad jobs) I was tasked with making the relay (Spike) shoot the actual cannon. I have no idea. I tinkered and set this up like so:

Subsystem
package org.usfirst.frc.team2141.robot.subsystems;

import org.usfirst.frc.team2141.robot.RobotMap;
import org.usfirst.frc.team2141.robot.commands.CannonCont rol;

import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.Relay.Direction;
import edu.wpi.first.wpilibj.Relay.Value;
import edu.wpi.first.wpilibj.command.Subsystem;

/**
*
*/
public class Cannon extends Subsystem {

Relay cannonFire;


public Cannon() {

cannonFire = new Relay(RobotMap.CANNON_CHANNEL);

}


public void cannonFire() {
cannonFire.set(Value.kOn);

}
// 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());
setDefaultCommand(new CannonControl());
}
}


Command
package org.usfirst.frc.team2141.robot.commands;

import org.usfirst.frc.team2141.robot.OI;
import org.usfirst.frc.team2141.robot.Robot;

import edu.wpi.first.wpilibj.command.Command;

/**
*
*/
public class CannonControl extends Command {

public CannonControl() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
requires(Robot.cannon);
}

// Called just before this Command runs the first time
protected void initialize() {
}

// Called repeatedly when this Command is scheduled to run
protected void execute() {
if (Robot.oi.getButtons()[5].get()) {
Robot.cannon.cannonFire();
}}

// 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() {
}
}


What am I doing wrong?
Reply With Quote