Go to Post Aaaaah! I think my head just exploded from looking at this awesomeness. You guys are great. This is super cool. :) - Ian Curtis [more]
Home
Go Back   Chief Delphi > Technical > Programming > NI LabVIEW
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 04-02-2011, 23:04
iblis432 iblis432 is offline
Co Captain/Chief Programmer
AKA: Bobby
FRC #2106 (Junkyard Dogs)
Team Role: Programmer
 
Join Date: Feb 2009
Rookie Year: 2008
Location: Virginia
Posts: 146
iblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to behold
turning a push button into a switch

I am trying to get the robot to switch a state based off the single press of a joystick button. I designed a system that i thought would work, but it began constantly switching the state back and forth without me pressing anything every (what I believe based off how i designed it) 10 ms.

I don't have the code with my right now, but in pseudo code this is what i did.

In periodic Tasks
__________________
"Don't worry, programming can fix it"
Reply With Quote
  #2   Spotlight this post!  
Unread 04-02-2011, 23:12
iblis432 iblis432 is offline
Co Captain/Chief Programmer
AKA: Bobby
FRC #2106 (Junkyard Dogs)
Team Role: Programmer
 
Join Date: Feb 2009
Rookie Year: 2008
Location: Virginia
Posts: 146
iblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to behold
turning a push button into a switch

I am trying to get the robot to switch a state based off the single press of a joystick button. I designed a system that i thought would work, but it began constantly switching the state back and forth without me pressing anything every (what I believe based off how i designed it) 10 ms.

I don't have the code with my right now, but in pseudo code this is what i did.

Code:
In periodic Tasks.vi

   10 ms loop
       If button pressed
               if global button data == true
                       set global button data = false
               if global button data == false
                       set global button data = true

In Teleop.vi

   If global button data == true
          set solenoid = forward
   else 
          set solenoid = reverse
So basically, I have two case structures inside each other in the periodic tasks loop thats constantly checking for if the button is pressed, and I THINK I have the state changing when the button is pressed. I put it in the 10 ms loop because i didn't want it switching every cycle just because we held the button for more than a nanosecond, but i didn't want a WAIT slowing down our teleop. Anyway, the state is sent to the Global Robot Data and called in teleop, where a single case structure determines the solenoids.

If anyone can tell me why it did what it did, how to fix it, or another approach altogether, I would very much appreciate it.

I will post the real code ASAP.
__________________
"Don't worry, programming can fix it"
Reply With Quote
  #3   Spotlight this post!  
Unread 04-02-2011, 23:29
WizenedEE's Avatar
WizenedEE WizenedEE is offline
Registered User
AKA: Adam
FRC #3238 (Cyborg Ferrets)
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Anacortes, WA
Posts: 395
WizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to all
Re: turning a push button into a switch

I attached the code we made this year. To use it, just put it in a vi, connect up your momentary button and "switched" output, and then make a shift register and wire that up to the top. The shift register is outside the vi so we can use the same vi many times (if it were inside, the shift register would maintain its values from call to call, not just from loop to loop.)

The problem with your program is that if you press the button for more than 10 ms, it will change twice. My program waits until the button then gets unpressed before going back to the "ready to receive button" state.

I have no idea why your code would switch when you're not pressing the button if that's the actual way you coded it.

My vi works fine in teleop; there's a 20ms loop in teleop and your code has a 10ms loop; it's not a big difference. The 20ms actually helps debounce the switch for us.

NOTE: This code is untested in the real world - you might have to do something to debounce switches. I did test it in the vi with the front panel controls though.

EDIT: Added bundle/unbundle to code to have only one shift register.
Attached Files
File Type: vi Latch.vi (8.2 KB, 28 views)

Last edited by WizenedEE : 04-02-2011 at 23:34.
Reply With Quote
  #4   Spotlight this post!  
Unread 05-02-2011, 00:03
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,579
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: turning a push button into a switch

Quote:
Originally Posted by WizenedEE View Post
I attached the code we made this year. To use it, just put it in a vi, connect up your momentary button and "switched" output, and then make a shift register and wire that up to the top. The shift register is outside the vi so we can use the same vi many times (if it were inside, the shift register would maintain its values from call to call, not just from loop to loop.)

