![]() |
Autonomous in iterative robot
We are very uncertain on how to run autonomous in iterative robot. I have searched much code on github and read tons of post here. I don't see a lot of Boolean management in the code I have have found. Using Boolean logic to protect sections of logic was the only way we could get autonomous to work at all last year. What that means is, that the logic in the first part of the autonomous is executed based on some Boolean condition, while later logic is protected by other Boolean logic whose conditions have not been met. This is just an example, I am not talking about timers, it applies to any logic in iterative autonomous.
If timerA < 5 && a==true && b==false && c==false Then do some work the next section of logic is dependent on Since timeA is done set it's Boolean a=false and b=true If timerB < 2 && a==false && b==true && c==false Then do some more work and complete by managing more Booleans Unless we used Booleans to mange state at any given time the robot would not work because all the code would execute simultaneously. We can handle Boolean arrays and the for loops to load them. We are really struggling to get any autonomous working at all because of the amount of Booleans we need to protect all the logic from executing simultaneously. So here is the question I am trying to answer. I see posts here and code in github but see very little if anything about autonomous iterative and Boolean management. If anything I see the opposite. I see these very elegant code sections but as far as i can tell they won't work. Are we missing something about autonomous iterative that everyone is doing to keep the logic from executing simultaneously, but we have missed? Any guidance would be greatly appreciated. Thanks |
Re: Autonomous in iterative robot
One of the simplest and easiest ways to have logic for autonomous not run at the same time is to use Thread.sleep(). It lets you run code, have the code halt for a set amount of milliseconds/seconds, then proceed with more code. An example:
Code:
public void autonomousInit() {Also, in the event you want to do multi-threading, let me know and I'll help you out there :P |
Re: Autonomous in iterative robot
Sorry, for the earlier post (I posted my answer to a different thread to this thread by mistake).
Here are some suggestions to avoid the long boolean array pattern:
As far as using a state based iterative method, there are probably many approaches. Here is a rough framework that include a timer to get you started: Code:
// Keeps track of time state was enteredHope that helps. |
Re: Autonomous in iterative robot
Quote:
OP, I would recommend going with the state machine approach that pblankenbaker describes. It closely mirrors what you are currently doing but adds more context and manageability. |
Re: Autonomous in iterative robot
These are all good suggestions and thank you. I am very interested in multi threading not quite sure how it works, but am pretty sure We are going to need it based on my understanding. I'd love to hear about it and see examples.
My question was more of a sanity check because I don't see a lot of Boolean and state discussion in Delphi or in code on git hub. I don't see the Boolean management technique that we used last year with our autonomous routine. So I am wondering if I have missed something obvious, like checking to see if the computer is plugged in, or the wpilib page in the Java section that demonstrates 10 ways to run iterative autonomous. On my team we call it "iterative choking" when the wheels start sputtering we know that that iterative is executing two different motor speeds simultaneously because our logic is flawed and lacks Boolean gatekeepers. Is the problem really about managing state in autonomous? Maybe I am searching on the wrong terms. The example with the case statements is really good and make sense. We are actually trying to avoid timers this year and rely on sensors. I use timers in my example because timers are used a lot by everyone. Do you guys experience iterative choking too? Or did I completely miss the lecture on iterative autonomous? Thanks |
Re: Autonomous in iterative robot
Quote:
Code:
switch (state) |
Re: Autonomous in iterative robot
Are using a command based approach? The command based approach seems to make it pretty simple. Keep grouping commands together until you get up to the full autonomous command.
If you're trying to maintain something in a state based approach, i would instead use an enum to manage the state. Then it could only be in one state and those states will have commands or actions assigned to them. It will also make it easier to write the logic to determine your state. Let me know if you have more questions. |
Re: Autonomous in iterative robot
Quote:
Case1: If (encoder < 400 && case1-Boolean == true && case2-Boolean == false) Then do some work State++ Break; Case2: If (encoder < 400 && case1-Boolean == false && case2-Boolean == true) Do some other work. Is there a way in eclipse to step throu the code while it is executing on the rio? |
Re: Autonomous in iterative robot
Quote:
|
Re: Autonomous in iterative robot
You can step through a Robot program in Eclipse using the debug mode and break points. See:
http://wpilib.screenstepslive.com/s/...-robot-program Be very, very careful when debugging code that involves movement. You may need to unplug motors or at a minimum make sure your robot is up on blocks. |
Re: Autonomous in iterative robot
Thank you both for the reply. It does have breaks, and I instrumented it so I could see where the code was in the console. It clearly was jumping into the 2nd if statement in the second case statement because it was checking for the same encoder value range.
We saw the same behavior last year and it was resolved with an army of Booleans. Either I missed the lecture on autonomous, or console cannot keep up, or what I a trying to do is more ambitious than the rio can handle. i am to see if there is a way to tail output from a log in putty. |
Re: Autonomous in iterative robot
Quote:
|
Re: Autonomous in iterative robot
Quote:
|
Re: Autonomous in iterative robot
It's late in the game for a change, but depending on how much code you've written so far, definitely look into the command based programming (can be found here: http://wpilib.screenstepslive.com/s/.../13809/c/88893 (or the full pdf manual here: http://wpilib.screenstepslive.com/s/4485/m/13809/pdf)
I've done state based programming before, and was kind of my "go to" way of programming. Command Based has a lot of advantages over the state machine way, and doesn't have that big of a learning curve if you already feel comfortable programming in Java |
Re: Autonomous in iterative robot
Hi mikets
Thanks for replying. I am hesitant on putting the code in because they often turn into code critiques rather than try to fix the problem. I'd send it to you as a private message after I clean it up. We tried lots of different things, tonight including calling classes to make the motors go. The robot is on blocks. Essentially the first case statement reads the encoder to 10K clicks, then switches, then reads between 10K and 20K clicks, and then switches into the final logic which changes state to go to the next case. It resets the encoder to zero, increments the state variable pop's into the control logic in case two and sputters like it's executing 3 different motor speeds simultaneously. What I call iterative choking. Maybe it is a CANTalon thing. The bigger problem is this was supposed to be a simple proof of concept to have the robot drive in a straight line and stop. So we could measure the actual distance to speed calculations. It's really turned into a major challenge. I am not ruling out operator error at all, however, I am not so certain these statements are really protecting the motors from other code. We checked for break. We will keep checking for logic errors. I will send you the code when I clean it up in a private email. |
help
Down below is my code and we want the robot to drive with arcade with a xbox controller also plz help me to get it to turn. And we are using the standard wheels on the robot
package org.usfirst.frc.team5713.robot; import edu.wpi.first.wpilibj.IterativeRobot; import edu.wpi.first.wpilibj.Joystick; import edu.wpi.first.wpilibj.RobotDrive; import edu.wpi.first.wpilibj.livewindow.LiveWindow; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.Talon; public class Robot extends IterativeRobot { RobotDrive drive = new RobotDrive(1,2,3,4); Joystick driveStick = new Joystick(0); Joystick controlStick = new Joystick(1); Talon frontLeft = new Talon(1); Talon rearLeft = new Talon(2); Talon frontRight = new Talon(3); Talon rearRight = new Talon(4); public void robotInit() { drive = new RobotDrive(1,2,3,4); driveStick = new Joystick(0); controlStick = new Joystick(1); frontLeft = new Talon(1); frontLeft.enableDeadbandElimination(true); frontLeft.set(+1.0); rearLeft = new Talon(2); rearLeft.enableDeadbandElimination(true); rearLeft.set(-1.0); frontRight = new Talon(3); frontRight.enableDeadbandElimination(true); frontRight.set(+1.0); rearRight = new Talon(4); rearRight.enableDeadbandElimination(true); rearRight.set(-1.0); public void teleopInit(){ drive = new RobotDrive(1,2,3,4); driveStick = new Joystick(0); controlStick = new Joystick(1); frontLeft = new Talon(1); frontLeft.enableDeadbandElimination(true); frontLeft.set(-1.0); rearLeft = new Talon(2); rearLeft.enableDeadbandElimination(true); rearLeft.set(+1.0); frontRight = new Talon(3); frontRight.enableDeadbandElimination(true); frontRight.set(-1.0); rearRight = new Talon(4); rearRight.enableDeadbandElimination(true); rearRight.set(+1.0); } public void teleopPeriodic() { while (isOperatorControl() && isEnabled()) { drive.setSafetyEnabled(true); double joystickLeftY = driveStick.getRawAxis(2); double joystickLeftX = driveStick.getRawAxis(1); drive.arcadeDrive(joystickLeftY, joystickLeftX, true); Timer.delay(0.01); } } also our team is using standard wheels and we have the middle wheel and back wheel connected to drive train and the middle wheel has two motors and the same applies to the other middle wheel. for going forward and backward can someone plz help |
| All times are GMT -5. The time now is 10:28. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi