Generic Components

Integrator

WinchControllers.IntegratorType
mutable struct Integrator

Discrete integrator with external reset.

Fields

  • dt::Float64

  • i::Float64: Default: 1.0

  • output::Float64: Default: 0.0

  • last_output::Float64: Default: 0.0

Example

int = Integrator(0.05, 2, 3)      # dt, integration constant, initial output  
input = 2
for i in 1:3
    out = calc_output(int, input) # calculate the output
    println(out)
    on_timer(int)                 # must be called on each time-step
end
reset(int, 3)                     # reset the integrator to the initial state
source
WinchControllers.IntegratorType
function Integrator(dt, i=1.0, x0=0.0)

Constructor for discrete integrator with external reset.

Parameters

  • dt: time-step [s]
  • i: integration constant
  • x0: initial and last output

Returns

  • a new struct of type Integrator
source
Base.resetFunction
reset(int::Integrator, x0=0.0)

Reset the integrator int to the value x0.

Parameters

  • int::Integrator: An integrator struct
  • x0: default value =0.0; initial and last output

Returns

  • nothing
source
WinchControllers.calc_outputMethod
calc_output(int::Integrator, input)

Calculate and return the output without updating last_output.

Parameters

  • int::Integrator: An integrator struct
  • input: The input value

Returns

  • the output value
source
WinchControllers.on_timerMethod
on_timer(int::Integrator)

Update the field last_output. Must be called once per time-step.

Parameters

  • int::Integrator: An integrator struct

Returns

  • nothing
source

UnitDelay

WinchControllers.UnitDelayType
mutable struct UnitDelay

UnitDelay, delay the input signal by one time step.

Fields

  • last_output::Float64: Default: 0

  • last_input::Float64: Default: 0

Example

ud = UnitDelay()
for i in 1:3
    out = calc_output(ud, i) # updates the input and calculates the output
    println(out)
    on_timer(ud)             # next time-step
end
source
Base.resetMethod
reset(ud::UnitDelay)

Reset the last_input and last_output of the struct ud to zero.

Parameters

  • ud::UnitDelay: A UnitDelay struct

Returns

  • nothing
source
WinchControllers.calc_outputMethod
calc_output(ud::UnitDelay, input)

Calculate and return the output and update the last_input, but not the last_output.

Parameters

  • int::UnitDelay: A UnitDelay struct
  • input: The input value

Returns

  • the last output
source
WinchControllers.on_timerMethod
on_timer(ud::UnitDelay)

Update the field last_output. Must be called once per time-step.

Parameters

  • ud::UnitDelay: A UnitDelay struct

Returns

  • nothing
source

RateLimiter

WinchControllers.RateLimiterType
mutable struct RateLimiter

Limit the rate of change of the output signal (return value of calc_output) to ± limit. Unit of limit: 1/s.

Fields

  • dt::Float64: Default: 0.05

  • limit::Float64: Default: 1

  • output::Float64: Default: 0

  • last_output::Float64: Default: 0

Example

using WinchControllers, ControlPlots
rl = RateLimiter(1.0, 0.8)
input =  [0,0,1,2,3,3,3,3,3,2,1,0,0,0,0,0]
out = zeros(16)
for i in 1:16
    out[i] = calc_output(rl, input[i])
    on_timer(rl)
end
plot(1:16, [input, out]; labels=["input", "output"])

rate_limiter.

source
WinchControllers.RateLimiterType
RateLimiter(dt, limit=1.0, x0=0.0)

Parameters

  • dt: the time-step [s]
  • limit: the rate limit, default: 1.0 [1/s]
  • x0: the initial output, default: 0.0

Returns

  • a struct of type RateLimiter
source
Base.resetFunction
reset(rl::RateLimiter, x0=0.0)

Reset the output and last_output of the struct ud to x0.

Parameters

  • rl::RateLimiter: A RateLimiter struct
  • x0: the initial value of the output signal

Returns

  • nothing
source
WinchControllers.calc_outputMethod
calc_output(rl::RateLimiter, input)

Calculate and return the output, but not the last_output.

Parameters

  • rl::RateLimiter: A RateLimiter struct
  • input: The input value

Returns

  • the new output
source
WinchControllers.on_timerMethod
on_timer(rl::RateLimiter)

Update the field last_output. Must be called once per time-step.

Parameters

  • rl::RateLimiter: A RateLimiter struct

Returns

  • nothing
source

Mixer_2CH

WinchControllers.Mixer_2CHType
mutable struct Mixer_2CH

Mix two analog inputs. It selects either input a or input b depending on the value of the digital input and implements soft switching with a blend time t_blend. Implements the following block diagram: mixer_2ch.

