Quote:
Originally Posted by Fauge7
suggestion #1: dont use iterative, Java is an object oriented programming for what it is meant for, objects!
|
I hope you aren't suggesting that this team completely rewrites their robot code to work in a new style a few weeks before the competition. "Don't use iterative" is a pretty overgeneralized statement to make: Plenty of teams use it, some to great success.
The main difference between Iterative and Command based besides structure and style is that Iterative is continuous and periodic, while Command based is built around being asynchronous. While it is also true that the Command based model does use more of the features of object oriented programming, that does not necessarily always make it better in this environment.
Quote:
Originally Posted by Fauge7
suggestion #2: post your code so we might be able to help
|
This. Even if you can only post the section that you are having trouble with, any amount of context can help us find a solution.
Quote:
Originally Posted by Fauge7
Code:
boolean buttonToggle = false;
if (button.isPressed()) {
buttonToggle = !buttonToggle;
}
//code for using it:
if (buttonToggle) {
motor.setSpeed(someSpeed);
}
|
This would work for a command based robot, but because of the periodic nature of Iterative robot, this code gets run about 50 times a second. Therefore, if the driver holds the button for more than 20ms, the toggle variable will flip more than once.
One solution is to only flip the variable on the rising edge of the button press - to check if the button is pressed, but was not pressed earlier. Example below.
Code:
boolean buttonToggle = false;
boolean buttonLast = false;
public void runToggle(boolean buttonValue){
if(buttonValue && !buttonLast)
buttonToggle = !buttonToggle;
buttonLast = buttonValue;
if(buttonToggle)
motor.setSpeed(someSpeed)
}
__________________

Carson Finalists (4488, 67, 225, 5659)

2x District Winner + Gracious Professionalism & Engineering Excellence, DCMP Finalist and Entrepreneurship

Galileo Finalists (1153, 4488, 1318, 1218)

2x District Winner + Chairman's & Industrial Design, DCMP Finalist and Quality Award

Oregon Rookie All Star, Curie Rookie All Star