コード例 #1
0
ファイル: lcm_test.py プロジェクト: sammy-tri/drake
 def test_publisher(self):
     lcm = DrakeLcm()
     dut = mut.LcmPublisherSystem.Make(channel="TEST_CHANNEL",
                                       lcm_type=lcmt_quaternion,
                                       lcm=lcm,
                                       publish_period=0.1)
     subscriber = Subscriber(lcm, "TEST_CHANNEL", lcmt_quaternion)
     model_message = self._model_message()
     self._fix_and_publish(dut, AbstractValue.Make(model_message))
     lcm.HandleSubscriptions(0)
     self.assert_lcm_equal(subscriber.message, model_message)
     # Test `publish_triggers` overload.
     mut.LcmPublisherSystem.Make(channel="TEST_CHANNEL",
                                 lcm_type=lcmt_quaternion,
                                 lcm=lcm,
                                 publish_period=0.1,
                                 publish_triggers={TriggerType.kPeriodic})
     # Test LcmInterfaceSystem overloads
     lcm_system = mut.LcmInterfaceSystem(lcm=lcm)
     dut = mut.LcmPublisherSystem.Make(channel="TEST_CHANNEL",
                                       lcm_type=lcmt_quaternion,
                                       lcm=lcm_system,
                                       publish_period=0.1)
     self._fix_and_publish(dut, AbstractValue.Make(model_message))
     lcm.HandleSubscriptions(0)
     self.assert_lcm_equal(subscriber.message, model_message)
     # Test `publish_triggers` overload.
     mut.LcmPublisherSystem.Make(channel="TEST_CHANNEL",
                                 lcm_type=lcmt_quaternion,
                                 lcm=lcm_system,
                                 publish_period=0.1,
                                 publish_triggers={TriggerType.kPeriodic})
コード例 #2
0
ファイル: lcm_test.py プロジェクト: thduynguyen/drake
 def test_lcm_interface_system_diagram(self):
     # First, check the class doc.
     self.assertIn("only inherits from LeafSystem",
                   mut.LcmInterfaceSystem.__doc__)
     # Next, construct a diagram and add both the interface system and
     # a subscriber.
     builder = DiagramBuilder()
     lcm = DrakeLcm()
     lcm_system = builder.AddSystem(mut.LcmInterfaceSystem(lcm=lcm))
     # Create subscriber in the diagram.
     subscriber = builder.AddSystem(
         mut.LcmSubscriberSystem.Make(channel="TEST_CHANNEL",
                                      lcm_type=lcmt_quaternion,
                                      lcm=lcm))
     diagram = builder.Build()
     simulator = Simulator(diagram)
     simulator.Initialize()
     # Publish test message.
     model_message = self._model_message()
     lcm.Publish("TEST_CHANNEL", model_message.encode())
     # Simulate to a non-zero time to ensure the subscriber picks up the
     # message.
     eps = np.finfo(float).eps
     simulator.AdvanceTo(eps)
     # Ensure that we have what we want.
     context = subscriber.GetMyContextFromRoot(
         simulator.get_mutable_context())
     actual_message = subscriber.get_output_port(0).Eval(context)
     self.assert_lcm_equal(actual_message, model_message)
コード例 #3
0
ファイル: lcm_test.py プロジェクト: sammy-tri/drake
 def test_subscriber(self):
     lcm = DrakeLcm()
     dut = mut.LcmSubscriberSystem.Make(channel="TEST_CHANNEL",
                                        lcm_type=lcmt_quaternion,
                                        lcm=lcm)
     model_message = self._model_message()
     lcm.Publish(channel="TEST_CHANNEL", buffer=model_message.encode())
     lcm.HandleSubscriptions(0)
     context = self._process_event(dut)
     actual_message = dut.get_output_port(0).Eval(context)
     self.assert_lcm_equal(actual_message, model_message)
     # Test LcmInterfaceSystem overloads
     lcm_system = mut.LcmInterfaceSystem(lcm=lcm)
     dut = mut.LcmSubscriberSystem.Make(channel="TEST_CHANNEL",
                                        lcm_type=lcmt_quaternion,
                                        lcm=lcm_system)
     lcm.Publish(channel="TEST_CHANNEL", buffer=model_message.encode())
     lcm.HandleSubscriptions(0)
     context = self._process_event(dut)
     actual_message = dut.get_output_port(0).Eval(context)
     self.assert_lcm_equal(actual_message, model_message)