Simon Van Mierlo 10 лет назад
Родитель
Сommit
0f1053b733

+ 1 - 1
debugging_fsa_cbd_composition/fsa_cbd_simulator/HierarchicalSimulator/cbd_sim_bigstep.xml

@@ -166,7 +166,7 @@
                         <script>
                         <![CDATA[
                             self.finalize()
-                            print '>>> (CBD) big step executed <<<'
+                            # print '>>> (CBD) big step executed <<<'
                         ]]>
                         </script>
                         <raise event="CBDBigStep.Finished" />

+ 1 - 1
debugging_fsa_cbd_composition/fsa_cbd_simulator/HierarchicalSimulator/cbd_sim_block.xml

@@ -35,7 +35,7 @@
                 <script>
                 <![CDATA[
                     self.computeBlock()
-                    print '>>> (CBD) block executed <<<'
+                    # print '>>> (CBD) block executed <<<'
                 ]]>
                 </script>
                 <raise event="CBDBlock.Finished" scope="narrow" target="'parent'">

+ 1 - 1
debugging_fsa_cbd_composition/fsa_cbd_simulator/HierarchicalSimulator/cbd_sim_simulation.xml

@@ -348,7 +348,7 @@
                     <transition target="../Stopped" cond="self.endCondition()">
                         <script>
                         <![CDATA[
-                            print '>>> (CBD) simulation executed <<<'
+                            # print '>>> (CBD) simulation executed <<<'
                             self.finalize()
                         ]]>
                         </script>

+ 1 - 1
debugging_fsa_cbd_composition/fsa_cbd_simulator/HierarchicalSimulator/cbd_sim_smallstep.xml

@@ -138,7 +138,7 @@
                     <transition target="../Stopped" cond="self.endCondition()">
                         <script>
                         <![CDATA[
-                            print '>>> (CBD) small step executed <<<'
+                            # print '>>> (CBD) small step executed <<<'
                             self.finalize()
                         ]]>
                         </script>

+ 7 - 2
debugging_fsa_cbd_composition/fsa_cbd_simulator/HierarchicalSimulator/fsa_sim_bigstep.xml

@@ -81,7 +81,12 @@
             <state id="ModeSelector" initial="Paused">
                 <state id="Paused">
                     <transition target="../Running/SmallStep" event="FSASmallStep.Execute">
-                        <raise event="FSASmallStep.Execute" scope="narrow" target="'child_simulator'" />
+                        <!-- used for state event transitions (and is None if none is detected) -->
+                        <parameter name="selected_transition" />
+                        <script>
+                            if selected_transition != None:
+                                self.selected_transition = selected_transition
+                        </script>
                     </transition>
                     <transition target="../Running/Continuous" event="FSABigStep.Execute">
                         <!-- used for state event transitions (and is None if none is detected) -->
@@ -196,7 +201,7 @@
                     <transition target="../Stopped" cond="self.endCondition()">
                         <script>
                         <![CDATA[
-                            print '>>> (FSA) big step executed <<<'
+                            # print '>>> (FSA) big step executed <<<'
                             self.finalize()
                         ]]>
                         </script>

+ 41 - 27
debugging_fsa_cbd_composition/fsa_cbd_simulator/HierarchicalSimulator/fsa_sim_simulation.xml

@@ -63,12 +63,18 @@
             <state id="ModeSelector" initial="Paused">
                 <state id="Paused">
                     <transition target="../Running/SmallStep" event="FSASmallStep.Execute">
-                        <raise event="FSASmallStep.Execute" scope="narrow" target="'child_simulator'" />
+                        <!-- used for state event transitions (and is None if none is detected) -->
+                        <parameter name="selected_transition" />
+                        <script>
+                            self.selected_transition = selected_transition
+                        </script>
                     </transition>
                     <transition target="../Running/BigStep" event="FSABigStep.Execute">
-                        <raise event="FSABigStep.Execute" scope="narrow" target="'child_simulator'">
-                            <parameter expr="None" />
-                        </raise>
+                        <!-- used for state event transitions (and is None if none is detected) -->
+                        <parameter name="selected_transition" />
+                        <script>
+                            self.selected_transition = selected_transition
+                        </script>
                     </transition>
                     <!-- In case a small step finishes a big step... -->
                     <transition target="." event="FSABigStep.Finished">
@@ -86,6 +92,16 @@
                             <parameter expr="event_list" />
                             <parameter expr="executed_transition" />
                         </raise>
+                        <script>
+                        <![CDATA[
+                            self.clock = clock
+                            self.state = state
+                            self.elapsed = elapsed
+                            self.time_next = time_next
+                            self.elapsed = elapsed
+                            self.event_list = event_list
+                        ]]>
+                        </script>
                    </transition>
                 </state>
                 <state id="Running" initial="BigStep">
@@ -105,6 +121,16 @@
                                 <parameter expr="event_list" />
                                 <parameter expr="executed_transition" />
                             </raise>
+                            <script>
+                            <![CDATA[
+                                self.clock = clock
+                                self.state = state
+                                self.elapsed = elapsed
+                                self.time_next = time_next
+                                self.elapsed = elapsed
+                                self.event_list = event_list
+                            ]]>
+                            </script>
                         </transition>
                     </state>
                     <state id="SmallStep">
@@ -219,13 +245,15 @@
                     </transition>
                 </state>
                 <state id="CheckTermination">
-                    <transition target="../Executing" cond="INSTATE('../../ModeSelector/Running/BigStep') and INSTATE('../../ChildState/Initialized') and not self.endCondition()">
+                    <transition target="../ExecutingBigStep" cond="INSTATE('../../ModeSelector/Running/BigStep') and INSTATE('../../ChildState/Initialized') and not self.endCondition()">
                         <raise event="FSABigStep.Execute" scope="narrow" target="'child_simulator'">
-                            <parameter expr="None" />
+                            <parameter expr="self.selected_transition" />
                         </raise>
                     </transition>
-                    <transition target="../Executing" cond="INSTATE('../../ModeSelector/Running/SmallStep') and INSTATE('../../ChildState/Initialized') and not self.endCondition()">
-                        <raise event="FSASmallStep.Execute" scope="narrow" target="'child_simulator'" />
+                    <transition target="../ExecutingSmallStep" cond="INSTATE('../../ModeSelector/Running/SmallStep') and INSTATE('../../ChildState/Initialized') and not self.endCondition()">
+                        <raise event="FSASmallStep.Execute" scope="narrow" target="'child_simulator'">
+                            <parameter expr="self.selected_transition" />
+                        </raise>
                     </transition>
                     <transition target="../Stopped" cond="self.endCondition()">
                         <script>
@@ -241,25 +269,11 @@
                         </raise>
                     </transition>
                 </state>
-                <state id="Executing">
-                    <transition target="../SettleBeforeCheckTermination" event="FSABigStep.Finished">
-                        <parameter name="clock" />
-                        <parameter name="state" />
-                        <parameter name="elapsed" />
-                        <parameter name="time_next" />
-                        <parameter name="event_list" />
-                        <parameter name="executed_transition" />
-                        <script>
-                        <![CDATA[
-                            self.clock = clock
-                            self.state = state
-                            self.elapsed = elapsed
-                            self.time_next = time_next
-                            self.elapsed = elapsed
-                            self.event_list = event_list
-                        ]]>
-                        </script>
-                   </transition>
+                <state id="ExecutingBigStep">
+                    <transition target="../SettleBeforeCheckTermination" event="FSABigStep.Finished" />
+                </state>
+                <state id="ExecutingSmallStep">
+                    <transition target="../SettleBeforeCheckTermination" event="FSASmallStep.Finished" />
                 </state>
                 <state id="Stopped" />
             </state>

+ 1 - 1
debugging_fsa_cbd_composition/fsa_cbd_simulator/HierarchicalSimulator/fsa_sim_smallstep.xml

@@ -161,7 +161,7 @@
                     <transition target="../Stopped" cond="self.endCondition()">
                         <script>
                         <![CDATA[
-                            print '>>> (FSA) small step executed <<<'
+                            # print '>>> (FSA) small step executed <<<'
                             self.finalize()
                         ]]>
                         </script>

+ 1 - 1
debugging_fsa_cbd_composition/fsa_cbd_simulator/HierarchicalSimulator/fsa_sim_transition.xml

