Stormworks: Build and Rescue

Stormworks: Build and Rescue

Stuck on a logic puzzle
I've been failing at trying to figure out how to setup a microcontroller to control a throttle lever with the w/s keys.

Basically I'm using less than and more than to tell if the input of the w/s keys is positive or negative, and have been toying with various logic parts to send signals to the throttle up and throttle down outputs, but instead of moving the throttle lever step by step as I press and release the keys, I've only managed so far to send the throttle lever all the way to 1 or to 0, no stops in between.

I'm sure there's a simple way to do it but I lack the fundamental knowledge in logic circuitry to know what would be the goto logic pieces to use.
< >
Showing 1-15 of 25 comments
DaMarkiM Apr 5, 2020 @ 7:28am 
Im not quite sure what you are trying to accomplish, but if i understand you correctly you might want to look into the counter.
You can send increment and decrement commands to it and clamp/read out its value.

So you can do an easy check of the w/s input, increment/decrement accordingly and just directly use the counters value as throttle.
If it is moving to fast you can add a timer that blocks consecutive commands. Just add an and-gate to check whether the timer is back to zero and you have a valid input.

to clarify - you want to create something like this:

IF cooldowntimer==0 AND Input==valid THEN increment/decrement END
DaMarkiM Apr 5, 2020 @ 7:41am 
example - this is the main signal path

a/d input -> Greater than 0 -> AND -> increment counter -> counter value to throttle output

then there is a little loop going from the AND gate to the timer and back into the AND gate

AND -> start/reset Timer -> Timer==0 -> AND

Setup the counter in such a way that its minimum value is 0 and its maximum value is 1. clamp between these values. Set increment steps as 0.1 or 0.01 depending on what kind of fine control you need.
Set up the timer with whatever delay seems reasonable to you (hows fast you want the throttle to change)

A valid input signal (bigger or less than zero) does two things: it increments/decrements the value and thus changes the throttle. It also start your cooldown timer. The and gate will only allow another change to the counter when the cooldown counter is done.
You can set up this system in a few different way depending on which kind of counter you use, you could use an invert, etc.

If you want to change the throttle step by step (lets say you have 5 speed leevels and each w/s input should only change the level up/down once) you can also use the impulse module. It will generate a one-time-only on signal on a rising edge. To switch up twice you need to click w, then release the key and then click w again.

just one of the possible ways to handle this kind of system. There are many other ways to do it, depending on how exactly you want your throttle to behave. but this is a relatively easy one for beginners, as the counter behaves very intuitive.
Jorg Hammond Apr 5, 2020 @ 7:53am 
Thanks for your input, I will try and practice what you describe, but my specific problem here cannot be resolved by the counter.

I want to use the numbers from w/d to actuate the on/off up and down of a lever. The counter does the reverse, i.e. translate on/off to number if I'm correct.

(Also by impulse module you meant the capacitor, is that right?)
Last edited by Jorg Hammond; Apr 5, 2020 @ 8:03am
Ra-Ra-Rasputin Apr 5, 2020 @ 8:46am 
A throttle lever with the w/s keys?

Step 1: Set the sensitivity of the w/s to 100%, this is the key to the whole procedure, as it disables the "analog" control.
Step 2: Constant value 0 to the B input on greater than and less than logic, the throttle on A side
Step 3: Connect less than to down input on the throttle lever and greater than to up input.

Done :)

It's a bit more involved doing backwards (digital to analog input), but that's possible with the up/down counter.
Last edited by Ra-Ra-Rasputin; Apr 5, 2020 @ 9:47am
ElfBossHogg Apr 5, 2020 @ 8:53am 
The only other thing you could consider is adding in a Delta check. For example you only want a result to be positive if it's either going up or its 1 (max value). If Delta is less the zero, i.e. you've released the key and it's returning to zero, then it would indicate no key press. However this may be a bit overkill once you set the sensitivity setting to 100%
Ra-Ra-Rasputin Apr 5, 2020 @ 9:29am 
Originally posted by ElfBossHogg:
The only other thing you could consider is adding in a Delta check. For example you only want a result to be positive if it's either going up or its 1 (max value). If Delta is less the zero, i.e. you've released the key and it's returning to zero, then it would indicate no key press. However this may be a bit overkill once you set the sensitivity setting to 100%

