diff --git a/examples/robot/test_components.jl b/examples/robot/test_components.jl index e9dca2f6..0f3b6f87 100644 --- a/examples/robot/test_components.jl +++ b/examples/robot/test_components.jl @@ -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 ## @@ -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)) diff --git a/examples/robot/utilities/components.jl b/examples/robot/utilities/components.jl index 6a2e3ee9..5d9d159e 100644 --- a/examples/robot/utilities/components.jl +++ b/examples/robot/utilities/components.jl @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index 5910e498..a66d6aff 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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) @@ -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, [ @@ -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