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_simulator_transform(imu_msg.transform), Vector3D.from_simulator_vector(imu_msg.accelerometer), Vector3D.from_simulator_vector(imu_msg.gyroscope), imu_msg.compass) self._imu_stream.send(msg) # Note: The operator is set not to automatically propagate # watermarks received on input streams. Thus, we can issue # watermarks only after the simulator callback is invoked. self._imu_stream.send(watermark_msg)
def process_collision(self, collision_event): """ Invoked when a collision event is received from the simulation. Args: collision_event (:py:class:`carla.CollisionEvent`): A collision event that contains the impulse, location and the object with which the ego-vehicle collided. """ game_time = int(collision_event.timestamp * 1000) self._logger.debug( "@[{}]: Received a collision event from the simulator.".format( game_time)) # Create a CollisionMessage. timestamp = erdos.Timestamp(coordinates=[game_time]) msg = CollisionMessage( collision_event.other_actor, Vector3D.from_simulator_vector(collision_event.normal_impulse), timestamp) # Send the CollisionMessage. self._collision_stream.send(msg) # TODO(ionel): This code will fail if process_collision is called twice # for the same timestamp (i.e., if the vehicle collides with two other # actors) self._collision_stream.send(erdos.WatermarkMessage(timestamp))