Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
44 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
defmodule ControlLoop.BangBangController do | ||
require Record | ||
|
||
Record.defrecord(:bb_controller, setpoint: 0, output_off: 0, output_on: 0) | ||
|
||
def update( bb_controller(setpoint: setpoint, output_off: output_off, output_on: output_on) = controller, input) do | ||
output = if input > setpoint, do: output_on, else: output_off | ||
|
||
{output, controller} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
defmodule ControlLoop.PIDController do | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
defmodule BangBangControllerTest do | ||
use ExUnit.Case | ||
import ControlLoop.BangBangController, only: :macros | ||
alias ControlLoop.BangBangController | ||
|
||
describe "setup" do | ||
test "basic creating and fetching" do | ||
c = bb_controller(setpoint: 1, output_off: 2, output_on: 3) | ||
|
||
assert bb_controller(c, :setpoint) == 1 | ||
assert bb_controller(c, :output_off) == 2 | ||
assert bb_controller(c, :output_on) == 3 | ||
end | ||
end | ||
|
||
describe "updating" do | ||
setup do | ||
%{c: bb_controller(setpoint: 1, output_off: 2, output_on: 3)} | ||
end | ||
test "update returns off value for below or at setpoint", %{c: controller} do | ||
assert { 2, controller } == BangBangController.update(controller, 0) | ||
assert { 2, controller } == BangBangController.update(controller, 1) | ||
end | ||
|
||
test "update returns on value for above setpoint", %{c: controller} do | ||
assert { 3, controller } == BangBangController.update(controller, 2) | ||
end | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.