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()