Go to Post The real question is has anybody ever learned anything actionable from a game hint or red herring. - Joe Ross [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 30-01-2012, 21:50
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
New to FRC programming... How does this look?

I am completely new at FRC programming, and I'm not sure what really is the best way to go about it. Anyone care to give suggestions?
Code:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.*;

public class RobotTemplate extends IterativeRobot {

    public RobotDrive drivetrain;
    public Joystick leftStick;
    public Joystick rightStick;
    public Joystick KTrigger;
    public Gyro gyro; //gyro
    public Watchdog getWatchdog;
    
    

    public void robotInit(){
        drivetrain = new RobotDrive(1, 2, 3, 4);  
        leftStick = new Joystick(1);    
        rightStick = new Joystick(2);
        KTrigger = new Joystick(3);
    }


    public void autonomousPeriodic(){
        getWatchdog.kill();
        int x = 1;
        do{    
            gyro.reset();

            int i=0;
            while(i<4){    
                drivetrain.drive(0.5,0.0); //START GOING STRAIGHT
                Timer.delay(4.0);
                drivetrain.drive(0.0,0.0); //STOP
                Timer.delay(4.0);
                gyro.reset();
                double angle = 0;
                do {
                    drivetrain.drive(0.0, 0.15); //TURN 
                    Timer.delay(0.5);
                    angle += gyro.getAngle(); //
                    gyro.reset();
                    log("Gyro reads "+angle);
                }while(angle<90); //Keep going in increments of .15 until gyro returns more than 90 degrees
                drivetrain.drive(0.0,0.0); //STOP
                Timer.delay(4.0);
                i++;
            }
        }while(x>0);
    } 

    public void teleopPeriodic() {
        getWatchdog().kill();
        while (isOperatorControl() && isEnabled()){
        Timer.delay(0.002);
                while(KTrigger.getTrigger()){
                    drivetrain.drive(0.0,0.0);
                    Timer.delay(1.0);
                }
            double leftYAxis = leftStick.getAxis(Joystick.AxisType.kY);
            double leftXAxis = leftStick.getAxis(Joystick.AxisType.kX);
            double rightYAxis = rightStick.getAxis(Joystick.AxisType.kY);
            double rightXAxis = rightStick.getAxis(Joystick.AxisType.kX);
            double powerValue = ((leftXAxis+rightXAxis)/2); // FIND RIGHT CALCULATION FOR 0-100% (0.0-1.0)
            double turnValue = ((leftYAxis+rightYAxis)/2);//FIND RIGHT CALCULATION FOR 0.0-1.0
            drivetrain.drive(powerValue,turnValue);
        }
    }
    public static String log(String aMessage){
        System.out.println(aMessage);
        return aMessage;
    }
}
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:18.

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