Go to Post Past success does not guarantee future results.... - Koko Ed [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 24-02-2011, 19:49
Garten Haeska's Avatar
Garten Haeska Garten Haeska is offline
Registered User
AKA: Garty
FRC #2861 (Infinity's End)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Lake City, MN
Posts: 219
Garten Haeska has a spectacular aura aboutGarten Haeska has a spectacular aura about
my code

Here is a copy of my code.
Please comment on it! I know i could just do the import "*" thing but i chose not to for future references!
If you have any questions please ask, but otherwise my comments in the code seem pretty straight forward!
Code:
  /*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.                             */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/

package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.SimpleRobot;//imports the robot template.
import edu.wpi.first.wpilibj.camera.AxisCamera;//imports camera.
import edu.wpi.first.wpilibj.Joystick;//imports the controller.
import edu.wpi.first.wpilibj.Timer;//imports the timer.
import edu.wpi.first.wpilibj.RobotDrive;//imports the drive.
import edu.wpi.first.wpilibj.Watchdog;//imports the safety timer.
import edu.wpi.first.wpilibj.Jaguar;//imports the arm jaguar.
import edu.wpi.first.wpilibj.DoubleSolenoid;//imporst the solenoids used on the robot.
import edu.wpi.first.wpilibj.Compressor;//imports compressor.
/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the SimpleRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class RobotTemplate extends SimpleRobot {
   RobotDrive drive = new RobotDrive(1,2); // drives the robot around; no jaguars needed to control unless specified.
   RobotDrive Arm = new RobotDrive(3,0);
   Joystick leftStick = new Joystick(1); // this is our game controller: can be anything that has a joystick.
   Timer timer = new Timer(); // Just a timer.
   Watchdog Fluffy = Watchdog.getInstance(); // safety timer.
   AxisCamera Cam = AxisCamera.getInstance(); // shows image on dashboard.
   Compressor comp = new Compressor(1,1); // compressor is pluged in digital I/O port 1, analog port 1.
   DoubleSolenoid grab = new DoubleSolenoid(1,2); // this is the solenoid that controls our manipulator.
   DoubleSolenoid deployM = new DoubleSolenoid(3,4);//This is the solenoid that controls our deploment.
   Jaguar arm = new Jaguar(3); // speed controller that controlls our arm hence the "arm" for the name.
   
           

    /**
     * This function is called once each time the robot enters autonomous mode.
     */
    public void autonomous() {
       while(isAutonomous()) {
       comp.start();
           {
       timer.start(); // Timer starts
       while(timer.get() < 4) { //while the timer is less than 3 sec. the arm will turn.
           Arm.drive(.75,0);//arm moves towards peg from starting configuration.
           timer.stop(); // stops the timer after 3 seconds.
       }
       Arm.drive(0,0);//Stops the arm so it doesnt kill anyone
           {
           timer.reset();// the timer resets it self.
           timer.start();//the timer starts again.
           while(timer.get()<4) {//while the timer is less than 4 sec. the robot will drive.
               drive.drive(.3,0);  // robot drives forward at 30% speed and 0% turn.
               timer.stop();//stops the arm from moving after the 4 seconds is up
               }
           drive.drive(0,0);//stops the robot so it doesn't kill anyone.
               {
                   grab.set(DoubleSolenoid.Value.kForward);// solenoid for the manipulator extends until let go.
               }
               {drive.drive(-.15,0);//drives backwards at 15% speed, zero turn so that we can get closer to our feeder station
    }
   }
  }
  comp.stop();
 }
}
    

    /**
     * This function is called once each time the robot enters operator control.
     */
    public void operatorControl() 
    {
        comp.start(); // our compressor starts.
        AxisCamera.getInstance();// the axis camera shows in dashboard not sure if we need this .
        Fluffy.setExpiration(5.0); // safety timer is set to call every 5 seconds.
        while  (isOperatorControl  () && isEnabled())// operator control is enabled.
        {
            Fluffy.feed();// feed safety timer.
            drive.arcadeDrive(leftStick);//Drive the robot with the left thumbstick on the game controller or the left joystick if using two.
            Fluffy.feed();// feed safety timer.
                if (leftStick.getRawButton(5))
                {
                    arm.set(.5);// when we press button 5 our arm goes up at 50% speed.
                }
                else if (leftStick.getRawButton(6))
                {
                    arm.set(-.5);//arm goes toward the ground at 50% speed when we press button 6. though it doesnt seem to do it.
                }
                else
                {
                    arm.set(0);// arm doesnt do anything when we dont press a button.
                if(leftStick.getRawButton(7))
                {
                    arm.set(1);// arm goes away from the ground at 100% speed when we press button 7.
                    }
                else if (leftStick.getRawButton(8))
                {
                    arm.set(-1);// arm goes towards the ground at 100% speed when we press button 8.
                }
                else
                {
                        arm.set(0);// arm doesnt do anything
                if(leftStick.getRawButton(2))
                {
                    Fluffy.feed();// feed safety timer.
                    grab.set(DoubleSolenoid.Value.kForward);// solenoid for the manipulator extends until let go.
                    Fluffy.feed();// feed safety timer.
                    }
                else
                {
                     Fluffy.feed();// feed safety timer.
                     grab.set(DoubleSolenoid.Value.kReverse);// solenoid for the manipulator retracts.
                     Fluffy.feed();// feed safety timer.
                if (leftStick.getRawButton(10))
                {
                    Fluffy.feed();// feed safety timer.
                    deployM.set(DoubleSolenoid.Value.kForward);
                    Fluffy.feed();// feed safety timer.
                    }
                else
                {
                     Fluffy.feed();//feed safety timer.
                     deployM.set(DoubleSolenoid.Value.kReverse);
                     Fluffy.feed();//feed safety timer.
                }
      }
     Timer.delay(.005);// call to check for a button being pressed every 5 milliseconds!
     }
    comp.stop();// compressor stops.
   }
  }
 }
}

Last edited by Garten Haeska : 24-02-2011 at 21:30. Reason: Updated the code
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 10:44.

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