-J.-
30-01-2012, 21:35
Hi, I'm trying to start using Java for my team. I haven't had success yet, so we're probably using LabVIEW again. Nevertheless, I'd like to know what went wrong with this 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. */
/*----------------------------------------------------------------------------*/
/*HOW (my name) CODES FOR ALL YALL
* I like using small variables. You will see lots of chars.
* I write my variables likeThis. That's called Pascal style, I think.
*/
package edu.wpi.first.wpilibj.templates;
//first stuff
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Timer;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the IterativeRobot
* 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 JRobot extends IterativeRobot {
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
//button mappings
//powers
//random variables
final boolean useSlowmo = false;
//actual objects
RobotDrive driveObject;
Joystick mainPad;
Jaguar motor1,motor2,motor3,motor4;
public void robotInit() {
mainPad = new Joystick(1);
motor1 = new Jaguar(1);
motor2 = new Jaguar(2);
motor3 = new Jaguar(3);
motor4 = new Jaguar(4);
driveObject = new RobotDrive(motor1,motor2,motor4,motor3);
//distanceMonitor = new Encoder(2,1,2,2);
//tooEasy = new KinectStick(1);
}
/**
* This function is called periodically during autonomous
*/
public void disabledInit() {
driveObject.stopMotor();
}
public void disabledContinuous() {
//blah blah nobody cares
Timer.delay(0.1);
}
public void disabledPeriodic() {
//¡Nos gustan a los deportes y no nos importan a quienes lo saben!
getWatchdog().feed();
}
public void autonomousInit() {
}
public void autonomousPeriodic() {
}
public void autonomousContinuous() {
getWatchdog().feed();
Timer.delay(0.1);
}
/**
* This function is called periodically during operator control
*/
public void teleopInit() {
//still nothing here
}
public void teleopPeriodic() {
}
public void teleopContinuous() {
//i use a double here so java doesn't complain about casting a float
/*this says: is useSlowmo false? if so, halve the joysticks.
otherwise, use full output.*/
double slowmoMultiplier = 1;
driveObject.mecanumDrive_Cartesian(mainPad.getX()* slowmoMultiplier,
mainPad.getY()*slowmoMultiplier,
mainPad.getTwist()*slowmoMultiplier,0.f);
}
}
EDIT: There are some odd pieces of code (like slowmoMultiplier) because this is edited down from a larger chunk with more features. This is just a drivetrain test, so I removed most of that.
/*----------------------------------------------------------------------------*/
/* 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. */
/*----------------------------------------------------------------------------*/
/*HOW (my name) CODES FOR ALL YALL
* I like using small variables. You will see lots of chars.
* I write my variables likeThis. That's called Pascal style, I think.
*/
package edu.wpi.first.wpilibj.templates;
//first stuff
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Timer;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the IterativeRobot
* 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 JRobot extends IterativeRobot {
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
//button mappings
//powers
//random variables
final boolean useSlowmo = false;
//actual objects
RobotDrive driveObject;
Joystick mainPad;
Jaguar motor1,motor2,motor3,motor4;
public void robotInit() {
mainPad = new Joystick(1);
motor1 = new Jaguar(1);
motor2 = new Jaguar(2);
motor3 = new Jaguar(3);
motor4 = new Jaguar(4);
driveObject = new RobotDrive(motor1,motor2,motor4,motor3);
//distanceMonitor = new Encoder(2,1,2,2);
//tooEasy = new KinectStick(1);
}
/**
* This function is called periodically during autonomous
*/
public void disabledInit() {
driveObject.stopMotor();
}
public void disabledContinuous() {
//blah blah nobody cares
Timer.delay(0.1);
}
public void disabledPeriodic() {
//¡Nos gustan a los deportes y no nos importan a quienes lo saben!
getWatchdog().feed();
}
public void autonomousInit() {
}
public void autonomousPeriodic() {
}
public void autonomousContinuous() {
getWatchdog().feed();
Timer.delay(0.1);
}
/**
* This function is called periodically during operator control
*/
public void teleopInit() {
//still nothing here
}
public void teleopPeriodic() {
}
public void teleopContinuous() {
//i use a double here so java doesn't complain about casting a float
/*this says: is useSlowmo false? if so, halve the joysticks.
otherwise, use full output.*/
double slowmoMultiplier = 1;
driveObject.mecanumDrive_Cartesian(mainPad.getX()* slowmoMultiplier,
mainPad.getY()*slowmoMultiplier,
mainPad.getTwist()*slowmoMultiplier,0.f);
}
}
EDIT: There are some odd pieces of code (like slowmoMultiplier) because this is edited down from a larger chunk with more features. This is just a drivetrain test, so I removed most of that.