![]() |
Java Iterative-Robot: Toggle Buttons?
Hey CheifDelphi,
I was wondering if anyone knows how to use toggle buttons in an Iterative-Robot in Java. :) Here is what I want the code to do: Apply a command to the robot when a button is pressed until a button is pressed. Is there a way to create commands in an Iterative Robot? I apologize in advance for inconveniencing you guys :( |
Re: Java Iterative-Robot: Toggle Buttons?
suggestion #1: dont use iterative, Java is an object oriented programming for what it is meant for, objects!
suggestion #2: post your code so we might be able to help suggestion #3:look at the code below here is some example code for suggestion number 1 Code:
boolean buttonToggle = false; |
Re: Java Iterative-Robot: Toggle Buttons?
Quote:
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:
Quote:
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; |
Re: Java Iterative-Robot: Toggle Buttons?
Quote:
Code:
boolean buttonToggle = false;Edit: Follow BL0X3R's suggestion to achieve true toggling functionality. |
Re: Java Iterative-Robot: Toggle Buttons?
Our team developed a short extension of the Joystick class implementing a couple of useful methods for cases like this.
One of those is a "getToggleButton(int buttonNumber)" that you can use just like getRawButton() in Joystick, the difference being that the return value of the method starts off false and alternates between true and false with each press of the button. The code is up in our github repo, here's a link to the specific class (robovikingStick) Hope that helps! - Ron Team #2607 controls mentor |
Re: Java Iterative-Robot: Toggle Buttons?
|
Re: Java Iterative-Robot: Toggle Buttons?
Quote:
Quote:
|
| All times are GMT -5. The time now is 04:28. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi