Hello,
We are currently at the FIRST Robotics Regional @ Richmond/VCU. We have been getting massive lag during tele op. However, this doesn't seem to be happening during autonomous. What we were told is that our code is "bloated/inefficient/RAM hog,etc". Can some one double check this code?
Here is our code(s):
RobotTemplate:
Code:
a/*----------------------------------------------------------------------------*/
/* 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.*;
import edu.wpi.first.wpilibj.DriverStationLCD.Line;
/**a
* 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 {
private static Joystick dualShock = new Joystick(1);
protected static Joystick jordansFolly = new Joystick(2);
protected static Jaguar jag1 = new Jaguar(1);
protected static Jaguar jag2 = new Jaguar(2);
protected static Jaguar shooterJag = new Jaguar(3);
protected static Victor rampMotor1 = new Victor(4);
protected static Victor rampMotor2 = new Victor(5);
protected static double shooterControl;
protected static RobotDrive drive = new RobotDrive(jag1, jag2);
// 1 for near, 2 for middle, 3 for far
// need some way of setting
/**
* This function is called once each time the robot enters autonomous mode.
*/
public void autonomous() {
// Will hopefully be able to hit all balls if positioned in a line
getWatchdog().setExpiration(7);
getWatchdog().feed();
shooterJag.set(1.0);
jag1.set(-1.0);
jag2.set(1.0);
Timer.delay(1.00);
jag1.set(0.0);
jag2.set(0.0);
shooterJag.set(0.0);
getWatchdog().setExpiration(20);
// needs code to turn pi/2 left, move 3 feet, turn back, and repeat above
// then do again
}
public void testOutput(String s, Line l) {
DriverStationLCD lcd = DriverStationLCD.getInstance();
lcd.println(l, 1, s);
lcd.updateLCD();
}
/**
* This function is called once each time the robot enters operator control.
*/
public void operatorControl() {
getWatchdog().setEnabled(true);
//shotDelay1.reset();
while(true && isOperatorControl() && isEnabled())
{
getWatchdog().feed();
// Solenoid sol1 = new Solenoid(1);
// sol1.set(false);
//Pneumatics.operate(dualShock, shotDelay1);
DualShock.drive(dualShock, jag1, jag2, drive);
shooterControl = jordansFolly.getZ()/-2.0 + 0.5;
shooterJag.set(shooterControl);
//THIS WORKS - ml. 2/22
//raises or lowers ramp while joystick trigger is held down
//Pressed returns false for some reason
if (jordansFolly.getTrigger())
{
rampMotor1.set(1.0);
rampMotor2.set(1.0);
}
else if (jordansFolly.getRawButton(2))
{
rampMotor1.set(-1.0);
rampMotor2.set(-1.0);
}
else
{
rampMotor1.set(0.0);
rampMotor2.set(0.0);
}
}
}
}
Code for Logitech DualShock controller:
Code:
/*/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.*;
import edu.wpi.first.wpilibj.DriverStationLCD.Line;
/**
*
* @author Robotics
*/
public class DualShock {
protected static double left;
protected static double right;
public static void testOutput(String s, Line l) {
DriverStationLCD lcd = DriverStationLCD.getInstance();
lcd.println(l, 1, s);
lcd.updateLCD();
}
public static void drive(Joystick dual, Jaguar jag1,
Jaguar jag, RobotDrive drive)
{
left = dual.getRawAxis(4); // Y-axis on left stick
right = dual.getY();
// left is jag 3, right is jag 2
drive.setLeftRightMotorSpeeds(left, right);
Timer.delay(0.005);
//pause for duration between update cycles of jaguars
//may not be needed
}
}
Here is the ZIP file for all the code:
http://qwh9pg.blu.livefilestore.com/...e.zip?download