PDA

View Full Version : Robot Dropping the Code


team1512
01-31-2010, 09:09 PM
Hello all, I am part of team 1512 and our robot is running using 2010 v19 imaging and a net beans java code. We have have had quite a bit of major success loading the code from a seperate PC and using the supplied classmate for the driver station. Usually the robot communicates well and then can be operated through teleoperated and autonomous, however our most recent code has seen that the robot communicates and stays in sync but somehow suddenly drops the code going from "teleoperated enabled" to "no robot code" even if the lights on the speed controllers still register a code. Both the disable and emergency stop buttons still work but the classmate won't even say "emergency stopped" if the button is pressed like it normally does. I reverted back again to our default code and that works so it is not the wiring something in the program is causing the robot to drop the code but there are no errors in the text as far as we can see. Please help... Thanks

Here is the 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. */

/*----------------------------------------------------------------------------*/



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 {





//HSLImage image;// = new HSLImage ();

RobotDrive drive = new RobotDrive(1, 2);

Joystick leftStick = new Joystick(1);

Joystick rightStick = new Joystick(2);

AxisCamera camera = AxisCamera.getInstance();

ColorImage image;// = camera.getImage();

Servo servo5 = new Servo(5);

DigitalInput button1 = new DigitalInput(1);

/**

* This function is called once each time the robot enters autonomous mode.

*/

public void autonomous()

{

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

drive.drive (0.0, 0.75); // drive 0% 75% turn



}

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();

}



drive.tankDrive(leftStick, rightStick); // drive with joysticks

camera.writeResolution(AxisCamera.ResolutionT.k320 x240);

camera.writeBrightness(0);

//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="+rightStick.getY());

System.out.println(" servo angle="+servo5.getRaw() + " f=" + f);

System.out.println(" Button1="+button1.get());

Timer.delay(0.005);



}

}

}

Robototes2412
02-01-2010, 06:36 PM
Yeah, the camera is a b*tch, try manually reconfing it and then pray.

Brent Strysko
02-01-2010, 10:32 PM
Team 1672 had a very similar problem today. Your best bet is just to start a new project and then re-paste the code as that fixed our problem. It seems to be a strange but in the linking portion of the code.

ericarseneau
02-02-2010, 08:04 PM
I strongly recommend you get the console output and see if there wasn't some kind of exeption that came out. I think we capture some exceptions and put them out on the LCD, but there is nothing that beats having the console up.

You can use NetConsole, or run the echo target in the build.xml of your project, or use ant echo from a shell inside your project directory.

will_1359
02-02-2010, 11:07 PM
yeah 1359 is having the same problem, first i did a reimage of the Classmate(there was another issue with half the DS not showing up) and that didn't fix the robot code problem, we also formatted and reloaded v19 to the cRIO and loaded our code in again, no worky. then i just did what was suggested here in this thread and whipped up some copy pasta with what used to be a working code, and it still doesn't work. kinda sucks. any other ideas?

ericarseneau
02-03-2010, 12:48 AM
Did you connect the console to see if an exception was coming out? If so then can we see what the exception output was?

omalleyj
02-03-2010, 02:05 PM
Guys you need to free the image. If you don't you run out of memory pretty quick. Check the output as Eric suggested.

Further tip: your code needs better organization. You waste a lot of cpu and bandwidth resetting the camera to the same values every single loop. That stuff should be moved into a constructor and done once.

omalleyj
02-03-2010, 02:39 PM
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="+rightStick.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

alex42
02-09-2010, 02:29 PM
When it loses the code, does it then regain the code after a few seconds, then repeat ad infinitum? If so, team 1072 has been having the same problem, although we're using LabVIEW. We've found that if we reimage the cRIO, the problem will usually go away for a few days (and if it doesn't fix it, we reimage it again until it does). We're still looking for a permanent fix though.