Go to Post I thanked the tradesmen on our team the same way i do ever year with a handshake and a "thanks for helping us guys", - Mike Schroeder [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
  #16   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,600
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.
  #17   Spotlight this post!  
Unread 28-11-2012, 12:57
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,126
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 Joe Ross View Post
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.
Joe, are you saying that you rewrote your 2012 LabVIEW code in Java using the command-based approach and successfully ran it on the robot?

Could the "huge, overly complicated, state machine in LabVIEW" have been partitioned and cleaned up to give results similar to the Java command-based system, or does LabVIEW not readily lend itself to that?


  #18   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: 443
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
  #19   Spotlight this post!  
Unread 28-11-2012, 16:06
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,600
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
Joe, are you saying that you rewrote your 2012 LabVIEW code in Java using the command-based approach and successfully ran it on the robot?
Yes.

Quote:
Originally Posted by Ether View Post
Could the "huge, overly complicated, state machine in LabVIEW" have been partitioned and cleaned up to give results similar to the Java command-based system, or does LabVIEW not readily lend itself to that?
It certainly could be cleaned up to much better then it is now, but it wouldn't be as clean as the Command based code. There's a lot of stuff going on in the background that makes the Command based code easier to use. I'm sure something similar could be implemented in LabVIEW, but it would take someone fairly skilled in LabVIEW to make it easy enough for a novice LabVIEW programmer to use.

Quote:
Originally Posted by otherguy View Post
The scheduler only interfaces with the commands. Commands then interface with the methods of a subsystem.


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
I do agree that in most cases the subsystem can update it's state in response to command.

There are sometimes that the state of a subsystem needs to be periodically updated, and isn't (necessarily) the result of a command. For example, consider a chassis subsystem that is keeping track of of the X-Y Location of the robot on the field using encoders and a gyro. The location may change when the robot isn't supposed to be moving, because the robot may be bumped. In order to get accurate results, you need to operate on small enough timesteps of data. If you don't have a command that is calling the updateLocation method, you will lose data.
  #20   Spotlight this post!  
Unread 28-11-2012, 16:36
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: 443
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 Joe Ross View Post
There are sometimes that the state of a subsystem needs to be periodically updated, and isn't (necessarily) the result of a command. For example, consider a chassis subsystem that is keeping track of of the X-Y Location of the robot on the field using encoders and a gyro. The location may change when the robot isn't supposed to be moving, because the robot may be bumped. In order to get accurate results, you need to operate on small enough timesteps of data. If you don't have a command that is calling the updateLocation method, you will lose data.
I would think your default command for the chassis would take care of calling the updateLocation() method for you if/when it's required?
__________________
http://team2168.org
  #21   Spotlight this post!  
Unread 28-11-2012, 16:36
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: 947
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

Quote:
Originally Posted by Joe Ross View Post
If you don't have a command that is calling the updateLocation method, you will lose data.
On this note, to those not yet familiar with the system, you can have "default commands" that run when nothing else is using a subsystem. For example, you might have a JoystickDrive command that runs at all times during teleoperated mode, unless you use another command to temporarily take control of the drive. This way, you would just have to make sure you are updating your location in all drive commands.
  #22   Spotlight this post!  
Unread 28-11-2012, 16:55
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,600
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 otherguy View Post
I would think your default command for the chassis would take care of calling the updateLocation() method for you if/when it's required?
You'd also have to add it to every other command that requires that subsystem, which gets messy.
  #23   Spotlight this post!  
Unread 28-11-2012, 17:14
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: 947
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

Quote:
Originally Posted by Joe Ross View Post
You'd also have to add it to every other command that requires that subsystem, which gets messy.
I haven't given a lot of thought to the ramifications, but you could make the location sensors its own Subsystem, which no commands "require". You should still be able to reference the "location system" in other commands to ask it for data, should be safe if you don't modify anything.

Meanwhile, your location system always just runs a default command that maintains the location udpates.
  #24   Spotlight this post!  
Unread 28-11-2012, 22:47
Brian Selle's Avatar
Brian Selle Brian Selle is online now
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: Command Based JAVA - Basic Tutorial

Quote:
Originally Posted by Joe Ross View Post
There are sometimes that the state of a subsystem needs to be periodically updated, and isn't (necessarily) the result of a command. For example, consider a chassis subsystem that is keeping track of of the X-Y Location of the robot on the field using encoders and a gyro. The location may change when the robot isn't supposed to be moving, because the robot may be bumped. In order to get accurate results, you need to operate on small enough timesteps of data. If you don't have a command that is calling the updateLocation method, you will lose data.
You could put in a call to update the position in the periodic loop before the scheduler runs in teleopPeriodic() or put it in teleopContinuous().
  #25   Spotlight this post!  
Unread 29-11-2012, 00:33
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 Based JAVA - Basic Tutorial

The biggest problem I see with calling an update function in a periodic function or having a Command update it is that it breaks the idea of what a Subsystem is supposed to be. Subsystems should be standalone classes with internal state corresponding to some aspect of the robot (eg. sensors, motors) with simple, non-blocking methods that modify that state. Having a periodic update function muddies that picture of a Subsystem.

So if updating from periodic or a Command violates the Subsystem's Subsystem-ness, what can be done instead? The answer was mentioned: make a background thread contained within the class. If you look at WPILibJ's PIDSubsystem, its interface is extremely simple: you have a couple ways to set the setpoint, and a way to read the current "position" (sensor value). Internally, however, there is a TimerTask acting as a PID feedback loop, working periodically. This thread is entirely encapsulated within the Subsystem, and allows the interface to be as simple as it is.

So define a Subsystem to work how you want to think about it: if you want to think about an arm as having a height above the ground, then make that the interface, leaving the rest of the details encapsulated within. If you want to think of a shooter wheel's speed in rpms instead of in [-1,1], you can do that, and implement some sort of feedback controller (like PID or bang-bang) internally. Subsystems are supposed to provide a useful interface to the robot's hardware so that commands can be simpler; sometimes, this means sacrificing a simple implementation (eg. motor power going to an arm) to make a more powerful interface (eg. setting the arm's height, allowing presets that can simplify both teleop and autonomous in a game like Logomotion).

As a rule of thumb for this design, if your Subsystem interface does stuff, you should rethink your setup. A Subsystem can do stuff internally, but its interface should be solely concerned with setting things. Doing things is the Commands' job.
__________________
I code stuff.
  #26   Spotlight this post!  
Unread 29-11-2012, 08:51
kdehaan42 kdehaan42 is offline
Registered User
FRC #2874 (Eagles)
Team Role: Leadership
 
Join Date: Jan 2012
Rookie Year: 2010
Location: Grain Valley
Posts: 15
kdehaan42 is an unknown quantity at this point
Re: Command Based JAVA - Basic Tutorial

Thank You, so much this is great
  #27   Spotlight this post!  
Unread 30-11-2012, 11:57
Dr. Osemwengie's Avatar
Dr. Osemwengie Dr. Osemwengie is offline
Founder and President
no team (Open Robotics University)
Team Role: Leadership
 
Join Date: May 2008
Rookie Year: 2006
Location: Dublin, Ohio
Posts: 28
Dr. Osemwengie is a jewel in the roughDr. Osemwengie is a jewel in the roughDr. Osemwengie is a jewel in the rough
Re: Command Based JAVA - Basic Tutorial

Quote:
Originally Posted by DaveFrederick View Post
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
Open Robotics University (http://www.openroboticsuniversity.net/) applied to participate in tracks C and D of the DARPA Robotics Challenge. Since we are an open-source university, individuals not enrolled in the university worldwide can join our team Open Robotics University to design software and robot for the competition. Here is the link for the DARPA Robotics Challenge: http://www.theroboticschallenge.org/about.php . The prize money for the winner is two million dollars ($2000000.00). I viewed your Command Based Java approach PowerPoint, we looking for individuals with your experience that would like to participate in our projects. We are also interested in individuals that are experts in Autodesk Inventor and mechanical engineering. For more details you can email me at osem@openroboticsuniversity.net
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 15:33.

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