Go to Post I began to see myself as an independent person who was not only being inspired, but able to inspire others and strengthen the FIRST program as a whole. - Jaine Perotti [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 27-11-2012, 21:41
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
Command Based JAVA - Basic Tutorial

I have put together a basic tutorial on how to use the Command Based JAVA approach.

All Feedback is welcome!

Dave Frederick
Mentor, Team 1895
Manassas, VA
Attached Files
File Type: zip df20705_Robotics_JAVA_Practice_board_v09.zip (3.70 MB, 318 views)
  #2   Spotlight this post!  
Unread 27-11-2012, 21:51
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Re: Command Based JAVA - Basic Tutorial

Yes! I've been waiting for this

Even the last version you posted was one of the best compilations I'd seen.
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional
  #3   Spotlight this post!  
Unread 27-11-2012, 21:58
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 Based JAVA - Basic Tutorial

Very well presented and detailed. I will be saving that for future use, if you don't mind.
__________________
All opinions are my own.
  #4   Spotlight this post!  
Unread 27-11-2012, 23:03
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,995
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Command Based JAVA - Basic Tutorial


For those of us who are curious but don't have the time right now to wade through this, can someone please post an "executive summary" of how this command-based architecture works "under the hood"?

Is it spawning threads in response to events?


  #5   Spotlight this post!  
Unread 28-11-2012, 01:20
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 429
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: Command Based JAVA - Basic Tutorial

Here's my understanding of the Command Based robot project. Please feel free to correct me where I'm wrong.

First an overview of the concept:
There are two major classes which are provided that can be extended to contain the majority of the robot specific code, the Subsystem class and the Command class.
Subsystems characterize mechanisms on your robot. So each subsystem (drivetrain, shooter, lift, etc) should extend the Subsystem class and implement any methods for the functionality that subsystem can perform. It abstracts hardware specific funcitons from the rest of the program. So the shooter may have a method setSpeed which takes a parameter in RPMs, but this alone wouldn't be enough to shoot a ball. You will likely need to interact with multiple subsystems to do that.

This is where the Command class comes in. The purpose of the command class is to build more complex sets of functions, a procedure to follow to complete a task. For many commands this requires using methods across a number of subsystems. Groups of commands can be created to complete a number of steps in series or parallel (or a mix of both).

Commands are then linked into operator interfaces (e.g. joystick buttons) or even executed from autonomous modes.

You need to conform somewhat rigidly to the framework for everything to work, but this can have the advantage of helping you organize your thoughts.


How it works:
New instances of Commands are created from events (e.g. button press from operator). These instances are passed to a scheduler which maintains a list of all the active commands. Commands have a number of methods which allow the scheduler to step through their execution (initialize(), execute(), isFinished(), end()).

Part of a command definition provides information as to which Subsystems are required for the particular command. This allows the scheduler to identify conflicting commands, and handle which ones get to execute. Basically whichever command was issued last will execute (if there was a subsystem dependency conflict).

The command based robot project builds on top or the iterative robot project. Methods for each game mode (teleopPeriodic(), autonomousPeriodic()) are called repeatedly (every 20ms - with each driver station update). Calls to the scheduler's run() method are required within the teleop and auto periodic mode methods to allow the scheduler to process outstanding commands.

I found this presentation to be particularly helpful. Start at slide 18.

Once you understand the model it makes building up a fairly complex system quite painless. Throwing together auto mode actions become quite easy, as it simply becomes a new command which calls other existing commands that in many cases have already been tested and proven to work in teleop.
__________________
http://team2168.org

Last edited by otherguy : 28-11-2012 at 02:13. Reason: added reference to slide # in linked presentation
  #6   Spotlight this post!  
Unread 28-11-2012, 09:12
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,995
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Command Based JAVA - Basic Tutorial

Quote:
Originally Posted by otherguy View Post
Basically whichever command was issued last will execute
This sounds problematic, unless I'm misunderstanding what was intended.


  #7   Spotlight this post!  
Unread 28-11-2012, 09:35
BigJ BigJ is offline
Registered User
AKA: Josh P.
FRC #1675 (Ultimate Protection Squad)
Team Role: Engineer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Milwaukee, WI
Posts: 943
BigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond repute
Re: Command Based JAVA - Basic Tutorial

Commands run "in parallel" unless they have a subsystem dependency conflict. Methods are provided by the Command class in order to allow a command to do something if it is "interrupted" by another command that requires the same subsystems.

See http://www.wbrobotics.com/javadoc/ed...l#interrupted()

The Command class also lets you set a command as non-interruptible, but I'm not sure if the scheduler actually honors that or if it is for you to fetch with isInterruptible when making some decisions somewhere.... I've never actually tried it.

Last edited by BigJ : 28-11-2012 at 09:38.
  #8   Spotlight this post!  
Unread 28-11-2012, 09:40
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,995
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Command Based JAVA - Basic Tutorial

Quote:
Originally Posted by BigJ View Post
Commands run "in parallel" unless they have a subsystem dependency conflict.
What's the time slice? Does everything run at the same priority?


  #9   Spotlight this post!  
Unread 28-11-2012, 09:43
BigJ BigJ is offline
Registered User
AKA: Josh P.
FRC #1675 (Ultimate Protection Squad)
Team Role: Engineer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Milwaukee, WI
Posts: 943
BigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond repute
Re: Command Based JAVA - Basic Tutorial

I haven't actually dived into the scheduler to look at it. I'm not sure if it threads or if it is basically splitting the IterativeRobot style command loops between the commands. We've never done anything particularly timing-intensive (yet ) so we never had to look. (that's why I added the quotation marks, hehe)

EDIT: The cookbook says commands are accessed around every 20ms. It doesn't mention anything about priority, though.

Last edited by BigJ : 28-11-2012 at 09:49.
  #10   Spotlight this post!  
Unread 28-11-2012, 10:00
JesseK's Avatar
JesseK JesseK is offline
Expert Flybot Crasher
FRC #1885 (ILITE)
Team Role: Mentor
 
Join Date: Mar 2007
Rookie Year: 2005
Location: Reston, VA
Posts: 3,608
JesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond repute
Re: Command Based JAVA - Basic Tutorial

The command architecture is an interesting concept for robotics, but only because our processors are powerful enough to jump through the extra layers of abstraction without effecting the mechanical performance. I've experimented with sending high-level (marshalled) commands from a prompt to my quadrotor with some success. The architecture is essentially a queue for predicates and closures. The key to success on a larger system is managing compounding and/or non-deterministic behavior that causes the command queue to get gummed up.

As a reviewer's note, the command queue itself should have overriding interrupts -- ways to interrupt the current command with a higher priority command for the same subsystem. End-users under high pressure in an intense match are REALLY good at hitting the wrong button (e.g. to tell an arm to go down when they really wanted it to go up) and then changing their minds in under a few milliseconds.
__________________

Drive Coach, 1885 (2007-present)
CAD Library Updated 5/1/16 - 2016 Curie/Carver Industrial Design Winner
GitHub
  #11   Spotlight this post!  
Unread 28-11-2012, 10:11
BigJ BigJ is offline
Registered User
AKA: Josh P.
FRC #1675 (Ultimate Protection Squad)
Team Role: Engineer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Milwaukee, WI
Posts: 943
BigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond repute
Re: Command Based JAVA - Basic Tutorial

As long as your commands require the same subsystem a new command will interrupt the first and go. This lets you run a "default" joystick driving command at all times and interrupt it to do a separate controlled command with the drive subsystem for something like an autoscoring mechanism in a game like '11.
  #12   Spotlight this post!  
Unread 28-11-2012, 11:57
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,995
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Command Based JAVA - Basic Tutorial

Quote:
Originally Posted by BigJ View Post
As long as your commands require the same subsystem a new command will interrupt the first and go.
I think you meant abort the first and go? Otherwise, you could get some pretty funky behavior when returning from the interrupt.


  #13   Spotlight this post!  
Unread 28-11-2012, 12:10
apalrd's Avatar
apalrd apalrd is offline
More Torque!
AKA: Andrew Palardy (Most people call me Palardy)
VRC #3333
Team Role: College Student
 
