![]() |
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? |
Re: Newbie How to control a spike
What is the problem exactly? When you run the command does the LED on the Spike change? Does the code deploy properly? More information would be helpful for solving the problem. Also put your code in code tags to make it more readable:
Code:
Example |
Re: Newbie How to control a spike
Sorry didnt know how to do tags
No the spike stays in neutral (orange) |
Re: Newbie How to control a spike
Do not name your spike object and the cannonFire() method the same thing. I'd change the spike name to cannonSpike if I were you but do whatever suits you best. Also, you will need to call that method (cannonFire) from something. But you will need to create a joystick instance to have a button to press. In your Robot.java file, create an instance of a joystick. To do this, add this line after the "public class Robot extends ___" line:
Code:
Joystick stick;Code:
stick = new Joystick(0); // new joystick on port 0. Change this if you wishCode:
if(stick.getRawButton(5) == true){ |
| All times are GMT -5. The time now is 00:43. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi