easyc "Initialize" Function

It seems that the Initialize function in easyc is running both when the bot is turned on and when the mode of movement is switched (driver -> autonomous) on the competition switch. We set numerous values in the initialize function and need them to stay constant. I don’t know much about the Initialize function and any extra information is appreciated.

This is normal (and unfortunate) behavior. Changing modes from auton->driver and driver->auton more or less forces a complete reset of the cortex when using EasyC.

Hmm… Ok. Is it possible to skip the contents of the initialize function if a global was to be set at the end of autonomous?

Yes, but not quite in the way you may think as normal globals get reinitialized as well.

EasyC has some “special” global variables accessed through the GlobalData© function, 20 are available. Use one of these, I may post a little example later if I have time.

Wow. That was the fastest reply in history. Also, I found the function you were talking about and it seems like it will work perfectly. Thank you!

Except unfortunately it doesn’t.

I tried using GlobalData(0) to store a flag indicating initialize state and it always remained at 0. It should be easy, but either I’m stupid or it’s broken. So… I vaguely remember doing this at some point in the past, have a read of this post and then the whole thread it’s in.


That was two years ago, EasyC seems to react differently now but I don’t have the time or energy to dig into this tonight.

Then try this code and see if it does what you need. It will allow the initialize code inside the conditional test to run exactly once upon power up and then never again (even if you download new code).

#include "Main.h"

void Initialize ( void )
    extern char ReadUserBit();
    // no idea why this delay is needed !
    Wait ( 100 ) ;
    PrintToScreen ( "user bit 0  %d\n" , ReadUserBit() ) ;
    if ( ReadUserBit() == 0 )
        // This will run once on power up and never again 
        PrintToScreen ( "Initialize my variables\n" ) ;
        PrintToScreen ( "We ran initialize already - no need to init my stuff\n" ) ;

Use a “user code” block to add the “extern char ReadUserBit();” statement, that’s an undocumented function that’s not in the API.h file.

If that doesn’t do what you need then perhaps EasyC tech support can help. Alternatively switch to something else (ie. ROBOTC, PROS or ConVEX) that doesn’t get in the way of programming so much.

So it appears GlobalData is still saved to flash, not sure I agree with this but that’s what it looks like.
In the original post you said that “We set numerous values in the initialize function and need them to stay constant”, if they are set more than once does that really matter? You want them to be constant, they will just be set each time initialize runs.