![]() |
Re: Share you Autonomous
We used to hardcode our autonomous routine in C++, but we found that compilation and deploy times added too much overhead and made it hard to quickly change routines on the fly.
To address this issue, we tried a scripted approach this year to autonomous. The first iteration of our "scripting" approach was a simple list of commands that the C++ codebase interpreted step-by-step: Code:
# sample one ball autoCode:
parallel(load(), turn(30.0))We looked at a lot of possibilities, and we decided on Lua, a scripting language popularly used in video games where processing has to finish in 20-30 millisecond time steps. As a plus, an open-source ANSI-C interpreter was available. We put together a quick prototype, exposing C++ functionality to Lua using its aliasing feature. However, we quickly realized that an issue inherent to using Lua (or any other general-purpose scripting language, for that matter) was that we lost the step-by-step and parallelization functionalities. At the same time, we didn't want to have to pause execution of the main robot loop to run our autonomous routine or have to coordinate multi-threaded execution. It turns out that Lua's coroutine functionality is perfect for achieving this functionality. When the Lua code calls a C++ function, the function pauses execution of the script and keeps a tab on the requested function. On each update of the script interpreter, the function is checked for completion, and upon completion, the script is resumed and is run until the next pause or the end of the script. This is great because from the script's perspective, everything is clean and nice and you don't have to deal with waiting for routines to complete and whatnot. The next issue we wanted to address was running parallel routines. To do this, we created two functions, beginActionGroup(name:string) and endActionGroup(). If calls to C++ functions are made between these two functions, the script delays execution and instead adds the routine to a list instead of running the routine immediately (and yielding execution of the script). When the action group is run, each of the sub-routines are run in parallel. To run action groups in parallel, the function runParallel(group1:string, group2:string, group3:string, ...) is called and behaves like any other routine (e.g. script execution is paused until completion). With these issues solved, we were able to write the following for our double ball hot routine: Code:
--[[Code:
function dribbleDrive(distance, waitTime) |
Re: Share you Autonomous
Seeing all the examples here makes me realize that there are major differences not only in coding styles or technologies used but also in the logic implemented. I wonder how much what teams do in autonomous is influenced by the style in which it's written.
At each step in our autonomous program we had multiple things that could happen. Basically, there was: 1) What if autonomous mode ends? 2) What if you're running out of time in autonomous mode? 3) What if the normal action of the step has completed? 4) What if none of the above have happened? This seems like it would be horribly awkward to code in the styles that most people appear to be using but it was no big deal for us since we had an explicit state machine. It seems weird to me that even teams that care enough to embed a Lua interpreter or write their own scripting language to run their autonomous modes don't seem to be doing anything like this. |
Re: Share you Autonomous
My answers are in bold red:
Quote:
|
Re: Share you Autonomous
Quote:
Code:
State next_state(State current_state){Does your robot always do the same thing on abortion of the Lua script? It seems like it should be possible to make it do different things since you could call some C++ function to set a variable to remember what mode you should go to after the script finishes. |
Re: Share you Autonomous
Quote:
Is it possible? Sure! Lua is really flexible in that you can call into C++, so yes, you would be able to call a C++ function to set a flag, and after autonomous your code could read that flag and act upon it. |
Re: Share you Autonomous
We implemented a simple state-machine framework this season. It was used in both teleop and autonomous.
It worked as such: States (which were a lot like commands) could return SUCCESS, FAILURE, or NOT_DONE. StateMachines would add a number of states into them, then map the state transitions. It would look something like Code:
int one = new DetectHotState(); //returns SUCCESS for left, FAILURE for right |
Re: Share you Autonomous
Here's our 2-ball script. Works off of a custom JavaFX text editor on the developer laptop than is FTP'd and saved on the crio in raw binary format.
Might open source it before 2015, not sure. Code:
Auton: 2 MoveKickTargetingIndenting doesnt actually matter, but linebreaks do. The way the commands work is as follows Code:
public class RequestPeriodic |
| All times are GMT -5. The time now is 23:57. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi