Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   using single solenoid like a double (http://www.chiefdelphi.com/forums/showthread.php?t=24690)

SteveO 02-02-2004 20:29

using single solenoid like a double
 
We're wondering if it is possible to use a single solenoid like a double basically by having to only press a button once instead of holding it down. Tell me if I'm crazy about the solenoid thing, but it seems possible to edit the program so that pressing the thumb or trigger on a joytick (pX_sw_whatever) once will keep the relay attached to its corresponding relay output in forward mode. How would you go about doing this? I think I have an idea, but I am a n00b and don't wanna embarass myself....

Guest 02-02-2004 20:42

Re: using single solenoid like a double
 
Quote:

Originally Posted by SteveO
We're wondering if it is possible to use a single solenoid like a double basically by having to only press a button once instead of holding it down. Tell me if I'm crazy about the solenoid thing, but it seems possible to edit the program so that pressing the thumb or trigger on a joytick (pX_sw_whatever) once will keep the relay attached to its corresponding relay output in forward mode.

The double-solenoid valve works by outputting air into one side of the piston to make it extend. You then set it in reverse (the spike) to put air into the other side of the piston to make it retract. You can't model a double-solenoid using a single-solenoid by changing the software. The purpose of a double-solenoid valve is to be able to actuate the piston in both directions, ONE single solenoid valve cannot do this, but TWO SINGLE solenoid valves can

SteveO 02-02-2004 20:50

Re: using single solenoid like a double
 
Quote:

Originally Posted by SilverStar
The double-solenoid valve works by outputting air into one side of the piston to make it extract. You then set it in reverse (the spike) to put air into the other side of the piston to make it extract. You can't model a double-solenoid using a single-solenoid by changing the software. The purpose of a double-solenoid valve is to be able to actuate the piston in both directions, ONE single solenoid valve cannot do this, but TWO SINGLE solenoid valves can

Ok so I am indeed crazy about the solenoid thing, but can anyone help me out with a way to keep the relay forward while only pressing the button once instead of holding it down?

Guest 02-02-2004 21:14

Re: using single solenoid like a double
 
Sure, the "toggle" code you need is at the repository:

http://nrg.chaosnet.org/repository/viewcode?id=23

deltacoder1020 02-02-2004 21:15

Re: using single solenoid like a double
 
if you mean you want to use two buttons like "on" and "off" buttons, here's one way to do it:

Code:

static char btn_status = 0;

if(p1_sw_aux1) btn_status = 1;
if(p1_sw_aux2) btn_status = 0;

relay1_fwd = btn_status;

basically, just declare a static variable (so that it holds its state), then use the input from the buttons to set the variable at the appropriate times. (note - some of the input variable names may be off, i'm doing this from memory only)

Guest 02-02-2004 21:17

Re: using single solenoid like a double
 
Quote:

Originally Posted by deltacoder1020
if you mean you want to use two buttons like "on" and "off" buttons, here's one way to do it:

Code:

static char btn_status = 0;

if(p1_sw_aux1) btn_status = 1;
if(p1_sw_aux2) btn_status = 0;

relay1_fwd = btn_status;

basically, just declare a static variable (so that it holds its state), then use the input from the buttons to set the variable at the appropriate times. (note - some of the input variable names may be off, i'm doing this from memory only)

The code needs to be made slightly more complex because, as I interpret it, SteveO wants one button to toggle, my code above solves that.

deltacoder1020 02-02-2004 21:21

Re: using single solenoid like a double
 
either way you want to work it.

velocipenguin 02-02-2004 21:33

Re: using single solenoid like a double
 
Couldn't you do it with a simple XOR operation?

i.e.
Code:

relay1_fwd ^= p1_sw_trig;

Guest 02-02-2004 21:38

Re: using single solenoid like a double
 
No, because the p1_sw_trig will remain true for more than one frame (unless your driver moves faster than light :) ). Thus, relay1_fwd would continuously switch from 0 to 1.

velocipenguin 02-02-2004 21:57

Re: using single solenoid like a double
 
Quote:

Originally Posted by SilverStar
No, because the p1_sw_trig will remain true for more than one frame (unless your driver moves faster than light :) ). Thus, relay1_fwd would continuously switch from 0 to 1.

Good point.

SteveO 02-02-2004 21:59

Re: using single solenoid like a double
 
ahhh merci SilverStar, I was thinking of using something similar with even or odd number of times pressing the button, this works

velocipenguin 02-02-2004 22:10

Re: using single solenoid like a double
 
If you do it this way, it should only toggle the relay output when the button transitions from one state to another. That should eliminate the problem of infinite toggling that was present in my last suggestion.

Code:

// declare this as a global variable
bool LastButtonValue=0;

// place the following within the main loop
if(p1_sw_trig!=LastButtonValue)
        relay1_fwd ^= p1_sw_trig;

LastButtonValue = p1_sw_trig;


Guest 02-02-2004 22:42

Re: using single solenoid like a double
 
Quote:

Originally Posted by velocipenguin
If you do it this way, it should only toggle the relay output when the button transitions from one state to another. That should eliminate the problem of infinite toggling that was present in my last suggestion.

Code:

// declare this as a global variable
bool LastButtonValue=0;
 
// place the following within the main loop
if(p1_sw_trig!=LastButtonValue)
relay1_fwd ^= p1_sw_trig;
 
LastButtonValue = p1_sw_trig;


umm... that's exactly what's in the repository link above .....

velocipenguin 02-02-2004 22:49

Re: using single solenoid like a double
 
It's a little more concise, but yeah, you're right. I shouldn't attempt to think when I haven't slept much - this is what happens. Sorry.

deltacoder1020 02-02-2004 22:51

Re: using single solenoid like a double
 
nothing really to be sorry about - posting the code here doesn't hurt.

also, instead of a global variable, i'd recommend a static - that way, you don't have any possible variable conflicts.


All times are GMT -5. The time now is 04:21.

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