Fields

  • dt::Float64

  • t_blend::Float64: Default: 1.0

  • factor_b::Float64: Default: 0

  • select_b::Bool: Default: false

Example

using WinchControllers, Test

m2 = Mixer_2CH(0.2, 1.0) # dt=0.2s, t_blend = 1.0s
x = ones(10)
y = 2*x
out = zeros(10)
for i in 1:length(x)
    in1=x[i]
    in2=y[i]
    out[i] = calc_output(m2, x[i], y[i])
    select_b(m2, i > 2)
    on_timer(m2)
end
@test all(out .≈ [1.0, 1.0, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.0, 2.0])
source
WinchControllers.Mixer_2CHMethod
Mixer_2CH(dt, t_blend)

Constructor for Mixer_2CH, a component for mixing two analog inputs.

Parameters

  • dt: the time-step [s]
  • t_blend: the time for blending over from one channel to the other [s]

Returns

  • a struct of type Mixer_2CH
source
WinchControllers.select_bMethod
select_b(m2::Mixer_2CH, select_b::Bool)

Select input a or b.

Parameters

  • m2::Mixer_2CH: the two-channel mixer
  • select_b: if true, select channel b, otherwise select channel a

Returns

  • nothing
source
WinchControllers.calc_outputMethod
calc_output(m2::Mixer_2CH, input_a, input_b)

Calculate and return the output of the two channel mixer.

Parameters

  • m2::Mixer_2CH: a two channel mixer component
  • input_a: input value of channel A
  • input_b: input value of channel B

Returns

  • the output value
source
WinchControllers.on_timerMethod
on_timer(m2::Mixer_2CH)

Update the field m2.factor_b. Must be called once per time-step.

Parameters

  • m2::Mixer_2CH: a two channel mixer

Returns

  • nothing
source

Mixer_3CH

WinchControllers.Mixer_3CHType
mutable struct Mixer_3CH

Mix three analog inputs. It selects either input a or input b or input c depending on the values of the digital inputs and implements soft switching with a blend time t_blend. Implements the following block diagram: mixer_3ch.

Fields

  • dt::Float64

  • t_blend::Float64: Default: 1.0

  • factor_b::Float64: Default: 0

  • factor_c::Float64: Default: 0

  • select_b::Bool: Default: false

  • select_c::Bool: Default: false

Example

using WinchControllers, ControlPlots

TIME = range(0.0, 10, 501)
SIN1 = sin.(TIME * 0.5 * 2pi) * 2
SIN2 = sin.(TIME * 0.25 * 2pi)
NOISE = (rand(501).-0.5) * 2
mix3 = Mixer_3CH(10, 0.25)
out  = zeros(501)

for i in 1:501                   # 10s with dt=0.02
    if i == 150
        select_b(mix3, true)
    elseif i == 300
        select_c(mix3, true)
    elseif i == 450
        select_c(mix3, false)        
    end
    out[i] = calc_output(mix3, SIN1[i], SIN2[i], NOISE[i])
    on_timer(mix3)
end
plot(TIME, out)
source
WinchControllers.get_stateMethod
function get_state(m3::Mixer_3CH)

Return the controller state as integer.

Returns WinchControllerState as integer.

  • wcsLowerForceControl = 0 # input b selected
  • wcsSpeedControl = 1 # input a selected
  • wcsUpperForceControl = 2 # input c selected
source
WinchControllers.select_bMethod
select_b(m3::Mixer_3CH, select_b::Bool)

Make input b the active input.

To make channel a the active input call:

select_b(m3, false)
select_c(m3, false)

Parameters

  • m3::Mixer_3CH: the three-channel mixer
  • select_b: if true, select channel b

Returns

  • nothing
source
WinchControllers.select_cMethod
select_c(m3::Mixer_3CH, select_c::Bool)

Make input c the active input.

Parameters

  • m3::Mixer_3CH: the three-channel mixer
  • select_c: if true, select channel c

Returns

  • nothing
source
WinchControllers.calc_outputMethod
calc_output(m3::Mixer_3CH, input_a, input_b, input_c)

Calculate and return the output of the three channel mixer.

Parameters

  • m3::Mixer_3CH: a three channel mixer component
  • input_a: input value of channel A
  • input_b: input value of channel B
  • input_c: input value of channel C

Returns

  • the output value
source
WinchControllers.on_timerMethod
on_timer(m3::Mixer_3CH)

Update the fields m3.factor_b and m3.factor_c. Must be called once per time-step.

Parameters

  • m3::Mixer_3CH: a three channel mixer

Returns

  • nothing
source