Go to Post You're on a team, weren't you taught Gracious Professionalism? It doesn't only apply to competitions, it applies to the real world. - Zac Schofield [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 09-01-2012, 22:51
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 592
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
New version of the WPILib Cookbook posted

There is a new version of the Robot Programming Cookbook posted on the WPILib project under the documents section. The example is (hopefully) substantially cleaned up. And it has a new section on writing command-based programs in C++ with a fairly extensive tutorial. I would highly encourage teams using Java to check it out. It makes writing complex robot programs much simpler and provides a "cookbook" method of organizing your code.

http://firstforge.wpi.edu/sf/docman/..._documentation

In addition there is a sample program called GearsBot provided with Netbeans that illustrates the features as a sample. It is a much more complex robot with PID Subsystems and a fairly complex autonomous program.

The version posted has a typo in it, so after you create the sample, just delete the line with the error in it that says:
Subsystem.registerDefaultCommands();

then it will be identical to the code we used in the Kickoff Workshop talk.

Brad
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
Reply With Quote
  #2   Spotlight this post!  
Unread 01-02-2012, 09:40
Brian Selle's Avatar
Brian Selle Brian Selle is offline
Mentor
FRC #3310 (Black Hawk Robotics)
Team Role: Engineer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Texas
Posts: 170
Brian Selle has a spectacular aura aboutBrian Selle has a spectacular aura aboutBrian Selle has a spectacular aura about
Re: New version of the WPILib Cookbook posted

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
}
Reply With Quote
  #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: 592
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
  #4   Spotlight this post!  
Unread 07-02-2012, 01:10
linuxboy linuxboy is offline
Registered User
AKA: Oliver Graff
FRC #3780
Team Role: Alumni
 
Join Date: Nov 2010
Rookie Year: 2009
Location: MI, USA
Posts: 217
linuxboy has much to be proud oflinuxboy has much to be proud oflinuxboy has much to be proud oflinuxboy has much to be proud oflinuxboy has much to be proud oflinuxboy has much to be proud oflinuxboy has much to be proud oflinuxboy has much to be proud oflinuxboy has much to be proud of
Re: New version of the WPILib Cookbook posted

Quote:
Originally Posted by BradAMiller View Post
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
Aside from the conceptual difficulty of singletons and static variables, are there any reasons not to use singletons? I can see the private constructor being useful in the way of "I instantiated the chassis, why is it throwing a PWM already allocated exception (or whatever)?"
- Oliver
Reply With Quote
  #5   Spotlight this post!  
Unread 12-02-2012, 13:11
cjlane1138 cjlane1138 is offline
Team 1138
FRC #1138 (Eagle Engineering)
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Los Angeles
Posts: 88
cjlane1138 is an unknown quantity at this point
Re: New version of the WPILib Cookbook posted

Does the command based coding style work with c++? We got to the requires() part, and it says that Error: requires() undeclared. It is not recognizing it as a function. Do you know why? It works in the ExampleCommand.cpp, but not when I make my own DriveCommand.cpp.
__________________
Eagle Engineering 1138
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:59.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi