Go to Post Now, I either need to convince Mike Martus to start the webhug early (or move it back 1 hour), skip the webhug, miss the first part of the presentation, or just clone myself. - Andy Baker [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

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 07-02-2009, 11:29
GunfighterJ's Avatar
GunfighterJ GunfighterJ is offline
Registered User
AKA: Joseph
FRC #2450 (RaiderBots)
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Minnesota
Posts: 34
GunfighterJ is an unknown quantity at this point
Question button Switch

Is there anyway so that when you press a button on a joystick it starts a motor, when you let go it continues going. And then when you press it again the motor stops. Is there a way to do this?
  #2   Spotlight this post!  
Unread 07-02-2009, 12:01
aaeamdar's Avatar
aaeamdar aaeamdar is offline
Post-A-Holic
AKA: Paul Dennis
FRC #1719 (The Umbrella Corp)
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Baltimore, MD
Posts: 231
aaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant future
Re: button Switch

This is actually a really simple issue for programming. The exact implementation depends on your programming environment. Here is how you would do it in C/C++:

Code:
bool motorIsRunning = false
...
if (theButton == PRESSED)
{
    motorIsRunning = !motorIsRunning;
}

...

if (motorIsRunning)
{
    motorValue = FULL_FWD;
}
else
{
    motorValue = STOP;
}
The one thing that this code will do that is different than what you are looking for (perhaps) is that if you hold down the button, it will continue to flip the motor flag. Of course, this is easy to fix, if you think about it.

Good luck,
Paul
  #3   Spotlight this post!  
Unread 07-02-2009, 12:49
GunfighterJ's Avatar
GunfighterJ GunfighterJ is offline
Registered User
AKA: Joseph
FRC #2450 (RaiderBots)
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Minnesota
Posts: 34
GunfighterJ is an unknown quantity at this point
Re: button Switch

Our team uses Labview. That's where the issue is because there isn't a "toogle" vi there
  #4   Spotlight this post!  
Unread 07-02-2009, 12:56
rfry11's Avatar
rfry11 rfry11 is offline
Team 2791 Head Programmer
AKA: Ryan Fry
FRC #2791 (Bionic Bison)
Team Role: Programmer
 
Join Date: Oct 2008
Rookie Year: 2008
Location: Latham, NY
Posts: 6
rfry11 will become famous soon enoughrfry11 will become famous soon enough
Send a message via AIM to rfry11
Re: button Switch

Our team has hit a snag here, too. We're trying to run a Victor whenever we push a button, but Labview doesn't seem to have an easy way of doing this, unfortunately.
__________________
2008 Pascack Pandamonium Champions. Giant thanks to teams 25 and 11!
  #5   Spotlight this post!  
Unread 07-02-2009, 13:54
aaeamdar's Avatar
aaeamdar aaeamdar is offline
Post-A-Holic
AKA: Paul Dennis
FRC #1719 (The Umbrella Corp)
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Baltimore, MD
Posts: 231
aaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant future
Re: button Switch

I don't know how to use LabView (to me it's a waste of time) and I'm not involved with the programming on my team. However, you can still create a variable in labview (make it a boolean, an integer, a double, who cares). And then make it TRUE or 1 when you press the button and flip it each successive press. And then assign the motor value based on that.

-Paul
  #6   Spotlight this post!  
Unread 07-02-2009, 15:33
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: button Switch

To remember something from one time you process joystick data to the next you need to use either a shift register, a feedback node, a local variable, or a global variable. Any of these will work. Then you do to that storage what the code above showed. You sometimes flip it, and use its value to affect the motor speed.

Greg McKaskle
  #7   Spotlight this post!  
Unread 07-02-2009, 17:01
GunfighterJ's Avatar
GunfighterJ GunfighterJ is offline
Registered User
AKA: Joseph
FRC #2450 (RaiderBots)
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Minnesota
Posts: 34
GunfighterJ is an unknown quantity at this point
Re: button Switch

I'm not sure exactly what to use but I think it would involve shift registers or select vi's
  #8   Spotlight this post!  
Unread 07-02-2009, 19:55
GunfighterJ's Avatar
GunfighterJ GunfighterJ is offline
Registered User
AKA: Joseph
FRC #2450 (RaiderBots)
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Minnesota
Posts: 34
GunfighterJ is an unknown quantity at this point
Re: button Switch

I made a primitive toggle switch. But it will only activate/deactivate at a precise time. Probably like every millisecond or something. This is a picture of what we have. The only issue is the starting and stopping at the right time.
Attached Thumbnails
Click image for larger version

Name:	Toggle issue.PNG
Views:	99
Size:	8.2 KB
ID:	7356  
  #9   Spotlight this post!  
Unread 07-02-2009, 20:10
Racer26 Racer26 is offline
Registered User
no team
Team Role: Alumni
 
Join Date: Apr 2003
Rookie Year: 2003
Location: Beaverton, ON
Posts: 2,229
Racer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond repute
Re: button Switch

You would use shift registers.

Create a false constant outside of your loop, and feed it to the shift register initializer, then have your joystick button feed the case indicator of a case structure. in the true case, put an inverter (NOT gate, on the Boolean tab), in the line, in the false case, just run it straight through. now feed that to the shift register output. tee the motor on/off into that wire now. I hope that made sense, I'd make a simple vi and show you, but i dont have LabVIEW on this pc.
  #10   Spotlight this post!  
Unread 08-02-2009, 00:13
bls0620's Avatar
bls0620 bls0620 is offline
Registered User
FRC #0368 (Team Kika Mana)
Team Role: College Student
 
Join Date: Jun 2008
Rookie Year: 2008
Location: Honolulu, HI
Posts: 29
bls0620 will become famous soon enoughbls0620 will become famous soon enough
Re: button Switch

Here is a code that I made for our team. I used a flag to prevent the switch from switching back and forth. FYI, you might have to change things a bit(even though there's not many stuff) for your project.
Attached Files
File Type: vi Switch rev.2.vi (11.3 KB, 56 views)
  #11   Spotlight this post!  
Unread 10-02-2009, 19:39
adamzg adamzg is offline
Mentor
AKA: Adam
FRC #3932 (Dirty Mechanics)
Team Role: Mentor
 
Join Date: Nov 2008
Rookie Year: 2008
Location: Boynton Beach, FL
Posts: 16
adamzg is an unknown quantity at this point
Re: button Switch

Hey,

Good idea that, using a sleep timer to keep from reading the joystick button press over and over. Here's my solution.
Attached Thumbnails
Click image for larger version

Name:	Toggle.jpg
Views:	51
Size:	31.8 KB
ID:	7391  
Attached Files
File Type: vi Toggle.vi (13.0 KB, 52 views)
Closed Thread


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
using a switch/button to turn on a motor smcmahon NI LabVIEW 3 26-01-2009 18:42
Push Button and Switch Suppliers for OI controls Goldberg204 Control System 8 11-01-2007 15:27
push-button switch on robot Conan Electrical 4 10-02-2006 22:03
Need Help Wiring Micro Switch/Limiting Switch Windward Electrical 2 07-02-2006 18:26
Button making Alex Burman Team Organization 7 10-10-2005 21:45


All times are GMT -5. The time now is 11: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