@@ -26,7 +26,7 @@
                 <script>
                 <![CDATA[
                     self.executeTransition()
-                    print '>>> (FSA) transition executed <<<'
+                    # print '>>> (FSA) transition executed <<< %s' % self.newState
                 ]]>
                 </script>
                 <raise event="FSATransition.Finished" scope="narrow" target="'parent'">

+ 2 - 2
debugging_fsa_cbd_composition/fsa_cbd_simulator/HierarchicalSimulator/models/bouncingball.py

@@ -79,8 +79,8 @@ 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.addBlock(ConstantBlock(block_name="init_velocity", value=0.0))
+        self.addBlock(ConstantBlock(block_name="init_position", value=1.0))
         
         self.addConnection("init_velocity", "out_v")
         self.addConnection("init_position", "out_x")

+ 3 - 1
debugging_fsa_cbd_composition/fsa_cbd_simulator/HierarchicalSimulator/run_debug.py

@@ -47,7 +47,7 @@ if __name__ == '__main__':
     options = Options(delta = CBD_DELTA)
     options.setMaxIterations(10000);
     fsamodel = BouncingBallFSA()
-    events = fsaclasses.Events([fsaclasses.RunTimeEvent('kick',0.2), fsaclasses.RunTimeEvent('kick',3.0), fsaclasses.RunTimeEvent('enough',5.0)])
+    events = fsaclasses.Events([fsaclasses.RunTimeEvent('kick',4.0), fsaclasses.RunTimeEvent('enough',5.0)])
     # events = fsaclasses.Events([fsaclasses.RunTimeEvent('kick',13.0), fsaclasses.RunTimeEvent('kick',23.0), fsaclasses.RunTimeEvent('kick',37.0) ,fsaclasses.RunTimeEvent('enough',60.0)])
     #events = Events([RunTimeEvent('enough',25.0)])
     controller = target.Controller(fsamodel, events, options, keep_running=True)
@@ -76,6 +76,8 @@ if __name__ == '__main__':
                 params = []
             elif action == "small_step":
                 params = []
+            elif action == "step_into":
+                params = []
             elif action == "pause":
                 params = []
             elif action == "add_breakpoint":

Разница между файлами не показана из-за своего большого размера
+ 414 - 126
debugging_fsa_cbd_composition/fsa_cbd_simulator/HierarchicalSimulator/target.py


+ 64 - 2
debugging_fsa_cbd_composition/fsa_cbd_simulator/HierarchicalSimulator/woven_sim_coordinator.xml

@@ -22,6 +22,9 @@
                     <transition target="../Running/SmallStep" event="small_step" port="user_input" />
                     <transition target="../Running/BigStep" event="big_step" port="user_input" />
                     <transition target="../Running/Continuous" event="continuous" port="user_input" />
+                    <transition target="../WaitingForStepIntoSuccess" event="step_into" port="user_input">
+                        <raise event="WovenSimulation.StepInto" scope="narrow" target="'child_simulator'" />
+                    </transition>
                     <transition target="../Running/Realtime" event="realtime" port="user_input">
                         <parameter name="realtime_scale" default="1.0" />
                         <script>
@@ -53,6 +56,14 @@
                         </raise>
                     </transition>
                 </state>
+                <state id="WaitingForStepIntoSuccess">
+                    <transition target="../Running/StepInto" event="StepInto.Success">
+                        <raise event="StepInto.Success" port="user_output" />
+                    </transition>
+                    <transition target="../Paused" event="StepInto.Failure">
+                        <raise event="StepInto.Failure" port="user_output" />
+                    </transition>
+                </state>
                 <state id="Running" initial="Continuous">
                     <state id="Continuous">
                         <transition target="../../WaitingForPaused" event="pause" port="user_input">
@@ -164,6 +175,52 @@
                             </raise>
                         </transition>
                     </state>
