Skip to content

Commit

Permalink
Add support for Manual Switches and update manual and changelog.
Browse files Browse the repository at this point in the history
  • Loading branch information
PerMalmberg committed Aug 1, 2023
1 parent ebe7afc commit e6e490c
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 18 deletions.
16 changes: 10 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

All notable changes to this project will be documented in this file. The version number refers to the version printed in Lua chat for the control unit/ECU, not the one displayed on the screen in offline mode.

## 0.2.xx - 2023-06-xx
## 1.0.0 - 2023-08-01

### Added
* New setting `setWaypointAlongRoute`, which, if enabled, makes the waypoint to be set for the next point in the route.
* Support for automatically opening and closing doors/gates when entering travel and hold states, respectively.

* Support to automatically opening and closing doors/gates when activating a route and reaching the final waypoint, respectively.
* Support for two Manual Switches that follow gate state or the state of the remote controller, depending on their name.
* New command `route-set-gate-control` to configure route control for a route.
* New setting `commChannel` for setting the channel to use for gate control
* New setting `gateCloseDelay` for setting the delay to wait for gates to close after landing.

### Fixed
* Formatting of a few log messages
Expand All @@ -18,9 +21,10 @@ All notable changes to this project will be documented in this file. The version
* Sped up fuel gauges so they show quicker, mostly noticeable on constructs with many elements.
* Extracted the stream code used for communicating with the screen into its own open-source library (https://github.com/PerMalmberg/du-stream) so it can be used to also communicate using emitter/receivers.

## 1.0.0 - 2023-07-25

This version is identical to 0.2.10 and marks the first 'complete' version and the end of free updates. Updates to this version are still free.
### Other
* Open Sourced these repositories:
* A library to communicate with screens and emitters/receivers: https://github.com/PerMalmberg/du-stream
* Code for gate control: https://github.com/PerMalmberg/du-yfs-gate-control

## 0.2.10 - 2023-06-24

Expand Down
56 changes: 47 additions & 9 deletions Manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Please read the entire manual before attempting to perform an installation, ther
- [Yoarii's Flight system](#yoariis-flight-system)
- [Overview](#overview)
- [Required elements (for Do-It-Yourself kits)](#required-elements-for-do-it-yourself-kits)
- [Optional parts](#optional-parts)
- [Routes and Waypoints](#routes-and-waypoints)
- [Route vs Floor mode](#route-vs-floor-mode)
- [Waypoint alignment](#waypoint-alignment)
Expand All @@ -13,7 +14,10 @@ Please read the entire manual before attempting to perform an installation, ther
- [Floors for parking; ground and space](#floors-for-parking-ground-and-space)
- [Cargo mass capacity](#cargo-mass-capacity)
- [Automatic shutdown](#automatic-shutdown)
- [Gate control](#gate-control)
- [Integrations](#integrations)
- [Gate control](#gate-control)
- [Elevator side](#elevator-side)
- [Manual switches](#manual-switches)
- [Fuel gauges](#fuel-gauges)
- [Installation as an elevator (ground to space)](#installation-as-an-elevator-ground-to-space)
- [Aligning the elevator to your ground construct](#aligning-the-elevator-to-your-ground-construct)
Expand Down Expand Up @@ -48,6 +52,10 @@ The goal of this project was initially to write a flight system capable of worki
* Aim for 3g for upward lift when fully loaded.
* Don't forget the brakes

#### Optional parts
* Emitter
* Receiver

### Routes and Waypoints

Routes is an important concept for this flight system as they are what guides the construct between positions. A route consists of two or more waypoints, a start, an end, and any number of waypoints in-between. A waypoint specifies a position in the world. When added to a route a waypoint is associated with other attributes, such as alignment direction and maximum speed. A route can also contain anonymous waypoints; these exists only in one route and can't be reused. When traveling along a route, the next waypoint dictates the direction the constructs forward should point in. Normally this is towards the waypoint itself, but it can be locked to another direction. When a route is run in reverse, the previous waypoint determines the alignment direction so that the the construct performs each movement in reverse along the entire route.
Expand Down Expand Up @@ -89,7 +97,9 @@ From the above it should be understood that taking off from lower atmosphere (su

When the last point in the route is reached, and the telemeter reports a distance less than the one configured, the script will automatically shutdown.

## Gate control
## Integrations

### Gate control

You can setup automatic control of gates or doors, completely automating the travel, this gets you:

Expand All @@ -98,7 +108,18 @@ You can setup automatic control of gates or doors, completely automating the tra

You do _not_ get automatically closed gates/doors on leaving the start of the route.

Link the following elements on the ground/space construct as follows, in the given order. Also name elements as stated in parenthesis.
Elements needed on the space/static construct:
* 1x Receiver
* 1x Emitter
* 1x Programming Board
* 1x Relay (2x if you want to control more than one gate/door)
* 1x XOR operator
* 1x OR operator
* 1x 2-Counter
* 2x Manual Switch
* Any number of gates/doors

Link the following elements on the ground/space construct as follows. You can link the elements in any order, with the exception of the first step which *must* be the first link on the programming board. Also name elements as stated in parenthesis.

1. PB -> Receiver (green link)
2. PB -> Emitter (green link)
Expand All @@ -112,18 +133,32 @@ Link the following elements on the ground/space construct as follows, in the giv
10. 2-counter -> XOR (blue link)
11. XOR -> OR (blue link)
12. OR -> PB (blue link)
13. Manual Switch (name: gates) -> Relay and/or gates/doors

*PB = Programming Board

Now copy the _contents_ of the latest released [Json file from here](https://github.com/PerMalmberg/du-elevator-docking-control/), right-click on the Programming Board, open the Advanced menu and click `Paste Lua Configuration from clipboard`. Ensure you get a success message on screen.
Now copy the _contents_ of the latest released [Json file from here](https://github.com/PerMalmberg/du-yfs-gate-control/releases/latest), right-click on the Programming Board, open the Advanced menu and click `Paste Lua Configuration from clipboard`. Ensure you get a success message on screen.

Right-click on the programming board and click `Edit Lua parameters` and set a unique communication channel, using alpha numerical characters only, no spaces. Ensure you keep the quotation marks! The channel must be unique per elevator/gate set or they will interfere with each other. Click OK to close the dialog.
Now activate the programming board to complete the setup of the worker side. It will turn itself off automatically.

On the elevator, in Lua chat, you must now run the command `set -commChannel CHANNEL`, replacing `CHANNEL` with the same channel name you used above.
Now activate the programming board to complete the setup of the worker side, look in Lua chat for any errors printed and adjust accordingly.

> Note: Gate Control is only active while running a route, not when manually controlling the construct with keys or via the `move` command.
#### Elevator side

The receiver *must* be linked on the first slot of the remote controller. You do this easiest by removing all links, then linking from the Remote Controller to the Receiver, followed by linking the Core, Telemeter, Screen, Databank(s) and Emitter.

In Lua chat, you must run the command `set -commChannel CHANNEL`, replacing `CHANNEL` with the same channel name you used on the programming board on the space/static construct so that they can communicate with each other. Next, for each route you want the elevator to control the gates, open the route for editing then run the command `route-set-gate-control -atStart true -atEnd true`, changing `true` to `false` if you don't want it to perform gate controls at that end. Finish by saving the route.

For example, the most common setup is to have gates/doors only at the space station. If we assume the first point in the route is at the ground, run `route-set-gate-control -atStart false -atEnd true`.

### Manual switches

If linked to the remote controller, the script can control two Manual Switches, depending on their names:

* A Manual Switch named "FollowGate" will be activated whenever the gate control opens the gates and deactivated when gates are closed.
* A Manual Switch named "FollowRemote" will follow the state of the Remote Controller.

## Fuel gauges

The screen shows up to four fuel tanks of each of the atmospheric and space types. It chooses the ones to display based on the lowest percentage and as such you can always see how close you are to run out of fuel, regardless of how many fuel tanks you have.
Expand Down Expand Up @@ -321,6 +356,9 @@ Hint: To activate snapping mode, point into empty space, then click middle mouse
| | -margin | meter | Y | Sets the margin, in meters, for the point. |
| | -maxSpeed | km/h | Y | Sets the max speed, in km/h for the point. |
| | -finalSpeed | km/h | Y | Sets the final speed, i.e. the speed to have when reaching the point. |
| route-set-gate-control | | | | Enables/disables gate control at the start/end of the route. |
| | -atStart | boolean | N | If true, gate controls are enabled at the start (first waypoint) of the route. |
| | -atEnd | boolean | N | If true, gate controls are enabled at the end (last waypoint) of the route. |
| route-print-pos-options | | number | N | Prints the options of the given point in the currently open route. |
| route-print | | | | Prints the current route to the console |
| pos-create-along-gravity | name of waypoint | | | Creates a waypoint relative to the constructs position along the gravity vector. |
Expand Down Expand Up @@ -374,8 +412,8 @@ Hint: To activate snapping mode, point into empty space, then click middle mouse
| | -pathAlignmentAngleLimit | degrees | Y | The threshold angle that determines if the construct will align to the flight path or the gravity vector. Default: 10 degrees. Set to 0 to disable path alignment. |
| | -pathAlignmentDistanceLimit | meter | Y | The threshold distance that determines if the construct will align to the flight path or the gravity vector. Default: 200m. |
| | -setWaypointAlongRoute | boolean | Y | If true, the next point in the route will become your waypoint. |
| | -commChannel | string | Y | If set to anything but an empty string, this defines the channel used to communicate with other constructs on. |
| | -gateCloseDelay | number | Y | The number of seconds to wait in the hold-state before giving the command to close gates for automatic parking. |
| | -commChannel | string | Y | If set to anything but an empty string, this enables gate controls and defines the channel used to communicate with other constructs on. |
| | -shutdownDelayForGate | number | Y | The number of seconds to wait in the hold-state after detecting a floor to land on before shutting down. Intended for when you have a gate above or beside the elevator that you want to close. Default 2 seconds. |
| get | See `set` | | Y | Prints the setting set with the `set` command, don't add the leading `-`. |
| get-all | | | | Prints all current settings. Don't add the "-" before the argument. Example: `get turnAngle`. |
| reset-settings | | | | Resets all settings to their defaults. |
Expand Down
2 changes: 1 addition & 1 deletion src/Settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function Settings.New(db)
pathAlignmentDistanceLimit = { default = flightDefaults.pathAlignmentDistanceLimit },
setWaypointAlongRoute = { default = false },
commChannel = { default = "" },
gateCloseDelay = { default = 2 }
shutdownDelayForGate = { default = 2 }
}

for k, v in pairs(containerSettings) do
Expand Down
16 changes: 15 additions & 1 deletion src/Start.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ local function Start(isECU)
local fuel ---@type Fuel
local info ---@type InfoCentral

local followRemote = library.getLinkByName("FollowRemote") ---@type any

if followRemote and (type(followRemote.activate) ~= "function" or type(followRemote.deactivate) ~= "function") then
followRemote = nil
end

if followRemote then
log.Info("Found FollowRemote switch")
followRemote.activate()

unit:onEvent("onStop", function()
followRemote.deactivate()
end)
end

Task.New("Main", function()
settingsDb.BeginLoad()
routeDb.BeginLoad()
Expand Down Expand Up @@ -81,7 +96,6 @@ local function Start(isECU)
fsm.SetState(Idle.New(fsm))
end


if not isECU then
screen = ScreenController.New(fc, settings)
wsad = Wsad.New(fc, settings)
Expand Down
17 changes: 17 additions & 0 deletions src/controller/GateControl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ function GateControl.Instance()
local wantsOpen = false
local enabled = true
local timer = Stopwatch.New()
local followGate = library.getLinkByName("FollowGate") ---@type any

if followGate and (type(followGate.activate) ~= "function" or type(followGate.deactivate) ~= "function") then
followGate = nil
end

if followGate then
log.Info("Found FollowGate switch")
end

---@param topic string
---@param data {state:string}
Expand Down Expand Up @@ -65,6 +74,14 @@ function GateControl.Instance()
timer.Restart()
pub.Publish("SendData",
{ topic = "GateControl", data = { desiredState = wantsOpen } })

if followGate then
if wantsOpen then
followGate.activate()
else
followGate.deactivate()
end
end
end
end)

Expand Down
2 changes: 1 addition & 1 deletion src/flight/state/Hold.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function Hold.New(fsm)
timer.Add("WaitForGatesToClose", function()
unit.exit()
end,
settings.Number("gateCloseDelay"))
settings.Number("shutdownDelayForGate"))
end

function s.Enter()
Expand Down

0 comments on commit e6e490c

Please sign in to comment.