Go to Post remember to turn the robot on. - Laura_587 [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: 7 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 18-07-2012, 14:48
shawn.schwartz's Avatar
shawn.schwartz shawn.schwartz is offline
Lead Systems Engineer
FRC #0004 (Team 4 ELEMENT)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2011
Location: Lake Balboa, CA
Posts: 27
shawn.schwartz is an unknown quantity at this point
Command Base Programming Tutorials/Help?

Hello Chief Delphi,

Our team's programming department needs more education in command base robot programming. We all understand programming logic, as we program other types of software, but we are having some trouble understanding command base Java. If anyone has any tutorials or sample code that we can use, we would greatly appreciate it. We especially need help with programming a drivetrain and pneumatics programming.

Thank you.
__________________
Shawn Schwartz
Programming/Head of Website & Media, Team 4 ELEMENT
team4element.com
"Innovation distinguishes between a leader and a follower." -Steve Jobs
Reply With Quote
  #2   Spotlight this post!  
Unread 18-07-2012, 17:26
plnyyanks's Avatar
plnyyanks plnyyanks is offline
Data wins arguments.
AKA: Phil Lopreiato
FRC #1124 (The ÜberBots), FRC #2900 (The Mighty Penguins)
Team Role: College Student
 
Join Date: Apr 2010
Rookie Year: 2010
Location: NYC/Washington, DC
Posts: 1,112
plnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond repute
Re: Command Base Programming Tutorials/Help?

Let's see...

Getting Started With Java for FRC
WPILib User Guide
Programming Guide (robot drive can be found on page 29 and pneumatics on page 34)
And here are two examples of team's java code that I found floating around CD Media: one and two.
__________________
Phil Lopreiato - "It's a hardware problem"
Team 1124 (2010 - 2013), Team 1418 (2014), Team 2900 (2016)
FRC Notebook The Blue Alliance for Android
Reply With Quote
  #3   Spotlight this post!  
Unread 18-07-2012, 20:05
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Re: Command Base Programming Tutorials/Help?

Oh my goodness! Opportunity!

If you are interested in learning command-based, I'd look into our base code that we have written. It follows the basic uses that the WPI stuff has, but gives you a way more in-depth look at how it works, lets you change it, and has a ton more features.

I'm currently working on video tutorials that are found here.

All information is available there. I'd love if you'd check it out! It's fine if you don't choose to use it, but I'd love some feedback anyways.

Thanks,

Joel
__________________
All opinions are my own.
Reply With Quote
  #4   Spotlight this post!  
Unread 21-07-2012, 21:19
shawn.schwartz's Avatar
shawn.schwartz shawn.schwartz is offline
Lead Systems Engineer
FRC #0004 (Team 4 ELEMENT)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2011
Location: Lake Balboa, CA
Posts: 27
shawn.schwartz is an unknown quantity at this point
Re: Command Base Programming Tutorials/Help?

Thank you guys for the information.

I liked your videos and thought that they were very helpful, joelg236. I will definitely be looking out for more videos from you. I would just add some more emphasis on what each package does and an example of programming a robot. For example, make a project and show how to add subsystems and commands, while showing the programming of a simple drivetrain and maybe some pneumatic programming. That way, new teams and/or programmers can know how to program solenoids for gear-shifting, or something like that?

I put our 2012 competition code on our team's Github page. So, if you guys want to check it out, here is the link: http://www.github.com/team4element/F...undRumble-2012

Do you guys think that it is too messy? How could we better improve our code, and its organization, in the future?


If anyone has their competition code online, could you please posts links?

Thank you CD!
__________________
Shawn Schwartz
Programming/Head of Website & Media, Team 4 ELEMENT
team4element.com
"Innovation distinguishes between a leader and a follower." -Steve Jobs

Last edited by shawn.schwartz : 21-07-2012 at 21:24.
Reply With Quote
  #5   Spotlight this post!  
Unread 21-07-2012, 21:40
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Re: Command Base Programming Tutorials/Help?

Thanks for the input! I am currently working on some videos about modules, about driving, threading, logging, game periods, and most importantly, how to use it for your code.
__________________
All opinions are my own.
Reply With Quote
  #6   Spotlight this post!  
Unread 04-08-2012, 12:55
DaveFrederick's Avatar
DaveFrederick DaveFrederick is offline
Registered User
FRC #1895
 
Join Date: Jan 2009
Location: Manassas,VA
Posts: 36
DaveFrederick is a jewel in the roughDaveFrederick is a jewel in the roughDaveFrederick is a jewel in the rough
Re: Command Base Programming Tutorials/Help?

I also see the need for some additional tutorials in this area.
I have been trying to figure out how to get the command based java approach to work but I don't fully comprehend the details.

My goal is to have a presentation that will walk any student thru the basics.

I am currently stuck on how the Commands are called by the autonomousInit, autonomousPeriodic, TeleopInit and TeleopPeriodic.

The cookbook is weak in this area.

I have attached my current presentation and Welcome feedback.

Dave Frederick
Team 1895, Mentor
Attached Files
File Type: zip df20705_Robotics_JAVA_Practice_board_v03.zip (543.3 KB, 77 views)
Reply With Quote
  #7   Spotlight this post!  
Unread 04-08-2012, 19:45
AllenGregoryIV's Avatar
AllenGregoryIV AllenGregoryIV is offline
Engineering Coach
AKA: Allen "JAG" Gregory
FRC #3847 (Spectrum)
Team Role: Coach
 
Join Date: Jul 2008
Rookie Year: 2003
Location: Texas
Posts: 2,544
AllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond repute
Send a message via AIM to AllenGregoryIV
Re: Command Base Programming Tutorials/Help?

That's an interesting presentation. I don't have specific notes right now but if I do I'll post them.

Here is a link to a presentation I gave this summer during our summer workshop series.
http://goo.gl/EjLHM (It looks better if you download it, the online viewer messes with the fonts).

Also here is the demo program I had students work with the next day.
https://github.com/Spectrum3847/SpectrumWorkshop
__________________

Team 647 | Cyber Wolf Corps | Alumni | 2003-2006 | Shoemaker HS
Team 2587 | DiscoBots | Mentor | 2008-2011 | Rice University / Houston Food Bank
Team 3847 | Spectrum | Coach | 2012-20... | St Agnes Academy
LRI | Alamo Regional | 2014-20...
"Competition has been shown to be useful up to a certain point and no further, but cooperation, which is the thing we must strive for today, begins where competition leaves off." - Franklin D. Roosevelt
Reply With Quote
  #8   Spotlight this post!  
Unread 07-08-2012, 20:13
DaveFrederick's Avatar
DaveFrederick DaveFrederick is offline
Registered User
FRC #1895
 
Join Date: Jan 2009
Location: Manassas,VA
Posts: 36
DaveFrederick is a jewel in the roughDaveFrederick is a jewel in the roughDaveFrederick is a jewel in the rough
Re: Command Base Programming Tutorials/Help?

Update to the draft. About 40% complete.
Lots more to learn.

Dave Frederick, Mentor
Team 1895, Manassas, VA
Attached Files
File Type: zip df20705_Robotics_JAVA_Practice_board_v04.zip (611.2 KB, 51 views)
Reply With Quote
  #9   Spotlight this post!  
Unread 16-08-2012, 18:11
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Command Base Programming Tutorials/Help?

Quote:
Originally Posted by DaveFrederick View Post
Update to the draft. About 40% complete.
Lots more to learn.

Dave Frederick, Mentor
Team 1895, Manassas, VA
I've been looking through your presentation, and it seems pretty good. I have some constructive criticism:
  • On slide 11 (talking about the RobotTemplate class), you talk about the "IterativeRobot" approach as something entirely separate from the Command approach. IterativeRobot is actually part of the Command-based approach, and can be used exactly like a typical IterativeRobot. The big difference between using IterativeRobot normally (putting all robot logic in either the periodic() or continuous() functions) and using Commands is that the periodic() functions MUST call
    Code:
    Scheduler.getInstance().run();
    This call handles all the details of executing and stopping Commands. In fact, you could simultaneously use the normal IterativeRobot approach and the Command approach... it would just be a terrible headache
  • This is more of a design concern than anything being wrong, but having two different Commands (LED_Off and LED_On) for a single idea (setting the LED's state) seems unnecessary and a bit cumbersome. Having a LED_Set Command that takes a boolean in the constructor would require less code, and would only change
    Code:
    button4.whenPressed(new LED_Off());
    button5.whenPressed(new LED_On());
    to
    Code:
    button4.whenPressed(new LED_Set(false));
    button5.whenPressed(new LED_Set(true));
    To make this easier, IndicatorLED could have a set() method that looked like this:
    Code:
    public void set(boolean state) {
        LED_one.set(!state); // since false == on for DigitalOutputs, negate state
    }
  • In slides 18 and 19 ("Create the commands used on the subsystem"), declaring a local copy of CommandBase's static variable indicatorLED isn't necessary. Because LED_On inherits from CommandBase, it can access all protected and public members of CommandBase, so the local version isn't necessary. The constructor then can become more concise:
    Code:
    requires(indicatorLED);
    The Scheduler only allows one running Command to require() a subsystem at a time, so that there isn't any fighting over resources. Take for example, two commands, TankDrive and ArcadeDrive. Both would require() the driveTrain Subsystem. If both were running at once, the results would be... surprising, to say the least. But since they both require() driveTrain, when one starts the other is automatically stopped so they don't cause trouble.

    A full example implementation of LED_Set (assuming IndicatorLED has a set() method as suggested before) would be:
    Code:
    public class LED_Set extends CommandBase {
        private boolean chosenState;
        public LED_Set(boolean state) {
            requires(indicatorLED);
            chosenState = state;
        }
    
        protected void initialize() {
            indicatorLED.set(chosenState);
        }
    
        protected void execute() {}
    
        protected boolean isFinished() {
            return true;
        }
    
        protected void end() {}
        
        protected void interrupted() {}
    }
  • On slide 22 ("Bind a joystick action to the command (within the OI Class)"), you say you don't understand what the static "instance" variable is for. This variable allows OI to be a lazy singleton, or more correctly a singleton with lazy initizialization. The basic pattern is this:
    Code:
    public class Singleton {
        private static Singleton instance;
        private Singleton() {}
        public static Singleton getInstance() {
            if(instance == null) {
                instance = new Singleton();
            }
            return instance;
        }
    }
    This fulfills two requirements: 1) that only one instance of the class exists, and 2) that the instance isn't initialized until it's used.
  • On slide 24 ("Final configuration of commands"), the idea of the two Commands autonomousCommand and teleopCommand is that you can easily start and stop all autonomous/teleop activity by simply start()ing and cancel()ing the corresponding command. To make a single command perform multiple actions, just inherit from CommandGroup, like this:
    Code:
    public class TeleopTemplate extends CommandGroup {
        public TeleopTemplate() {
            addSequential(new FirstCommand()); // sequential commands run one after the other
            addParallel(new ParallelCommand()); // this command will run at the same time as SecondCommand and ThirdCommand
            addSequential(new SecondCommand());
            addSequential(new ThirdCommand());
            addSequential(new WaitForChildren()); // wait for ParallelCommand to finish
            addSequential(new FourthCommand()); // Will only run after both ThirdCommand and ParallelCommand have completed
        }
    }
    WaitForChildren is a Command provided by WPILib, the rest can be any command you create.
  • On slide 36 (when implementing the DynamicServoAngle command), I'm not sure why you say you need to instantiate the joystick on each execute()... To me it seems that it shouldn't work, as I'm under the impression that multiple instances of the same Joystick would cause errors. Joysticks are typically supposed to remain in the OI class; in my code I don't even expose them directly, instead having functions like getDriveRightAxis() and getDriveLeftAxis(). eg:
    Code:
    public class OI {
        // ... other stuff ...
        private Joystick joyServo = new Joystick(SERVO_JOYSTICK_PORT);
        public getServoAxis() {
            return joyServo.getRawAxis(1);
        }
    }

Last edited by Ginto8 : 16-08-2012 at 18:28.
Reply With Quote
  #10   Spotlight this post!  
Unread 16-08-2012, 19:37
DaveFrederick's Avatar
DaveFrederick DaveFrederick is offline
Registered User
FRC #1895
 
Join Date: Jan 2009
Location: Manassas,VA
Posts: 36
DaveFrederick is a jewel in the roughDaveFrederick is a jewel in the roughDaveFrederick is a jewel in the rough
Re: Command Base Programming Tutorials/Help?

Thank you for the feedback. I will review your comments in detail this weekend and update the presentation accordingly.

I posted an updated version a couple of days ago on a similar thread.
Http://www.chiefdelphi.com/forums/sh...3&postcount=12

I'm fairly new to Object Oriented programming and struggle with JAVA. It took me about two weeks to get the first example to work. I have a much better understanding now but miles to go.

While looking for help to learn this command based programming, I saw a lot of questions and few answers. I hoped to fill some of the void.

Thank you again,
Dave Frederick
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 09:36.

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