![]() |
Switching to Iterative
Hey! I've been working on some code that seems a bit too elaborate for the SimpleRobot template, so I wanted to try out Iterative. I looked for a template, and didn't find one, so then I searched the forum here, and found that the "BuiltinDefaultCode" is essentially the template, with a lot of code I'd probably never use mixed in. I realized that I actually know very little about FRC programming (or at least feel like it). Could someone please help explain a the different methods in the BuiltinDefaultCode (and some of the other things they threw into the code for kicks)? I've removed most of the "actual code" that I'm pretty sure isn't necessary (but I still have questions about), and this is what I was left with (in case it helps).
Code:
#include "WPILib.h" |
Re: Switching to Iterative
I can't help too much with that code, but if you want a simpler Iterative Robot to play with team 2704 made a custom iterative robot this year, you can get a PDF copy of our code at http://www.firstplusplus.com/samplerobot-code.html
Our iterative robot is in our O2C class, if you just want the code it should be: The .h Code:
#ifndef O2C_H // If not DefinedCode:
#include "O2C.h"Edit: If you want to learn how to do Object Oriented Coding for FRC and if you have an NXT our website FirstPlusPlus.com has a full tutorial that can teach you how we do Iterative, Event Driven Coding |
Re: Switching to Iterative
Check out http://users.wpi.edu/~bamiller/WPIRo...ive_robot.html
Quote:
They provide two different types of loops. The basic idea here being that there's stuff that you need to update periodically, like the values you send to your drive motors, but that doesn't have to be done as quickly as possible (waiting 1/100 of a second is OK). But there are other things that you need to do as frequently as possible, like try to detect state changes on a limit switch. You can rely on these functions being called for you repeatedly for as long as the robot is in that state (teleop, auto, disabled). |
Re: Switching to Iterative
Quote:
In particular, the continuous methods no long exist, periodic rate has changed, and there are now test methods. Quote:
|
Re: Switching to Iterative
1 Attachment(s)
Here is what the java iterative template looks like. C++ should be similar.
|
Re: Switching to Iterative
Quote:
Also, if you look at what was originally posted, it contains the continuous functions, so it's possible the OP is not using the latest revision of the base code. |
Re: Switching to Iterative
1 Attachment(s)
I'm using the base code we had at the end of the season this year. One of the volunteers gave us the "latest" update on a flash drive at the competition (thanks, whoever that was!). The original code had these comments, though:
Code:
/** |
Re: Switching to Iterative
Quote:
Quote:
|
Re: Switching to Iterative
Thanks all! So what should have gone into continuous? Is it like the all-encompassing "while isEnabled()" of SimpleRobot? How do teams that use iterative know how often something needs to be called, and on that matter, how do you set how often something gets called (in Periodic)?
|
Re: Switching to Iterative
How 2704 does our code (and it's different than most teams) is we program entirely with Event Driven State Machines, so our code is written as a lot of reactions to what is happening instead of like a script. Then if we want to run it we pretty much just tell the code to go.
Edit: So in periodic the code only gets called as often as you call it, in our code it is called every iteration and figures out what needs to do from that. In 2704's paradigm we assume that our code is called every single iteration, even if it does nothing that iteration. Edit #2: In Periodic it runs through the entire code every iteration, every 50ms all of teleop will run, or all of autonomous will run; wheras in SimpleRobot you write it more like a script, loop here loop there, in Iterative you write it in a lot of State Machines |
Re: Switching to Iterative
That seems like a pretty solid way to do things. Since I started I did some work programming LED patterns with state machines, but am still a bit confused with how to set the rate at which commands happen, and the rate at which each command needs to be executed. Is there some documentation somewhere about this? Like how often you need to query sensors or read joystick values or send motors commands? I still don't understand Periodic(). I thought you put stuff inside it like this:
Code:
UINT16 numloop_within_second = numloops % (UINT32)GetLoopsPerSec(); |
Re: Switching to Iterative
How we would do that type of thing would be like this:
Code:
// in .h:The idea is that you have full control over what runs every iteration, and the entire code runs each iteration. So maybe you only call LED_FLASHER.Run() every time (clock.Now()%5) == 0 (every five miliseconds), but you have full control over what is going on. |
| All times are GMT -5. The time now is 12:19. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi