Stormworks: Build and Rescue

Stormworks: Build and Rescue

37 ratings
Heading Hold Microcontroller
   
Award
Favorite
Favorited
Unfavorite
Vehicles: Sea
Tags: v0.10.27
File Size
Posted
Updated
41.653 KB
22 Jul, 2019 @ 8:22am
21 Jun, 2020 @ 8:50am
6 Change Notes ( view )

Subscribe to download
Heading Hold Microcontroller

Description
Given a current heading, and a desired heading, output rudder commands to keep vessel pointed towards desired heading.

Currently it is setup to support a "Toggle and Go" setup whereby when a toggle button is enabled, the current heading is set to the desired heading. The microcontroller will then output rudder commands to hold the heading that the vessel was pointing towards when the toggle button was enabled. By using the Heading adjust left/right input nodes, you can bind physical buttons to slightly tweak the desired heading in one direction or the other. It also allows the player to manually manipulate the vessel temporarily to avoid obstacles or adjust approaches. When no further player input is detected, the controller will resume heading hold.

To disable the system, simply toggle the button off. When a new heading is desired, simply re-toggle the button and again, the current heading will be set as the new desired heading hold.

Node Descriptions

System Enabled (Input): Whether or not the system is enabled. This should be bound to the toggle button on your vessel that you will use to enable and disable the heading hold system.

Current Heading (Input): This will come directly from the Compass Sensor on your vessel. This controller handles all the conversions for you, it just accepts the raw input from the sensor.

Heading Adjust Left (Input): Allows you to adjust the desired heading by one degree to the left. Best if bound to a pilot seat hotkey or a Standard (not toggle) button.

Heading Adjust Right (Input): Allows you to adjust the desired heading by one degree to the right. Best if bound to a pilot seat hotkey or a Standard (not toggle) button.

Rudder Player Input (Input): This should come from your control seat. This allows the pilot player to manipulate the vessel manually (to avoid obstacles, adjust approach, etc.) temporarily. Once input is no longer detected, the heading hold system will re-engage automatically.

Rudder Output (Output): This is the output commands that will be sent to your rudder control surface(s). This is what actually turns the vessel to hold the desired heading.

Stored Heading (Output) (Optional): This is an optional output that simply outputs the heading that the controller is attempting to hold. It will be the heading that was the vessel's current heading when the system was toggled on.

Current Heading Output Degrees (Output) (Optional): An optional output that simply outputs the current world heading in degrees. This allows you to not worry about converting the current heading into degrees from the compass' -0.5 to 0.5 scale.
82 Comments
tomatosoup 7 Jan @ 4:53pm 
I did some weird math that converted the heading that comes from the keypad, to the number the heading hold PID wants.
360*(1 - (floor((keypadHeading - 1) / 360) + (keypadHeading - 1) / 360))=desiredHeading
Mr. Leonard  [author] 7 Jan @ 7:30am 
Hey tomato, thanks for bringing that to my attention. You are right, there is definitely an error in the heading output value not matching up with the world heading. I don't have a lot of time today to work on it, but it looks like the displayed output heading is showing 180 when the vessel is facing north. See this image:

https://imgur.com/a/5LRVrNE

So it seems it is off by 180 degrees. I will get this fixed as soon as I have time and re-upload. Until then, the hold functionality does still work as expected.
tomatosoup 6 Jan @ 9:26pm 
hi leonard, i added a keypad to this microcontroller but noticed there was some issues. i checked with tooltips and realized the heading thats being used is.. not really whats normally considered heading.
For further reference you can use this function to convert compass to heading, where X=compass.
ceil(((1-x)%1)*360)
How are you using the compass? I need to get my keypad to output desiredheading to the logic. Ie; when I was going heading 240 (actual) the script was saying heading was 122 or something in that range.
Mr. Leonard  [author] 10 Nov, 2024 @ 9:02am 
@Ozruul, are you wanting to override the set heading with a number input? If so, you'll have to modify it to add a new input node that allows you to set the heading from a number input. As it is currently, the only way to modify the set heading is to toggle it on (which will set the heading hold to your current vehicle's heading), or by adjusting it left/right with the momentary inputs (Heading Adjust Left and Right inputs).
Ozruul 10 Nov, 2024 @ 8:08am 
how do i make it passive? so it'll always hold heading but i can override with my own commands
Oranje 30 Jul, 2024 @ 7:35pm 
ok ty :D
Mr. Leonard  [author] 30 Jul, 2024 @ 5:46pm 
It should yes. Some users have told me they have added it to their helis
Oranje 30 Jul, 2024 @ 1:10pm 
does this work for helicopters
Mr. Leonard  [author] 15 Jul, 2024 @ 6:16pm 
This one is a bit different from your typical keypad heading set system. Basically you point your vehicle in the direction you want to hold heading, then activate the System Enabled input via a button or other toggle input. The MC then automatically sets your current heading to the held heading. Then you can use the adjust left or right to fine-tune the direction you want to travel. If you would rather input a heading in any direction from a keypad, this may not be the most optimized for your use, however, it would not be difficult to add an additional input to this MC that serves as the "held" heading, while keeping the rest of the logic the same.
SpeedKiller.txt 16 Jun, 2024 @ 4:25pm 
Why dont you have a number input for the heading?