Skip to content

Commit

Permalink
some progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Uwe Fechner committed Dec 19, 2024
1 parent 5fcf8c1 commit bdc94cd
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/torque_controlled_generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ of drum and motor are combined into one value (stiff coupling). =#
"""
mutable struct TorqueControlledMachine
Model of a winch with an torqrue controlled generator and a gearbox.
Model of a winch with an torque controlled generator and a gearbox.
"""
@with_kw mutable struct TorqueControlledMachine <: AbstractWinchModel @deftype Float64
set::Settings
Expand All @@ -38,6 +38,8 @@ Model of a winch with an torqrue controlled generator and a gearbox.
brake_acc = -25.0
"if the brake of the winch is activated"
brake::Bool = true;
"last set speed"
last_set_speed = 0.0;
end

function TorqueControlledMachine(set::Settings)
Expand All @@ -61,6 +63,7 @@ function calc_viscous_friction(wm::TorqueControlledMachine, omega)
end

function calc_acceleration(wm::TorqueControlledMachine, speed, force; set_torque=nothing, set_speed=nothing, use_brake = false)
dt = 1/wm.set.sample_freq
if use_brake && ! isnothing(set_speed)
if abs(set_speed) < 0.9 * wm.v_min
wm.brake = true
Expand All @@ -73,13 +76,17 @@ function calc_acceleration(wm::TorqueControlledMachine, speed, force; set_torque
return wm.brake_acc * speed
end
end
# limit the acceleration
if ! isnothing(set_speed)
if set_speed > speed + 1
set_speed = speed + 1
elseif set_speed < speed - 1
set_speed = speed - 1
if !isnothing(set_speed)
# limit the acceleration
MAX_ACC = wm.set.max_acc
limited_speed = set_speed
if set_speed > wm.last_set_speed + MAX_ACC*dt
limited_speed = wm.last_set_speed + MAX_ACC*dt
elseif set_speed < wm.last_set_speed - MAX_ACC*dt
limited_speed = wm.last_set_speed - MAX_ACC*dt
end
# calculate set_torque based on the limited speed

end
omega = wm.set.gear_ratio/wm.set.drum_radius * speed
τ = calc_coulomb_friction(wm) * smooth_sign(omega) + calc_viscous_friction(wm, omega)
Expand Down

0 comments on commit bdc94cd

Please sign in to comment.