|
| 1 | + |
| 2 | +# Drawing procedure |
| 3 | +draw_mech := proc(sol::{list(`=`),set(`=`)}, data::{list(`=`),set(`=`)}, dof) |
| 4 | + |
| 5 | + local p0,p1,p2,p3,p3b,p4,p5,rRj,g3,p_act,sp,aa; |
| 6 | + rRj := 0.002: # radius of joint symbols |
| 7 | + |
| 8 | + p0 := evalf(subs(sol,data,dof, [comp_XYZ(P0, ground)])): |
| 9 | + p1 := evalf(subs(sol,data,dof, [comp_XYZ(P1, ground)])): |
| 10 | + p2 := evalf(subs(sol,data,dof, [comp_XYZ(P2, ground)])): |
| 11 | + p3 := evalf(subs(sol,data,dof, [comp_XYZ(P3, ground)])): |
| 12 | + p3b := evalf(subs(sol,data,dof, [comp_XYZ(P3b, ground)])): |
| 13 | + p4 := evalf(subs(sol,data,dof, [comp_XYZ(P4, ground)])): |
| 14 | + g3 := evalf(subs(sol,data,dof, [comp_XYZ(Gflap, ground)])): |
| 15 | + p5 := evalf(subs(sol,data,dof, [comp_XYZ(P5, ground)])): |
| 16 | + p_act := evalf(subs(sol,data,dof, [x1,y1])): |
| 17 | + |
| 18 | + |
| 19 | + sp := plot(CurveFitting:-Spline(subs(sol,data,theta3(t)=flap_open, |
| 20 | + [[comp_XYZ(P2, RF2)][1..2], |
| 21 | + [comp_XYZ(Pcurv1, RF2)][1..2], |
| 22 | + [comp_XYZ(Pcurv2, RF2)][1..2], |
| 23 | + [comp_XYZ(P3b, RF2)][1..2]]),v), |
| 24 | + v=subs(sol,data,theta3(t)=flap_open,comp_X(P2,RF2)..comp_X(P3b,RF2)),thickness=3,color=ColorTools:-GetPalette("Mono")["BlackishGray"]): |
| 25 | + |
| 26 | + if mode = 1 then aa := subs(data,LP/2) else aa:=0 end if: |
| 27 | + display( #plottools:-disk(p0[1..2],rRj,color="Yellow"), |
| 28 | + plottools:-disk(p2[1..2],rRj,color="Gray"), |
| 29 | + plottools:-disk(p3[1..2],rRj,color="Gray"), |
| 30 | + plottools:-disk(p3b[1..2],rRj,color="Gray"), |
| 31 | + plottools:-disk(p4[1..2],rRj,color="white"), |
| 32 | + #plottools:-disk(g3[1..2],rRj,color="Violet"), |
| 33 | + plottools:-disk(p5[1..2],rRj,color="white"), |
| 34 | + |
| 35 | + #plottools:-line(p0[1..2],p1[1..2],thickness=1,color="orange"), |
| 36 | + plottools:-line(p_act[1..2],p1[1..2],thickness=7,color=ColorTools:-GetPalette("Mono")["NeutralGray"]), |
| 37 | + plottools:-line(p1[1..2],p2[1..2] ,thickness=2,color=ColorTools:-GetPalette("Mono")["VeryLightGray"]), |
| 38 | + plottools:-line(p2[1..2],p3[1..2] ,thickness=1,color=ColorTools:-GetPalette("Mono")["WhitishGray"],linestyle=dash), |
| 39 | + plottools:-rotate(plottools:-translate(sp,p2[1]+aa,p2[2]),subs(sol,data,dof, theta1(t)),p2[1..2]), |
| 40 | + |
| 41 | + plottools:-polygon([p4[1..2],p5[1..2],g3[1..2]],color="Red"), |
| 42 | + |
| 43 | + scaling = constrained,size=[800,300]); |
| 44 | + |
| 45 | +end proc: |
| 46 | +# Plot position function |
| 47 | +plot_position := proc() |
| 48 | + |
| 49 | + local A,B: |
| 50 | + |
| 51 | + |
| 52 | + A := plot(subs(sol_kine, data, theta3(t) = q1_profile, theta1(t) * 180 /Pi), T = 0..3*actuation_time, color = c_set[1], |
| 53 | + title = typeset("Position of ", theta__1(t)),labels=["time [s]","Angle [�]"],size = [800, 500]): |
| 54 | + |
| 55 | + B := plot(subs(sol_kine, data, theta3(t) = q1_profile, s(t)), T = 0..3*actuation_time, color = c_set[2], |
| 56 | + title = typeset("Position of", s(t)),labels=[t (s),typeset([m])],size = [800, 500]): |
| 57 | + |
| 58 | + print(plots[display](Array([A, B]))): |
| 59 | + |
| 60 | +end proc: |
| 61 | +# Plot velocity function |
| 62 | +plot_velocity := proc() |
| 63 | + |
| 64 | + local A,B: |
| 65 | + |
| 66 | + A := plot(subs(sol_kine, data, theta_base, vel_theta1), T = 0..3*actuation_time, color = c_set[1], |
| 67 | + title = typeset("Velocity of ", theta__1(t)),labels=["time [s]", "velocity [rad/s]"],size = [800, 500]): |
| 68 | + |
| 69 | + B := plot(subs(sol_kine, data, theta_base, vel_s), T = 0..3*actuation_time, color = c_set[2], |
| 70 | + title = typeset("Velocity of ", s(t)),labels=["time [s]", "velocity [m/s]"],size = [800, 500]): |
| 71 | + |
| 72 | + print(plots[display](Array([A, B]))): |
| 73 | +end proc: |
| 74 | +# Plot acceleration function |
| 75 | +plot_acceleration := proc() |
| 76 | + |
| 77 | + local A,B: |
| 78 | + |
| 79 | + |
| 80 | + A := plot(subs(sol_kine, data, theta_base, acc_theta1), T = 0..3*actuation_time, color = c_set[1], |
| 81 | + title = typeset("Acceleration of ", theta__1(t)),labels = ["time [s]", " acceleration [rad/s^2]"],size = [800, 500]): |
| 82 | + |
| 83 | + B := plot(subs(sol_kine, data, theta_base, acc_s), T = 0..3*actuation_time, color = c_set[2], |
| 84 | + title = typeset("Acceleration of ", s(t)),labels = ["time [s]", "acceleration [m/s^2]"],size = [800, 500]): |
| 85 | + |
| 86 | + print(plots[display](Array([A, B]))): |
| 87 | + |
| 88 | +end proc: |
| 89 | +# Plot system configurations |
| 90 | +plot_system := proc() |
| 91 | + |
| 92 | + local A,B: |
| 93 | + |
| 94 | + |
| 95 | + A := draw_mech(sol_kine, data, theta3(t)=flap_closed, title = "Configuration Recursive", size = [500,500]): |
| 96 | + |
| 97 | + B := draw_mech(sol_kine, data, theta3(t)=flap_open , title = "Configuration Recursive", size = [500,500]): |
| 98 | + |
| 99 | + print(plots[display](Array([A, B]))); |
| 100 | +end proc: |
| 101 | +# Plot reaction forces for NE approach |
| 102 | +plot_reactionforces := proc() |
| 103 | + |
| 104 | + local A,B: |
| 105 | + |
| 106 | + A := odeplot(sol_dae, [t,R1y(t)], t = 0..3*actuation_time-0.001,color=c_set[1],labels=[typeset(t),typeset([N])],title="Reaction force R1y(t) prismatic joint"): |
| 107 | + B := odeplot(sol_dae, [t,T1z(t)], t = 0..3*actuation_time-0.001,color=c_set[2],labels=[typeset(t),typeset([N])],title="Reaction force T1z(t) prismatic joint"): |
| 108 | + print(plots[display](Array([A, B]))): |
| 109 | + |
| 110 | + A := odeplot(sol_dae, [t,R2x(t)], t = 0..3*actuation_time-0.001,color=c_set[3],labels=[typeset(t),typeset([N])],title="Reaction force R2x(t) prismatic joint"): |
| 111 | + B := odeplot(sol_dae, [t,R2y(t)], t = 0..3*actuation_time-0.001,color=c_set[4],labels=[typeset(t),typeset([N])],title="Reaction force R2y(t) prismatic joint"): |
| 112 | + print(plots[display](Array([A, B]))): |
| 113 | + |
| 114 | + A := odeplot(sol_dae, [t,R3x(t)], t = 0..3*actuation_time-0.001,color=c_set[5],labels=[typeset(t),typeset([N])],title="Reaction force R3x(t) prismatic joint"): |
| 115 | + B := odeplot(sol_dae, [t,R3y(t)], t = 0..3*actuation_time-0.001,color=c_set[6],labels=[typeset(t),typeset([N])],title="Reaction force R3y(t) prismatic joint"): |
| 116 | + print(plots[display](Array([A, B]))): |
| 117 | + |
| 118 | + A := odeplot(sol_dae, [t,R4x(t)], t = 0..3*actuation_time-0.001,color=c_set[7],labels=[typeset(t),typeset([N])],title="Reaction force R4x(t) prismatic joint"): |
| 119 | + B := odeplot(sol_dae, [t,R4y(t)], t = 0..3*actuation_time-0.001,color=c_set[8],labels=[typeset(t),typeset([N])],title="Reaction force R4y(t) prismatic joint"): |
| 120 | + print(plots[display](Array([A, B]))): |
| 121 | + |
| 122 | +end proc: |
| 123 | +# Plot sampled act() and s(t) |
| 124 | +plot_samples := proc() |
| 125 | + |
| 126 | + local A,B,C,D: |
| 127 | + |
| 128 | + A := plot(samples_act,color=c_set[1],labels=["samples","sampled force [N]"] ,style=point, title="Sampled actuator force"): |
| 129 | + B := plot(samples_s ,color=c_set[2],labels=["samples","sampled motion [m]"],style=point, title="Sampled motion of the actuator"): |
| 130 | + |
| 131 | + C := plot(subs(subs_act,act(t)),t=0..actuation_time,color=c_set[1],labels=["time [s]","Force [N]"],title="Fitted actuator force"): |
| 132 | + D := plot(subs(subs_s, s(t) ),t=0..actuation_time,color=c_set[2],labels=["time [s]","Extension [m]"],title="Fitted motion of the actuator"): |
| 133 | + |
| 134 | + print(plots[display](Array([A,B]))): |
| 135 | + print(plots[display](Array([C,D]))): |
| 136 | + |
| 137 | + |
| 138 | +end proc: |
| 139 | +# Plot hydraulic analysis results |
| 140 | +plot_hydr := proc() |
| 141 | + |
| 142 | + local C,D: |
| 143 | + |
| 144 | + C := plot(subs(hydr_sol_dinam,hydr_data,A(t)),t=0..actuation_time ,labels=["time [s]",typeset(m^2)],title="Valve area",color=c_set[1]); |
| 145 | + D := plot(subs(hydr_sol_dinam,hydr_data,V3(t)),t=0..actuation_time,labels=["time [s]",typeset(m^3)],title="Volume" ,color=c_set[2]); |
| 146 | + print(plots[display](Array([C,D]))): |
| 147 | + |
| 148 | + C := plot(subs(hydr_sol_dinam,hydr_data,p1(t)),t=0..actuation_time,labels=["time [s]","Pressure[bar]"],title="Pressure P1",color=c_set[3]); |
| 149 | + D := plot(subs(hydr_sol_dinam,hydr_data,p2(t)),t=0..actuation_time,labels=["time [s]","Pressure[bar]"],title="Pressure P2",color=c_set[4]); |
| 150 | + print(plots[display](Array([C,D]))): |
| 151 | + |
| 152 | + C := plot(subs(hydr_sol_dinam,hydr_data,p3(t)),t=0..actuation_time, labels=["time [s]","Pressure[bar]"],title="Pressure P3",color=c_set[5]); |
| 153 | + D := plot(subs(hydr_sol_dinam,hydr_data,q1__lex(t)),t=0..actuation_time,labels=["time [s]","Flow rate[m^3/s]"],title="Leakage flow rate",color=c_set[6]); |
| 154 | + print(plots[display](Array([C,D]))): |
| 155 | + |
| 156 | + C := plot(subs(hydr_sol_dinam,hydr_data,q__12(t)),t=0..actuation_time,labels=["time [s]","Flow rate[m^3/s]"],title="Q12 flow rate",color=c_set[7]); |
| 157 | + D := plot(subs(hydr_sol_dinam,hydr_data,q__23(t)),t=0..actuation_time,labels=["time [s]","Flow rate[m^3/s]"],title="Q23 flow rate",color=c_set[7]); |
| 158 | + print(plots[display](Array([C,D]))): |
| 159 | + |
| 160 | +end proc: |
| 161 | +# Dynamic optimization - NE |
| 162 | +dynam_opt_ne := proc(aaa,bbb,ccc,ddd,eee) |
| 163 | + local param,E,G,NE,NG,r_vars0,dof0,vel_dof0,qD0,vel_qD0,ics0,sol_act_dinam,dae_ics,dae_sys,sol_dae,cost_fun,i,k: |
| 164 | + |
| 165 | + param := [L1 = aaa,LP = bbb,anc = ccc,x1 = ddd,y1 = eee]: |
| 166 | + |
| 167 | + #Estimate the initial conditions |
| 168 | + dof0 := theta3(t) = flap_closed: |
| 169 | + vel_dof0 := diff(theta3(t),t) = 0: |
| 170 | + qD0 := op(evalf(subs(dof0, data_dae,param, sol_kine))): |
| 171 | + vel_qD0 := op(subs(vel_dof0, dof0, data_dae,param, [sol_vel])): |
| 172 | + ics0 := [dof0, vel_dof0, qD0, vel_qD0]: |
| 173 | + |
| 174 | + #Estimate the actuation force |
| 175 | + sol_act_dinam := subs(forcesub,gamma(t)=q1_profile_t,sol_kine,theta3(t)=q1_profile_t,data_dae,param,sol_act): |
| 176 | + |
| 177 | + #Estimate the reaction forces |
| 178 | + E, G := GenerateMatrix(subs(forcesub,gamma(t)=theta3(t),eqns), diff(q_vars,t,t) union r_vars): |
| 179 | + NE := evalf(subs(subs(forcesub,gamma(t)=theta3(t),sol_act), ics0, data_dae,param, E)): |
| 180 | + NG := evalf(subs(subs(forcesub,gamma(t)=theta3(t),sol_act), ics0, data_dae,param, G)): |
| 181 | + LinearSolve(NE, NG): |
| 182 | + r_vars0 := [seq(r_vars[i] = %[-i],i=1..nops(r_vars))]: |
| 183 | + |
| 184 | + #Assembling the generic DAE |
| 185 | + dae_ics := subs(t=0,data_dae,convert(convert(ics0,set) minus {diff(theta1(t),t)=0} ,D) union r_vars0 ): |
| 186 | + dae_sys := convert(subs(sol_act_dinam,forcesub,gamma(t)=q1_profile_t,data_dae, ne_eqns) union dae_ics,set): |
| 187 | + sol_dae := dsolve(dae_sys,numeric,stiff=true,parameters = [L1,LP,anc,x1,y1]): |
| 188 | + sol_dae(parameters = subs(param,[L1,LP,anc,x1,y1])): |
| 189 | + |
| 190 | + #Cost function |
| 191 | + cost_fun :=1/W*add(subs(data_dae,param,(delta__s[k]-rhs(sol_dae(k/np*actuation_time)[10]))^2),k=1..np); |
| 192 | +end proc: |
| 193 | +# Dynamic optimization - Lagrange |
| 194 | +dynam_opt_lagr := proc(aaa,bbb,ccc,ddd,eee,fff) |
| 195 | + local param,E,G,NE,NG,l_vars0,dof0,vel_dof0,qD0,vel_qD0,ics0,sol_act_dinam,dae_ics,dae_sys,sol_dae,cost_fun,i,k,subs_inertia, delta__s: |
| 196 | + |
| 197 | + |
| 198 | + |
| 199 | + subs_inertia := {m1 = subs(data_dae,sp=0.010,l=0.004,4510*L1*sp*l), |
| 200 | + Iz1 = subs(data_dae,l=0.004,sp=0.010,1/12*4510*L1*sp*l*(L1^2+sp^2)), |
| 201 | + m2 = subs(data_dae,sp=0.010,l=0.004,4510*LP*sp*l), |
| 202 | + Iz2 = subs(data_dae,l=0.004,sp=0.010,1/12*4510*LP*sp*l*(LP^2+sp^2)) |
| 203 | + }: |
| 204 | + param := [L1 = aaa,LP = bbb,anc = ccc,x1 = ddd,y1 = eee, s__closed = fff]: |
| 205 | + |
| 206 | + #Estimate the initial conditions |
| 207 | + dof0 := theta3(t) = flap_closed: |
| 208 | + vel_dof0 := diff(theta3(t),t) = 0: |
| 209 | + qD0 := op(evalf(subs(dof0, data_dae,param, sol_kine))): |
| 210 | + vel_qD0 := op(subs(vel_dof0, dof0, data_dae,param, [sol_vel])): |
| 211 | + ics0 := [dof0, vel_dof0, qD0, vel_qD0]: |
| 212 | + |
| 213 | + #Estimate the actuation force |
| 214 | + sol_act_dinam := subs(forcesub,gamma(t)=q1_profile_t,sol_kine,theta3(t)=q1_profile_t,subs_inertia,data_dae,param,sol_act): |
| 215 | + |
| 216 | + #Estimate the reaction forces |
| 217 | + E, G := GenerateMatrix(subs(forcesub,gamma(t)=theta3(t),eqns), diff(q_vars,t,t) union l_vars): |
| 218 | + NE := evalf(subs(subs(forcesub,gamma(t)=theta3(t),sol_act), ics0,subs_inertia, data_dae, E)): |
| 219 | + NG := evalf(subs(subs(forcesub,gamma(t)=theta3(t),sol_act), ics0,subs_inertia, data_dae, G)): |
| 220 | + LinearSolve(NE, NG): |
| 221 | + l_vars0 := [seq(l_vars[i] = %[-i],i=1..nops(l_vars))]: |
| 222 | + |
| 223 | + #Assembling the generic DAE |
| 224 | + dae_ics := subs(t=0,subs_inertia,data_dae,convert(convert(ics0,set),D) union l_vars0 ): |
| 225 | + dae_sys := convert(subs(sol_act_dinam,forcesub,gamma(t)=q1_profile_t,subs_inertia,data_dae, la_eqns) union dae_ics,set): |
| 226 | + sol_dae := dsolve(dae_sys,numeric, method = rosenbrock_dae ,stiff = true, output = listprocedure,parameters = [L1,LP,anc,x1,y1]): |
| 227 | + sol_dae(parameters = subs(param,[L1,LP,anc,x1,y1])): |
| 228 | + |
| 229 | + #Cost function |
| 230 | + delta__s := [seq(evalf(subs(T=i/np*actuation_time,subs(param_opt,Fd_s))),i=1..np)]; |
| 231 | + cost_fun :=1/W*add(subs(subs_inertia,data_dae,param,(delta__s[k]-rhs(sol_dae(k/np*actuation_time)[4]))^2),k=1..np); |
| 232 | +end proc: |
| 233 | + |
0 commit comments