My vi works fine in teleop; there's a 20ms loop in teleop and your code has a 10ms loop; it's not a big difference. The 20ms actually helps debounce the switch for us.

NOTE: This code is untested in the real world - you might have to do something to debounce switches. I did test it in the vi with the front panel controls though.
You can put shift registers or feedback nodes inside the VI if you set it to be reentrant in the VI properties.

Here's how my team does it: http://forums.usfirst.org/showthread.php?t=10544
Reply With Quote
  #5   Spotlight this post!  
Unread 05-02-2011, 00:08
WizenedEE's Avatar
WizenedEE WizenedEE is offline
Registered User
AKA: Adam
FRC #3238 (Cyborg Ferrets)
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Anacortes, WA
Posts: 395
WizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to all
Re: turning a push button into a switch

Quote:
Originally Posted by Joe Ross View Post
You can put shift registers or feedback nodes inside the VI if you set it to be reentrant in the VI properties.

Here's how my team does it: http://forums.usfirst.org/showthread.php?t=10544
Wow, that's pretty amazing.

I guess labview can run the robot without motors.
Reply With Quote
  #6   Spotlight this post!  
Unread 05-02-2011, 00:28
iblis432 iblis432 is offline
Co Captain/Chief Programmer
AKA: Bobby
FRC #2106 (Junkyard Dogs)
Team Role: Programmer
 
Join Date: Feb 2009
Rookie Year: 2008
Location: Virginia
Posts: 146
iblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to behold
Re: turning a push button into a switch

Quote:
Originally Posted by WizenedEE View Post
Wow, that's pretty amazing.

I guess labview can run the robot without motors.

Oh yeah, you can simulate the entire system without even connecting to the cRIO if you know what your doing. I rarely get the robot until the last minute, so I'm usually simulating everything, though my simulation didn't pick up the constant solenoid changing.

Anyway, thanks for the help everyone. will test it out tomorrow.
__________________
"Don't worry, programming can fix it"
Reply With Quote
  #7   Spotlight this post!  
Unread 05-02-2011, 03:06
Acarid Acarid is offline
<3 Nested Clusters
FRC #2521
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Eugene, Oregon
Posts: 10
Acarid is an unknown quantity at this point
Re: turning a push button into a switch

Looks like you accidentally made two topics...
http://www.chiefdelphi.com/forums/sh...ad.php?t=90955
Reply With Quote
  #8   Spotlight this post!  
Unread 05-02-2011, 10:36
Bharat Nain's Avatar
Bharat Nain Bharat Nain is offline
Registered User
no team
Team Role: Alumni
 
Join Date: Jan 2004
Rookie Year: 2003
Location: New York
Posts: 2,000
Bharat Nain has a reputation beyond reputeBharat Nain has a reputation beyond reputeBharat Nain has a reputation beyond reputeBharat Nain has a reputation beyond reputeBharat Nain has a reputation beyond reputeBharat Nain has a reputation beyond reputeBharat Nain has a reputation beyond reputeBharat Nain has a reputation beyond reputeBharat Nain has a reputation beyond reputeBharat Nain has a reputation beyond reputeBharat Nain has a reputation beyond repute
Send a message via AIM to Bharat Nain Send a message via MSN to Bharat Nain
Re: turning a push button into a switch

Quote:
Originally Posted by Acarid View Post
Looks like you accidentally made two topics...
http://www.chiefdelphi.com/forums/sh...ad.php?t=90955
Thanks. I merged the threads.
__________________
-= Bharat Nain =-

Whatever you do, you need courage. Whatever course you decide upon, there is always someone to tell you that you are wrong. There are always difficulties arising that tempt you to believe your critics are right. To map out a course of action and follow it to an end requires some of the same courage that a soldier needs. Peace has its victories, but it takes brave men and women to win them. - Ralph Waldo Emerson
Reply With Quote
  #9   Spotlight this post!  
Unread 06-02-2011, 09:47
wilsonmw04's Avatar
wilsonmw04 wilsonmw04 is online now
Coach
FRC #1086 (Blue Cheese)
Team Role: Teacher
 
