Multiswitch - ini

More
24 Feb 2016 15:37 #43558 by jschl
Multiswitch - ini was created by jschl
I'd like to combine several switches in one channel. An arduino board on the receiver side should entangle the signal and switch some mosfets and other things. My idea was to use TRIM_L as a switch (step=191). With a hardware switch (i.e. AIL DR) and a three-state switch (i.e. MIX) I'd like to create the following setup:
AIL DR0 - MIX0 -> TRIM_L+ -> switch 1 on
AIL DR0 - MIX1 -> TRIM_L+ -> switch 2 on
AIL DR0 - MIX2 -> TRIM_L+ -> switch 3 on
AIL DR1 - MIX0 -> TRIM_L+ -> switch 4 on
...
AIL DR0 - MIX0 -> TRIM_L- -> switch 1 off
...
The result of the signal should be binary encoded, my idea for a calculation is:
-100 + (100 if sw1 is on) + (50 if sw 2 is on) + (25 if sw3 is on) + (12 if sw4 is on) ...
I tried quite a while but couldn't solve it.
Could anybody give me a hint?

Thanks in advance
Joerg

Please Log in or Create an account to join the conversation.

More
24 Feb 2016 17:31 #43563 by wukong
Replied by wukong on topic Multiswitch - ini

jschl wrote: I'd like to combine several switches in one channel. An arduino board on the receiver side should entangle the signal and switch some mosfets and other things. My idea was to use TRIM_L as a switch (step=191). With a hardware switch (i.e. AIL DR) and a three-state switch (i.e. MIX) I'd like to create the following setup:
AIL DR0 - MIX0 -> TRIM_L+ -> switch 1 on
AIL DR0 - MIX1 -> TRIM_L+ -> switch 2 on
AIL DR0 - MIX2 -> TRIM_L+ -> switch 3 on
AIL DR1 - MIX0 -> TRIM_L+ -> switch 4 on
...
AIL DR0 - MIX0 -> TRIM_L- -> switch 1 off
...
The result of the signal should be binary encoded, my idea for a calculation is:
-100 + (100 if sw1 is on) + (50 if sw 2 is on) + (25 if sw3 is on) + (12 if sw4 is on) ...
I tried quite a while but couldn't solve it.
Could anybody give me a hint?

Thanks in advance
Joerg


Hi,

Not too sure what you mean by solve, but if you are talking about the arduino side, you could do many if-else statements to detect the 16 unique values for the 16 possible switch combinations?

however, isn't there an issue with using the AIL DR Sw + MIX sw + Trim_L to represent 4 switches? The combination of AIL DR, Mix and Trim only has 12 possible combinations (2 x 3 x 2), where as 4 switches has 16 possible combinations (2^4).

Please Log in or Create an account to join the conversation.

More
24 Feb 2016 17:53 #43564 by jschl
Replied by jschl on topic Multiswitch - ini
Hi,
the arduino side is out of question.
I'd like to use the combination of AIL DR and MIX (2x3 switches) and switch by using TRIM_L up/down. AIL DR and MIX in combination define the switch number (1-6), the trim-click itself should put the switch on or off.
Out of this data I'd like to generate a combined output for all 6 switches in one channel in a binary additional manner.
-100 + (100 if sw1 is on) + (50 if sw 2 is on) + (25 if sw3 is on) + (12 if sw4 is on) ...
so, if you would get a signal value of -38 (+/- 2), sw2 (+50) and sw4 (+12) are on whereas all others are off.
May be that 3-6-12-25-50-100 (additional output for ch6-ch5-ch4....) is not possible to detect (the distance of 3 may be to small), in that case one could combine only 5 switches (6-12-24-48-96) or even 4.
Joerg

Please Log in or Create an account to join the conversation.

More
25 Feb 2016 00:02 #43593 by mwm
Replied by mwm on topic Multiswitch - ini
This has been done a number of times in the forum. If you really get stuck, try searching (use google with the form URL as a search term, not the forum search) for 6-way switch or similar.

The trick is to use the "Add" mix type instead of the default "Replace" mix type. You then start with a fixed mix of 0, and three fixed mixes that add values enabled by the AIL_DR, MIX1 and MIX2 switches: 100, -33 and -66 work.

Do not ask me questions via PM. Ask in the forums, where I'll answer if I can.

My remotely piloted vehicle ("drone") is a yacht.

Please Log in or Create an account to join the conversation.

More
25 Feb 2016 09:23 #43606 by jschl
Replied by jschl on topic Multiswitch - ini
thanks mwm, I found samples to send a MIX0-1-2 to one channel, but that is a 3 or even 6 way (in combination with AIL DR) single switch, I want to produce six 2-way switches by selecting the switch number with the help of the MIX/AIL_DR combinations and switch them on or off with the TRIM_L buttons. I can't find samples for this approach.
Another way to realize the task could be to send a single momentary impulse with a specific signal range (depending on the values of MIX and AIL DR) when pushing TRIM_L and detect that with the arduino. But I don't know how to do that either.

Please Log in or Create an account to join the conversation.

More
25 Feb 2016 14:16 #43612 by mwm
Replied by mwm on topic Multiswitch - ini
Ah, my bad - I misread it. Of course, I'm still sure I don't understand what you want, as your two different alternatives seem to have different numbers of possible outputs.

If you can live with a single output channel with 7 possible values - one if your chosen TRIM_L button isn't pressed, and then one of 6 selected by AIL_DR and MIX if that button is pressed, then that's relatively straightforward.

Do not ask me questions via PM. Ask in the forums, where I'll answer if I can.

My remotely piloted vehicle ("drone") is a yacht.

Please Log in or Create an account to join the conversation.

More
25 Feb 2016 21:03 #43646 by jschl
Replied by jschl on topic Multiswitch - ini
... ok, my fault - I try to describe it more in detail:
Let's assume AILDR0 and MIX0 are set, these two settings should define switch 1 to be handled. Then I want to put on switch 1 by TRIM_L+ or put it off by TRIM_L-
with AILDR0 and MIX1 set I'd like to define switch 2, which also should be switched on/off with TRIM_L
AILDR0 and MIX2 define switch 3, AILDR1 and MIX0 switch 4, AILDR1 and MIX1 switch 5 and AILDR1 and MX2 switch 6. TRIM_L should do the switching work, whereas AILDR and MIX simply define which switch is meant to be switched on/off by TRIM_L.

The result could be coded in a binary starting by -100
If switch 1 is on, one could assign an offset of 100 - if off, the offset is 0
If switch 2 is on, one could assign an offset of 50 - if off, the offset is 0
If switch 3 is on, one could assign an offset of 25 - if off, the offset is 0
.,
if switch 6 is on, the offset is 3
Lets do an example: sw1 on, sw2 off sw3 on, sw4 off, sw5 off, sw6 on means:
100 + 0 + 25 + 0 + 0 + 3 = 128
so the output signal for the dest-channel should be set to -100+128 = 28
But 3 as the distance between two values my be to short.
Another solution for encoding the signal could be a momentary impulse for a single switch to be set:
we have 6 switches, that means if we use a neg.signal to switch off and a positive to switch on, we could simply define:
+/- 120 for switch 1, +/- 100 for switch 2 ... +/- 20 for switch 6
This would mean the same signal-distance for all switches. To set the upper examples with this szenario we would have to send 120/-100/80/-60/-40/20 with a defined signal-length to give the arduino the chance to detect. But as these kind of switches are not time-relevant, that is absolutely ok.

This logic could be even expanded to define 12 momentary switches. The arduino then interpretes each +/- signal as two momentary switches. When put on TRIM_R, you would have 6 binary switches on TRIM_L and 12 momentary switches on TRIM_R. That would be nice for trucks or boats... When adding a third pysical switch with 2 positions, you could even double the number - as long as you could detect the smaller differences of the single signal values.

Hope that you will understand my ideas a little bit better now.

Please Log in or Create an account to join the conversation.

More
25 Feb 2016 23:39 #43654 by mwm
Replied by mwm on topic Multiswitch - ini
Yeah, that's about what I thought. I'm not sure it's possible, and the obvious way to try it is going to need 14 virtual channels. The stock build only has 10. Some clever tweaking might be able to reduce that to only 8, but I have a feeling that's going to require a lot of extra mixes - like 36 just for switch encoding - and you only get 48 of those for all your virtual and output channels, so that's liable to be an issue.

The nasty part of what you want is turning it on with TRIM_L+ and off with TRIM_L-, but that may be because I'm assuming that you want the channel to remain unchanged until you hit one of those two buttons. If that's not what you want, then maybe try again. That means you need a channel to record the the current value for each switch as well as one that decodes to whether or not that switch is active. That's 12 virtual channels. And of course, two for the trim buttons. So maybe try your alternate method, which is the one I was more confused about. Care to describe it in more detail.

The output channel encoding isn't much of an issue - that just takes 7 mixes: First is fixed 0, then 2-7 are fixed at 100, 50, 25, etc. using a mux type of add and enabled by the appropriate switch numbers. You can set the highest value to 128 instead of 100, which will help some. Your first post talked about using negative values; so you can set the first mix at -128, then add 128, 64, 32,16, 8 and 4 to it as required.

Another possibility might be to change the encoding you use between the arduino and the transmitter. For instance, if instead of trying to cram all 64 values into one channel, you sent 1 switch per channel, then six of your virtual channels turn into output channels, which means you now have enough virtual channels. But that depends on what receiver you have and how you're getting signals into the Arduino.

Do not ask me questions via PM. Ask in the forums, where I'll answer if I can.

My remotely piloted vehicle ("drone") is a yacht.

Please Log in or Create an account to join the conversation.

More
26 Feb 2016 17:02 #43690 by jschl
Replied by jschl on topic Multiswitch - ini
The channel need not to remain unchanged (as long it goes back to 0), I could handle that easily within the arduino-code. An impulse while hitting TRIM_L+/- would be ok.
My idea now is that both TRIM_L+/- manipulate a virtual channel, which should output -1, +1 or 0 if nothing is hit (lets call this OnOffSwitch).
This should be the input for another virtual channel, which should work that way
baseValue set to 0
if AIL DR1 is set add 60 * OnOffSwitch to baseValue (if AIL DR0 is set, baseValue remains 0)
if MIX0 is set add 20 * OnOffSwitch to the above calculated result
if MIX1 is set add 40 * OnOffSwitch to the above calculated result
if MIX2 is set add 60 * OnOffSwitch to the above calculated result
If the total result (the signal value) now for example is -100, you would know that you had hit the TRIM_L- with a AIL DR1 and MIX1 set. The signal itself can be in a range from -120 to 120 and should be active only when TRIM_L is hit, otherwise should send 0.
So far ok, BUT:
How can I manage that in the model.ini??

Please Log in or Create an account to join the conversation.

More
27 Feb 2016 01:44 #43739 by mwm
Replied by mwm on topic Multiswitch - ini
If I understand, you're now letting the arduino handle the state tracking to construct your 6-bit value. That simplifies things considerably.

The only problem is that each mix in a mixer only gets two inputs: the SRC and the value from the previous mixer. So to add 60 * OnOffSwitch to the previous value, you need a virtual channel for each of the possible values. But we can fix that by factoring out OnOffSwitch. So you wind up with:

Two virtual channels for the TRIM_L buttons, as documented in the manual. Tutorials in the Writing a deviationTx model file mentioend below.

A virtual channel for OnOffSwitch (you can name virtual channels - I advise you to do so). That has three mixes: First one is fixed 0, second one is fixed -100 with a switch of TRIM_L-, third one is fixed 100 if with a switch of TRIM_L+. Note that when multiplying, channel values are treated as percentage, so a value of 100 is 1.

Your output channel is now the one you described:
Mix 0 is fixed value of 0
Mix 1 is fixed, value of 60, switch set to AIL DR1
Mix 2 is fixed, value of 20, switch set to MIX0
Mix 3 is fixed, value of 40, switch set to MIX1
Mix 4 is fixed, value of 60, switch set to MIX2

Up to this point, this is the 6-way switch I thought you wanted originally. This is covered - well, almost - in the Advanced Flight Controller section of Writing a deviationTx model .

So now we factor in the OnOffSwitch state with Mix 5, which has OnOffSwitch as the src, mux type is multiply, curve type is Min/Max (I prefer that for switches).

Do not ask me questions via PM. Ask in the forums, where I'll answer if I can.

My remotely piloted vehicle ("drone") is a yacht.

Please Log in or Create an account to join the conversation.

More
27 Feb 2016 10:30 #43764 by jschl
Replied by jschl on topic Multiswitch - ini
I managed it! The basic idea is to record the switch state with virt10 (values 20-40-60-80-100-120)
You need to set up a virtual channels for each trim-switch (virt1-4), then you simply have to use a switch for virt1-4 in both channels 9 and 10.
Then I'll get explicit signal values with negativ values for switch-off signals and positive values for switch-on values. Now I can detect 6 on/off or 12 momentary switches on each channel, which could be easily doubled, that you could switch a lot of lights and other things...and the deviation would be perfect for boats and trucks as well... (as long as my arduino will detect the signal distance properly)
Thanks, mwm.
Here's my ini-section...

[channel9]
template=complex
[mixer]
src=virt10
dest=Ch9
muxtype=min/max
scalar=0
[mixer]
src=virt10
dest=Ch9
switch=virt1
muxtype=mult
scalar=100
[mixer]
src=virt10
dest=Ch9
switch=virt2
muxtype=mult
scalar=-100

[channel10]
template=complex
[mixer]
src=virt10
dest=Ch10
muxtype=min/max
scalar=0
[mixer]
src=virt10
dest=Ch10
switch=virt3
muxtype=mult
scalar=100
[mixer]
src=virt10
dest=Ch10
switch=virt4
muxtype=mult
scalar=-100

[virtchan1]
name=trim_Lup
template=simple
[mixer]
src=virt1
dest=virt1

[virtchan2]
name=trim_Ldown
template=simple
[mixer]
src=virt2
dest=virt2

[virtchan3]
name=trim_Rup
template=simple
[mixer]
src=virt3
dest=virt3

[virtchan4]
name=trim_Rdown
template=simple
[mixer]
src=virt4
dest=virt4

[virtchan10]
name=switchSelector
template=complex
[mixer]
src=virt10
dest=virt10
switch=MIX0
muxtype=min/max
curvetype=fixed
scalar=20
[mixer]
src=virt10
dest=virt10
switch=MIX1
muxtype=min/max
curvetype=fixed
scalar=40
[mixer]
src=virt10
dest=virt10
switch=MIX2
muxtype=min/max
curvetype=fixed
scalar=60
[mixer]
src=virt10
dest=virt10
switch=AIL DR1
muxtype=ADD
curvetype=fixed
scalar=60

....

[trim5]
src=Virt1
pos=TRIM_L+
neg=None
step=193
value=-100,0,0
[trim6]
src=Virt2
pos=TRIM_L-
neg=None
step=193
value=-100,0,0
[trim7]
src=Virt3
pos=TRIM_R+
neg=None
step=193
value=-100,0,0
[trim8]
src=Virt4
pos=TRIM_R-
neg=None
step=193
value=-100,0,0

Please Log in or Create an account to join the conversation.

More
18 Mar 2016 10:14 #44783 by jschl
Replied by jschl on topic Multiswitch - ini
Just to complete the thread ... I set up my arduino with the following code

volatile int time = 0;
volatile int value = 0;
bool switches[6]; //switches
int numsw = 6;

void setup() {
for (int i=0;i<numsw;++i)
{
pinMode (i+3, OUTPUT);
digitalWrite (i+3,LOW);
}
Serial.begin(115200);
attachInterrupt(0, signalRising, RISING);
}

void loop() { }

void signalRising() {
attachInterrupt(0, signalFalling, FALLING);
time = micros();
}

void signalFalling() {
attachInterrupt(0, signalRising, RISING);
value = micros() - time;
setSwitch(value);
}

void setSwitch(int a)
{
bool on = (a-1500)>0;
int offset= abs(a-1500);
int pos = round(offset/80);
if ((pos>0) && (pos<=6))
{
switches[pos-1] = on;
digitalWrite(pos+2, switches[pos-1] ? HIGH : LOW);
}
}

Now I'm able to switch 6 leds by selecting the number of the switch with the MIX and AIL - Switches on the devo (6 Combinations possible), and turn the correspondent switch on/off by the TRIM_R up-down switch.
The detected values of the pulse width are very accurate. The measured value for the signal "switch 1 to be switched on" ranges from 1.576 to 1.584ms, "switch 2 on" is from 1.656 to 1.664ms. That means, that it would be possible to double the switches with another switch on the devo, as the next pwm-signal will have a distance of 0.040ms then.
With this result I can easily switch a lot of switches on a boat or truck, as there is not only TRIM_R on the devo and FMOD or other switches could be used as well. So 1 channel can easily be used for 12 on/off switches or 24 push buttons which remain switched as long as TRIM is pushed
The arduino is capable to handle 2 channels, which should be enough for me. Deviation is great, not only for helis or planes...

Please Log in or Create an account to join the conversation.

More
19 Mar 2016 10:14 #44824 by jschl
Replied by jschl on topic Multiswitch - ini
... sorry, there is a bug in the old code, in set_switch it has to be

int pos = round(offset/80.0);

Please Log in or Create an account to join the conversation.

Time to create page: 0.046 seconds
Powered by Kunena Forum