コード例 #1
0
ファイル: mechanical.py プロジェクト: rowhit/BMSpy
 def PartialDynamicSystem(self, ieq, variable):
     """
     returns dynamical system blocks associated to output variable
     """
     if ieq == 0:
         # w2=Rw1
         if variable == self.physical_nodes[0].variable:
             # w1=w2/R
             return [
                 Gain(self.physical_nodes[1].variable, variable,
                      1 / self.ratio)
             ]
         elif variable == self.physical_nodes[1].variable:
             # w2=Rw1
             return [
                 Gain(self.physical_nodes[0].variable, variable, self.ratio)
             ]
     elif ieq == 1:
         # C1=-RC2
         if variable == self.variables[0]:
             # C1=-RC2
             return [Gain(self.variables[1], variable, -self.ratio)]
         elif variable == self.variables[1]:
             # C2=-C1/R
             return [Gain(self.variables[0], variable, -1 / self.ratio)]
コード例 #2
0
ファイル: mechanical.py プロジェクト: rowhit/BMSpy
 def PartialDynamicSystem(self, ieq, variable):
     """
     returns dynamical system blocks associated to output variable
     """
     if ieq == 0:
         # v=Rw
         if variable == self.physical_nodes[0].variable:
             # W=V/r
             return [
                 Gain(self.physical_nodes[1].variable, variable,
                      1 / self.wheels_radius)
             ]
         elif variable == self.physical_nodes[1].variable:
             # V=rw
             return [
                 Gain(self.physical_nodes[0].variable, variable,
                      self.wheels_radius)
             ]
     elif ieq == 1:
         # C=-FR
         if variable == self.variables[0]:
             # C=-FR
             return [Gain(self.variables[1], variable, -self.wheels_radius)]
         elif variable == self.variables[1]:
             # F=-C/R
             return [
                 Gain(self.variables[0], variable, -1 / self.wheels_radius)
             ]
コード例 #3
0
ファイル: electrical.py プロジェクト: itamarNov/BMSpy
    def PartialDynamicSystem(self,ieq,variable):
        """
        returns dynamical system blocks associated to output variable
        """
#        print(ieq,variable.name)
        if ieq==0:
            # U1-U2=R(i1)
            if variable==self.physical_nodes[0].variable:
                # U1 is output
                # U1=R(i1)+U2
                return [WeightedSum([self.physical_nodes[1].variable,self.variables[0]],variable,[1,self.R])]
            elif variable==self.physical_nodes[1].variable:
                # U2 is output
                # U2=-R(i1)+U2
                return [WeightedSum([self.physical_nodes[0].variable,self.variables[0]],variable,[1,-self.R])]
            elif variable==self.variables[0]:
                # i1 is output
                # i1=(U1-U2)/R
                return [WeightedSum([self.physical_nodes[0].variable,self.physical_nodes[1].variable],variable,[1/self.R,-1/self.R])]
        elif ieq==1:
            # i1=-i2
            if variable==self.variables[0]:
                #i1 as output
                return [Gain(self.variables[1],self.variables[0],-1)]
            elif variable==self.variables[1]:
                #i2 as output
                return [Gain(self.variables[0],self.variables[1],-1)]
コード例 #4
0
ファイル: mechanical.py プロジェクト: rowhit/BMSpy
 def PartialDynamicSystem(self, ieq, variable):
     """
     returns dynamical system blocks associated to output variable
     """
     if ieq == 0:
         # U1=0
         if variable == self.variables[0]:
             return [Gain(self.commands[0], variable, -self.Tmax)]
コード例 #5
0
ファイル: electrical.py プロジェクト: itamarNov/BMSpy
 def PartialDynamicSystem(self,ieq,variable):
     """
     returns dynamical system blocks associated to output variable
     """
     if ieq==0:
         # U1=0
         if variable==self.physical_nodes[0].variable:
             v=Step('Ground',0)
             return[Gain(v,variable,1)]                
コード例 #6
0
    def PartialDynamicSystem(self, ieq, variable):
        """
        returns dynamical system blocks associated to output variable
        """

        if ieq == 0:

            if variable == self.physical_nodes[0].variable:
                print('1')
                # U1 is output
                # U1=i1/pC+U2
                Uc = Variable(hidden=True)
                block1 = ODE(self.variables[0], Uc, [1], [0, self.C])
                sub1 = Sum([self.physical_nodes[1].variable, Uc], variable)
                return [block1, sub1]
            elif variable == self.physical_nodes[1].variable:
                print('2')
                # U2 is output
                # U2=U1-i1/pC
                Uc = Variable(hidden=True)
                block1 = ODE(self.variables[0], Uc, [-1], [0, self.C])
                sum1 = Sum([self.physical_nodes[0].variable, Uc], variable)
                return [block1, sum1]


#            elif variable==self.variables[0]:
#                print('3')
#                # i1 is output
#                # i1=pC(U1-U2)
#                ic=Variable(hidden=True)
#                subs1=Subtraction(self.physical_nodes[0].variable,self.physical_nodes[1].variable,ic)
#                block1=ODE(ic,variable,[0,self.C],[1])
#                return [block1,subs1]
        elif ieq == 1:
            # i1=-i2
            if variable == self.variables[0]:
                # i1 as output
                #                print('Bat1#0')
                return [Gain(self.variables[1], self.variables[0], -1)]
            elif variable == self.variables[1]:
                # i2 as output
                #                print('Bat1#1')
                return [Gain(self.variables[0], self.variables[1], -1)]
コード例 #7
0
ファイル: inductor.py プロジェクト: Xnaff/BMSpy
    def partial_dynamic_system(self, ieq, variable):
        """
        returns dynamical system blocks associated to output variable
        """

        if ieq == 0:

            #            if variable==self.physical_nodes[0].variable:
            # print('1')
            #                # U1 is output
            #                # U1=i1/pC+U2
            #                Uc=Variable(hidden=True)
            #                block1=ODE(self.variables[0],Uc,[1],[0,self.C])
            #                sub1=Sum([self.physical_nodes[1].variable,Uc],variable)
            #                return [block1,sub1]
            #            elif variable==self.physical_nodes[1].variable:
            #                print('2')
            #                # U2 is output
            #                # U2=U1-i1/pC
            #                Uc=Variable(hidden=True)
            #                block1=ODE(self.variables[0],Uc,[-1],[0,self.C])
            #                sum1=Sum([self.physical_nodes[0].variable,Uc],variable)
            #                return [block1,sum1]
            if variable == self.variables[0]:  # i1=(u1-u2)/Lp
                print('3')
                # i1 is output
                # i1=pC(U1-U2)
                uc = Variable(hidden=True)
                subs1 = Subtraction(
                    self.physical_nodes[0].variable, self.physical_nodes[1].variable, uc)
                block1 = ODE(uc, variable, [1], [0, self.L])
                return [block1, subs1]
        elif ieq == 1:
            # i1=-i2
            if variable == self.variables[0]:
                # i1 as output
                return [Gain(self.variables[1], self.variables[0], -1)]
            elif variable == self.variables[1]:
                # i2 as output
                return [Gain(self.variables[0], self.variables[1], -1)]
コード例 #8
0
ファイル: mechanical.py プロジェクト: rowhit/BMSpy
 def PartialDynamicSystem(self, ieq, variable):
     """
     returns dynamical system blocks associated to output variable
     """
     if ieq == 0:
         # C1=-f*Tmax*sign(w1-w2)
         if variable == self.variables[0]:
             ut = Variable('unsigned clutch friction torque', hidden=True)
             b1 = Gain(self.commands[0], ut, self.Tmax)
             dw = Variable('Delta rotationnal speed', hidden=True)
             sdw = Variable('Sign of delta rotationnal speed')
             b2 = WeightedSum([
                 self.physical_nodes[0].variable,
                 self.physical_nodes[1].variable
             ], dw, [-1, 1])
             b3 = Sign(dw, sdw)
             b4 = Product(ut, sdw, variable)
             return [b1, b2, b3, b4]
     elif ieq == 1:
         # C1=-C2
         if variable == self.variables[0]:
             return [Gain(self.variables[1], variable, -1)]
         if variable == self.variables[1]:
             return [Gain(self.variables[0], variable, -1)]
コード例 #9
0
ファイル: derivative.py プロジェクト: rowhit/BMSpy
#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]])
コード例 #10
0
fv1 = 0.01
fv2 = 0.01
#e=bmsp.Step(1.,'e')

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
コード例 #11
0
ファイル: electric_motor.py プロジェクト: tsa-heidi/BMSpy
Ui = bms.Variable(('Voltage corrector integrator', 'Uci'))
Uc = bms.Variable(('Voltage command', 'Uc'))
Um = bms.Variable(('Voltage Input motor', 'Uim'))
e = bms.Variable(('Counter electromotive force', 'Cef'))
Uind = bms.Variable(('Voltage Inductor', 'Vi'))
Iind = bms.Variable(('Intensity Inductor', 'Ii'))
Tm = bms.Variable(('Motor torque', 'Tm'))
Text = bms.Variable(('Resistant torque', 'Tr'))
T = bms.Variable(('Torque', 'T'))
W = bms.Variable(('Rotationnal speed', 'w'))
Pe = bms.Variable(('Electrical power', 'Pe'))
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
])
コード例 #12
0
vehicle = TranslationalNode(mass, SCx, friction_v, 'vehicle')

engine = ThermalEngine(crankshaft, wmin, wmax, Tmax, fuel_flow)
clutch = Clutch(crankshaft, shaft_gb1, Tmax_c)
gr1 = GearRatio(shaft_gb1, shaft_gb2, 0.05)
brake = Brake(shaft_gb2, Tmax_b)
wheels = Wheel(shaft_gb2, vehicle, r)

# Commands
subs1 = WeightedSum([Vt, vehicle.variable], engine.commands[0], [Ge, -Ge])
v1 = bms.Variable('', hidden=True)
subs2 = WeightedSum([Vt, vehicle.variable], v1, [-Gb, Gb], -Vb)
sat1 = Saturation(v1, brake.commands[0], 0, 1)

# clutch
cc = bms.Variable('Clutch command')
gc = Gain(crankshaft.variable, cc, 1/(wrc-wec), wec/(wec-wrc))
satc = Saturation(cc, clutch.commands[0], 0, 1)

ps = bms.PhysicalSystem(600, 600, [engine, gr1, clutch, wheels, brake], [
                        subs1, subs2, sat1, gc, satc])
ds = ps.dynamic_system

# ds._ResolutionOrder2()
ds.Simulate()
ds.PlotVariables([[Vt, vehicle.variable], [engine.throttle, brake.commands[0],
                                           clutch.commands[0]], [engine.max_torque, engine.variables[0]]])
ds.PlotVariables(
    [[crankshaft.variable, shaft_gb1.variable, shaft_gb2.variable]])
ds.PlotVariables([[wheels.variables[0], clutch.variables[0]]])
コード例 #13
0
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()