Go to Post Part of the magic of FIRST is the interaction between different teams- and that becomes clear as day as the clock starts ticking. - mhayon [more]
Home
Go Back   Chief Delphi > FIRST > General Forum
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #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
  #2   Spotlight this post!  
Unread 19-11-2015, 19:19
Jalerre's Avatar
Jalerre Jalerre is offline
Registered User
FRC #4965 (FIRE)
Team Role: Alumni
 
Join Date: Apr 2014
Rookie Year: 2013
Location: Anderson, SC
Posts: 147
Jalerre is on a distinguished road
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
__________________
Vex
2013: 415 - Fabrication, Programming, Electrical
2014: 415D - Captain, Programming Lead
FTC
2014: 7354 - Programming Lead
FRC
2013: 415 - Safety Animation, Fabrication
2014-2015: 4965 - Programming & Electrical
2016: 4965 - Captain, Programming Lead, Electrical
Reply With Quote
  #3   Spotlight this post!  
Unread 20-11-2015, 14:04
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
Re: Newbie How to control a spike

Sorry didnt know how to do tags

No the spike stays in neutral (orange)
Reply With Quote
  #4   Spotlight this post!  
Unread 20-11-2015, 18:29
EmileH's Avatar
EmileH EmileH is offline
starting to feel the burn
AKA: Emile Hamwey
FRC #1058 (The PVC Pirates) & SLFF (NE Way You Want It)
Team Role: Programmer
 
Join Date: Dec 2014
Rookie Year: 2011
Location: New England
Posts: 541
EmileH has a brilliant futureEmileH has a brilliant futureEmileH has a brilliant futureEmileH has a brilliant futureEmileH has a brilliant futureEmileH has a brilliant futureEmileH has a brilliant futureEmileH has a brilliant futureEmileH has a brilliant futureEmileH has a brilliant futureEmileH has a brilliant future
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;
Add this line after the "public Robot()" (constructor) line:
Code:
stick = new Joystick(0); // new joystick on port 0. Change this if you wish
Then, when you press button 5 on the joystick you will want the code to run the method inside the Cannon subsystem. Add the following lines under the operatorControl method:

Code:
  if(stick.getRawButton(5) == true){
            	Cannon.cannonFire();
            }
This should get you all set from there in terms of programming. You can remove the Command file if you so desire.
__________________
2016-present: High School Student, FRC 1058 PVC Pirates

Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:32.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi