View Single Post
  #4   Spotlight this post!  
Unread 14-01-2014, 12:31
omalleyj omalleyj is offline
Registered User
AKA: Jim O'Malley
FRC #1279 (Cold Fusion)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: New Jersey
Posts: 132
omalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to behold
Re: Iterative Robot - Need Help!!!

Code:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.Victor;

public class RobotTemplate extends IterativeRobot {
    
    int joystickPort = 1;
    
    int leftMotorChannel = 2;
    int rightMotorChannel = 1;
    
    int pressureSwitchChannel = 1;
    //The GPIO channel that the pressure switch is attached to.
    int compressorRelayChannel = 1;
    //The relay channel that the compressor relay is attached to.
    
    int relayModuleNumber = 1;
    int relayChannelNumber = 2;
    
    int victorOneChannel = 3;
    int victorTwoChannel = 4;
Its not required, but its good practice to make 'variables' that you don't intend to vary as final. That way they can't be accidentally changed later. e.g.
final int victorOneChannel = 3;

Code:
    
    RobotDrive theRobot = new RobotDrive(leftMotorChannel, rightMotorChannel);
    Joystick driveStick = new Joystick(joystickPort);
    Compressor mainCompressor = new Compressor(pressureSwitchChannel, compressorRelayChannel);
    Relay spike = new Relay(relayModuleNumber, relayChannelNumber);
    Victor wheelOne = new Victor(victorOneChannel);
    Victor wheelTwo = new Victor(victorTwoChannel);
    
    //if relay doesn't work - use this:
    Solenoid pistonExtract = new Solenoid (1);
    Solenoid pistonRetract = new Solenoid (2);
    
    public void robotInit() {
        mainCompressor.start();
    }
You might want to put the initial state of your solenoids, relays, shooter motors, etc. in Init as well.

Code:
    public void autonomousPeriodic() {
        // will fill later
    }

    public void teleopPeriodic() {
        
        //variables expected to update periodically
        double moveValue = driveStick.getAxis(Joystick.AxisType.kY);
        double rotateValue = driveStick.getAxis(Joystick.AxisType.kX);
        
        theRobot.arcadeDrive(moveValue, -rotateValue); //robot driving
        
        double speed = 1.0; //adjustment back of joystick

        if (driveStick.getTrigger()) { //shooter wheels
            wheelOne.set(speed);
            wheelTwo.set(speed);
        }else{
            wheelOne.set(0.0);
            wheelTwo.set(0.0);
        }
Depending on how long your wheels take to get up to speed, and how much driving you do with them on, you may want to toggle the shooter wheel state rather than require the driver to hold it constantly while setting up a shot. (more a customer satisfaction issue than code issue )
Code:
        //one variation to work with piston
        if (driveStick.getRawButton(3)) { //top-middle button
            spike.setDirection(Relay.Direction.kForward);
        } else if (driveStick.getRawButton(4)) {
            spike.setDirection(Relay.Direction.kReverse);
        }else{
            spike.set(Relay.Value.kOff);
        }
Same here.
Code:
        //which one to choose?
        
        //second variation to work with piston
        if (driveStick.getRawButton(5)) {
            pistonExtract.set(true);
            pistonRetract.set(false);
        }else if (driveStick.getRawButton(6)) {
            pistonRetract.set(false);
            pistonExtract.set(true);
        }else{
            pistonExtract.set(false);
            pistonExtract.set(false);
        }
is the duplicate Extract a typo? I think the intent was setting Retract false in one of them.
Code:
        
    }
    
    public void testPeriodic() {
        
    }
    
}
Consider using a separate operator joystick, so the driver won't have to worry about which buttons he's pressing while trying to evade defenders.
Reply With Quote