Esempio n. 1
0
    def process_imu(self, imu_msg):
        """Invoked when an IMU message is received from the simulator.

        Sends IMU measurements to downstream operators.

        Args:
            imu_msg (carla.IMUMeasurement): IMU reading.
        """
        game_time = int(imu_msg.timestamp * 1000)
        timestamp = erdos.Timestamp(coordinates=[game_time])
        watermark_msg = erdos.WatermarkMessage(timestamp)
        with erdos.profile(self.config.name + '.process_imu',
                           self,
                           event_data={'timestamp': str(timestamp)}):
            with self._lock:
                msg = IMUMessage(
                    timestamp,
                    Transform.from_carla_transform(imu_msg.transform),
                    Vector3D.from_carla_vector(imu_msg.accelerometer),
                    Vector3D.from_carla_vector(imu_msg.gyroscope),
                    imu_msg.compass)
                self._imu_stream.send(msg)
                # Note: The operator is set not to automatically propagate
                # watermark messages received on input streams. Thus, we can
                # issue watermarks only after the Carla callback is invoked.
                self._imu_stream.send(watermark_msg)
Esempio n. 2
0
    def process_point_clouds(self, simulator_pc):
        """ Invoked when a point cloud is received from the simulator.
        """
        game_time = int(simulator_pc.timestamp * 1000)
        timestamp = erdos.Timestamp(coordinates=[game_time])
        watermark_msg = erdos.WatermarkMessage(timestamp)
        with erdos.profile(self.config.name + '.process_point_clouds',
                           self,
                           event_data={'timestamp': str(timestamp)}):
            # Ensure that the code executes serially
            with self._lock:
                assert len(
                    simulator_pc.raw_data) > 0, 'Lidar did not send any points'
                # Include the transform relative to the vehicle.
                # simulator_pc.transform returns the world transform, but
                # we do not use it directly.
                msg = PointCloudMessage(
                    timestamp,
                    PointCloud.from_simulator_point_cloud(
                        simulator_pc, self._lidar_setup))

                if self._release_data:
                    self._lidar_stream.send(msg)
                    self._lidar_stream.send(watermark_msg)
                else:
                    # Pickle the data, and release it upon release msg receipt.
                    pickled_msg = pickle.dumps(
                        msg, protocol=pickle.HIGHEST_PROTOCOL)
                    with self._pickle_lock:
                        self._pickled_messages[msg.timestamp] = pickled_msg
                    self._notify_reading_stream.send(watermark_msg)
    def process_images(self, simulator_image):
        """ Invoked when an image is received from the simulator.

        Args:
            simulator_image: a carla.Image.
        """
        game_time = int(simulator_image.timestamp * 1000)
        timestamp = erdos.Timestamp(coordinates=[game_time])
        watermark_msg = erdos.WatermarkMessage(timestamp)
        with erdos.profile(self.config.name + '.process_images',
                           self,
                           event_data={'timestamp': str(timestamp)}):
            # Ensure that the code executes serially
            with self._lock:
                msg = None
                if self._camera_setup.camera_type == 'sensor.camera.rgb':
                    msg = FrameMessage(
                        timestamp,
                        CameraFrame.from_simulator_frame(
                            simulator_image, self._camera_setup))
                elif self._camera_setup.camera_type == 'sensor.camera.depth':
                    # Include the transform relative to the vehicle.
                    # simulator_image.transform returns the world transform,
                    # but we do not use it directly.
                    msg = DepthFrameMessage(
                        timestamp,
                        DepthFrame.from_simulator_frame(
                            simulator_image,
                            self._camera_setup,
                            save_original_frame=self._flags.
                            visualize_depth_camera))
                elif (self._camera_setup.camera_type ==
                      'sensor.camera.semantic_segmentation'):
                    msg = SegmentedFrameMessage(
                        timestamp,
                        SegmentedFrame.from_simulator_image(
                            simulator_image, self._camera_setup))

                if self._release_data:
                    self._camera_stream.send(msg)
                    self._camera_stream.send(watermark_msg)
                else:
                    # Pickle the data, and release it upon release msg receipt.
                    pickled_msg = pickle.dumps(
                        msg, protocol=pickle.HIGHEST_PROTOCOL)
                    with self._pickle_lock:
                        self._pickled_messages[msg.timestamp] = pickled_msg
                    self._notify_reading_stream.send(watermark_msg)
Esempio n. 4
0
    def process_gnss(self, gnss_msg):
        """Invoked when a GNSS measurement is received from the simulator.

        Sends GNSS measurements to downstream operators.
        """
        game_time = int(gnss_msg.timestamp * 1000)
        timestamp = erdos.Timestamp(coordinates=[game_time])
        watermark_msg = erdos.WatermarkMessage(timestamp)
        with erdos.profile(self.config.name + '.process_gnss',
                           self,
                           event_data={'timestamp': str(timestamp)}):
            with self._lock:
                msg = GNSSMessage(
                    timestamp,
                    Transform.from_simulator_transform(gnss_msg.transform),
                    gnss_msg.altitude, gnss_msg.latitude, gnss_msg.longitude)
                self._gnss_stream.send(msg)
                self._gnss_stream.send(watermark_msg)
Esempio n. 5
0
    def send_actor_data(self, msg):
        """ Callback function that gets called when the world is ticked.
        This function sends a WatermarkMessage to the downstream operators as
        a signal that they need to release data to the rest of the pipeline.

        Args:
            msg: Data recieved from the simulation at a tick.
        """
        game_time = int(msg.elapsed_seconds * 1000)
        self._logger.info('The world is at the timestamp {}'.format(game_time))
        timestamp = erdos.Timestamp(coordinates=[game_time])
        watermark_msg = erdos.WatermarkMessage(timestamp)
        with erdos.profile(self.config.name + '.send_actor_data',
                           self,
                           event_data={'timestamp': str(timestamp)}):
            localization_update, control_update = False, False
            if (self._flags.carla_localization_frequency == -1
                    or self._next_localization_sensor_reading is None
                    or game_time == self._next_localization_sensor_reading):
                if self._flags.carla_mode == 'pseudo-asynchronous':
                    self._update_next_localization_pseudo_asynchronous_ticks(
                        game_time)
                self.__send_hero_vehicle_data(self.pose_stream, timestamp,
                                              watermark_msg)
                self.__send_ground_actors_data(timestamp, watermark_msg)
                self.__update_spectactor_pose()
                localization_update = True

            if self._flags.carla_mode == "pseudo-asynchronous" and (
                    self._flags.carla_control_frequency == -1
                    or self._next_control_sensor_reading is None
                    or game_time == self._next_control_sensor_reading):
                self._update_next_control_pseudo_asynchronous_ticks(game_time)
                self.__send_hero_vehicle_data(self.pose_stream_for_control,
                                              timestamp, watermark_msg)
                self.__update_spectactor_pose()
                control_update = True

            # If we sent a localization message, but did not have a message
            # through control for this time, then we need to tick the simulator
            # forward. (only if we are in the pseudo-asynchronous mode)
            if self._flags.carla_mode == "pseudo-asynchronous" and (
                    localization_update and not control_update):
                self._consume_next_event()
Esempio n. 6
0
    def send_actor_data(self, msg):
        """ Callback function that gets called when the world is ticked.
        This function sends a WatermarkMessage to the downstream operators as
        a signal that they need to release data to the rest of the pipeline.

        Args:
            msg: Data recieved from the simulation at a tick.
        """
        # Ensure that the callback executes serially.
        with self._lock:
            game_time = int(msg.elapsed_seconds * 1000)
            self._logger.info(
                'The world is at the timestamp {}'.format(game_time))
            timestamp = erdos.Timestamp(coordinates=[game_time])
            watermark_msg = erdos.WatermarkMessage(timestamp)
            with erdos.profile(self.config.name + '.send_actor_data',
                               self,
                               event_data={'timestamp': str(timestamp)}):
                if (self._flags.carla_localization_frequency == -1
                        or self._next_localization_sensor_reading is None or
                        game_time == self._next_localization_sensor_reading):
                    if self._flags.carla_mode == 'pseudo-asynchronous':
                        self._update_next_localization_pseudo_async_ticks(
                            game_time)
                    self.__send_hero_vehicle_data(self.pose_stream, timestamp,
                                                  watermark_msg)
                    self.__send_ground_actors_data(timestamp, watermark_msg)
                    self.__update_spectactor_pose()

                if self._flags.carla_mode == "pseudo-asynchronous" and (
                        self._flags.carla_control_frequency == -1
                        or self._next_control_sensor_reading is None
                        or game_time == self._next_control_sensor_reading):
                    self._update_next_control_pseudo_asynchronous_ticks(
                        game_time)
                    self.__send_hero_vehicle_data(self.pose_stream_for_control,
                                                  timestamp, watermark_msg)
                    self.__update_spectactor_pose()