Thread: my code
View Single Post
  #7   Spotlight this post!  
Unread 27-02-2011, 16:57
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
Re: my code

well the arm is two window motors running in snyc on port 3 because im using a split pwm cable. I dont really know how to program it. I have not tested the autonomus because me team doesnt realize that a programmer should get some time with the robot, and could you give me any help on how to run my arm, on a joystick, im using a game controller with two joysticks, the left is for arcade drive and the right i want to be bor the arm. and i do have my arm declared as a jaguar in a spot too.

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,3);
   //drives the arm in autonomy.
   Joystick leftStick = new Joystick(1);
   // this is our game controller: can be anything that has a joystick.
   Joystick rightStick = new Joystick(2);
   // kellers joystick for lights.
   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() < 3) {
           //while the timer is less than 3 sec. the arm will turn.
           Arm.drive(1,0);
           //arm moves towards peg from starting configuration
           //at 100% speed, zero % turn because it cant turn!
           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 robot 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.
               }
               {
               timer.reset();
               // the timer resets itself.
               timer.start();
               //the timer restarts itself again.
               while(timer.get()<6)
                   //while the timer is less than 6 seconds the 
                   //robot will go in reverse
                     drive.drive(-.15,0);
                     //drives backwards at 15% speed, zero turn so that
                     //we can get closer to our feeder station.
                     timer.stop();
                //Stops the robot from moving after the 6 seconds are up.
               }
               drive.drive(0,0);
   }
  }
  comp.stop();
  // compressor stops not sure if we need this.
 }
}
    

    /**
     * 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.
            Arm.tankDrive(leftStick, 0, leftStick, 4);
                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);
                    //the minibot deployment is launched make sure you dont let go!
                    Fluffy.feed();
                    // feed safety timer.
                    }
                else
                {
                     Fluffy.feed();
                     //feed safety timer.
                     deployM.set(DoubleSolenoid.Value.kReverse);
                     //minibot deployment is retracted make sure minibot is climbing first!
                     Fluffy.feed();
                     //feed safety timer.
                
        
       }
      }
     Timer.delay(.005);
     // call to check for a button being pressed every 5 milliseconds!
     }
    comp.stop();
    // compressor stops.
   }
  }
 }
}
__________________
"Sometimes the questions are

complicated but the answers are simple."

- Dr. Seuss

Last edited by Garten Haeska : 27-02-2011 at 20:28. Reason: put in my new code
Reply With Quote