Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   CANNotInitializedException (http://www.chiefdelphi.com/forums/showthread.php?t=113534)

tac 15-02-2013 01:51

CANNotInitializedException
 
We've been trying to get our CANJaguar code working, but it keeps returning the CANNotInitializedException.

Our code right now is

Code:

public void robotInit(){
    try {
          CANJaguar armMotor = new CANJaguar (4,      CANJaguar.ControlMode.kPosition);
    } catch (CANTimeoutException ex){
          ex.printStackTrace();
}

What the console says:
Code:

[Squawk VM] Version: 2011 FRC, Nov  5 2011, 14:34:13
[cRIO] FPGA Hardware GUID: 0x1394f6dc1feb42ec6910e5767ed1d22c
[cRIO] FPGA Software GUID: 0xa14c11bde4bb64aef6a86fc52a294cd9
[cRIO] DIO LoopTiming: 260, expecting: 261
[cRIO] edu.wpi.first.wpilibj.can.CANNotInitializedException
[cRIO]    at edu.wpi.first.wpilibj.can.CANExceptionFactory.checkStatus(CANExceptionFactory.java:44)
[cRIO]    at edu.wpi.first.wpilibj.can.JaguarCANDriver.sendMessage(JaguarCANDriver.java:36)
[cRIO]    at edu.wpi.first.wpilibj.CANJaguar.sendMessage(CANJaguar.java:574)
[cRIO]    at edu.wpi.first.wpilibj.CANJaguar.getTransaction(CANJaguar.java:637)
[cRIO]    at edu.wpi.first.wpilibj.CANJaguar.getFirmwareVersion(CANJaguar.java:1199)
[cRIO]    at edu.wpi.first.wpilibj.CANJaguar.initCANJaguar(CANJaguar.java:247)
[cRIO]    at edu.wpi.first.wpilibj.CANJaguar.<init>(CANJaguar.java:286)
[cRIO]    at edu.wpi.first.wpilibj.templates.RobotTemplate.robotInit(RobotTemplate.java:70)
[cRIO]    at edu.wpi.first.wpilibj.SimpleRobot.startCompetition(SimpleRobot.java:104)
[cRIO]    at edu.wpi.first.wpilibj.RobotBase.startApp(RobotBase.java:156)
[cRIO]    in virtual method #10 of javax.microedition.midlet.MIDlet(bci=17)
[cRIO]    at javax.microedition.midlet.MIDletTunnelImpl.callStartApp(64)
[cRIO]    at com.sun.squawk.imp.MIDletMainWrapper.main(110)
[cRIO]    in virtual method #95 of com.sun.squawk.Klass(bci=25)
[cRIO]    at com.sun.squawk.Isolate.run(1506)
[cRIO]    at java.lang.Thread.run(231)
[cRIO]    in virtual method #47 of com.sun.squawk.VMThread(bci=42)
[cRIO]    in static method #3 of com.sun.squawk.VM(bci=6)
[cRIO] WARNING: Robots don't quit!
[cRIO] ---> The startCompetition() method (or methods called by it) should have handled the exception above.
[cRIO] task 0x25c7bb8 (System Web Services Load Thread) deleted: errno=0 (0) status=0 (0)
[cRIO] task 0x28784f8 (mDNS resolve) deleted: errno=0 (0) status=0 (0)
[cRIO] task 0x2bff230 (mDNS resolve) deleted: errno=0 (0) status=0 (0)

We'd love your help. Thanks!

arithehun 16-02-2013 22:49

Re: CANNotInitializedException
 
Also, you cannot define a jaguar inside of a code block (in this case, your "try" block, and then use it anywhere outside of the block. Outside of any method, but inside your class, type (you may have already done this):

Code:

CANJaguar armMotor;
Then, change your code that you displayed to this:
(Basically remove the CANJaguar variable marker):

Code:

public void robotInit(){
    try {
          armMotor = new CANJaguar (4,      CANJaguar.ControlMode.kPosition);
    } catch (CANTimeoutException ex){
          ex.printStackTrace();
}

Essentially, what is happening is that you're not initializing your global CANJaguar variable. How Java works is that it allows global and local variables of the same name. So the Jaguar that you're initializing isn't the same one that you're using at line 70. You made a new Jaguar also called "armMotor" and initialized that one. Because it had a conflicting name, Java resolved this by "hiding" the global variable from that function. The armMotor inside robotInit() was discarded after robotInit ended. The other armMotor that you defined elsewhere was never touched. By removing the CANJaguar reference, you're not creating a new variable anymore but instead initializing the existing global one, which is what you intended on doing.

Metis 13-01-2014 21:46

Re: CANNotInitializedException
 
The described error will occur if the cRIO has not had a CAN plugin set when the firmware was flashed. You need to re-image the cRIO to solve the problem.

Ipiano 15-01-2014 21:06

Re: CANNotInitializedException
 
AriTheHun, I believe you would be correct if the issue were a CANTimeoutException, but this is a CANNotInitializedException, which, as Metis said, is supposed to occur when the CAN Driver is not properly loaded.

notmattlythgoe 16-01-2014 07:51

Re: CANNotInitializedException
 
Quote:

Originally Posted by arithehun (Post 1234715)
Also, you cannot define a jaguar inside of a code block (in this case, your "try" block, and then use it anywhere outside of the block. Outside of any method, but inside your class, type (you may have already done this):

Code:

CANJaguar armMotor;
Then, change your code that you displayed to this:
(Basically remove the CANJaguar variable marker):

Code:

public void robotInit(){
    try {
          armMotor = new CANJaguar (4,      CANJaguar.ControlMode.kPosition);
    } catch (CANTimeoutException ex){
          ex.printStackTrace();
}

Essentially, what is happening is that you're not initializing your global CANJaguar variable. How Java works is that it allows global and local variables of the same name. So the Jaguar that you're initializing isn't the same one that you're using at line 70. You made a new Jaguar also called "armMotor" and initialized that one. Because it had a conflicting name, Java resolved this by "hiding" the global variable from that function. The armMotor inside robotInit() was discarded after robotInit ended. The other armMotor that you defined elsewhere was never touched. By removing the CANJaguar reference, you're not creating a new variable anymore but instead initializing the existing global one, which is what you intended on doing.

This would actually cause a compilation error, not a runtime error as the jaguar object would be out of scope when you tried to use it.

Joe Hershberger 16-01-2014 15:13

Re: CANNotInitializedException
 
Quote:

Originally Posted by Ipiano (Post 1327811)
AriTheHun, I believe you would be correct if the issue were a CANTimeoutException, but this is a CANNotInitializedException, which, as Metis said, is supposed to occur when the CAN Driver is not properly loaded.

So does it work if you select a CAN driver in the imaging tool?


All times are GMT -5. The time now is 22:15.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi