def test_publisher(self): lcm = DrakeMockLcm() dut = mut.LcmPublisherSystem.Make( channel="TEST_CHANNEL", lcm_type=quaternion_t, lcm=lcm, publish_period=0.1) model_message = self._model_message() self._fix_and_publish(dut, AbstractValue.Make(model_message)) raw = lcm.get_last_published_message("TEST_CHANNEL") actual_message = quaternion_t.decode(raw) self.assert_lcm_equal(actual_message, model_message)
def test_publisher_cpp(self): lcm = DrakeMockLcm() dut = mut.LcmPublisherSystem.Make( channel="TEST_CHANNEL", lcm_type=quaternion_t, lcm=lcm, use_cpp_serializer=True) model_message = self._model_message() model_value = self._model_value_cpp() self._fix_and_publish(dut, model_value) raw = lcm.get_last_published_message("TEST_CHANNEL") actual_message = quaternion_t.decode(raw) self.assert_lcm_equal(actual_message, model_message)
def test_serializer(self): dut = mut.PySerializer(quaternion_t) model_message = self._model_message() value = dut.CreateDefaultValue() self.assert_lcm_not_equal(value.get_value(), model_message) # Check deserialization. dut.Deserialize(model_message.encode(), value) self.assert_lcm_equal(value.get_value(), model_message) # Check serialization. raw = dut.Serialize(value) reconstruct = quaternion_t.decode(raw) self.assert_lcm_equal(reconstruct, model_message)
def test_publisher(self): lcm = DrakeMockLcm() dut = mut.LcmPublisherSystem.Make( channel="TEST_CHANNEL", lcm_type=quaternion_t, lcm=lcm) model = self._model_message() dut.set_publish_period(period=0.1) context = dut.CreateDefaultContext() context.FixInputPort(0, AbstractValue.Make(model)) dut.Publish(context) raw = lcm.get_last_published_message("TEST_CHANNEL") value = quaternion_t.decode(raw) self.assert_lcm_equal(value, model)
def _cpp_value_to_py_message(self, value): serializer = mut._Serializer_[quaternion_t]() raw = serializer.Serialize(value) return quaternion_t.decode(raw)
def _handler(self, raw): quat = quaternion_t.decode(raw) self.assertTupleEqual((quat.w, quat.x, quat.y, quat.z), self.wxyz) self.count += 1
def handler(raw): msg = quaternion_t.decode(raw) self.assertTupleEqual((msg.w, msg.x, msg.y, msg.z), wxyz) called[0] = True