Quote:
Originally Posted by Greg McKaskle
If you are feeding the watchdog, but not feeding as often as you said you would, you'll get this behavior. I'd inspect the code to see how often and for how long your yields are delaying the code. Certain routines such as Teleop need to return quickly or they will cause you to miss joystick packets. If these are OK, look to either feed more often or adjust the period so that it doesn't expect to be fed any more often.
Remember. The user watchdog helps you know when your code isn't running as often as you thought it would, and gives it a way to fail safely when certain mistakes are made such as crashing or infinite loops.
Greg McKaskle
|
We're using iterative robot template.. so do we put it in teleop periodic?
Here's our code... if anyone's intersted
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. */
/*----------------------------------------------------------------------------*/
//Sky Hawk
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.Gyro;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.PIDController;
import edu.wpi.first.wpilibj.PIDOutput;
//import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.camera.AxisCamera;
import edu.wpi.first.wpilibj.camera.AxisCameraException;
import edu.wpi.first.wpilibj.image.ColorImage;
import edu.wpi.first.wpilibj.image.NIVisionException;
/**
* 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 SkyHawkVersion3 extends IterativeRobot {
double kScoreThreshold = .01;
AxisCamera cam;
private DigitalInput i1 = new DigitalInput(2);
private DigitalInput i2 = new DigitalInput(3);
private Solenoid s1, s2, s4, s3;
private Compressor airCompressor;
Gyro gyro = new Gyro(1);
private Victor roller = new Victor(6);
private Victor flyWheel = new Victor(5);
private Victor release = new Victor(8);
private Victor arm = new Victor(7);
//private Relay spike1 = new Relay(1);//Relfay 1
private Joystick stickRight = new Joystick(1);//USB 1
private Joystick stickLeft = new Joystick(2);//USB 2
private Jaguar rightBackJaguar = new Jaguar(1);//PWM 1
private Jaguar rightFrontJaguar = new Jaguar(2);//PWM 2
private Jaguar leftBackJaguar = new Jaguar(3);//PWM 3
private Jaguar leftFrontJaguar = new Jaguar(4);//PWM 4
private double sensitivity1;//Right Joystick Sensitivity
private double sensitivity2;//Winder sensitivity
private double y2;//Left Joystick Y-axis
private double x2;//Left Joystick X-axis
private double y1;//Right Joystick Y-axis
private double x1;//Right Joystick X-axis
private double rightBackSpeed;
private double rightFrontSpeed;
private double leftBackSpeed;
private double leftFrontSpeed;
TrackerDashboard trackerDashboard = new TrackerDashboard();
PIDController turnController = new PIDController(.08, 0.0, 0.5, gyro, new PIDOutput() {
public void pidWrite(double output) {
// drive.arcadeDrive(0, output);
}
}, .005);
public void Airsystem() //turns on the enitre air system
{
airCompressor = new Compressor(1,2); //Digtial I/O,Relay
airCompressor.start(); // Start the air compressor
s1 = new Solenoid(1); // Solenoid port
s2 = new Solenoid(2);
s3 = new Solenoid(3);
s4 = new Solenoid(4);
s1.set(true);
s2.set(false);
s3.set(false);
s4.set(false);
}
public void kickFlyWheel()//DOES EVERYTHING THAT INCLUDES KICKING
{
roller.set(.5);
flyWheel.set(-1*sensitivity2);
if(((stickLeft.getRawButton(1))))
{
roller.set(0);
Timer.delay(.5);
s2.set(false);
s1.set(true);
Timer.delay(.75);
s1.set(false);
s2.set(true);
}
roller.set(.5);
}
public void robotInit() //Initializes functions prior to start of the match
{
getWatchdog().setExpiration(0.2);
Timer.delay(10.0);
cam = AxisCamera.getInstance();
cam.writeResolution(AxisCamera.ResolutionT.k320x240);
cam.writeBrightness(0);
gyro.setSensitivity(.007);
turnController.setInputRange(-360.0, 360.0);
turnController.setTolerance(1 / 90. * 100);
turnController.disable();
Airsystem();
}
//Strafing
public void mecanumDrive()
{
y1= -1* stickRight.getY();
x1= -1*stickRight.getX();
y2= stickLeft.getY();
x2= stickLeft.getX();
sensitivity1= -1*((((stickRight.getRawAxis(3))+1)/2)+.01);//Throttle is now
//from 1% to 100%
sensitivity2= -1*((((stickLeft.getRawAxis(3))+1)/2)+.01);//Throttle is now
//from 1% to 100%
rightBackSpeed = sensitivity1*(y1-x1);
rightFrontSpeed = sensitivity1*(y1+x1);
leftBackSpeed = sensitivity1*(y2+x2);
leftFrontSpeed = sensitivity1*(y2-x2);
rightBackJaguar.set(rightBackSpeed);
rightFrontJaguar.set(rightFrontSpeed);
leftFrontJaguar.set(leftFrontSpeed);
leftBackJaguar.set(leftBackSpeed);
}
public void autonomousPeriodic() {
try {
//Camera crapthingy
if (cam.freshImage()) {// && turnController.onTarget()) {
double gyroAngle = gyro.pidGet();
ColorImage image = cam.getImage();
Thread.yield();
Target[] targets = Target.findCircularTargets(image);
Thread.yield();
image.free();
}
} catch (NIVisionException ex) {
ex.printStackTrace();
} catch (AxisCameraException ex) {
ex.printStackTrace();
}
//End camera crapthingit
if ((i1.get())&&!(i2.get()))
{
// Front position Autonomous code
}
if (!(i1.get())&&!(i2.get()))
{
// Middle position Autonomous code
}
if (!(i1.get())&&(i2.get()))
{
// Far position Autonomous code
}
}
/**
* This function is called while the robot is disabled.
*/
public void disabledPeriodic()
{
// airCompressor.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOff);
}
/**
* This function is called at the beginning of teleop
*/
public void autonomousInit()
{
}
public void compressorCheck() //turns on/off compressor based on full
{
if (airCompressor.getPressureSwitchValue()) {
airCompressor.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOff);
} else {
airCompressor.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOn);
}
}
public void teleopInit() {
}
boolean lastTrigger = false;
/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() {
getWatchdog().feed();
long startTime = Timer.getUsClock();
//Canera
try {
if (cam.freshImage()) {// && turnController.onTarget()) {
double gyroAngle = gyro.pidGet();
ColorImage image = cam.getImage();
Thread.yield();
Target[] targets = Target.findCircularTargets(image);
Thread.yield();
image.free();
}
} catch (NIVisionException ex) {
ex.printStackTrace();
} catch (AxisCameraException ex) {
ex.printStackTrace();
}
Thread.yield();
mecanumDrive();
Thread.yield();
kickFlyWheel();
Thread.yield();
//pneumaticsKicker();
compressorCheck();
Thread.yield();
// System.out.println("Time : " + (Timer.getUsClock() - startTime) / 1000000.0);
//System.out.println("Gyro Angle: " + gyro.getAngle());
}
}