Join Date: Mar 2009
Rookie Year: 2009
Location: Auburn Hills, MI
Posts: 1,347
apalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond repute
Re: Command Based JAVA - Basic Tutorial

A few questions on the command architecture (without reading the paper at the beginning of the document):

-Do subsystems get poked by run() also? Or does run() just poke all of the active commands?

-Is the architecture designed for the subsystems to store the subsystem state, or for the commands to store subsystem state? I would assume the subsystems store their state, but if they don't get poked then the have to wait for a command in progress to do anything (or you have to manually poke them, or start a new thread).
__________________
Kettering University - Computer Engineering
Kettering Motorsports
Williams International - Commercial Engines - Controls and Accessories
FRC 33 - The Killer Bees - 2009-2012 Student, 2013-2014 Advisor
VEX IQ 3333 - The Bumble Bees - 2014+ Mentor

"Sometimes, the elegant implementation is a function. Not a method. Not a class. Not a framework. Just a function." ~ John Carmack
  #14   Spotlight this post!  
Unread 28-11-2012, 13:56
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 429
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: Command Based JAVA - Basic Tutorial

Quote:
Originally Posted by apalrd View Post
Do subsystems get poked by run() also? Or does run() just poke all of the active commands?
The scheduler only interfaces with the commands. Commands then interface with the methods of a subsystem.

Quote:
Originally Posted by apalrd View Post
Is the architecture designed for the subsystems to store the subsystem state, or for the commands to store subsystem state?
The state of a subsystem is kept track of by the subsystem.
The state of a command sequence is kept track of by the commands and scheduler.

A subsystem only knows how to interact with itself. It can turn a motor on/off, it can read the status of a sensor. Alone, it doesn't do you much good. The subsystem alone is not intended to be completing complex tasks.
The command keeps track of state through it's methods (previously mentioned). The command has something it needs to do, in the execute() method. Then a check is performed to see if a terminating condition is met, in the isFinished() method. So the command itself has a notion of what needs to be done and when it should consider the task complete.

Multiple commands can be linked together (series or parallel execution) in a Command Group. This allows more complex tasks to be built up from a simple set of commands, simply by calling the commands in the right order.

For example if you wanted to aquire a ball from a made up robot with a drop down intake, a lift system which moved balls vertically,you may have the following subsystems and methods within them:
Dropdown_Intake()
raise()
isRaised()
lower()
isLowered()
collect()
discard()
Elevator_Lift()
driveUp()
driveDown()
isBallPresent()
The above subsystems and methods strictly set output values and read input values.

You may then create the following commands:
RaiseIntake()
LowerIntake()
CollectIntake()
And then the following Command Group to aquire one ball:
RaiseLiftUntilBallPresent()
it could execute the following commands in sequence
LowerIntake()
ElevatorUp()
CollectIntake()
and the group of commands could terminate when ElevatorLift.isBallPresent() returns true.

Other command groups could then be created as necessary re-using some of the above commands for other teleop or autonomous functions.
__________________
http://team2168.org
  #15   Spotlight this post!  
Unread 28-11-2012, 12:17
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,544
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Command Based JAVA - Basic Tutorial

Quote:
Originally Posted by Ether View Post
That goes to the heart of what I was asking. What you've described sounds like you have to write a state machine if you want time delays and/or wait for events like limit switches etc
The scheduler handles some of that for you. You can register a command to run at an event for a button or switch (eg when pressed, when released, while held), and the scheduler will poll it for you and trigger the command. You can also run several commands consecutively, or in parallel by defining a Command Group. However, if you want to do something complex, you would have to implement your own state machine.

I've been playing with the command based system, and our 2012 robot which was implemented in a huge, overly complicated, state machine in LabVIEW was able to be reduced to about 20 fairly simple commands without the need for additional state machines.

Quote:
Originally Posted by Ether View Post
I think you meant abort the first and go? Otherwise, you could get some pretty funky behavior when returning from the interrupt.
You are correct that it would be more proper to call it an abort. However, interrupted is the term that the command based library uses. There is an optional method for a command to define that allows it to clean up before it is interrupted.

Last edited by Joe Ross : 28-11-2012 at 12:35.
Closed Thread


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