My FTC team is wanting to do a few cool things with transferring variables used and changed in autonomous to teleop mode to re-use. The first one we are trying to use is, “Alliance,” where we want to change what the default color of the lights are when not giving any other information to show what alliance we are (mostly for fun and the nice aesthetics). Moving forward we would want to transfer things like heading, field position, and various other values.
I’ve been told by others that a “Singleton” class is the way to do this, but the team and I cannot quite figure out how this works. I’ve also seen others suggest writing to a file (CSV or something) and then reading that file in the start() or init() method. Both of these things are well above my knowledge, and I couldn’t find anything online that resolved this, so I thought CD would be a great place to start.
Our repository can be found here. It is quite simple as I am the programming mentor and generally not too familiar with java.
I have no experience with FTC, but you can read about the Singleton Pattern here. Basically you have a staticgetInstance() method that always returns the same instance from a static final member variable.
I think you need some advice from an FTC expert here. Having said that: Does it not work to call AllianceSingleton.getInstance().SetAlliance() and then AllianceSingleton.getInstance().GetAlliance() ?