View Single Post
  #3   Spotlight this post!  
Unread 06-02-2012, 08:13
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 590
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: New version of the WPILib Cookbook posted

Quote:
Originally Posted by btslaser View Post
Thanks for this cookbook... it has helped us tremendously.

One question... in the example Command described, you get various subsystems using [Subsystem].getInstance(). In the Subsystem class there is not a static instance member, rather it is in the CommandBase. Do you recommend putting the static instance in the CommandBase or putting it in the Subsystem and writing a GetInstance() method on the Subsystem? Sample below.


public class DriveWithJoystick extends CommandBase {
Chassis m_chassis;

public DriveWithJoystick() {
m_chassis = Chassis.getInstance(); // not available...
requires(m_chassis); // reserve the chassis subsystem
}
We thought that it was easier to use the CommandBase class. What happened was that I did a presentation on the command based programming style and found myself spending 10 minutes explaining about singletons and static variables. And the code looked much cleaner if you just can reference the subsystem class instances with a simple variable. So either works, but we thought it was cleaner to not use all the static variables - and the subsystems themselves, often only a few lines of non-boilerplate code, got much smaller.

Brad
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
Reply With Quote