View Single Post
  #5   Spotlight this post!  
Unread 15-01-2015, 22:00
Team3266Spencer's Avatar
Team3266Spencer Team3266Spencer is offline
Team Captain and Lead Programmer
AKA: Spencer Lanman
FRC #3266 (Robots-R-US)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Richmond, Indiana
Posts: 280
Team3266Spencer is an unknown quantity at this point
Re: Unhandled exception instantiating robot

Quote:
Originally Posted by dash121 View Post
I am having the same problem. The specific error that is given "ERROR Unhandled exception: java.lang.NullPointerException at [edu.wpi.first.wpilibj.PWM.startLiveWindowMode(PWM. java:484), org.usfirst.frc.team4085.robot.Robot.teleopPeriodi c(Robot.java:117), edu.wpi.first.wpilibj.IterativeRobot.startCompetit ion(IterativeRobot.java:150), edu.wpi.first.wpilibj.RobotBase.main(RobotBase.jav a:234)]"

Can you help me?

Code:
package org.usfirst.frc.team4085.robot;

import java.io.IOException;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.BuiltInAccelerometer;
import edu.wpi.first.wpilibj.PowerDistributionPanel;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.command.Scheduler;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
import edu.wpi.first.wpilibj.Talon;


import org.usfirst.frc.team4085.robot.commands.ExampleCommand;
import org.usfirst.frc.team4085.robot.subsystems.ExampleSubsystem;

import edu.wpi.first.wpilibj.*;

/**
 * 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 Robot extends IterativeRobot {

	public static final ExampleSubsystem exampleSubsystem = new ExampleSubsystem();
	public static OI oi;

    Command autonomousCommand;
    Joystick lstick = new Joystick(0);
    Joystick rstick = new Joystick(1);
    PowerDistributionPanel PDP = new PowerDistributionPanel();
    BuiltInAccelerometer Accel = new BuiltInAccelerometer();
    LiveWindow Window = new LiveWindow();
    Talon Left = new Talon(0);
    Talon Right = new Talon(1);
    RobotDrive chassis = new RobotDrive(Left,Right);
    SmartDashboard smart = new SmartDashboard();

    /**
     * This function is run when the robot is first started up and should bDahe
     * used for any initialization code.
     */
    public void robotInit() {
		oi = new OI();
        // instantiate the command used for the autonomous period
        autonomousCommand = new ExampleCommand();
    }
	
	public void disabledPeriodic() {
		Scheduler.getInstance().run();
	}

    public void autonomousInit() {
        // schedule the autonomous command (example)
        if (autonomousCommand != null) autonomousCommand.start();
    }

    /**
     * This function is called periodically during autonomous
     */
    public void autonomousPeriodic() {
        Scheduler.getInstance().run();
    }

    
	public void teleopInit() {
		// This makes sure that the autonomous stops running when
        // teleop starts running. If you want the autonomous to 
        // continue until interrupted by another command, remove
        // this line or comment it out.
        if (autonomousCommand != null) autonomousCommand.cancel();
    }

    /**
     * This function is called when the disabled button is hit.
     * You can use it to reset subsystems before shutting down.
     */
    public void disabledInit(){

    }

    /**
     * This function is called periodically during operator control
     */
    @SuppressWarnings({"static-access" })
	public void teleopPeriodic() {
        Scheduler.getInstance().run();
        double counter = 0.0;
        while(isEnabled())
        {
        	smart.putNumber("Timer", counter++);
        }
        while(true)
        {
        	
        	chassis.setSafetyEnabled(false);
        	
        	chassis.tankDrive(lstick, rstick);
        	
        	
        	smart.putNumber("The X Axis", Accel.getX());
        	
        	
        	smart.putNumber("The Y Axis", Accel.getY());
        	smart.putNumber("The Z Axis", Accel.getZ());
        	smart.putNumber("The Temp of the roboRIO", PDP.getTemperature());
        	smart.putNumber("This is the test", smart.getNumber("Put a number here", 1));
        	
        	
        	Window.setEnabled(isEnabled());
        	Left.startLiveWindowMode();
        	Right.startLiveWindowMode();
        	Accel.startLiveWindowMode();
        	PDP.startLiveWindowMode();
        	
        	
        	smart.putNumber("Total Current", PDP.getTotalCurrent());
        	smart.putNumber("Total Energy", PDP.getTotalEnergy());
        	smart.putNumber(" Total Power", PDP.getTotalPower());
        	smart.putNumber("Match Time", Timer.getMatchTime());

        	
        	int inChar = 0;
            System.out.println("Enter a Character:");
            try {
                inChar = System.in.read();
                System.out.print("You entered ");
                System.out.println(inChar);
            }
            catch (IOException e){
                System.out.println("Error reading from user");
            }
            
            int outChar = 5;
				if (inChar == outChar ){
					System.out.println("Hello World");
				}
				else
				{
					System.out.println("Not J");
				}
        }
			}
        	
     
    
    /**
     * This function is called periodically during test mode
     */
    public void testPeriodic() {
        LiveWindow.run();
    }
}
I'm not sure about the exception that was thrown but there should not be while(isEnabled()) and while(true) loops inside of your teleopPeriodic method! This function is called periodically and so it is already part of a loop. Therefore you should write the code knowing its going to be called every ~30 ms. Also, you should not be trying to read user input on the rRIO.
__________________
2012: Buckeye Regional, Queen City Regional, Human Player
2013: Queen City Regional, Buckeye Regional, Crossroads Regional
Shooter Operator
2014: Crossroads Regional, Queen City Regional
Catapult Operator
2015: Georgia Southern Classic Regional (Winner), Queen City Regional
Chainsaw Operator
Want to talk? TeamSpeak: team3266.noip.me
Reply With Quote