def monitor(d_context): # Stop the simulation once there's any contact. context = plant.GetMyContextFromRoot(d_context) query_object = plant.get_geometry_query_input_port().Eval(context) if query_object.HasCollisions(): return EventStatus.ReachedTermination(plant, "Contact") else: return EventStatus.DidNothing()
def viz_monitor(control_d_context): # Simulate control, visualizing in original diagram. assert (control_context is control_plant.GetMyContextFromRoot(control_d_context)) from_control.copy_state(control_context, context) d_context.SetTime(control_d_context.get_time()) diagram.Publish(d_context) return EventStatus.DidNothing()
def test_event_status(self): system = ZeroOrderHold(period_sec=0.1, vector_size=1) # Existence check. EventStatus.Severity.kDidNothing EventStatus.Severity.kSucceeded EventStatus.Severity.kReachedTermination EventStatus.Severity.kFailed self.assertIsInstance(EventStatus.DidNothing(), EventStatus) self.assertIsInstance(EventStatus.Succeeded(), EventStatus) status = EventStatus.ReachedTermination(system=system, message="done") # Check API. self.assertIsInstance(status, EventStatus) self.assertEqual( status.severity(), EventStatus.Severity.kReachedTermination) self.assertIs(status.system(), system) self.assertEqual(status.message(), "done") self.assertIsInstance( status.KeepMoreSevere(candidate=status), EventStatus) status = EventStatus.Failed(system=system, message="failed") self.assertIsInstance(status, EventStatus)
def monitor(root_context): context = sys.GetMyContextFromRoot(root_context) if context.get_time() >= 1.: return EventStatus.ReachedTermination(sys, "Time reached") else: return EventStatus.DidNothing()
def _on_forced_unrestricted(self, context, state): test.assertIsInstance(context, Context) test.assertIsInstance(state, State) test.assertFalse(self.called_forced_unrestricted) self.called_forced_unrestricted = True return EventStatus.Succeeded()
def _on_forced_discrete(self, context, discrete_state): test.assertIsInstance(context, Context) test.assertIsInstance(discrete_state, DiscreteValues) test.assertFalse(self.called_forced_discrete) self.called_forced_discrete = True return EventStatus.Succeeded()
def _on_forced_publish(self, context): test.assertIsInstance(context, Context) test.assertFalse(self.called_forced_publish) self.called_forced_publish = True return EventStatus.Succeeded()
def _on_per_step_unrestricted(self, context, state): test.assertIsInstance(context, Context) test.assertIsInstance(state, State) self.called_per_step_unrestricted = True return EventStatus.Succeeded()
def _on_per_step_publish(self, context): test.assertIsInstance(context, Context) self.called_per_step_publish = True return EventStatus.Succeeded()