Go to Post By affiliating yourself with a team, you are representing them at all times, as you are a member and part of that team. - Chris is me [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 04-08-2012, 12:55
DaveFrederick's Avatar
DaveFrederick DaveFrederick is offline
Registered User
FRC #1895
 
Join Date: Jan 2009
Location: Manassas,VA
Posts: 37
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, 78 views)
Reply With Quote
  #2   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,547
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
  #3   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: 37
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
  #4   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
  #5   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: 37
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 11:11.

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