One of my teams has a single python file (main.py) that implements their custom driver controls logic. But they also have the autonomous code in that same file, because it’s more convenient and shares code with the driver controls (functions like dispenseBlocks()). They have several different routines to run for auton.
They have logic like this:
if slotNumber == 1:
runManualControls()
elif slotNumber == 2:
runLeftField()
elif slotNumber == 3:
....
Nicely organized. But there’s problems here:
(1) They can’t find a way to detect at runtime what slot the program is running under, so they have a hack with a variable at the top of the file:
slotNumber = 1
They change it, change the Slot to 1, save. Then change it to 2, change the Slot to 2, then save. Repeat for all slots they need.
(2) Another problem is that they can’t control how the program name displays on the Gen2 brain. So as they toggle through the slots, sometimes under extreme time pressure (!), they just see the same name scrolling by. The Gen2 brain doesn’t even offer a helpful indicator of what slot # is currently selected (e.g. 1:Code, 2:Code, etc.). Even that would have been helpful.
My questions:
(1) Are we missing something? Is there a way to access the current Slot # at runtime?
(2) Is there a way to programmatically set the program display name on the brain?
BTW, before you suggest that we add an LED button to correspond to each program…the kids thought of that already. First, the ports on their brain are nearly at capacity - adding 4-5 new cables is not a good option. Second, the bot also doesn’t have a great place to add a bunch of LEDs physically (possibly fixable with rebuilding).
Another solution we’ve thought of is to share code - but can the brain support multiple python files, and python modules? But this is still kind of suboptimal, because you now have to maintain and load each python file into each slot, every time you change the shared module code, right? That’s bound to lead to mistakes.
We figure, all we really need is:
(1) Must-have: runtime slot # access, like:
if brain.slotNumber == 1:
(2) Ideally: I know this is a harder challenge due to bootstrapping the program, but a way to configure the program name based on slot #?
Suggestions welcome! Thank you.