View unanswered posts | View active topics It is currently Mon Sep 01, 2014 10:06 pm






Reply to topic  [ 4 posts ] 
NXT Datalogging Exception 
Author Message
Rookie

Joined: Tue Feb 19, 2013 4:11 pm
Posts: 8
Post NXT Datalogging Exception
I am trying to create a datalog with my accelerometer values in RobotC.

When I ran the program, an error screen appeared reading:

Byte Code Interpreter Exception:
...
Exception Type: 'Real Adress Range Exception(59)'

The reason I find this confusing is that in the line of coded in question (marked by the arrow), I cast the long variable robotstate.lasttime into an integer.

Here is my code (the important bits):

Code:
const int kDatalogSize = 1000;

task main ()   {
   nDatalogSize = kDatalogSize;
   const int kDataPointType1 = 1;
   const int kDataPointType2 = 2;

  while(true) {

     if(nUsedDatalogBytes >= kDatalogSize) {
        SaveNxtDatalog();
        PlaySound(soundBeepBeep);
        wait1Msec(2000);
        return;
     }
     
     AddToDatalog(kDataPointType1, robotstate.accelvals.x);
 --> AddToDatalog(kDataPointType2, (int)robotstate.lasttime);
     updatestate();
  }
}


Important notes:
robotstate.accelvals.x is an integer (yet no errors).
robotstate.lasttime is essentially nPgmTime(also a long)

I did change a line of code in RobotCIntrinsics: I commented out the initial delaration for AddToDatalog(); and uncommented another declaration to take integers as values:

Code:
//intrinsic void AddToDatalog(compileConst int nDataPtIndex, const short data)
intrinsic void AddToDatalog(compileConst int nDataPtIndex, const int  nDataValue)


Anyone know why I am receiving this error?

P.S Posted this earlier in another section, hopefully I get better luck here.


Wed Feb 20, 2013 5:24 pm
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: NXT Datalogging Exception
Your error seems to be an overflow one (the variable has overflowed into the adjacent memory slot). I think this is because longs are larger than ints, and therefore you can't cast longs to ints (it will compile, but at runtime the cast will fail). You can cast ints to longs though. The workaround would be to write your own casting function to handle this, something like:
Code:
int longToInt(long input)
{
    if (input==0)
        return 0;
    else if (input>32767) //upper limit of int variables
        return 32767;
    else if (input<-32768) //lower limit of int variables
        return 32768;
    else
        return long;
}

The above code should work, but I haven't tested it. Get back to me if you're still around :)
Of course, you can change the limiting behavior to return 0 or whatever.

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Sat May 18, 2013 3:25 pm
Profile
Rookie

Joined: Tue Feb 19, 2013 4:11 pm
Posts: 8
Post Re: NXT Datalogging Exception
Oops, no kidding, thanks for the help. Your solution works but I'll have to work something else out though since it doesn't work for my purposes. I need to enter very large numbers into the datalog which i'm not sure it supports. I'll fool around some more with the different datalogging options and see what I can figure out.


Thu Jun 20, 2013 6:08 pm
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: NXT Datalogging Exception
Ok. Good luck, and post what you come up with when you're done :)

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Fri Jun 21, 2013 12:56 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.