|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#16
|
||||||
|
||||||
|
Re: Command Based JAVA - Basic Tutorial
Quote:
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. 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
|
||||
|
||||
|
Re: Command Based JAVA - Basic Tutorial
Quote:
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
|
||||
|
||||
|
Re: Command Based JAVA - Basic Tutorial
Quote:
Quote:
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()The above subsystems and methods strictly set output values and read input values.raise()Elevator_Lift() You may then create the following commands: RaiseIntake()And then the following Command Group to aquire one ball: RaiseLiftUntilBallPresent()it could execute the following commands in sequenceand 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. |
|
#19
|
||||||
|
||||||
|
Re: Command Based JAVA - Basic Tutorial
Quote:
Quote:
Quote:
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
|
||||
|
||||
|
Re: Command Based JAVA - Basic Tutorial
Quote:
|
|
#21
|
|||
|
|||
|
Re: Command Based JAVA - Basic Tutorial
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
|
||||||
|
||||||
|
Re: Command Based JAVA - Basic Tutorial
You'd also have to add it to every other command that requires that subsystem, which gets messy.
|
|
#23
|
|||
|
|||
|
Re: Command Based JAVA - Basic Tutorial
Quote:
Meanwhile, your location system always just runs a default command that maintains the location udpates. |
|
#24
|
||||
|
||||
|
Re: Command Based JAVA - Basic Tutorial
Quote:
|
|
#25
|
||||
|
||||
|
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. |
|
#26
|
|||
|
|||
|
Re: Command Based JAVA - Basic Tutorial
Thank You, so much this is great
![]() |
|
#27
|
||||
|
||||
|
Re: Command Based JAVA - Basic Tutorial
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|