Quote:
Originally Posted by MrRoboSteve
That can be a valid approach, too, if the limit switch is exclusively part of one subsystem. In the past, we've gotten in situations where there's a tangle of subsystem references, only to get access to sensor state. The SensorSubsystem prevents that.
Having one subsystem referencing another also makes it easier to accidentally command the referenced subsystem. This breaks the "requires" model in the command-based framework, which is present to help you reason about where commanding might be coming from. You can certainly produce a correct program by doing so, but it is harder to think about. We deliberately design our robot program so that it is easy to think about.
|
I'm a C++ guy and I think one could solve the problem of subsystems driving other subsystems by making all motor driving functions non-const and all sensor reading functions const. This way one could provide only a const pointer to the other subsystems but non-const pointers to the commands allowing commands to drive the subsystems but not allow the other subsystems to, yet allow both access to sensor readings.
I did a quick look to see if Java provides similar, but it looks like perhaps not.
I'm trying to think if the idea of sharing a sensor between two subsystems perhaps indicates that a better subsystem configuration is possible. I'm not sure I like collecting *all* sensors into a globally accessible sensor class-- one subsystem may reset an encoder and mess up code in another for example.
I guess I prefer the idea of making access functions in a subsystem that owns a sensor better, but I think it could use further discussion.
I suspect perhaps that code in a subsystem that needs a sensor from another subsystem might better be coded in a command that requires both subsystems. But I think I can also think of counterexample where that won't work well.
Can you give a good concrete example where two subsystems require a single sensor so we can kick around various approaches to resolve it within the command based paradigm?