Join Date: Dec 2006
Rookie Year: 2007
Location: Midlothian, VA
Posts: 1,887
wilsonmw04 has a reputation beyond reputewilsonmw04 has a reputation beyond reputewilsonmw04 has a reputation beyond reputewilsonmw04 has a reputation beyond reputewilsonmw04 has a reputation beyond reputewilsonmw04 has a reputation beyond reputewilsonmw04 has a reputation beyond reputewilsonmw04 has a reputation beyond reputewilsonmw04 has a reputation beyond reputewilsonmw04 has a reputation beyond reputewilsonmw04 has a reputation beyond repute
Re: turning a push button into a switch

Quote:
Originally Posted by Acarid View Post
Looks like you accidentally made two topics...
http://www.chiefdelphi.com/forums/sh...ad.php?t=90955
Yeah, I told Iblis about this last night. We live in a rather rural county where most of my students only option for net access is dial up. It does some strange things sometimes. Thanks for merging the two.

We are still working on our code. Thanks for all the advice. We will post code this week. Thanks again for all the help.
__________________
Currently: Coach FRC 1086/FTC 93
2006-2011 Coach FRC 2106/FTC 35
If you come to a FRC event to see a robot competition, you are missing the point.
Reply With Quote
  #10   Spotlight this post!  
Unread 04-02-2011, 23:30
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,579
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: turning a push button into a switch

Based on your pseudo-code, I'm not sure why it would be toggling without anything pressed. However, it will definitely toggle every 10 ms when the button is pressed.

What you need to do is to save the state of the button in the previous loop and compare it to the value in the current loop and only do something when it changes. You can save old values using feedback nodes or shift registers.

Take a look at the "button action" examples from http://team358.org/files/programming...2009-/LabVIEW/
Reply With Quote
  #11   Spotlight this post!  
Unread 05-02-2011, 03:02
Acarid Acarid is offline
<3 Nested Clusters
FRC #2521
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Eugene, Oregon
Posts: 10
Acarid is an unknown quantity at this point
Re: turning a push button into a switch

Take a look at this:
http://zone.ni.com/reference/en-XX/h...feedback_node/

When you wire something into a feedback node, it's previous value comes out.
If its previous value is false, and its current value is true, then it was just pressed and you can change states.
This ensures it will only change states once per press.

I attached an example of this here.
Attached Thumbnails
Click image for larger version

Name:	feedbacknode.PNG
Views:	79
Size:	4.2 KB
ID:	9973  
Reply With Quote
  #12   Spotlight this post!  
Unread 05-02-2011, 10:00
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,752
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: turning a push button into a switch

The attached code does work, but may I suggest replacing the negate and AND with a notEqual node? In Boolean algebra, they are equivalent, but if this were a number or string, Boolean doesn't work any longer. I also think the verbal description is probably more understandable to others.

Greg McKaskle
Reply With Quote
  #13   Spotlight this post!  
Unread 06-02-2011, 07:32
Acarid Acarid is offline
<3 Nested Clusters
FRC #2521
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Eugene, Oregon
Posts: 10
Acarid is an unknown quantity at this point
Re: turning a push button into a switch

Quote:
Originally Posted by Greg McKaskle View Post
The attached code does work, but may I suggest replacing the negate and AND with a notEqual node? In Boolean algebra, they are equivalent, but if this were a number or string, Boolean doesn't work any longer. I also think the verbal description is probably more understandable to others.

Greg McKaskle
A not-equal wouldn't be quite the same, since it'd also activate when the button is released. A greater-than might work though... I'm not entirely sure if it'd work with booleans... hmm.
Reply With Quote
  #14   Spotlight this post!  
Unread 06-02-2011, 08:31
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,752
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: turning a push button into a switch

Good catch. That is why it is better to actually write and run code and not just talk about it.

Greg McKaskle
Reply With Quote
  #15   Spotlight this post!  
Unread 06-02-2011, 12:22
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: turning a push button into a switch

Quote:
Originally Posted by Acarid View Post
A not-equal wouldn't be quite the same, since it'd also activate when the button is released. A greater-than might work though... I'm not entirely sure if it'd work with booleans... hmm.
Greater-than and less-than are perfectly happy with boolean values. My favorite idiom for detecting the moment of a button press is to use a feedback node and a greater-than. Using a less-than instead will detect the button release.
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 21:16.

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