View Single Post
  #1   Spotlight this post!  
Unread 17-02-2015, 08:38
Dinnesy Dinnesy is offline
Registered User
FRC #4968 (Robo Hawks)
Team Role: Teacher
 
Join Date: Dec 2013
Rookie Year: 2014
Location: Lively
Posts: 19
Dinnesy is an unknown quantity at this point
Robot Connection Resetting

Recently, my team has noticed our robot's connection resetting itself for no apparent reason and giving us the following output in the console:
Connection reset at edu.wpi.first.wpilibj.CameraServer.serve(CameraSer ver.java:346)
edu.wpi.first.wpilibj.CameraServer$1.run(CameraSer ver.java:77)
java.lang.Thread.run(Thread.java:745)

I'm assuming there is something wrong with the camera code, but I have no idea what.

Here is the code we are using:
Code:
package org.usfirst.frc.team4968.robot;


import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Victor;

/**
 * Robot Drive sample code, modified by Ryley Ongarato for use by the Robohawks/team 4968's robot.
 * Allows robot to be driven arcade style and Microsoft vision camera to be displayed on frc dashboard (cameraHW).
 * Also allows for a crate to be grabbed via the grabbing system, and (WIP) lifted via the lifting system.
 * Features a brake(button 1) and a one axis camera.
 **/
public class Robot extends SampleRobot {
    RobotDrive myRobot;
    Victor grabSystem = new Victor(2);
    double grabSystemSpeed;
    Victor liftSystem = new Victor(3);
    double lifeSystemSpeed;
    Victor camAxis = new Victor(4);
    double camAxisSpeed;
    Joystick stick;
    Joystick leftstick;
    CameraServer server;

    public Robot() {
    	myRobot = new RobotDrive(0, 1);
    	myRobot.setExpiration(0.1);
    	stick = new Joystick(0);
    	leftstick = new Joystick(1);
    	server = CameraServer.getInstance();
    	server.setQuality(30);						//Camera Compression rate/Quality
    	server.startAutomaticCapture("cam0");		//the camera is displayed on the frc dashboard as cameraHW.
    }

    /**
     * Basic Autonomous Drive at speed x for x seconds.
     **/
    public void autonomous() {
        myRobot.setSafetyEnabled(false);
        myRobot.drive(0.1, 0.0);					// drive forwards at (x) speed
        Timer.delay(1.0);							// for (x) seconds
        myRobot.drive(0.0, 0.0);					// stop robot after x seconds
    }

    /**
     * Runs during Teleop mode. This code drives the robot via arcade steering. Also includes the brake, lift, and grabbing code.
     **/
    	public void operatorControl() {
    	myRobot.setSafetyEnabled(true);
    	while (isOperatorControl() && isEnabled()) {

    	//-------------------------Robot Drive-------------------------//
    		if (stick.getRawButton(1)){
            	myRobot.arcadeDrive(stick.getX() * 0.3, stick.getY() * 0.3);		//Brake (stops motors, will flip robot at high speed)               
            	System.out.println("Button 1 pressed!");       	 
        		}
        	else{ myRobot.arcadeDrive(stick.getX() * 0.5, stick.getY() * 0.5);		//Arcade style driving, using the right stick with speed capped at 50%
        		}
        //-------------------------Grab System-------------------------//
            double grabSystemSpeed = 0;
            	grabSystemSpeed = leftstick.getX();									//Retrieves value from the leftstick's x axis and sets it to grabSystemSpeed
            	grabSystem.set(grabSystemSpeed);  									//Apply grabSystemSpeed to the grabSystem 
    			
    	//-------------------------Lift System-------------------------//
        	double liftSystemSpeed = 0; 
        		liftSystemSpeed = -leftstick.getY();								//Retrieves value from the leftstick's x axis and sets it to grabSystemSpeed
        		liftSystem.set(liftSystemSpeed);  									//Apply grabSystemSpeed to the grabSystem
    			}
    	//-------------------------Camera Axis-------------------------//
    	double camAxisSpeed = 0; 
    		if (stick.getRawButton(3)){ 
    			camAxisSpeed = (1.0);											//Move camera axis up               
    			}
    		else if (stick.getRawButton(4)){
    			camAxisSpeed = (-1.0); 											//Move camera axis down
    			}
    		camAxis.set(camAxisSpeed);
	}
    
    /**
     * Runs during test mode. Used for testing new code/code changes.
     **/
    public void test() {
    
     }
}
Reply With Quote