Go to Post When someone asks me to define Gracious Professionalism, I'm just going to send them to AndyMark. - rsisk [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 05-06-2012, 17:23
2185Bilal's Avatar
2185Bilal 2185Bilal is offline
Driver, Ld. Programmer, Electrical
AKA: Bilal Majeed
FRC #2185 (Ramazoidz)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2011
Location: Toronto, Canada
Posts: 110
2185Bilal will become famous soon enough
Post Code and Deployment Help

Hello with the help of Youtube and CD I was finally able to make my first java program for the robot.

Here it is:

The main class:
Code:
// ***************** THIS CODE WAS WRITTEN BY BILAL MAJEED ***************** //   

package bilal.robotics.code;

// ***************** TO BE USED COMPONENTS ***************** //
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Timer;

public class Team2185Main extends IterativeRobot {
    
    Jaguar leftMotor1 = new Jaguar(1);  // define the 1st left motor 
    Jaguar leftMotor2 = new Jaguar(2);  // define the 2nd left motor
    
    Jaguar rightMotor1 = new Jaguar(3); // define the 1st right motor 
    Jaguar rightMotor2 = new Jaguar(4); // define the 2nd right motor 
    
        
    RobotDrive drive = new RobotDrive (leftMotor1, leftMotor2, rightMotor1, rightMotor2);   // define the robot drive system
    
    Joystick controller = new Joystick(1);  // define the joystick as controller 
    final int buttonA = 1;                  // define button 1 as buttonA
    
    Shooter shooter;
    
    
// ***************** INITIALIZATION CODE ***************** //    
    public void robotInit() 
    {
        shooter = new Shooter(); // call the shooter class
    }
    
        
// ***************** AUTONOMOUS METHODS ***************** //  
    public void autonomousInit() 
    {
        for(int i=0; i<4; i++){
            drive.drive(0.5,0.0);    // drive forward at 1/2 speed
            Timer.delay(2.0);        // wait 2 sec
            drive.drive(0.0, 0.75);  // drive with 0% speed and 75% turn
            Timer.delay(0.75);       // wait for the 90 degree turn to complete
        }
        drive.drive(0.0,0.0); 
        
        
            
                  
    }

    public void autonomousPeriodic()
    {
        
    }
    
    public void autonomousContinuous()
    {
        
    }
    
        
// ***************** TELOP METHODS ***************** //    
    public void teleopInit()
    {
       while(isOperatorControl() && isEnabled())
        {
            drive.tankDrive(controller, 2, controller, 5);  // drive the robot according to joystick
            
            if (controller.getRawButton(buttonA))   // if button 1 is pressed on the controller 
            {                                       // then make the robot drive forward
                leftMotor1.set(1);                          
                leftMotor2.set(1);
                rightMotor1.set(1);
                rightMotor2.set(1);
            }
        }
    }
    
    public void telopPeriodic()
    {
        shooter.shoot();    // every 20mS call the shooting class 
    }
    
    public void telopContinuous()
    {
        
    }
    
        
// ***************** DISABLED METHODS ***************** //   
    public void disabledInit() 
    {
        
    }
    
    public void disabledPeriodic()
    {
        
    }
    
    public void disabledContinuous()
    {
        
    }
       
}
And the shooter Class:
Code:
package bilal.robotics.code;

import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Joystick.ButtonType;


public class Shooter 
{
    Jaguar shooter = new Jaguar(5);
    
    Joystick controller = new Joystick(2);
    
    final int buttonA = 1;
    
       
    
    public Shooter()
    {
        
    }
    
    public void shoot(){
        if(controller.getRawButton(buttonA)) {
            shooter.set(controller.getRawAxis(2));
        }
    }
    
}
So please tell me anything i did wrong, or a better way to do it.
Thanks

Also how would i deploy this code on to the robot.


Thanks
__________________
RAMAZOIDZ

2009 Toronto West Regional - Regional Winners
2009 Waterloo Regional - Regional Winners
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 08:48.

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