This was not a mistake. The staff at a competition do not directly control the enabling or disabling of the robots but instead use the tournament manager software. Robots need to be disabled after the autonomous period, if this were not done it would be difficult to limit the time to 15 seconds and allow scoring to take place. The sequence usually is
enable driver control
If for some reason there is a technical problem the autonomous period may be restarted but this is rare.
EasyC will run the code in the initialize function every time the robot is enabled followed by either the autonomous or operator function as needed. All regular global and static variables are initialized each time as well but there is an array of “global data” that can be used to track things that need to be run once, this array is called “GlobalData” and contains 20 long integers.
You will see in the thread that I started by writing my own code to allow non-volatile storage of user settings in the flash memory. By the last post I had discovered that EasyC does in fact have a crude mechanism for storing the contents of the GlobalData array in flash where the array will be reloaded on power on. Now the bad news, out of respect for the EasyC developers I can’t tell you how to do this The developers had a reason for hiding the API and I have to leave it to them to choose to expose it again. There are two issues, the first is that repeated erasure of the flash will eventually destroy it, the number of cycles is not that high and they did not implement any mechanisms (as I did with my own code) to remedy this. The second reason is that during a flash erase (which is required before flash can be re-written) real time performance will be lost, that is, it takes approximately 20mS to erase a flash page during which time interrupts and other background operations cannot operate properly. Your best bet (unless you hack the runtime library as I did) is to use jumpers or a potentiometer to store such settings as autonomous routine selection.
I wanted to add that since the original thread I ported the code to ROBOTC, it works quite well for its intended use and is a shame I cannot release it for the same reasons as above.
Ok, I’ve tried accessing this and it appears it too is being reset back to 0 whenever disable the field with the switch after autonomous. Should this be the case? Perhaps I understood you wrong - maybe you explained it in your last post.
The whole reason for us to get an LCD panel was to make autonomous selections… I’d really like to figure a way around this…
Let me try an example later and post some working code if it is as I remember.
Some weird stuff happening, looks like GlobalData is being written to flash despite what I said earlier. I need to figure out if this was a change in 126.96.36.199 or if it in fact existed in earlier versions. It seems to get written if leaving Initialize. Not what I expected at all, however, the last time I looked into this was several months ago.
Well, EasyC sure is a mess. Here’s what I have been able to figure out so far.
The GlobalData array is saved to flash when using the competition switch connected to the joystick. This seems to happen when the robot is disabled and a difference detected between what is in the GlobalData array and the flash memory. When the robot is powered on the GlobalData is loaded from flash, the problem here is that if you want to use GlobalData to indicate that code should be run exactly once then this only happens the first time after a new program is downloaded and never on subsequent power cycles. None of this happens if the competition switch is not connected as the robot will never see a disabled condition. I do not like the way GlobalData is being saved to flash, EasyC is doing a page erase each time the robot is disabled and a difference in the data detected, this is putting unneeded stress on that flash page without knowledge of the programmer. I’m not sure what’s going on with Intelitek these days but the lack of updates gives me a feeling they are not putting much resource into EasyC so doubt this will be improved. GlobalData is saved to flash at address 0x0805F800 if anyone is interested.
Anyway, the ideas from below will never work, we need to find a different way.
EasyC has a whole bunch of undocumented functions. One pair it has are ReadUserBit() and WriteUserBit(). These functions seem to be used by the competition control code to save some state information using an unconnected GPIO port (portF). I notice that ReadUserBit() returns 0 when initialize first runs before the robot is enabled and then disabled but returns 1 after that. This would appear to be something we can use to allow some initialization code to run just once. The code below is a work in progress but the idea is something like this.
Another way would be to abandon the whole idea of only running this code once. It doesn’t really matter if the selection code runs again before driver control, the autonomous has already run so what if that variable gets set back to 0. Anyway, I will give it some more thought, the more I use EasyC the less I like the way the underlying library code is written, there is lots of power there if you bypass their code but it’s not really practical for most students.
There’s nothing official as far as I can see. In ROBOTC there are flags to do this but they are only valid when the robot is enabled, it’s as if when the robot is disabled it always indicates autonomous mode.
I have another idea for creating some global data that would behave in the way that I thought GlobalData was. When I used GlobalData the last time I did not have the competition switch connected, normally it can not get written to flash under user control, that was the undocumented function I had found.
I am posting this Test Code… It might be helpful in the Future with EasyC.
As of EasyC v188.8.131.52, when the COMPETITION SWITCH SIMULATOR is set to DISABLE, a Reset appears to be performed, which Clears all Global Variables, including the ones declared as Static within a Function. Repository_Concept_000a.zip (7.04 KB)
I know it’s going far back in the thread, but I have an answer from personal experience that addresses the original question as far as GlobalData is concerned and may or may not help you (MarkO) with your experiments.
We have written in EasyC an autonomous selection routine that runs before each match (inside of the initialize function).
It is fairly simple, pressing either the left or right LCD button decrements or increments GlobalData(1). Then, inside of the autonomous function there is a switch/case that runs our routine based upon this number.
In my experiance when hooked to a match controller (in competition), the GlobalData(1) retained its value completely, even when the robot is turned off.
To be clear, if we choose to run our #4 routine, in the next match when we start up our robot again the value is already at 4.
I have not done significant testing with this using a competition switch simulator or the handheld switch.
In competition I follow the following procedures:
With the robot and controller turned off, Connect the joystick to the field.
Turn on the controller.
Turn on the robot.
After the match is over and we are given the all clear to remove our robots
from the field, remove the cable connecting the controller to the field.
This causes the initialize function to run again (not sure if this is significant or not) then goes into driver control.
Turn off both the robot and controller.
I do not disconnect the 9V battery as recommended.
If I follow these procedures exactly, I do not need to remove the 9V. However, if I were to turn off the controller then disconnect from the field and turn off the robot, the cortex would remain disabled and the 9V would need to be disconnected and reconnected or else problems will arise at the beginning of the next match.
I’m not sure if these procedures are significant or not, but since they aren’t exactly standard I figured they would help if you were to attempt to replicate my results.
Unless GlobalData retaining its value even when the robot is powered off is an already known fact…