There is talk in the commentary regarding having code to detect if there is a restart by examining the logs.
Can anyone clarify what state the logs are in before the race/at the start of racing?
- Does the logs folder itself exist, but empty of all files?
- There is not even a logs folder, it is created when the first log is created?
Any advice would be appreciated
Thanks
- Pi Hard
The log folder doesn't exist to start with unless you've included it as part of your upload. Its created early on in the Race.py file when it calls
and
from the RaceCodeFunctions.py file.
The way Claire suggests on the stream is during boot up to check for the existance of either
Processing %s.txt
orUser %s.txt
where %s is the local time. It's a pretty good solution, but it could have problems if your robot has to be rebooted or if your check happens after the logs files have been created.I've taken a slightly different approach. At the start of the race, when the light turns second green I quickly write an empty file to the log folder. Then, during the startup (or restart) I check for the existence of that file. If it finds that file, it's because we restarted during the session and it goes straight back to racing. If it doesn't find the file, it continues to wait for the light sequence.
Like Jamie, I decided to create another file. I write a timestamp in it to check that it isn't from an earlier race or testing simulation and to have it stop on time for Arron. The code I use follows:
Weird Duplicate
I'm only here because I wanted to try to get comment #666. :(
I have an idea for a very simple boot-detection method very similar/identical to what Jamie has described above. We may have even used it for the first time in a race last night. Should be universal but I will have a look at how it would fit into the standard code tonight and drop a few lines of code here as an example.
Beware of making assumptions about what might be in the formulapi folder. For example I see the entire set of standard code modules in that folder even though they are not part of my uploads. (In fact I now rely on the ThunderBorg.py module being in that folder, even though I don't upload it.) After the first suggestion of reboot detection methods last season it turned out that the logs folder wasn't actually being emptied as had been stated and that caused a false start for one competitor (RasPerras?). I believe since then it is now routinely emptied or deleted but I'm not 100% sure. Hope Arron can confirm.
We empty the
~/formulapi/logs
folder each time we write the card, just before we copy over the uploaded code into~/formulapi
This means that the
~/formulapi/logs
folder should exist when your code is started and will be empty unless your uploaded code includes alogs
folder with data in it already. The standard upload script excludes everything in thelogs
folder to be safe :)Pico is right that we had a problem in the past which has now been fixed. Put simply if you run
it will work, unless there are a large number of files. When it fails it leaves them all in place :(
We solved this by changing the script to
which will work regardless of how many files are saved.
The standard image we write the uploaded code to already includes a full copy of the Formula Pi code, meaning teams could just upload the files they have changed. We would advise you to upload all files anyway as that copy is a bit out of date now. It will always have a working copy of
ThunderBorg.py
though :)Thanks everyone for your help and suuggetsions.
We've now put some code in to hopefully restart on a powercycle.
We've also updated race.py to try and drive into as many walls as possible to hopefully trigger a powercycle. This should look pretty odd as we zigzag across the track.
Bring on the next round, and the consequent mayhem.
Having spent my fair share of time running into the walls I found that it doesn't normally force a restart. Most of the restarts have been during racing and crashing into other mosterborgs. If you want to test a reboot, you could just manually reboot with this code.
You could trigger it every time you cross the line, or just once at a particular point on the track. It would be more reliable, and you don't have to purposely run the monsterborg into the walls.
Add new comment