|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||||
|
||||||
|
Making more reusable commands
Last year, we used Java with the command framework. I was very happy with how it ended up, our code was the best organized and easiest to modify that it's ever been. We used RobotBuilder, which reduced much of the tediousness of creating subsystems. However, we ended up with over 60 commands.
We did end up with a lot of very similar commands, that could be abstracted to the following: turning on a motor at a fixed speed turning off the motor extending a pneumatic solenoid retracting a pneumatic solenoid toggling a pneumatic solenoid. For each of these, we made methods in the subsystem for a particular motor or a particular solenoid that translated a forward or reverse on the solenoid to an extend or retract (which depended on which way the solenoid was wired and plumbed). I'd like to be able to reduce the number of very similar commands and subsystem methods I had a few thoughts, but none of us are very experienced with OO design patterns, so I'm hoping someone has a better way. 1) create generic commands, and make the solenoid/motor in the subsystem public, and pass the solenoid/motor to the command. This is probably the simplest, but I lose the ability to easily translate a forward/reverse to an extend/retract in one place. 2) do #1, but extend the solenoid class to have a parameter to determine whether forward is extend or retract. This solves #1s problem, but then it makes it much harder to use robot builder 3) make a solenoid interface for extend/retract, and have the subsystem implement the interface. Then you could pass the subsystem to a generic command. However, you would be limited to a single solenoid per subsystem. Does anyone have other ideas? What did your team do? |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|