Example #1
0
    def test_read_write(self):
        """
        Unit test of reader.
        """
        self.assertTrue(cyber.ok())
        # Read.
        reader_node = cyber.Node("listener")
        reader = reader_node.create_reader("channel/chatter", SimpleMessage,
                                           self.callback)
        self.assertEqual(reader.name, "channel/chatter")
        self.assertEqual(reader.data_type, SimpleMessage)
        self.assertEqual(SimpleMessage.DESCRIPTOR.full_name,
                         "apollo.common.util.test.SimpleMessage")

        # Write.
        msg = SimpleMessage()
        msg.text = "talker:send Alex!"
        msg.integer = 0

        self.assertTrue(cyber.ok())
        writer_node = cyber.Node("writer")
        writer = writer_node.create_writer("channel/chatter", SimpleMessage, 7)
        self.assertEqual(writer.name, "channel/chatter")
        self.assertEqual(writer.data_type,
                         "apollo.common.util.test.SimpleMessage")
        self.assertTrue(writer.write(msg))

        # Wait for data to be processed by callback function.
        time.sleep(0.1)
Example #2
0
 def test_init(self):
     """
     Test cyber.
     """
     self.assertTrue(cyber.init())
     self.assertTrue(cyber.ok())
     cyber.shutdown()
     self.assertTrue(cyber.is_shutdown())
Example #3
0
 def test_reader(self):
     """
     Unit test of reader.
     """
     self.assertTrue(cyber.ok())
     test_node = cyber.Node("listener")
     reader = test_node.create_reader("channel/chatter", SimpleMessage,
                                      callback)
     self.assertEqual(reader.name, "channel/chatter")
     self.assertEqual(reader.data_type, SimpleMessage)
     self.assertEqual(SimpleMessage.DESCRIPTOR.full_name,
                      "apollo.common.util.test.SimpleMessage")
Example #4
0
    def _callback_sensor_data(self, carla_sensor_data):
        """
        Callback function called whenever new sensor data is received

        :param carla_sensor_data: carla sensor data object
        :type carla_sensor_data: carla.SensorData
        """
        if cyber.ok():
            if self.update_lock.acquire(False):
                self.current_sensor_data = carla_sensor_data
                # self.send_tf_msg()
                self.sensor_data_updated(carla_sensor_data)
                self.update_lock.release()
Example #5
0
    def test_writer(self):
        """
        unit test of writer.
        """
        msg = SimpleMessage()
        msg.text = "talker:send Alex!"
        msg.integer = 0

        self.assertTrue(cyber.ok())
        test_node = cyber.Node("node_name1")
        writer = test_node.create_writer("channel/chatter", SimpleMessage, 7)
        self.assertEqual(writer.name, "channel/chatter")
        self.assertEqual(writer.data_type, "apollo.common.util.test.SimpleMessage")
        self.assertTrue(writer.write(msg))
Example #6
0
    def _carla_update_child_actors(self, _):
        """
        Private callback registered at carla.World.on_tick()
        to trigger cyclic updates of the actors

        After successful locking the mutex
        (only perform trylock to respect bridge processing time)
        the existing actors are updated.

        :param carla_timestamp: the current carla time
        :type carla_timestamp: carla.Timestamp
        :return:
        """
        if cyber.ok():
            if self.update_child_actors_lock.acquire(False):
                # cache actor_list once during this update-loop
                self.actor_list = self.carla_world.get_actors()
                self.update_child_actors()
                # actors are only created/deleted around once per second
                time.sleep(1)
                self.update_child_actors_lock.release()
Example #7
0
    def _carla_time_tick(self, carla_timestamp):
        """
        Private callback registered at carla.World.on_tick()
        to trigger cyclic updates.

        After successful locking the update mutex
        (only perform trylock to respect bridge processing time)
        the clock and the children are updated.
        Finally the ROS messages collected to be published are sent out.

        :param carla_timestamp: the current carla time
        :type carla_timestamp: carla.Timestamp
        :return:
        """
        if cyber.ok():
            if self.update_lock.acquire(False):
                if self.timestamp_last_run < carla_timestamp.elapsed_seconds:
                    self.timestamp_last_run = carla_timestamp.elapsed_seconds
                    # can't do this since there's no 'sim time' in cyber
                    # self._update_clock(carla_timestamp)
                    self.update()
                self.update_lock.release()