Should also note that, after designing brakes that depend on hitting S while driving around, the delta reduction of the analog on release is not linear. The reduction of the reset analog works on a curve, which makes it very useful for its purpose, but not so kind to tying logic to it.

At the least it does respond to hitting the opposite direction, so you can make it react to sudden peaks... but like said before, the key is 100% sensitivity.
Last edited by Ra-Ra-Rasputin; Apr 5, 2020 @ 9:31am
Jorg Hammond Apr 5, 2020 @ 9:45am 
I knew there was a quick and simple solution to it!

I ended up using the Delta to detect if I was pressing w or s and setting up on each branch a 1-tick clock looping on an AND gate like squall-leonhart1 suggested. I experienced a bit of confusion when having to chose between the four different timer types but managed it in the end.

Check it if you want to have a laugh : https://steamcommunity.com/sharedfiles/filedetails/?id=2049461956

Ra, why would you set the comparison value to 2 in your solution? (Since w/d output values from -1 to 1 I fail to see your reasoning.)
Ra-Ra-Rasputin Apr 5, 2020 @ 9:47am 
Originally posted by Rashtek Frites:
Ra, why would you set the comparison value to 2 in your solution? (Since w/d output values from -1 to 1 I fail to see your reasoning.)

That's because literally when writing the message i was also working on something that i wrote the constant value 2 to. My brain wires crossed. :lunar2019deadpanpig:
Ra-Ra-Rasputin Apr 5, 2020 @ 9:50am 
Anyhow, here's the setup i use. Would've posted it earlier but was working on something else.

https://steamcommunity.com/sharedfiles/filedetails/?id=2049489862
Last edited by Ra-Ra-Rasputin; Apr 5, 2020 @ 9:51am
DaMarkiM Apr 5, 2020 @ 10:07am 
Hey Rashtek, ive had a look at your curcuit.

For me it produces some weird behaviours - let me know whether they are intended:
1) due to the w/s input not immediately going back to 0 it stays active even without input
2) since you take the delta releasing the w button actually produces a throttle down signal

correct me if it is, but i assume this is not intended.

If all you want to do is move a throttle lever via the w/s control you really dont need more than a greater and lower than 0 check and output this directly to the throttle lever.
As Rasputin described this works best if you click on your seat and set the sensitivity of the w/s to 100% (otherwise you have a behaviour of slowly going back to zero after letting go of the key which produces a delayed input)




Jorg Hammond Apr 5, 2020 @ 10:16am 
Thanks for having a look.

I forgot to mention that my solution is intended for a sticky analog input. I'm assuming the behaviour you observed stems from the fact that your control is to reset.

When I tried the simpler setup of greater or lesser check direct to the lever inputs, it was not very responsive, but I hadn't had the idea of playing with the sensitivity setting. I'll give this an another try and look at Ra's example as soon as I am done dragging this sample crucible with a motorised canoe in a storm. :steamhappy:
Jorg Hammond Apr 5, 2020 @ 11:01am 
Yes, in your last paragraph you describe exactly what Rasputin has implemented, your solution is nice and simple as should be. Plus by doing it this way you don't ever run the risk of having your sticky control and your lever out of sync if you use one and the other.

What was tripping me up is that I only use sticky controls, I still lack intuition to tell when reset is a better idea.

At least I learned how to wire a timer to an AND gate! Thanks again everyone.
Last edited by Jorg Hammond; Apr 5, 2020 @ 11:20am
DaMarkiM Apr 5, 2020 @ 11:58am 
great to see that your problem could be solved.
you can still use the timer if you want a slower change in throttle for more precise control.
so it wasnt for naught
Jorg Hammond Apr 5, 2020 @ 12:19pm 
My timer is already at 1 tick, and it's the best I can get since I used Delta and it processes tick by tick, but I guess I can try with direct analog input on reset and 100% sensibility.

What is the duration of a tick?
ElfBossHogg Apr 5, 2020 @ 1:54pm 
One tick is 1/60th of a second. 60 ticks per second.
< >
Showing 1-15 of 25 comments
Per page: 1530 50

Date Posted: Apr 5, 2020 @ 7:10am
Posts: 25