From 87ac3b9a6d56b0282cbdb5eb71d6bd6d8ba2b525 Mon Sep 17 00:00:00 2001 From: Marc Garcia Puig Date: Tue, 28 Apr 2020 18:12:22 +0200 Subject: [PATCH] Minor fixes and code style adaptation --- CHANGELOG.md | 1 + LibCarla/source/carla/sensor/SensorRegistry.h | 2 +- LibCarla/source/carla/sensor/data/DVSEvent.h | 28 +++++++++++-------- .../sensor/s11n/DVSEventArraySerializer.h | 11 ++++---- .../carla/source/libcarla/SensorData.cpp | 18 ++++++------ PythonAPI/examples/manual_control.py | 4 +-- .../Carla/Source/Carla/Sensor/DVSCamera.cpp | 4 +-- .../Carla/Source/Carla/Sensor/DVSCamera.h | 16 +++++------ 8 files changed, 44 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d14c902ea..5f2228fae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Fixed missing include directive in file **WheelPhysicsControl.h** * Fixed gravity measurement bug from IMU sensor * OpenDRIVE ingestion bugfixes + * Added Dynamic Vision Sensor (DVS) camera based on ESIM simulation http://rpg.ifi.uzh.ch/esim.html ## CARLA 0.9.9 diff --git a/LibCarla/source/carla/sensor/SensorRegistry.h b/LibCarla/source/carla/sensor/SensorRegistry.h index 6f4903ce9..ebf4ce871 100644 --- a/LibCarla/source/carla/sensor/SensorRegistry.h +++ b/LibCarla/source/carla/sensor/SensorRegistry.h @@ -15,6 +15,7 @@ // 1. Include the serializer here. #include "carla/sensor/s11n/CollisionEventSerializer.h" +#include "carla/sensor/s11n/DVSEventArraySerializer.h" #include "carla/sensor/s11n/EpisodeStateSerializer.h" #include "carla/sensor/s11n/GnssSerializer.h" #include "carla/sensor/s11n/ImageSerializer.h" @@ -23,7 +24,6 @@ #include "carla/sensor/s11n/NoopSerializer.h" #include "carla/sensor/s11n/ObstacleDetectionEventSerializer.h" #include "carla/sensor/s11n/RadarSerializer.h" -#include "carla/sensor/s11n/DVSEventArraySerializer.h" // 2. Add a forward-declaration of the sensor here. class ACollisionSensor; diff --git a/LibCarla/source/carla/sensor/data/DVSEvent.h b/LibCarla/source/carla/sensor/data/DVSEvent.h index facd57c7d..26b177a69 100644 --- a/LibCarla/source/carla/sensor/data/DVSEvent.h +++ b/LibCarla/source/carla/sensor/data/DVSEvent.h @@ -14,32 +14,36 @@ namespace data { #pragma pack(push, 1) struct DVSEvent { - /** Default constructor **/ + /// Default constructor DVSEvent() = default; - /** Copy Constructor **/ + /// Copy Constructor DVSEvent(const DVSEvent &arg) :x(arg.x), y(arg.y), t(arg.t), pol(arg.pol){} - /** Moving constructor **/ + /// Moving constructor DVSEvent(const DVSEvent &&arg) :x(std::move(arg.x)), y(std::move(arg.y)), t(std::move(arg.t)), pol(std::move(arg.pol)){} - /** Constructor **/ + /// Constructor DVSEvent(std::uint16_t x, std::uint16_t y, std::int64_t t, bool pol) : x(x), y(y), t(t), pol(pol) {} - /** Assignement operator **/ - DVSEvent &operator=(const DVSEvent &other) - { - x = other.x; y = other.y; t = other.t; pol = other.pol; + /// Assignement operator + DVSEvent &operator=(const DVSEvent &other) { + x = other.x; + y = other.y; + t = other.t; + pol = other.pol; return *this; } - /** Move Assignement operator **/ - DVSEvent &operator=(const DVSEvent &&other) - { - x = std::move(other.x); y = std::move(other.y); t = std::move(other.t); pol = std::move(other.pol); + /// Move Assignement operator + DVSEvent &operator=(const DVSEvent &&other) { + x = std::move(other.x); + y = std::move(other.y); + t = std::move(other.t); + pol = std::move(other.pol); return *this; } diff --git a/LibCarla/source/carla/sensor/s11n/DVSEventArraySerializer.h b/LibCarla/source/carla/sensor/s11n/DVSEventArraySerializer.h index 17a359e9a..bc7ed0f73 100644 --- a/LibCarla/source/carla/sensor/s11n/DVSEventArraySerializer.h +++ b/LibCarla/source/carla/sensor/s11n/DVSEventArraySerializer.h @@ -54,19 +54,18 @@ namespace s11n { sensor.GetFOVAngle(), }; - /** Reset the output buffer **/ + /// Reset the output buffer output.reset(sizeof(DVSHeader) + (events.size() * sizeof(data::DVSEvent))); - /** Pointer to data in buffer **/ + /// Pointer to data in buffer unsigned char *it = output.data(); - /** Copy the header into the output buffer **/ + /// Copy the header into the output buffer std::memcpy(it, reinterpret_cast(&header), sizeof(header)); it += sizeof(DVSHeader); - /** Copy the events into the output buffer **/ - for (auto e : events) - { + /// Copy the events into the output buffer + for (auto e : events) { std::memcpy(it, reinterpret_cast(&e), sizeof(data::DVSEvent)); it += sizeof(data::DVSEvent); } diff --git a/PythonAPI/carla/source/libcarla/SensorData.cpp b/PythonAPI/carla/source/libcarla/SensorData.cpp index dade764e2..a6784ace3 100644 --- a/PythonAPI/carla/source/libcarla/SensorData.cpp +++ b/PythonAPI/carla/source/libcarla/SensorData.cpp @@ -99,18 +99,18 @@ namespace data { } std::ostream &operator<<(std::ostream &out, const DVSEvent &event) { - out << "Event(" << event.x - << ',' << event.y - << ',' << event.t - << ',' << event.pol << ')'; + out << "Event(x=" << std::to_string(event.x) + << ", y=" << std::to_string(event.y) + << ", t=" << std::to_string(event.t) + << ", pol=" << std::to_string(event.pol) << ')'; return out; } std::ostream &operator<<(std::ostream &out, const DVSEventArray &events) { - out << "EventArray(frame=" << events.GetFrame() - << ", timestamp=" << events.GetTimestamp() - << ", dimensions=" << events.GetWidth() << 'x' << events.GetHeight() - << ", number_of_events=" << events.size() + out << "EventArray(frame=" << std::to_string(events.GetFrame()) + << ", timestamp=" << std::to_string(events.GetTimestamp()) + << ", dimensions=" << std::to_string(events.GetWidth()) << 'x' << std::to_string(events.GetHeight()) + << ", number_of_events=" << std::to_string(events.size()) << ')'; return out; } @@ -350,7 +350,7 @@ void export_sensor_data() { .add_property("pol", &csd::DVSEvent::pol) .def(self_ns::str(self_ns::self)) ; - + class_, boost::noncopyable, boost::shared_ptr>("DVSEventArray", no_init) .add_property("width", &csd::DVSEventArray::GetWidth) .add_property("height", &csd::DVSEventArray::GetHeight) diff --git a/PythonAPI/examples/manual_control.py b/PythonAPI/examples/manual_control.py index b3987a4c7..20b9983dd 100755 --- a/PythonAPI/examples/manual_control.py +++ b/PythonAPI/examples/manual_control.py @@ -900,7 +900,6 @@ class CameraManager(object): self.transform_index = 1 self.sensors = [ ['sensor.camera.rgb', cc.Raw, 'Camera RGB', {}], - ['sensor.camera.dvs', cc.Raw, 'Dynamic Vision Sensor', {}], ['sensor.camera.depth', cc.Raw, 'Camera Depth (Raw)', {}], ['sensor.camera.depth', cc.Depth, 'Camera Depth (Gray Scale)', {}], ['sensor.camera.depth', cc.LogarithmicDepth, 'Camera Depth (Logarithmic Gray Scale)', {}], @@ -908,6 +907,7 @@ class CameraManager(object): ['sensor.camera.semantic_segmentation', cc.CityScapesPalette, 'Camera Semantic Segmentation (CityScapes Palette)', {}], ['sensor.lidar.ray_cast', None, 'Lidar (Ray-Cast)', {}], + ['sensor.camera.dvs', cc.Raw, 'Dynamic Vision Sensor', {}], ['sensor.camera.rgb', cc.Raw, 'Camera RGB Distorted', {'lens_circle_multiplier': '3.0', 'lens_circle_falloff': '3.0', @@ -983,7 +983,7 @@ class CameraManager(object): lidar_img = np.zeros((lidar_img_size), dtype = int) lidar_img[tuple(lidar_data.T)] = (255, 255, 255) self.surface = pygame.surfarray.make_surface(lidar_img) - if self.sensors[self.index][0].startswith('sensor.camera.dvs'): + elif self.sensors[self.index][0].startswith('sensor.camera.dvs'): array = np.frombuffer(image.to_image().raw_data, dtype=np.dtype("uint8")) array = np.reshape(array, (image.height, image.width, 4)) array = array[:, :, :3] diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/DVSCamera.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/DVSCamera.cpp index 14ee451f1..3906e7e43 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/DVSCamera.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/DVSCamera.cpp @@ -253,7 +253,7 @@ ADVSCamera::DVSEventArray ADVSCamera::simulation (float DeltaTime) } else { - /** Dropping event because time since last event < refractory_period_ns **/ + /** Dropping event because time since last event < refractory_period_ns **/ } this->ref_values[i] = curr_cross; } @@ -285,4 +285,4 @@ template T ADVSCamera::sampleNormalDistribution(bool deterministic, static std::mt19937 gen_deterministic(0); auto dist = std::normal_distribution(mean, sigma); return deterministic ? dist(gen_deterministic) : dist(gen_nondeterministic); -} \ No newline at end of file +} diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/DVSCamera.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/DVSCamera.h index 7ea163fb1..49880119a 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/DVSCamera.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/DVSCamera.h @@ -13,7 +13,7 @@ namespace dvs { - /** DVS Configuration structure **/ + /// DVS Configuration structure struct Config { float Cp; @@ -35,7 +35,7 @@ namespace dvs return static_cast(nanoseconds) / 1e9; } -}//namespace dvs +} // namespace dvs /// Sensor that produce Dynamic Vision Events UCLASS() @@ -56,22 +56,22 @@ protected: ADVSCamera::DVSEventArray simulation (float DeltaTime); private: - //! @return Sample from normal distribution (real-valued). + /// @return Sample from normal distribution (real-valued). template T sampleNormalDistribution( bool deterministic, T mean, T sigma); private: - /** Images containing last (current) and previous image **/ + /// Images containing last (current) and previous image TArray last_image, prev_image; - /** Image containing the last reference vaklue to trigger event **/ + /// Image containing the last reference vaklue to trigger event TArray ref_values; - /** Image containing time of last event in seconds **/ + /// Image containing time of last event in seconds TArray last_event_timestamp; - /** Current time in nanoseconds **/ + /// Current time in nanoseconds std::int64_t current_time; - /** DVS simulation configuration **/ + /// DVS simulation configuration dvs::Config config; };