+                    <state id="StepInto" initial="Paused">
+                        <state id="Paused">
+                            <transition target="../BigStep" event="big_step" port="user_input" />
+                            <transition target="../SmallStep" event="small_step" port="user_input" />
+                            <!-- When a big step finishes after the last small step -->
+                            <transition target="../../../Paused" event="CBDBigStep.Finished">
+                                <parameter name="clock" />
+                                <parameter name="iteration" />
+                                <parameter name="time_next" />
+                                <parameter name="state" />
+                                <raise event="CBDBigStep.Finished" port="user_output" />
+                                <raise event="CBDBigStep.State" port="user_output">
+                                    <parameter expr="clock" />
+                                    <parameter expr="iteration" />
+                                    <parameter expr="time_next" />
+                                    <parameter expr="state" />
+                                </raise>
+                            </transition>
+                        </state>
+                        <state id="BigStep">
+                            <transition target="../../../Paused" event="CBDBigStep.Finished">
+                                <parameter name="clock" />
+                                <parameter name="iteration" />
+                                <parameter name="time_next" />
+                                <parameter name="state" />
+                                <raise event="CBDBigStep.Finished" port="user_output" />
+                                <raise event="CBDBigStep.State" port="user_output">
+                                    <parameter expr="clock" />
+                                    <parameter expr="iteration" />
+                                    <parameter expr="time_next" />
+                                    <parameter expr="state" />
+                                </raise>
+                            </transition>
+                        </state>
+                        <state id="SmallStep">
+                            <transition target="../Paused" event="CBDSmallStep.Finished">
+                                <parameter name="new_current_component_idx" />
+                                <parameter name="new_state" />
+                                <raise event="CBDSmallStep.Finished" port="user_output" />
+                                <raise event="CBDSmallStep.State" port="user_output">
+                                    <parameter expr="new_current_component_idx" />
+                                    <parameter expr="new_state" />
+                                </raise>
+                            </transition>
+                        </state>
+                    </state>
                     <transition target="../Paused" event="WovenSimulation.Finished">
                         <parameter name="clock" />
                         <parameter name="state" />
@@ -243,7 +300,6 @@
                     <transition target="../Paused" after="self.sccd_yield()" />
                 </state>
                 <state id="Paused">
-                    <!-- TODO: Here, check which simulator has 'control' (i.e., when stepping into). For example, we would then send a CBDBigStep.Execute to WovenSimulator. -->
                     <transition target="../Executing" cond="INSTATE('../../ModeSelector/Running/Continuous') and INSTATE('../../ChildState/Initialized')">
                         <raise event="WovenSimulation.Execute" scope="narrow" target="'child_simulator'" />
                     </transition>
@@ -258,9 +314,15 @@
                     <transition target="../Executing" cond="INSTATE('../../ModeSelector/Running/SmallStep') and INSTATE('../../ChildState/Initialized')">
                         <raise event="FSASmallStep.Execute" scope="narrow" target="'child_simulator'" />
                     </transition>
+                    <transition target="../Executing" cond="INSTATE('../../ModeSelector/Running/StepInto/SmallStep') and INSTATE('../../ChildState/Initialized')">
+                        <raise event="CBDSmallStep.Execute" scope="narrow" target="'child_simulator'" />
+                    </transition>
+                    <transition target="../Executing" cond="INSTATE('../../ModeSelector/Running/StepInto/BigStep') and INSTATE('../../ChildState/Initialized')">
+                        <raise event="CBDBigStep.Execute" scope="narrow" target="'child_simulator'" />
+                    </transition>
                 </state>
                 <state id="Executing">
-                    <transition target="../Paused" cond="INSTATE('../../ModeSelector/Paused')" />
+                    <transition target="../Paused" cond="INSTATE('../../ModeSelector/Paused') or INSTATE('../../ModeSelector/Running/StepInto/Paused')" />
                     <transition target="../PrePaused" event="WovenSimulation.Finished" cond="INSTATE('../../ModeSelector/Running/Continuous') or INSTATE('../../ModeSelector/Running/Realtime')" />
                 </state>
             </state>

+ 93 - 6
debugging_fsa_cbd_composition/fsa_cbd_simulator/HierarchicalSimulator/woven_sim_simulation.xml

@@ -178,6 +178,13 @@
                             self.realtime_scale = float(realtime_scale)
                         </script>
                     </transition>
+                    <!-- We allow step into only when paused, because we then know the system is stable (pause is only possible after a big step). -->
+                    <transition target="../Running/ChildStep" event="WovenSimulation.StepInto" cond="isinstance(self.fsa_state, CBDState)">
+                        <raise event="StepInto.Success" scope="narrow" target="'parent'" />
+                    </transition>
+                    <transition target="." event="WovenSimulation.StepInto" cond="not isinstance(self.fsa_state, CBDState)">
+                        <raise event="StepInto.Failure" scope="narrow" target="'parent'" />
+                    </transition>
                     <transition target="." event="FSABigStep.Finished">
                         <parameter name="fsa_clock" />
                         <parameter name="fsa_state" />
@@ -293,6 +300,49 @@
                             </raise>
                         </transition>
                     </state>
+                    <state id="ChildStep" initial="Paused">
+                        <state id="Paused">
+                            <transition target="../BigStep" event="CBDBigStep.Execute" />
+                            <transition target="../SmallStep" event="CBDSmallStep.Execute" />
+                            <!-- When a big step finishes after the last small step -->
+                            <transition target="../../../Paused" event="CBDBigStep.Finished">
+                                <parameter name="clock" />
+                                <parameter name="iteration" />
+                                <parameter name="time_next" />
+                                <parameter name="state" />
+                                <raise event="CBDBigStep.Finished" scope="narrow" target="'parent'">
+                                    <parameter expr="clock" />
+                                    <parameter expr="iteration" />
+                                    <parameter expr="time_next" />
+                                    <parameter expr="state" />
+                                </raise>
+                            </transition>
+                        </state>
+                        <state id="BigStep">
+                            <transition target="../../../Paused" event="CBDBigStep.Finished">
+                                <parameter name="clock" />
+                                <parameter name="iteration" />
+                                <parameter name="time_next" />
+                                <parameter name="state" />
+                                <raise event="CBDBigStep.Finished" scope="narrow" target="'parent'">
+                                    <parameter expr="clock" />
+                                    <parameter expr="iteration" />
+                                    <parameter expr="time_next" />
+                                    <parameter expr="state" />
+                                </raise>
+                            </transition>
+                        </state>
+                        <state id="SmallStep">
+                            <transition target="../Paused" event="CBDSmallStep.Finished">
+                                <parameter name="new_current_component_idx" />
+                                <parameter name="new_state" />
+                                <raise event="CBDSmallStep.Finished" scope="narrow" target="'parent'">
+                                    <parameter expr="new_current_component_idx" />
+                                    <parameter expr="new_state" />
+                                </raise>
+                            </transition>
+                        </state>
+                    </state>
                     <transition target="../Paused" cond="self.breakpointTriggers(INSTATE('Realtime'))">
                         <raise event="Breakpoint.Triggered" scope="narrow" target="'parent'">
                             <parameter expr="self.triggered_bp" />
@@ -479,13 +529,16 @@
                 </state>
                 <state id="CheckTermination">
                     <transition target="../Executing" cond="(INSTATE('../../ModeSelector/Running/Continuous') or INSTATE('../../ModeSelector/Running/BigStep') or INSTATE('../../ModeSelector/Running/SmallStep')) and INSTATE('../../FSAChildState/Initialized') and not isinstance(self.fsa_state, CBDState)">
-                        <raise event="FSASmallStep.Execute" scope="narrow" target="'child_fsa_simulator'" />
-                        <script>print 'Executing a FSA small step... (no CBD state)'</script>
+                        <raise event="FSASmallStep.Execute" scope="narrow" target="'child_fsa_simulator'">
+                            <parameter expr="None" />
+                        </raise>
+                        <script># print 'Executing a FSA small step... (no CBD state)'</script>
                     </transition>
                     <transition target="../ExecutingCBD" cond="(INSTATE('../../ModeSelector/Running/Continuous') or INSTATE('../../ModeSelector/Running/BigStep') or INSTATE('../../ModeSelector/Running/SmallStep')) and INSTATE('../../CBDChildState/Initialized') and isinstance(self.fsa_state, CBDState)">
                         <raise event="CBDBigStep.Execute" scope="narrow" target="'child_cbd_simulator'" />
-                        <script>print 'Executing a CBD big step... (CBD state)'</script>
+                        <script># print 'Executing a CBD big step... (CBD state)'</script>
                     </transition>
