View Single Post
  #3   Spotlight this post!  
Unread 22-01-2014, 19:49
StylesOfKimchi StylesOfKimchi is offline
Registered User
FRC #2785
 
Join Date: Jan 2014
Location: Kent, CT
Posts: 4
StylesOfKimchi is an unknown quantity at this point
Re: New Robot programmers. Trouble deploying

This isn't the exact code from the robot, but majority of it is the same.
This is from my computer, so its the closest thing I have to it.
Only differences should be some variable names

AerialAssist IterativeRobot Class:
Line 84 is commented and put in red font

Code:
public class PreWinter extends IterativeRobot {
    
    private Command autonomousCommand;
    private Joystick theJoystick = new JoystickOne( RobotMap.PORT, RobotMap.NUM_AXES, RobotMap.NUM_BUTTONS );
    private MecanumDrive chassis;
    /*
    * This sets global variables that can be manipulated in order to make use
    * of the joystick. The three "~ValueError" variables calibrate the initial
    * settings of the joystick.
    */
    private double xValueError;
    private double yValueError;
    private double twistValueError;
    private double xValue;
    private double yValue;
    private double twistValue;
    /*
    * Timer Variables
    */
    private Timer whatTime;
    private double cToField;
    private double autonomousStart;
    private double teleOpStart;
    private double lastTimeWritten;
    /*
    * Misc. Variables
    */
    private DataLogger collectData;
    private final String FILE_NAME = new String("PrewinterRobotData");
    private DriverStation driverStation;

    /**
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
     */
    public void robotInit() {
        /*
        * Creates initial objects
        */
        whatTime = new Timer();
        whatTime.start();
        lastTimeWritten = whatTime.get();
        //line 84
        collectData = new DataLogger(FILE_NAME);
        driverStation = DriverStation.getInstance();
        /*
        * Finds the beginning values of X and Y in order to calculate any error
        * values the joystick may have.
        */
        xValueError = theJoystick.getAxis(Joystick.AxisType.kX);
        yValueError = theJoystick.getAxis(Joystick.AxisType.kY);
        twistValueError = theJoystick.getAxis(Joystick.AxisType.kTwist);
        // instantiate the command used for the autonomous period
        autonomousCommand = new AutonomousCommand();
        // Initialize all subsystems
        chassis = new MecanumDrive();
        chassis.initDefaultCommand();
        CommandBase.init();
    }
    
    /*
    * Runs once after the robot connects to the field
    */
    public void disabledInit() {
        cToField = whatTime.get();
        collectData.nextLine("Joystick X-Error: " + xValueError);
        collectData.nextLine("Joystick Y-Error: " + yValueError);
        collectData.nextLine("Joystick Twist-Error: " + twistValueError);
    }
    
    /*
    * Runs periodically as the robot is connected to the field
    */
    public void disabledPeriodic() {
        collectSomeData();
    }

    /*
    * Runs once at the start of the autonomous period begins
    */
    public void autonomousInit() {
        // schedule the autonomous command (example)
        autonomousCommand.start();
        autonomousStart = whatTime.get();
    }

    /**
    * Runs periodically as the robot is running through autonomous mode
     */
    public void autonomousPeriodic() {
        Scheduler.getInstance().run();
        collectSomeData();
    }

    /*
    * Runs once at the start of the teleop period
    */
    public void teleopInit() {
	// This makes sure that the autonomous stops running when
        // teleop starts running. If you want the autonomous to 
        // continue until interrupted by another command, remove
        // this line or comment it out.
        autonomousCommand.cancel();
        teleOpStart = whatTime.get();
    }

    /**
     * This function is called periodically during operator control
     */
    public void teleopPeriodic() {
        Scheduler.getInstance().run();
       /*
       * Finds the values of the joystick. Calibrates the x, y, and twist values
       * based on the initial configuration
       */
        xValue = theJoystick.getAxis(Joystick.AxisType.kX) - xValueError;
        yValue = theJoystick.getAxis(Joystick.AxisType.kY) - yValueError;
        twistValue = theJoystick.getAxis(Joystick.AxisType.kTwist) - twistValueError;
        /*
        * Moves and twists the robot
        */
        if(Math.abs(xValue) > RobotMap.ERROR_BOUND || Math.abs(yValue) > RobotMap.ERROR_BOUND )
            chassis.getDrivetrain().mecanumDrive_Cartesian( xValue - xValueError, yValue - yValueError, 0, 0 );
        if(Math.abs(twistValue)  > RobotMap.ERROR_BOUND)
            chassis.getDrivetrain().mecanumDrive_Cartesian( 0, 0, twistValue - twistValueError, 0);
        collectSomeData();
    }
    
    /**
     * This function is called periodically during test mode
     */
    public void testPeriodic() {
        LiveWindow.run();
    }
    
    public void collectSomeData() {
        if(whatTime.get() - lastTimeWritten > 100) {
            collectData.nextLine("Battery Voltage: " + driverStation.getBatteryVoltage());
            collectData.nextLine("Joystick X-Value: " + xValue);
            collectData.nextLine("Joystick Y-Value: " + yValue);
            collectData.nextLine("Joystick Twist-Value: " + twistValue);
            lastTimeWritten = whatTime.get();
        }
    }
}
DataLogger Class:
Code:
package edu.wpi.first.wpilibj.templates;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import javax.microedition.io.Connector;

/**
 * Datalogger class. prints data to file
 * @author Justin S. and Jeremy G.
 */
public class DataLogger {

    private PrintStream out = null;
    private boolean enabled = false;

    public DataLogger(String filename) {
        try {
            OutputStream os = Connector.openOutputStream(filename);
            out = new PrintStream(os);
            enabled = true;
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }

    /**
     * Prints a string to file
     * @param s 
     */
    public void sameLine(String s) {
        if (enabled) {
            out.print(s);
            out.flush();
        }
    }

    /**
     * Prints a string to file, appends with a newline char
     * @param s 
     */
    public void nextLine(String s) {
        if (enabled) {
            out.println(s);
            out.flush();
        }
    }
}
Reply With Quote