Procházet zdrojové kódy

started building the hybrid model but need to sleep.

Cláudio Gomes před 9 roky
rodič
revize
b2759abbe3

+ 127 - 0
debugging_fsa_cbd_composition/fsa_cbd_simulator/models/power_window.py

@@ -0,0 +1,127 @@
+from CBDMultipleOutput.Source.CBD import ConstantBlock, NegatorBlock, \
+    IntegratorBlock, CBD, ProductBlock, AdderBlock
+from fsa_cbd_woven_classes import InputConstantBlock, CBDState, WhenCrossesZeroTrigger
+from fsaclasses import FSAModel, Transition, Event, State
+
+
+class PowerWindow(FSAModel):
+    def __init__(self):
+        Started = CBDState("Started", PowerWindowStarted("Started"))
+        Neutral = State("Neutral")
+        Pass_up = CBDState("Pass_up", PowerWindowUp("Pass_up"))
+        Driver_Up = CBDState("Driver_Up", PowerWindowUp("Driver_Up"))
+        Pass_Down = CBDState("Pass_Down", PowerWindowDown("Pass_Down"))
+        Driver_Down = CBDState("Driver_Down", PowerWindowDown("Driver_Down"))
+        Obj_Detected = CBDState("Obj_Detected", PowerWindowDown("Obj_Detected"))
+        
+        start = Transition("start", Started, Neutral)
+        
+        p_up = Transition("p_up", Neutral, Pass_Up)
+        p_down = Transition("p_down", Neutral, Pass_Down)
+        d_up = Transition("d_up", Neutral, Driver_Up)
+        d_down = Transition("d_down", Neutral, Driver_Down)
+        
+        
+        initial2Freefall = Transition("Initial2Freefall", initial, freeFall)
+        freefall2Collision = Transition("Freefall2Collision", freeFall, collision)
+        freefall2Collision.trigger = WhenCrossesZeroTrigger("x", up_direction=False);
+        collision2Freefall = Transition("Collision2Freefall", collision, freeFall)
+        freefall2Kicked = Transition("Freefall2Kicked", freeFall, kicked)
+        freefall2Kicked.trigger = Event("kick");
+        kicked2Freefall = Transition("kicked2Freefall", kicked, freeFall)
+        freefall2End = Transition("Freefall2End", freeFall, end)
+        freefall2End.trigger = Event("enough");
+        
+        self.states = [
+                       initial,
+                       freeFall,
+                       collision,
+                       kicked,
+                       end
+                       ]
+        
+        self.initialState = initial
+        
+        self.transitions = [
+                            initial2Freefall,
+                            freefall2Collision,
+                            collision2Freefall,
+                            freefall2Kicked,
+                            kicked2Freefall,
+                            freefall2End
+                            ]
+        
+       
+    
+        
+        
+
+class BouncingBallFreefall(CBD):
+    def __init__(self, blockName, delta_t = 0.01):
+        CBD.__init__(self,blockName, input_ports=[], output_ports=["out_v", "out_x"])
+        
+        self.addBlock(InputConstantBlock(block_name="in_x"))
+        self.addBlock(InputConstantBlock(block_name="in_v"))
+        
+        self.addBlock(ConstantBlock(block_name="gravity", value=-9.81))
+        self.addBlock(ConstantBlock(block_name="delta", value=delta_t))
+        
+        self.addBlock(IntegratorBlock(block_name="intgv"))
+        self.addBlock(IntegratorBlock(block_name="intvx"))
+        
+        self.addConnection("delta", "intgv",  input_port_name="delta_t")
+        self.addConnection("delta", "intvx",  input_port_name="delta_t")
+        self.addConnection("in_v", "intgv",  input_port_name="IC")
+        self.addConnection("in_x", "intvx",  input_port_name="IC")
+        
+        self.addConnection("gravity", "intgv")
+        self.addConnection("intgv", "intvx")
+        self.addConnection("intgv", "out_v")
+        self.addConnection("intvx", "out_x")
+    
+    def setDeltaT(self, deltaT):
+        CBD.setDeltaT(self, deltaT)
+        self.getBlockByName("delta").setValue(deltaT);
+    
+    
+
+class BouncingBallInitial(CBD):
+    def __init__(self, blockName, delta_t=0.01):
+        CBD.__init__(self,blockName, input_ports=[], output_ports=["out_v", "out_x"])
+        
+        self.addBlock(ConstantBlock(block_name="init_velocity", value=15.0))
+        self.addBlock(ConstantBlock(block_name="init_position", value=10.0))
+        
+        self.addConnection("init_velocity", "out_v")
+        self.addConnection("init_position", "out_x")
+    
+
+
+class BouncingBallCollision(CBD):
+    def __init__(self, blockName, delta_t=0.01):
+        CBD.__init__(self,blockName, input_ports=[], output_ports=["out_v"])
+        
+        self.addBlock(InputConstantBlock(block_name="in_v"))
+        
+        self.addBlock(ConstantBlock(block_name="coeficient", value=-0.8))
+        self.addBlock(ProductBlock(block_name="mult"))
+        
+        self.addConnection("in_v", "mult")
+        self.addConnection("coeficient", "mult")
+        self.addConnection("mult", "out_v")
+
+
+class BouncingBallKicked(CBD):
+    def __init__(self, blockName, delta_t=0.01):
+        CBD.__init__(self,blockName, input_ports=[], output_ports=["out_v"])
+        
+        self.addBlock(InputConstantBlock(block_name="in_v"))
+        
+        self.addBlock(ConstantBlock(block_name="kick_impact", value=20))
+        self.addBlock(AdderBlock(block_name="sum"))
+        
+        self.addConnection("in_v", "sum")
+        self.addConnection("kick_impact", "sum")
+        self.addConnection("sum", "out_v")
+
+

binární
debugging_fsa_cbd_composition/fsa_cbd_simulator/models/power_window_fsa_model.pdf


+ 5 - 5
debugging_fsa_cbd_composition/fsa_cbd_simulator/models/power_window_fsa_model.svg

@@ -5551,9 +5551,9 @@
      borderopacity="1.0"
      inkscape:pageopacity="0.0"
      inkscape:pageshadow="2"
-     inkscape:zoom="2.8284272"
-     inkscape:cx="421.28184"
-     inkscape:cy="477.29205"
+     inkscape:zoom="2.0000001"
+     inkscape:cx="331.20634"
+     inkscape:cy="426.3577"
      inkscape:document-units="px"
      inkscape:current-layer="layer1"
      showgrid="false"
@@ -5570,7 +5570,7 @@
         <dc:format>image/svg+xml</dc:format>
         <dc:type
            rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
-        <dc:title></dc:title>
+        <dc:title />
       </cc:Work>
     </rdf:RDF>
   </metadata>
@@ -5883,7 +5883,7 @@
        style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#marker5922)" />
     <path
        style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#marker9390)"
-       d="m 169.33485,583.75037 c 0,0 47.59819,-63.62994 116.66515,-63.62994 69.06696,0 127.97201,57.62994 127.97201,57.62994"
+       d="m 177.33485,534.75037 c 0,0 39.59819,-14.62994 108.66515,-14.62994 69.06696,0 127.97201,57.62994 127.97201,57.62994"
        id="path9388"
        inkscape:connector-curvature="0"
        sodipodi:nodetypes="czc" />