-
Notifications
You must be signed in to change notification settings - Fork 6
Module Management
Without knowing what you're doing, modules can be tricky to keep track of. Sometimes it might seem like there are too many modules to properly manage. ATALibJ tries to fill module management with a few useful tools that let you properly manage all of the features and modules that you have to deal with. Hopefully they fill your needs.
##Subsystems Module management revolves around subsystems. They have an impressive amount of different ways to use them, each offering different benefits. Considering module management encompasses multiple modules, subsystems are exactly what you need.
###Using subsystems to encompass groups If you have a group of logically similar modules, consider making them a subsystem. You don't need to extend subsystem or anything like that. Just insert them into an array and pass it into the constructor. Like this
Subsystem mySubsystem = new Subsystem(new Module[] {
mod1, mod2, mod3
});
###Subsystem Builder
If you need to have a subsystem that changes as the program does, subsystem builders help you do that. They allow you to add and remove modules as needed, and turn into Subsystem instances using toSubsystem(). This is handy when you need a "snapshot" of which modules are part of a group at a certain point. (for example, a driving subsystem would include extra sensors during autonomous mode)
###Features that use multiple modules together
By extending Subsystem, you can create an easy-to-use class that uses multiple modules to make extra features. Sometimes, you need the different modules to interact together in a way that they can't do individually. This structure allows you to do that.
public class MySubsystem extends Subsystem {
private final MyModule mod1, mod2, mod3;
public MySubsystem(MyModule mod1, MyModule mod2, MyModule mod3) {
super(new Module[] {mod1, mod2, mod3});
this.mod1 = mod1;
this.mod2 = mod2;
this.mod3 = mod3;
}
public void foo() {
if(mod1.foo())
mod2.bar();
mod3.buz();
}
}
###Groups
A group is an object that performs the functions of the class on all of its elements. ATALibJ has a group-type class for every class in edu.first.module.actuators. This is because logically, only elements that "do" things can be considered part of a "group" of those things.
By using groups, you can considerably bring down verbose and boilerplate code. This is provided that your robot would benefit from it. Some robot designs don't lend themselves to easy integration with the "group" concept.
Bottom line is - if you can use a group without losing features, do it.
###Group VS ModuleGroup A group is a collection of instances of the specified class that performs the functions of the class on all of its members. A module group is a subsystem (collection of modules) that also performs the functions of the class on all of its members. The difference is that a module group is more specific. If you are using your own implementation of SpeedController, for example, you cannot insert that into a TalonModuleGroup. You would need to use a SpeedControllerGroup.