|
#16
|
||||
|
||||
|
Re: toggle switch
usually push buttons are used to turn something on while you hold it, and off when you let it go. In that case, if it goes OnOffOnOffOn for a 100mS when you push it, you probably wont notice (unless you put a scope on the output signal).
The case in this thread, where he wants a single button to act as a toggle, I dont know if Ive seen a team do this before? |
|
#17
|
|||||
|
|||||
|
Re: toggle switch
Quote:
The TechnoKats have used a toggle function for shifting the drive train between high and low gear for the past few years. |
|
#18
|
|||
|
|||
|
Re: toggle switch
We did last year, and a couple years before that. We had "feet" on our robot that were pneumatically activated to make the robot unmoveable. The button on the control panel toggled their state. Pressing it while they were down would raise them, or lower them if they were up.
I've never come across the problem where the signal would bounce. I'm not sure if thats something IFI compensated for, or if it just hasn't been a problem yet. Windward: If you use the code that I gave you, the "char oldstate" has to be defined either globally or staticly. Either put it at the top of the code, above any function, or use "static char oldstate;" instead of "char oldstate". That code should go below the default relay stuff, otherwise they will override it. |
|
#19
|
||||
|
||||
|
Re: toggle switch
I did a little searching on threads from previous years. In the past people have monitored input switches on the operator interface, and seen switch-bounce.
I was thinking perhaps IFI filters the switch inputs, but from what I have been able to find so far, they dont. Unless someone does further testing, or IFI comes up and says they have debounced the switches in the interface, I would design your systems to debounce the switch inputs (user interface and on the robot) if your application requires knowledge of single-push button actions. from a thread in 2004: Quote:
|
|
#20
|
||||
|
||||
|
Re: toggle switch
If you are having problems with the OI reading multiple clicks with one click due to your reaction time being slower then one loop on the processor you can do this:
Code:
static unsigned int loops = 30;
if (p1_sw_trig && loops >= 30)
{
relay1_fwd = !relay1_fwd;
relay1_rev = !relay1_fwd;
loops = 0;
}
if (loops < 30)
loops++;
Edit: Fixed a small bug Last edited by iBheat : 22-01-2006 at 15:50. |
|
#21
|
||||
|
||||
|
Re: toggle switch
you have the basic idea, but you need a few more lines of code.
the way its written 'loops' will keep incrementing, eventually it will get to zero and your switches will be ignored for almost a second (till it gets to 30 again, 786mS later) |
|
#22
|
||||
|
||||
|
Re: toggle switch
Quote:
|
|
#23
|
||||
|
||||
|
Re: toggle switch
I am trying to get the code to work with 2 spikes. It works with 1 spike, but I'm still a little confused on how to modify.
Code:
if(initVar != 1)
{
relay2_fwd != relay2_rev;
initVar = 1;
}
if (p1_sw_trig && !oldstate)
{
relay1_fwd = !relay1_rev;
relay1_rev = !relay1_fwd;
relay2_fwd = !relay2_rev;
relay2_rev = !relay2_fwd;
}
if (p1_sw_trig != oldstate)
oldstate = p1_sw_trig;
I am not sure where to procede from here. |
|
#24
|
||||
|
||||
|
Re: toggle switch
what do you want the 2nd spike to do? trigger the same as the first one?
trigger the opposite direction? |
|
#25
|
|||
|
|||
|
Re: toggle switch
Quote:
While that may work, It's a bit different then what I had.. Code:
if(initVar != 1)
{
relay2_fwd != relay2_rev;
initVar = 1;
}
if (p1_sw_trig && !oldstate)
{
relay1_fwd = !relay1_fwd;
relay1_rev = !relay1_rev;
relay2_fwd = !relay2_fwd;
relay2_rev = !relay2_rev;
}
if (p1_sw_trig != oldstate)
oldstate = p1_sw_trig;
If thats confusing consider this: Code:
char A = 0;
printf("%i",A);
A = !A;
printf("%i",A);
A = !A;
printf("%i",A);
0 1 0 I'm not sure if this post will help, or just confuse you more. Let me know if you still don't understand. |
|
#26
|
||||
|
||||
|
Re: toggle switch
I want to use the 2 spikes to activate and retract a piston.
I understand how you take the opposite of the present state I didn't realize that I switched the forward and reverse. I will try to fix that next. |
|
#27
|
||||
|
||||
|
Re: toggle switch
check the electrical section of the pneumatics manual. You only need one spike per cylinder. The two valves can be controlled by the FWD and REV outputs off the spike, using battery ground for the return.
or you can use two diodes, so that FWD powers one valve, and REV (reversed voltage) powers the other valve. remember the spike has three output states: forward, reverse, and off. |
|
#28
|
||||
|
||||
|
Re: toggle switch
Quote:
But when the second wait() comes up the computer either crashes, and with it commented it, it doesn't work. What's wrong. void wait(void) { time = 0; count = 0; for (count=0; count <10000; count++) { for (time=0; time < 50; time++) { prev = 1; } time = 0; } count = 0; time = 0; } void fire(void) { printf("Piston Forward\r"); relay1_rev = 0; relay1_fwd = 1; wait(); printf("Piston Back\r"); relay1_fwd = 0; relay1_rev = 1; // wait(); printf("Firing done!\r"); prev = 0; } if (p1_sw_trig == 1 && prev == 0) { prev =1; fire(); } |
|
#29
|
||||
|
||||
|
Re: toggle switch
you cant do wait loops like that on robot controller code.
you need a counter than increments on each 'pass through' of the code. your wait loop is making all the code in the RC wait until the loop is done. The other uC in the RC thinks the code has gone out to lunch, so it shuts the controller down. |
|
#30
|
||||
|
||||
|
Re: toggle switch
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PRESSURE SWITCH | Mr. Steve | Pneumatics | 20 | 01-12-2005 10:20 |
| Toggle switch with pneumatic | The yellowdart | Programming | 2 | 21-02-2005 14:08 |
| Pneumatics on a toggle switch | Idaman323 | Programming | 3 | 15-02-2005 18:42 |
| LEDs in switch box. | ZZII 527 | Electrical | 5 | 06-03-2004 19:39 |
| 3 way toggle switch programming | LeadRiccardoT | Programming | 3 | 17-02-2003 02:02 |