View unanswered posts | View active topics It is currently Tue Sep 02, 2014 9:19 am






Reply to topic  [ 3 posts ] 
problem with large arrays 
Author Message
Rookie

Joined: Thu Mar 10, 2011 9:48 pm
Posts: 2
Post problem with large arrays
Hey all,

I've been experiencing a weird issue lately that might have to with something to do with how ROBOTC stores arrays somehow.

Basically, I have a program which performs two steps:
1. monitor the robot's motors and print to the debug stream when any of the motor values change.
2. read a large (several hundred) array of values and use them to control the motors.
It's a cute little way to "record" actions and then run them again later. and it works.
sometimes.

Anyway, to implement this, I loop through continuously to check each motor compared to an array of old values (1.), and then read from a gigantic array of recorded values which i've explicitly declared in my code (2.). Step 1 works just fine first, and once i've pasted the resulting array into my code, step 2 also works fine. but then when i try to monitor the motor positions again (step 1), things get messy.

For your convenience, I simplified my code down to the smallest thing possible.
Right now, I
-declare a really big array, foo (in my original code, this was a two dimensional array, but 1D breaks too)
-allow the user to control two of the motors (port2 and port3)
-and compare the old value of the motors to the current value. if the two differ, I print a timestamp and the old and new motor values to the debug stream.
First off, if you comment out the declaration of foo (or even just the last few entries in it, to make it shorter), and then run, it should work properly. press either button, 8U or 8D or 7U or 7D. the debug stream should alert you that the values have changed, from 0 to 127 (or -127) and then back to 0. you should get 2 new entries each time you press and release the button.
However, if you run it as is, and then press button 8U or 7U, you should get a couple thousand new entries on the debug screen. if you read the entries, you'll note that the third item, motor_old[i], is always 0. so for some reason, all the values in motor_old have decided to become constants set at 0. that's why you get so many entries--on each loop, motor_old[i] is always 0, and 0 != 127, so each loop prints a new line rather than only printing when the value changes.

so... any ideas as to the problem? or workarounds?

Code:
task main(){
  int foo[] = {
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0
  };

  writeDebugStream("\n\nRunning...\n");
 
  const int NUMBER_OF_VARIABLES = 10;
  int motor_old[NUMBER_OF_VARIABLES];
  while(true){

    //or insert whatever motor code you'd like
    motor[port2] = 127 * ( vexRT[Btn8U] - vexRT[Btn8D] );
    motor[port3] = 127 * ( vexRT[Btn7U] - vexRT[Btn7D] );
   
    for(int i=0; i < 10; i++){
      if(motor_old[i] != motor[i]){
        motor_old[i] = motor[i];
        writeDebugStream("%d,%d,%d,%d\n",nSysTime,motor[i], motor_old[i]);
      }
    }
  }
}


Thu Mar 10, 2011 10:19 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3210
Location: Rotterdam, The Netherlands
Post Re: problem with large arrays
I don't think you can supply more than 2 "%"' parameters to writeDebugStream();

You have 4 "%" and 3 variables which you're printing. There's a mismatch.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Mar 11, 2011 2:13 am
Profile WWW
Rookie

Joined: Thu Mar 10, 2011 9:48 pm
Posts: 2
Post Re: problem with large arrays
Oh, my bad--typo on my part. still runs, oddly enough/

the code still doesn't work when I remove the extra "%d", though.

Code:
writeDebugStream("%d,%d,%d\n",nSysTime,motor[i], motor_old[i]);


Fri Mar 11, 2011 3:26 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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.