Skip to content

Commit

Permalink
axis test working
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Oct 13, 2023
1 parent 91db2ca commit 9a52380
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
40 changes: 21 additions & 19 deletions examples/robot/test_components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,39 +97,42 @@ myinertia(args...; kwargs...) = ModelingToolkitStandardLibrary.Mechanical.Rotati

mytorque(args...; kwargs...) = ModelingToolkitStandardLibrary.Mechanical.Rotational.ConstantTorque(args...; kwargs...)

@mtkmodel AxisTest begin
@mtkmodel AxisTest2 begin
@components begin
axis2 = AxisType2()
# fixed = myfixed() # bug in @mtkmodel
fixed = mytorque(tau_constant=1, use_support=false) # bug in @mtkmodel
fixed = myfixed() # bug in @mtkmodel
# fixed = mytorque(tau_constant=1, use_support=true) # bug in @mtkmodel
# inertia = myinertia(J=1)
# constant1 = Constant(k=1)
constant2 = Constant(k=1)
constant2 = Constant(k=0)
constant3 = Constant(k=1)
constant4 = Constant(k=1)
constant5 = Constant(k=1)

constant6 = Constant(k=1)
constant7 = Constant(k=1)
constant8 = Constant(k=1)
constant9 = Constant(k=1)
constant10 = Constant(k=1)

constant5 = Constant(k=0)
end
@equations begin
connect(axis2.flange, fixed.flange)
# connect(axis2.flange, inertia.flange_a)
# constant1.output.u ~ motor.axisControlBus.current_ref # This is connected to the controller output
constant2.output.u ~ motor.axisControlBus.speed_ref
constant3.output.u ~ motor.axisControlBus.angle_ref
constant4.output.u ~ motor.axisControlBus.motion_ref
constant5.output.u ~ motor.axisControlBus.acceleration_ref
constant2.output.u ~ axis2.axisControlBus.speed_ref
constant3.output.u ~ axis2.axisControlBus.angle_ref
constant4.output.u ~ axis2.axisControlBus.motion_ref
constant5.output.u ~ axis2.axisControlBus.acceleration_ref
end
end

@named axisTest = AxisTest()
@named axisTest = AxisTest2()
m = structural_simplify(axisTest)
m = structural_simplify(IRSystem(axisTest))
# m = structural_simplify(IRSystem(axisTest)) # Yingbo: solution unstable with IRSystem simplification

cm = complete(axisTest)
prob = ODEProblem(m, [
D(D(cm.axis2.gear.gear.phi_b)) => 0
], (0.0, 5))
sol = solve(prob, Rodas4())
@test SciMLBase.successful_retcode(sol)
plot(sol, layout=length(states(m)))
u = cm.axis2.controller.PI.ctr_output.u
@test abs(sol(prob.tspan[2], idxs=u)) < 1e-6

##

Expand All @@ -142,7 +145,6 @@ m = structural_simplify(IRSystem(axisTest))
@named pp = PathPlanning1(;)
@named pp6 = PathPlanning6(;)

@named oneaxis = OneAxis()
@named oneaxis = OneAxis()

ssys = structural_simplify(IRSystem(oneaxis))
Expand Down
6 changes: 2 additions & 4 deletions examples/robot/utilities/components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@ function AxisType2(; name, kp = 10, ks = 1, Ts = 0.01, k = 1.1616, w = 4590, D =
axisControlBus = AxisControlBus()
end

eqs = [connect(gear.flange_b, flange)
connect(gear.flange_b, angleSensor.flange)
connect(gear.flange_b, speedSensor.flange)
eqs = [
connect(gear.flange_b, flange, angleSensor.flange, speedSensor.flange, accSensor.flange)
connect(motor.flange_motor, gear.flange_a)
connect(gear.flange_b, accSensor.flange)
connect(motor.axisControlBus, axisControlBus)
(angleSensor.phi.u ~ axisControlBus.angle)
(speedSensor.w.u ~ axisControlBus.speed)
Expand Down
7 changes: 4 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ connections = [connect(world.frame_b, rev.frame_a)
modele = ModelingToolkit.expand_connections(model)

# ssys = structural_simplify(model)#, allow_parameter = false)
ssys = structural_simplify(IRSystem(modele)) # Yingbo, this fails with SymbolicIR but not with MTK
ssys = structural_simplify(IRSystem(modele)) # Yingbo, Rotation-matrix dummy derivatives

D = Differential(t)

Expand Down Expand Up @@ -744,7 +744,8 @@ eqs = [connect(world.frame_b, gearConstraint.bearing)


# @test_skip begin
ssys = structural_simplify(IRSystem(model)) # Index out of bounds, Yingbo
ssys = structural_simplify(model) # Yingbo: Sym doesn't have a operation or arguments!
ssys = structural_simplify(IRSystem(model)) # Yingbo: Not a well formed derivative expression

prob = ODEProblem(ssys,
[
Expand Down Expand Up @@ -826,7 +827,7 @@ eqs = [connect(world.frame_b, freeMotion.frame_a)
# ssys = structural_simplify(model, allow_parameters = false)
ssys = structural_simplify(IRSystem(model))

# Can't get initial condition to bite, Yingbo
# Yingbo: acceleration dummy derivatives
prob = ODEProblem(ssys,
[
freeMotion.v_rel_a .=> [0,1,0] # Movement in y direction
Expand Down

0 comments on commit 9a52380

Please sign in to comment.