Go to Post There's a fine line between cockiness and confidence. Confidence is one of the major keys to success and happiness in life. As long as one can carefully stay on the right side of the line, staying connfident while remaining humble, and ego can be quite beneficial. - Karthik [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Spotlight this post!  
Unread 01-03-2016, 16:09
BL0X3R BL0X3R is offline
Registered User
AKA: Nick
FRC #4488 (ShockWave)
Team Role: Programmer
 
Join Date: Mar 2013
Rookie Year: 2013
Location: Hillsboro
Posts: 43
BL0X3R is on a distinguished road
Re: Java Iterative-Robot: Toggle Buttons?

Quote:
Originally Posted by Fauge7 View Post
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 View Post
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 View Post
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
http://www.chiefdelphi.com/forums/image.php?type=sigpic&userid=74752&dateline=139804  7731 Oregon Rookie All Star, Curie Rookie All Star
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 06:42.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi