Go to Post So once and a while no matter how addicted you may be, try to think outside the 48'x24' box of FIRST. - Tytus Gerrish [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 06-01-2014, 21:31
hasin5 hasin5 is offline
Registered User
None #4777
 
Join Date: Jan 2013
Location: Canada
Posts: 20
hasin5 is an unknown quantity at this point
Iterative Robot - Need Help!!!

Hi,

This code is iterative robot template based.

If you can spot something that is wrong in the code below, please let me know so I can fix the error. Suggestions would also be nice. Will this code work for the following functions:

1. Mobility
2. Moving wheels through motors
3. Pneumatics -> Piston

Also, for function #3, I know I have two instances of the code. One is the relay version and the other is the solenoid version. Which one do I use?

Also, I'd appreciate it if anyone can look over the parameters to see if they are correct in the constructors.

Here is the code:
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;
    
    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();
    }

    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);
        }
        
        //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);
        }
        
        //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);
        }
        
    }
    
    public void testPeriodic() {
        
    }
    
}
Reply With Quote
 


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:45.

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