Last active
August 29, 2015 14:20
-
-
Save tallakt/c8f4c1d8e1d425fb3282 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
defmodule LineFollower do | |
using Time.PLC | |
# These may be extracted to a separate module | |
# input and output are macros that generate something lacced 'optical' and 'pwm' | |
# that somehow link to the signal 'objects'. Think Ruby 'attr' function | |
# the physical addresses are linked to the actual hardware being used | |
input :optical, "I3.0", desc: "Optical line sensor" | |
output :pwm, "PIW100", desc: "Steering motor PWM input" | |
signal :tmp do | |
input |> time_on(~t"100 ms") |> time_off(~t"100 ms") | |
end | |
# at this point tmp is a discrete signal 'object' | |
freeze do | |
# at this point tmp represents the instantaneous value of the tmp signal | |
pwm_output = case tmp do | |
true -> | |
100.0 | |
_ -> | |
-100.0 | |
end | |
end | |
# at this point, pwm_output is converted from instantaneous value to a signal 'object' | |
pwm_output |> assign_to pwm | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment