![]() |
Impressions: Command Based Robot
So, this year I decided to climb out of my familiar cave and try something new with our robot coding by switching to the (C++) Command Based pattern (this decision was helped by the great presentation from Brad Miller at CMP last year), rather than using my usual home-brewed iterative robot (still C++).
Overall, I am glad I made the switch, because our robot this year is much more complex than past years, and I know I would have struggled with tuning various systems using the 5 analog inputs on the Driver Station dash board; but I've also caught myself longing to just ditch the commands and just code a bunch of GetRawButtons in TeleopPeriodic and an Iterative switch case in AutonomousPeriodic (which I know I can do without wholly ditching the command based pattern). A lot of the problems I've had can be attributed to unfamiliarity with the pattern, but there are a lot of cases where the pattern simply feels to restrictive or requires a lot of added complexity to implement something fairly simple. To the point, I thought it might be helpful/interesting to share what I perceived to be the pros and cons of the command based pattern: Pros: Cons: I think next season (assuming I am still with my team), I am certainly going to use RobotBuilder, SmartDashboard, and LiveWindow, however I don't know if I'm a fan of the Command system as a universal pattern, it certainly works great for special modes and cases, but for general robot operation it seems like it overcomplicates things; and in autonomous, simple sequences are very easy to build, however the command structure starts to feel burdensome when we begin trying to coordinate multiple actions to be time efficient. |
Re: Impressions: Command Based Robot
One thing that will help with having a ton of similar commands is to try to make your commands as reusable as possible.
We have a DeployArmCommand this year that pretty much covers all of the uses we need. We pass in a boolean if the arm should be deployed or not and a speed at which the rollers should spin. This command can then be used for any situation we need it for. One of the biggest cons so far IMHO with the command based structure is the lack of conditionals for command groups. What we did to get around this was save the state that we need from a previous command in that command and pass the command in to the next command through the constructor. That way we can access the state of the first command after it has finished executing. Overall we have very much enjoyed using the command based structure as I believe it is a great tool to teach OOD. |
Re: Impressions: Command Based Robot
One of the things we have realized that help cut down on the "weird and goofy commands" or commands that rely on each other is that a command only needs to "require" Subsystems that it intends to write to or change. If you're using a Subsystem in a read-only capacity you should be able to use it anywhere you want anytime you want.
|
Re: Impressions: Command Based Robot
Quote:
If you build this functionality into your command, then does that simply leave your subsystem as container classes for actuators and sensors? |
Re: Impressions: Command Based Robot
Quote:
If you'd like I can send you a presentation that our team did for Command Based programming, it's for Java, but a lot of the concepts should be the same. It is very basic though, so most of it is probably going to be at a lower level than you'd like. |
Re: Impressions: Command Based Robot
Quote:
Code:
addSequential(new DropIntakeCmd());This sort of construction allowed us to write our sequences and autons via flowcharting on a chalkboard. However, after attempting CommandBase last year with C++ I can say that it was a bit more of a pain. Java is much much cleaner in my opinion. Codebase for reference: https://github.com/FRC125/NU14 |
Re: Impressions: Command Based Robot
Quote:
We've ended up putting Safety logic in the subsystem, so that everyone is guaranteed to use it, but put Business logic in the command. |
Re: Impressions: Command Based Robot
Quote:
|
Re: Impressions: Command Based Robot
Quote:
Also, I cannot wait until next year when we can use ENUMs to send in different states to subsystems and commands. |
Re: Impressions: Command Based Robot
As an example of what I mean by business logic, here is the bulk of code from our collector:
We need to know the state of the collector when we control our arm (the two can collide while the collector is up). So having the collector subsystem know it's state seems like the appropriate way to manage this. Code:
void Collector::MoveCollector(bool extend) |
Re: Impressions: Command Based Robot
Quote:
Quote:
This became a problem in autonomous as well, since the spin-up routine didn't end, a seperate command needed to be created to do the same thing, but with a different life-span. (I've since realized that adding this in parallel would have been the better solution, however the nuances of the parallel/sequential weren't clear at the time) |
Re: Impressions: Command Based Robot
Quote:
Quote:
Quote:
Code:
addSequential(new SpinUp(speed));Quote:
Code:
// Does nothing, and keeps doing it foreverQuote:
|
Re: Impressions: Command Based Robot
Quote:
|
Re: Impressions: Command Based Robot
Quote:
I really like RobotBuilder as a tool and have used it extensively since beta testing last year. I've come to appreciate the structure it builds. In fact, I start all my rookie programming sessions with it and every student who shows a mild interest in programming. Our commands this year are limited to a few items we need to do infrequently. I don't see us going back to commands unless a student shows a very strong interest. |
Re: Impressions: Command Based Robot
As others have mentioned, one of the keys to command-based programming is dividing your robot up into as many different subsystems as possible, not just a few broad ones. When you put 2 actuators which don't always move at the same time in a subsystem, you are going to run into problems. I found this especially true when I was attempting to improve the code that our old programmer made last year. One of the big features I wanted was the ability for the operator to turn on the shooter wheel before we were ready to shoot, that way we wouldn't have to wait as long once we were lined up. Unfortunately, he had put the shooter motor in the same subsystem as our complex indexing system, and so implement such a simple feature as the ability to toggle a motor on/off required a huge restucturing of our code. So I guess this is one con.
Although I am generally a big advocate for command-based. I feel as though the benefits it offers are worth the extra hassle. And honestly, it works perfectly well and can do whatever you need it to do so long as you code it in the "correct" way (although that is much easier said than done). |
| All times are GMT -5. The time now is 02:34. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi