@author: Steven Masfaraud """ import bms from bms.signals.functions import Ramp from bms.blocks.continuous import ODE K = 1. tau = 1.254 #e=bms.Step('e',1.) e = Ramp('e', 1.) s = bms.Variable('s', [0]) block = ODE(e, s, [K], [1, tau]) ds = bms.DynamicSystem(10, 100, [block]) #res=ds.ResolutionOrder() #print(res) ds.Simulate() #ds.PlotVariables() #ds.DrawModel() ## External plot for verification import matplotlib.pyplot as plt plt.figure() plt.plot(ds.t, e.values) plt.plot(ds.t, s.values) s_inf = K * (ds.t.copy() - tau) plt.plot(ds.t, e.values) plt.plot(ds.t, s_inf)
# -*- coding: utf-8 -*- """ Created on Tue Dec 22 18:42:33 2015 @author: steven """ import bms from bms.signals.functions import Sinus from bms.blocks.continuous import ODE K = 1 Q = 0.3 w0 = 3 #e=bms.Step('e',4.) e = Sinus('e', 4., 5) s = bms.Variable('s', [0]) block = ODE(e, s, [1], [1, 2 * Q / w0, 1 / w0**2]) ds = bms.DynamicSystem(5, 200, [block]) #ds.DrawModel() ds.Simulate() ds.PlotVariables()
#I2=Sinus(('input','i'),100.) #O2=bms.Variable(('Output','O'))# #b=ODE(I2,O2,[0,1],[1]) #ds2=bms.DynamicSystem(15,3000,[b]) #ds2.Simulate() #ds2.PlotVariables() #print(b.Mi,b.Mo) #print() #============================================================================== # Feedback with derivative for stability test #============================================================================== I = Step(('input', 'i'), 100.) AI = bms.Variable(('adapted input', 'ai'), [100.]) dI = bms.Variable(('error', 'dI')) O = bms.Variable(('Output', 'O')) # F = bms.Variable(('Feedback', 'F')) # b1 = Gain(I, AI, Ka) b2 = WeightedSum([AI, dI], F, [1, -1]) b3 = ODE(O, dI, [1, tau], [Kb]) b4 = Gain(F, O, 1 / Kc) # #ds. ds = bms.DynamicSystem(0.1, 20, [b1, b2, b3, b4]) ds.Simulate() ds.PlotVariables([[I, O, dI, F]])
cc = Sinus(('Brake command', 'cc'), 0.5, 0.1, 0, 0.5) it = Step(('Input torque', 'it'), 100) rt = Step(('Resistant torque', 'rt'), -80) tc = bms.Variable(('brake Torque capacity', 'Tc')) bt = bms.Variable(('brake torque', 'bt')) w1 = bms.Variable(('Rotational speed shaft 1', 'w1')) #dw12=bms.Variable(('Clutch differential speed','dw12')) st1 = bms.Variable(('Sum torques on 1', 'st1')) et1 = bms.Variable(('Sum of ext torques on 1', 'et1')) b1 = Gain(cc, tc, Cmax) b2 = WeightedSum([it, rt], et1, [1, 1]) b3 = CoulombVariableValue(et1, w1, tc, bt, 0.1) #b3=Coulomb(it,dw12,ct,150) b4 = ODE(st1, w1, [1], [fv1, I1]) #b5=ODE(st2,w2,[1],[fv2,I2]) b6 = WeightedSum([it, rt, bt], st1, [1, 1, 1]) #b7=WeightedSum([it,rt],et1,[1,1]) ds = bms.DynamicSystem(100, 400, [b1, b2, b3, b4, b6]) #ds.DrawModel() r = ds.Simulate() ds.PlotVariables([[w1], [tc, bt, rt, it, st1, et1]]) import matplotlib.pyplot as plt plt.figure() plt.plot(r) plt.show() #ds.PlotVariables([[cc]])
Pm = bms.Variable(('Mechanical power', 'Pm')) block1 = Subtraction(Wc, W, dW) block2 = ODE(dW, Ui, [1], [0, tau_i]) block3 = Gain(dW, Up, Gc) block4 = Sum([Up, Ui], Uc) block4a = Saturation(Uc, Um, -Umax, Umax) block5 = Subtraction(Um, e, Uind) block6 = ODE(Uind, Iind, [1], [R, L]) block7 = Gain(Iind, Tm, k) block8 = Sum([Tm, Text], T) block8a = Coulomb(Tm, W, Text, Tr, 2) block9 = ODE(T, W, [1], [0, J]) block10 = Gain(W, e, k) block11 = Product(Um, Iind, Pe) block11a = Product(Tm, W, Pm) ds = bms.DynamicSystem(10, 1000, [ block1, block2, block3, block4, block4a, block5, block6, block7, block8, block8a, block9, block10, block11, block11a ]) # ds.DrawModel() r = ds.Simulate() # r=ds._ResolutionOrder() # print(ba) ds.PlotVariables([ [Wc, W, dW], [Tm, Text, T], ]) ds.PlotVariables([[Um, e, Uind], [Pe, Pm], [Iind]])
import bms from bms.signals.functions import Step from bms.blocks.continuous import Gain, ODE, Sum, Subtraction, Product Ka = 3 Kb = 4 Kc = 3 tau = 1 I = Step(('input', 'i'), 100.) AI = bms.Variable(('adapted input', 'ai'), [100.]) dI = bms.Variable(('error', 'dI')) O = bms.Variable(('Output', 'O')) F = bms.Variable(('Feedback', 'F')) b1 = Gain(I, AI, Ka) b2 = Subtraction(AI, F, dI) b3 = ODE(dI, O, [Kb], [1, tau]) b4 = Gain(O, F, Kc) ds = bms.DynamicSystem(3, 1000, [b1, b2, b3, b4]) r = ds.Simulate() ds.PlotVariables([[I, O, dI, F]]) # I2=Step(('input','i'),100.) #O2=bms.Variable(('Output','O'))# # ds2=bms.DynamicSystem(3,600,[ODE(I2,O2,[Ka*Kb],[1+Kc*Kb,tau])]) # ds2.Simulate() # ds2.PlotVariables()
# e=bmsp.Step(1.,'e') cc = Sinus(('Clutch command', 'cc'), 0.5, 0.1, 0, 0.5) it = Step(('Input torque', 'it'), 200) rt = Step(('Resistant torque', 'rt'), -180) tc = bms.Variable(('Clutch Torque capacity', 'Tc')) ct = bms.Variable(('clutch torque', 'ct')) w1 = bms.Variable(('Rotational speed shaft 1', 'w1')) w2 = bms.Variable(('Rotational speed shaft 2', 'w2')) dw12 = bms.Variable(('Clutch differential speed', 'dw12')) st1 = bms.Variable(('Sum torques on 1', 'st1')) st2 = bms.Variable(('Sum torques on 2', 'st2')) b1 = Gain(cc, tc, Cmax) b2 = WeightedSum([w1, w2], dw12, [1, -1]) b3 = CoulombVariableValue(it, dw12, tc, ct, 1) # b3=Coulomb(it,dw12,ct,150) b4 = ODE(st1, w1, [1], [fv1, I1]) b5 = ODE(st2, w2, [1], [fv2, I2]) b6 = WeightedSum([it, ct], st1, [1, 1]) b7 = WeightedSum([rt, ct], st2, [1, -1]) ds = bms.DynamicSystem(50, 150, [b1, b2, b3, b4, b5, b6, b7]) # ds.DrawModel() r = ds.Simulate() ds.PlotVariables([[dw12, w1, w2], [tc, ct, rt, it]]) # ds.PlotVariables([[cc]])