|
Re: Robot Dropping the Code
1512 try this:
/*----------------------------------------------------------------------------*/
/* 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.SensorBase;
//import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Servo;
import edu.wpi.first.wpilibj.camera.AxisCamera;
import edu.wpi.first.wpilibj.camera.AxisCameraException;
//import edu.wpi.first.wpilibj.image.HSLImage;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.image.ColorImage;
import edu.wpi.first.wpilibj.image.NIVisionException;
//import edu.wpi.first.wpilibj.CounterBase;
/**
* 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);
Joystick leftStick = new Joystick(1);
Joystick rightStick = new Joystick(2);
AxisCamera camera;
ColorImage image;// = camera.getImage();
Servo servo5 = new Servo(5);
DigitalInput button1 = new DigitalInput(1);
public RobotTemplate(){
Timer.delay(5.0);
camera = AxisCamera.getInstance();
Timer.delay(5.0);
camera.writeResolution(AxisCamera.ResolutionT.k320 x240);
camera.writeBrightness(0);
}
/**
* This function is called once each time the robot enters autonomous mode.
*/
public void autonomous()
{
//don't use this code unless you know your robot won't
//hit something at 50% speed for 2 seconds
for (int i = 0; i < 4; i++)
{
drive.drive(-0.5, 0.0); //drive 50% fwd 0% turn
Timer.delay(2.0); // wait 2 seconds
//this turn may not be enough for your robot
drive.drive (0.25, 0.75); // drive 25% 75% turn
Timer.delay(2.0);
}
drive.drive(0.0, 0.0); //stops all drive/turn
}
/**
* This function is called once each time the robot enters operator control.
*/
public void operatorControl() {
getWatchdog().setEnabled(false);
float f=0;
float increment = (float) 0.5;
int direction=0;
while (true && isOperatorControl() && isEnabled()) // loop until change
{
try {
image = camera.getImage();
} catch (AxisCameraException ex) {
ex.printStackTrace();
} catch (NIVisionException ex) {
ex.printStackTrace();
}
/* do stuff with the image */
try {
image.free();
} catch (NIVisionException ex){
ex.printStackTrace();
}
drive.tankDrive(leftStick, rightStick); // drive with joysticks
//Timer.delay(3.0);
// servo5.setAngle(rightStick.getX()*100.0);
servo5.setAngle(f);
if (direction==0) f=f+increment; else f=f-increment;
if (f>255.0) direction=1;
if (f<0.0) direction=0;
System.out.println("leftstickx="+leftStick.getX()+ "leftSticky="+leftStick.getY());
System.out.println(" rightstickx="+rightStick.getX()+"rightSticky="+rig htStick.getY());
System.out.println(" servo angle="+servo5.getRaw() + " f=" + f);
System.out.println(" Button1="+button1.get());
Timer.delay(0.020);//.005? Really need it that fast?
}
}
}
be careful cutting and pasting, your code as posted has two typos
|