+                    <transition target="../SteppedInto" cond="INSTATE('../../ModeSelector/Running/ChildStep/SmallStep') or INSTATE('../../ModeSelector/Running/ChildStep/BigStep')" />
                     <transition target="../WaitingRealtime" cond="INSTATE('../../ModeSelector/Running/Realtime') and INSTATE('../../FSAChildState/Initialized')" />
                     <transition target="../Stopped" cond="INSTATE('../../ModeSelector/Stopped')">
                         <script>
@@ -512,13 +565,47 @@
                     </transition>
                     <!-- We execute a step when the wait time is smaller than the smallest possible delay. -->
                     <transition target="../Executing" cond="self.waitTime() / 1000.0 &lt;= self.sccd_yield() and not isinstance(self.fsa_state, CBDState) and INSTATE('../../FSAChildState/Initialized')">
-                        <raise event="FSASmallStep.Execute" scope="narrow" target="'child_fsa_simulator'" />
-                        <script>print 'Executing a FSA small step... (no CBD state - RT)'</script>
+                        <raise event="FSASmallStep.Execute" scope="narrow" target="'child_fsa_simulator'">
+                            <parameter expr="None" />
+                        </raise>
+                        <script># print 'Executing a FSA small step... (no CBD state - RT)'</script>
                     </transition>
                     <transition target="../ExecutingCBD" cond="self.waitTime() / 1000.0 &lt;= self.sccd_yield() and isinstance(self.fsa_state, CBDState) and INSTATE('../../CBDChildState/Initialized')">
                         <raise event="CBDBigStep.Execute" scope="narrow" target="'child_cbd_simulator'" />
                     </transition>
                 </state>
+                <state id="SteppedInto" initial="Waiting">
+                    <state id="Waiting">
+                        <transition target="../ExecutingCBDSmallStep" cond="INSTATE('../../../ModeSelector/Running/ChildStep/SmallStep') and INSTATE('../../../CBDChildState/Initialized')">
+                            <raise event="CBDSmallStep.Execute" scope="narrow" target="'child_cbd_simulator'" />
+                        </transition>
+                        <transition target="../SettleBeforeWaiting" cond="INSTATE('../../../ModeSelector/Running/ChildStep/BigStep') and INSTATE('../../../CBDChildState/Initialized')">
+                            <raise event="CBDBigStep.Execute" scope="narrow" target="'child_cbd_simulator'" />
+                        </transition>
+                    </state>
+                    <state id="ExecutingCBDSmallStep">
+                        <transition target="../SettleBeforeWaiting" event="CBDSmallStep.Finished" />
+                    </state>
+                    <state id="SettleBeforeWaiting">
+                        <transition target="../Waiting" after="self.sccd_yield()" />
+                    </state>
+                    <transition target="../Executing" event="CBDBigStep.Finished">
+                        <parameter name="cbd_clock" />
+                        <parameter name="cbd_state" />
+                        <parameter name="cbd_iteration" />
+                        <parameter name="cbd_time_next" />
+                        <script>
+                            self.wovenUpdateGlobalState()
+                            self.woven_lib.dumpGlobalState(self.woven_model, self.woven_global_state, self.fsa_clock / 1000.0, self.fsa_state)
+                            self.cbd_clock = cbd_clock
+                            self.woven_triggered_when_transition = self.wovenGetTriggeredWhenTransition()
+                        </script>
+                        <raise event="FSASmallStep.Execute" scope="narrow" target="'child_fsa_simulator'">
+                            <parameter expr="self.woven_triggered_when_transition" />
+                        </raise>
+                        <script># print 'Executing a FSA small step... (after CBD big step)'</script>
+                    </transition>
+                </state>
                 <state id="ExecutingCBD">
                     <transition target="../Executing" event="CBDBigStep.Finished">
                         <parameter name="cbd_clock" />
@@ -534,7 +621,7 @@
                         <raise event="FSASmallStep.Execute" scope="narrow" target="'child_fsa_simulator'">
                             <parameter expr="self.woven_triggered_when_transition" />
                         </raise>
-                        <script>print 'Executing a FSA small step... (after CBD big step)'</script>
+                        <script># print 'Executing a FSA small step... (after CBD big step)'</script>
                     </transition>
                 </state>
                 <state id="Executing">