Exemple #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)
Exemple #2
0
def test_negative_vector_from_carla():
    """ Tests that Vector3D throws a ValueError if incorrect vector is
    passed. """
    DummyType = namedtuple("DummyType", "x, y, z")
    dummy_instance = DummyType(0, 0, 0)
    with pytest.raises(ValueError):
        Vector3D.from_carla_vector(dummy_instance)
Exemple #3
0
    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_carla_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))
Exemple #4
0
def test_from_carla_vector(x, y, z):
    """ Tests the creation of Vector3D from Carla. """
    carla_vector3d = carla.Vector3D(x, y, z)
    vector3d = Vector3D.from_carla_vector(carla_vector3d)
    assert isinstance(vector3d, Vector3D), "The returned object is not of type"
    "Vector3D"
    assert np.isclose(carla_vector3d.x, vector3d.x), "X value is not the same"
    assert np.isclose(carla_vector3d.y, vector3d.y), "Y value is not the same"
    assert np.isclose(carla_vector3d.z, vector3d.z), "Z value is not the same"