OCCRA
Go to Post I'm a lazy mechanical designer. Any problem I can bunt into the programming world I will. - JamesCH95 [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 5 votes, 5.00 average. Display Modes
  #16   Spotlight this post!  
Unread 12-22-2013, 08:26 PM
garyk garyk is offline
Programming Mentor, 972 and 2643
FRC #2643 (Dark Matter)
Team Role: Mentor
 
Join Date: Dec 2006
Rookie Year: 2005
Location: Santa Clara (Silicon Valley) Calif.
Posts: 171
garyk has a brilliant futuregaryk has a brilliant futuregaryk has a brilliant futuregaryk has a brilliant futuregaryk has a brilliant futuregaryk has a brilliant futuregaryk has a brilliant futuregaryk has a brilliant futuregaryk has a brilliant futuregaryk has a brilliant futuregaryk has a brilliant future
Re: C++ Toggle Button

Quote:
Originally Posted by thelegend View Post
I am trying to make a toggle for switching between Arcade Drive and Tank drive. I wrote and tested this code but the only result I get is a switch between Tank to Arcade, not the other way back. I have such a complicated system because I believe that if I simply set a variable to be True or False, it won't compensate for if the driver holds on to the button. That's why I have a clause in there that checks if the button has been released.

If you find any issues, please reply!

<< code deleted >>
Note to future EEs - and not pertaining to our FRC/FTC control systems - mechanical switches "bounce" when they close, there are multiple on/off events before the switch consistently stays closed. This may not matter if you're just turning something on, but it will confuse any "toggle" algorithms, registering multiple toggles. Mechanical switches have to be "debounced", which can be done with an r-s latch in hardware, or by designing in an time interval after the first make, in which other transitions are ignored. Our joystick buttons are debounced in this manner because they provide a clean off => on transition. I haven't tried it, but I think if one designed a toggle algorithm for, say, a microswitch (like we use for limit switches) connected to a digital input of the Digital Sidecar, one would see multiple toggles for one switch "make."

Apologies, I don't remember if there are contact bounces when a mechanical switch disconnects. When I can get to our control system I'll test this out and post an update.

Remember, again, we don't need to worry about this for our joystick buttons, they've been debounced for us.
__________________

Silicon Valley Regional 2005, 2006 972
Silicon Valley Regional 2007 668 Xerox Creativity Award
Championship Event 2007 668
Portland Regional 2008 668
Silicon Valley Regional 2008 668, 972
Beta Test Team 2008 668 (with 100 & 254)
Silicon Valley Regional 2009 668 Regional Chairman's Award; 2643
Sacramento Regional 2009 668 Winning Alliance (thanks, 1717 & 2473!), 2010 Winning Alliance 3256
CalGames 2006, 2007, 2008, 2009, 2010, 2011 Field Tech
NorCal FTC Regional 2008, 2009 Inspector
Championship Event 2009
San Diego, Silicon Valley Regionals; Champ. Event 2010 668, 2643, 3256
Silicon Valley, Madera Regional 2012 2643
WRRF Programming Instructor 2006-2016
Regional Woodie Flowers Award 2014 2643 Utah Regional

Reply With Quote
  #17   Spotlight this post!  
Unread 12-23-2013, 03:02 AM
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics Club)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 799
mikets is a name known to allmikets is a name known to allmikets is a name known to allmikets is a name known to allmikets is a name known to allmikets is a name known to all
Re: C++ Toggle Button

Quote:
Originally Posted by garyk View Post
Note to future EEs - and not pertaining to our FRC/FTC control systems - mechanical switches "bounce" when they close, there are multiple on/off events before the switch consistently stays closed. This may not matter if you're just turning something on, but it will confuse any "toggle" algorithms, registering multiple toggles. Mechanical switches have to be "debounced", which can be done with an r-s latch in hardware, or by designing in an time interval after the first make, in which other transitions are ignored. Our joystick buttons are debounced in this manner because they provide a clean off => on transition. I haven't tried it, but I think if one designed a toggle algorithm for, say, a microswitch (like we use for limit switches) connected to a digital input of the Digital Sidecar, one would see multiple toggles for one switch "make."

Apologies, I don't remember if there are contact bounces when a mechanical switch disconnects. When I can get to our control system I'll test this out and post an update.

Remember, again, we don't need to worry about this for our joystick buttons, they've been debounced for us.
Yes, debounce could be an issue if you are using a tight loop monitoring the switches. But I assume a reasonable robot loop will have a delay in it, typically between 20-100 msec. That is the time interval where you ignore all the bounces of the switches. Our team uses our own "Multi-tasking Robot" class instead of the SimpleRobot or the IterativeRobot templates that provides a very constant timed loop. This takes care of all the debounce issue automatically.
__________________
Reply With Quote
  #18   Spotlight this post!  
Unread 03-02-2018, 10:43 PM
ewpratten ewpratten is offline
Registered User
AKA: Evan Pratten
FRC #5024 (Raider Robotics)
Team Role: Programmer
 
Join Date: Feb 2018
Rookie Year: 2016
Location: London ON, Canada
Posts: 3
ewpratten is an unknown quantity at this point
Re: C++ Toggle Button

With these solutions, wouldn't the bool just flicker between the two states if the button is held? is there any way to fix this?
Reply With Quote
  #19   Spotlight this post!  
Unread 03-02-2018, 10:53 PM
SoftwareBug2.0's Avatar
SoftwareBug2.0 SoftwareBug2.0 is offline
Registered User
AKA: Eric
FRC #1425 (Error Code Xero)
Team Role: Mentor
 
Join Date: Aug 2004
Rookie Year: 2004
Location: Tigard, Oregon
Posts: 551
SoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond repute
Re: C++ Toggle Button

Quote:
Originally Posted by ewpratten View Post
With these solutions, wouldn't the bool just flicker between the two states if the button is held? is there any way to fix this?
The idea is that it only goes between states when it sees the input change from being low to high. Since a button constantly being held should result in no input state changes, the output should not change. I can elaborate if you're interested.
Reply With Quote
  #20   Spotlight this post!  
Unread 03-03-2018, 08:57 AM
ewpratten ewpratten is offline
Registered User
AKA: Evan Pratten
FRC #5024 (Raider Robotics)
Team Role: Programmer
 
Join Date: Feb 2018
Rookie Year: 2016
Location: London ON, Canada
Posts: 3
ewpratten is an unknown quantity at this point
Re: C++ Toggle Button

Here is my solution:

bool toggle = false;
if (pJoyDrive->GetXButtonReleased()){ toggle = !toggle; }
Reply With Quote
  #21   Spotlight this post!  
Unread 03-05-2018, 12:36 PM
SoftwareBug2.0's Avatar
SoftwareBug2.0 SoftwareBug2.0 is offline
Registered User
AKA: Eric
FRC #1425 (Error Code Xero)
Team Role: Mentor
 
Join Date: Aug 2004
Rookie Year: 2004
Location: Tigard, Oregon
Posts: 551
SoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond reputeSoftwareBug2.0 has a reputation beyond repute
Re: C++ Toggle Button

Quote:
Originally Posted by ewpratten View Post
Here is my solution:

bool toggle = false;
if (pJoyDrive->GetXButtonReleased()){ toggle = !toggle; }
The main problem here is that you need to make the variable "toggle" live longer than the current iteration of the loop.
Reply With Quote
Reply


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 09:50 PM.

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


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