Shop OBEX P1 Docs P2 Docs Learn Events
Change in unrelated code causes a UART error and additional — Parallax Forums

Change in unrelated code causes a UART error and additional

newnapmannewnapman Posts: 4
edited 2005-07-13 20:29 in General Discussion
Basically stated: I have for some time received ‘[noparse][[/noparse]Error IDE-0042] Unknown unhandled exception in JVM (0).’ Errors when valid code has been added. I see other forum topics with the same issues. (IE: http://forums.parallax.com/showthread.php?p=467449) These errors when debugged led to different errors and finally ‘IndexOutOfBoundsException’ Errors in the UART SendByte() function. Yet this ‘valid code’ added elsewhere never has any baring on the UART errors. The ‘valid code’ is separate and sometimes never executed. Yet the UART error occurs.

Why does this simple change in code, which I consider to be a valid change, cause propagating errors in the UART????

EXPLANATION:

Today I tracked down what happened and what caused the errors. I have much more code that I can post if others want to see it, but for now I’ll attach just the relevant code (because there is a lot).

The attached file, “split_looped_16_PD_turning_2.java” always worked, then a simple ‘if’ statement change and the problems began.

Here is my debugging effort:

Working Code Section:
  public static void Prepare_To_Go() {
    //
    i = 0;
    DirectionD = (DirectionD+1600)%3600;
    dgain += 2;
    //
    rover.misc.print("min=85; max=260; direction=");
    rover.misc.print(DirectionD);
    rover.misc.print("; pgain=2.5; dgain=");
    rover.misc.println(dgain);
    //
    state = C_STATE_GO;
    //
    if ( dgain > 14 ) {
      state = C_STATE_KILL;
    }
  }



The Change:
  public static void Prepare_To_Go() {
    //
    i = 0;
    DirectionD = (DirectionD+1600)%3600;
    dgain += 2; 
    //
    if ( dgain > 14 ) {
      state = C_STATE_KILL;
      return;
    }
    //
    rover.misc.print("min=85; max=260; direction=");
    rover.misc.print(DirectionD);
    rover.misc.print("; pgain=2.5; dgain=");
    rover.misc.println(dgain);
    //
    state = C_STATE_GO;
  }



The ERROR:
[noparse][[/noparse]Error IDE-0042] Unknown unhandled exception in JVM (0).

Reproducible always. Even with battery change (not brownout). (I'm using a 7.4V battery source for mobility.)

Memory 10K of 32K used. Approx. stack=6, heap=1234

Only change since working is program constants and an "if() { return; }" in the middle of a function. Maybe it is the mid-function return…

ANOTHER CHANGE:
  public static void Prepare_To_Go() {
    //
    i = 0;
    DirectionD = (DirectionD+1600)%3600;
    dgain += 2;
    //
    if ( dgain > 14 ) {
      state = C_STATE_KILL;
    }
    else {
      //
      rover.misc.print("min=85; max=260; direction=");
      rover.misc.print(DirectionD);
      rover.misc.print("; pgain=2.5; dgain=");
      rover.misc.println(dgain);
      //
      state = C_STATE_GO;
    }
  }



THE NEW ERROR:
Changed code to if() {} else {}, without a return; statement.

[noparse][[/noparse]Error IDE-0024] Unknown bytecode in the JEM file (ldc2_w).

NOW, TIME FOR DEBUG:
Placed stop at the last known good place (line 191). Stepped forward to the next line of code (thus executing the code at line 191, a motor stop command(), and…
[noparse][[/noparse]Error IDE-0015] Stack trace is corrupt.
[noparse][[/noparse]Error IDE-0024] Unknown bytecode in the JEM file (ldc2_w).

I traced the code into my motor control code till the error happened (same error).
[noparse][[/noparse]Error IDE-0015] Stack trace is corrupt.
[noparse][[/noparse]Error IDE-0024] Unknown bytecode in the JEM file (ldc2_w).

Error happened in my motor controller package: “parallax16sc.java” approx line 140, 142, or 144, during a UART.sendByte(). (I have seen it error on any of those lines.)

*Note: I am using the “Parallax Servo Controller (Serial) Module” as a PWM generator to then control an RC car. The Servo Controller merely replaces a RC receive that has the ability to output the same PWM signal.

*NOTE: This section of code has always worked before (nearly 1000s of times), and doesn't explain why the code “if() { return; }” change is now causing errors.

*Note, UART.sendByte() is called successfully through out the whole program. Only when a large portion of the code ends, and a final URAT command is sent to stop the motors, does this error happen.

Removed all .class files in all folders (lib, Project, etc), and added a CPU.delay(1); after every UART write. In the “parallax16sc.java” code.

NEW ERROR:
[noparse][[/noparse]Error IDE-0028] Unhandled exception in JVM: java.lang.IndexOutOfBoundsException
Exception thrown in file 'C:\Documents and Settings\Rayburn\MyDocuments\JIDE Data\lib\stamp\core\Uart.java' at line 364

This is the standard unmodified stamp.core.UART code. As well, how code there be an ‘out of bounds index’ error here? I thought the ‘if statements’ in the UART code kept this from happening.

TRIED AN OLD SIMILAR PROGRAM:
I Loaded an old program, that is similar, with many repeated UART calls. “split_looped_14_PD_turning.java”

!!!SUCCESSFULL!!!

Okay…

removed "if() {} else {}" in original code (referenced above).

Went back to code:
  public static void Prepare_To_Go() {
    //
    i = 0;
    DirectionD = (DirectionD+1600)%3600;
    dgain += 2;
    //
    rover.misc.print("min=85; max=260; direction=");
    rover.misc.print(DirectionD);
    rover.misc.print("; pgain=2.5; dgain=");
    rover.misc.println(dgain);
    //
    state = C_STATE_GO;
    //
    if ( dgain > 14 ) {
      state = C_STATE_KILL;
    }
  }



!!!SUCCESSFULL!!!

YET! Look at “split_looped_16_PD_turning_2.java” line 191. The error happens in there, before about 10 lines of code when the Prepare_To_Go() faction is called! (Granted that function is also called, long before, during program initialization.)

This change in code is thus never reached & has no baring on the UART.sendByte() calls in the motor controller code! Just the change in memory from the function declaration alone, causes the UART error. Again, the two code-spaces (this function and the UART code), is completely separate!

Please also note that the cause-and-effect of the ‘if’ statement (the state= C_STATE_KILL; code) happens regardless of were it is put. There is no error caused by that statement.

Why does this simple change in code, which I consider to be a valid change, cause propagating errors in the UART????

Comments

  • newnapmannewnapman Posts: 4
    edited 2005-07-13 20:29
    The Full Subject is:
    Change in unrelated code causes a UART error and additional "Unknown unhandled exception" Errors

    Sorry it was truncated.
Sign In or Register to comment.