From 4984326edbc10e1bd8fb16ca69659eceecb0638c Mon Sep 17 00:00:00 2001 From: pronif Date: Fri, 17 May 2019 13:52:57 +0100 Subject: [PATCH 01/11] Handle tf_prefix correctly Ignore tf_prefix if not present in param server, check it is well formatted otherwise --- ouster_ros/os1.launch | 2 ++ ouster_ros/src/os1_cloud_node.cpp | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ouster_ros/os1.launch b/ouster_ros/os1.launch index 16cc1c05..c894b652 100644 --- a/ouster_ros/os1.launch +++ b/ouster_ros/os1.launch @@ -9,6 +9,7 @@ + @@ -24,6 +25,7 @@ + diff --git a/ouster_ros/src/os1_cloud_node.cpp b/ouster_ros/src/os1_cloud_node.cpp index 8a7e8ec7..18759c75 100644 --- a/ouster_ros/src/os1_cloud_node.cpp +++ b/ouster_ros/src/os1_cloud_node.cpp @@ -28,9 +28,12 @@ int main(int argc, char** argv) { ros::NodeHandle nh("~"); auto tf_prefix = nh.param("tf_prefix", std::string{}); - auto sensor_frame = tf_prefix + "/os1_sensor"; - auto imu_frame = tf_prefix + "/os1_imu"; - auto lidar_frame = tf_prefix + "/os1_lidar"; + if (!tf_prefix.empty()) { + if (tf_prefix.back() != '/') tf_prefix.append(1, '/'); + } + auto sensor_frame = tf_prefix + "os1_sensor"; + auto imu_frame = tf_prefix + "os1_imu"; + auto lidar_frame = tf_prefix + "os1_lidar"; ouster_ros::OS1ConfigSrv cfg{}; auto client = nh.serviceClient("os1_config"); From b10d92232ee48e1244fe773a7bc761f49041aeac Mon Sep 17 00:00:00 2001 From: Daniel D'Souza Date: Tue, 11 Jun 2019 09:02:30 -0500 Subject: [PATCH 02/11] turn on position independent code for ouster_ros now this library can be used when building dynamic libraries. --- ouster_ros/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ouster_ros/CMakeLists.txt b/ouster_ros/CMakeLists.txt index ea92b2a5..15106655 100644 --- a/ouster_ros/CMakeLists.txt +++ b/ouster_ros/CMakeLists.txt @@ -43,6 +43,7 @@ catkin_package( ) add_library(ouster_ros STATIC src/os1_ros.cpp) +set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) target_link_libraries(ouster_ros ${catkin_LIBRARIES}) add_dependencies(ouster_ros ${PROJECT_NAME}_gencpp) From f56ce82084acd83b99cebde49f2c7786d88cce8d Mon Sep 17 00:00:00 2001 From: Daniel D'Souza Date: Tue, 11 Jun 2019 09:04:22 -0500 Subject: [PATCH 03/11] turn on PIC for ouster_example turn on Position Independent Code for ouster_example. This allows you to build dynamic libraries with this library. --- ouster_client/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ouster_client/CMakeLists.txt b/ouster_client/CMakeLists.txt index 7b73a16c..5b3e0c26 100644 --- a/ouster_client/CMakeLists.txt +++ b/ouster_client/CMakeLists.txt @@ -26,6 +26,7 @@ endif() add_library(ouster_client STATIC src/os1.cpp src/os1_util.cpp) +set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) target_link_libraries(ouster_client jsoncpp) target_include_directories(ouster_client PUBLIC include) target_include_directories(ouster_client SYSTEM PRIVATE ${jsoncpp_INCLUDE_DIRS}) From d5d9462ab5b1c5f700a7739c8cd4584138513be9 Mon Sep 17 00:00:00 2001 From: Behrooze Sirang Date: Wed, 19 Jun 2019 16:37:49 -0700 Subject: [PATCH 04/11] Use iterator_traits to access value_type so that raw points work --- ouster_client/include/ouster/os1_util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ouster_client/include/ouster/os1_util.h b/ouster_client/include/ouster/os1_util.h index e78164c4..6a683b35 100644 --- a/ouster_client/include/ouster/os1_util.h +++ b/ouster_client/include/ouster/os1_util.h @@ -82,7 +82,7 @@ std::vector get_px_offset(int W); template std::function batch_to_iter( const std::vector& xyz_lut, int W, int H, - const typename iterator_type::value_type& empty, C&& c, F&& f) { + const typename std::iterator_traits::value_type& empty, C&& c, F&& f) { int next_m_id{W}; int32_t cur_f_id{-1}; From 2b058ed1614eb430abc93c73c7549aeb3997a23d Mon Sep 17 00:00:00 2001 From: standmit Date: Wed, 14 Aug 2019 22:16:16 +0700 Subject: [PATCH 05/11] timestamp mode configurable --- ouster_client/include/ouster/os1.h | 21 +++++++++++++++++++ ouster_client/src/os1.cpp | 33 ++++++++++++++++++++++++++++-- ouster_ros/os1.launch | 2 ++ ouster_ros/src/os1_node.cpp | 11 ++++++++++ 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/ouster_client/include/ouster/os1.h b/ouster_client/include/ouster/os1.h index 08363cc7..12de828c 100644 --- a/ouster_client/include/ouster/os1.h +++ b/ouster_client/include/ouster/os1.h @@ -34,6 +34,12 @@ enum lidar_mode { MODE_2048x10 }; +enum timestamp_mode { + TIME_FROM_INTERNAL_OSC = 1, + TIME_FROM_SYNC_PULSE_IN, + TIME_FROM_PTP_1588 +}; + struct version { int16_t major; int16_t minor; @@ -106,6 +112,20 @@ lidar_mode lidar_mode_of_string(const std::string& s); */ int n_cols_of_lidar_mode(lidar_mode mode); +/** + * Get string representation of a timestamp mode + * @param timestamp_mode + * @return string representation of the timestamp mode, or "UNKNOWN" + */ +std::string to_string(timestamp_mode mode); + +/** + * Get timestamp mode from string + * @param string + * @return timestamp mode corresponding to the string, or 0 on error + */ +timestamp_mode timestamp_mode_of_string(const std::string& s); + /** * Listen for OS1 data on the specified ports * @param lidar_port port on which the sensor will send lidar data @@ -125,6 +145,7 @@ std::shared_ptr init_client(int lidar_port = 7502, int imu_port = 7503); std::shared_ptr init_client(const std::string& hostname, const std::string& udp_dest_host, lidar_mode mode = MODE_1024x10, + timestamp_mode ts_mode = TIME_FROM_INTERNAL_OSC, int lidar_port = 7502, int imu_port = 7503); /** diff --git a/ouster_client/src/os1.cpp b/ouster_client/src/os1.cpp index efd580b0..87cfa43b 100644 --- a/ouster_client/src/os1.cpp +++ b/ouster_client/src/os1.cpp @@ -46,6 +46,11 @@ const std::array, 5> lidar_mode_strings = { {MODE_1024x20, "1024x20"}, {MODE_2048x10, "2048x10"}}}; +const std::array, 3> timestamp_mode_strings = { + {{TIME_FROM_INTERNAL_OSC, "TIME_FROM_INTERNAL_OSC"}, + {TIME_FROM_SYNC_PULSE_IN, "TIME_FROM_SYNC_PULSE_IN"}, + {TIME_FROM_PTP_1588, "TIME_FROM_PTP_1588"}}}; + int udp_data_socket(int port) { struct addrinfo hints, *info_start, *ai; @@ -232,6 +237,26 @@ int n_cols_of_lidar_mode(lidar_mode mode) { } } +std::string to_string(timestamp_mode mode) { + auto end = timestamp_mode_strings.end(); + auto res = std::find_if(timestamp_mode_strings.begin(), end, + [&](const std::pair& p) { + return p.first == mode; + }); + + return res == end ? "UNKNOWN" : res->second; +} + +timestamp_mode timestamp_mode_of_string(const std::string& s) { + auto end = timestamp_mode_strings.end(); + auto res = std::find_if(timestamp_mode_strings.begin(), end, + [&](const std::pair& p) { + return p.second == s; + }); + + return res == end ? timestamp_mode(0) : res->first; +} + std::string get_metadata(const client& cli) { Json::StreamWriterBuilder builder; builder["enableYAMLCompatibility"] = true; @@ -294,8 +319,8 @@ std::shared_ptr init_client(int lidar_port, int imu_port) { std::shared_ptr init_client(const std::string& hostname, const std::string& udp_dest_host, - lidar_mode mode, int lidar_port, - int imu_port) { + lidar_mode mode, timestamp_mode ts_mode, + int lidar_port, int imu_port) { auto cli = init_client(lidar_port, imu_port); int sock_fd = cfg_socket(hostname.c_str()); @@ -328,6 +353,10 @@ std::shared_ptr init_client(const std::string& hostname, sock_fd, {"set_config_param", "lidar_mode", to_string(mode)}, res); success &= res == "set_config_param"; + success &= do_tcp_cmd( + sock_fd, {"set_config_param", "timestamp_mode", to_string(ts_mode)}, res); + success &= res == "set_config_param"; + success &= do_tcp_cmd(sock_fd, {"get_sensor_info"}, res); success &= reader->parse(res.c_str(), res.c_str() + res.size(), &cli->meta, &errors); diff --git a/ouster_ros/os1.launch b/ouster_ros/os1.launch index 16cc1c05..c6c361a8 100644 --- a/ouster_ros/os1.launch +++ b/ouster_ros/os1.launch @@ -6,12 +6,14 @@ + + diff --git a/ouster_ros/src/os1_node.cpp b/ouster_ros/src/os1_node.cpp index 8dfc9cac..824a96d4 100644 --- a/ouster_ros/src/os1_node.cpp +++ b/ouster_ros/src/os1_node.cpp @@ -151,6 +151,7 @@ int main(int argc, char** argv) { auto imu_port = nh.param("os1_imu_port", 7502); auto replay = nh.param("replay", false); auto lidar_mode = nh.param("lidar_mode", std::string{}); + auto timestamp_mode = nh.param("timestamp_mode", std::string{}); // fall back to metadata file name based on hostname, if available auto meta_file = nh.param("metadata", std::string{}); @@ -167,6 +168,15 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } + if (not timestamp_mode.size()) { + timestamp_mode = OS1::to_string(OS1::TIME_FROM_INTERNAL_OSC); + } + + if (!OS1::timestamp_mode_of_string(timestamp_mode)) { + ROS_ERROR("Invalid timestamp mode %s", timestamp_mode.c_str()); + return EXIT_FAILURE; + } + if (!replay && (!hostname.size() || !udp_dest.size())) { ROS_ERROR("Must specify both hostname and udp destination"); return EXIT_FAILURE; @@ -195,6 +205,7 @@ int main(int argc, char** argv) { auto cli = OS1::init_client(hostname, udp_dest, OS1::lidar_mode_of_string(lidar_mode), + OS1::timestamp_mode_of_string(timestamp_mode), lidar_port, imu_port); if (!cli) { From f3dc5ec292e4bbd260e8bac8d686069b9a3d2ec6 Mon Sep 17 00:00:00 2001 From: Krishtof Korda Date: Tue, 10 Sep 2019 20:08:47 -0700 Subject: [PATCH 06/11] Ez/readme improvement (#113) Change OS-1 to OS1 throughout and clean up links Submitted on behalf of @Emily-Zhang --- README.md | 8 ++-- ouster_client/README.md | 22 +++++------ ouster_ros/README.md | 84 ++++++++++++++++++++++++++--------------- ouster_viz/README.md | 24 ++++++------ 4 files changed, 81 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index f698d621..a8e8c1a6 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# OS-1 Example Code -Sample code for connecting to and configuring the OS-1, reading and visualizing +# OS1 Example Code +Sample code for connecting to and configuring the OS1, reading and visualizing data, and interfacing with ROS. See the `README.md` in each subdirectory for details. ## Contents -* [ouster_client/](ouster_client/README.md) contains an example C++ client for the OS-1 sensor -* [ouster_viz/](ouster_viz/README.md) contains a visualizer for the OS-1 sensor +* [ouster_client/](ouster_client/README.md) contains an example C++ client for the OS1 sensor +* [ouster_viz/](ouster_viz/README.md) contains a visualizer for the OS1 sensor * [ouster_ros/](ouster_ros/README.md) contains example ROS nodes for publishing point cloud messages ## Sample Data diff --git a/ouster_client/README.md b/ouster_client/README.md index b253d85d..dbaf6285 100644 --- a/ouster_client/README.md +++ b/ouster_client/README.md @@ -1,24 +1,24 @@ -# OS-1 Example Client +# OS1 Example Client ## Contents -* `ouster_client/` contains a simple C++ client for the OS-1 sensor +* `ouster_client/` contains a simple C++ client for the OS1 sensor that + prints lidar data to the terminal * can be built both with and without ROS. See the instructions in - `ouster_ros` for building in a ROS environment + [ouster_ros/](../ouster_ros/README.md) for building in a ROS environment ## Building the Sample Client * The sample client requires a compiler supporting C++11 or newer and CMake * Build with `cd /path/to/ouster_example/ouster_client && mkdir build - && cd build && cmake .. && make` + && cd build && cmake .. && make` where `/path/to/ouster_example` is where you've cloned the repository ## Running the Sample Client -* The sample client includes a small driver program that just prints - some data to the terminal -* Make sure the OS-1 is connected to the network and has obtained a - DHCP lease. See accompanying documentation for more details -* You should see a binary called `ouster_client_example` in your build +* Make sure the OS1 is connected to the network and has obtained a + DHCP lease. See section 3.1 in the accompanying + [software user guide](https://www.ouster.io/downloads) for more details +* An executable called `ouster_client_example` is generated in the build directory on success -* Run `ouster_client_example ` where - `` is the hostname or IP address of the OS-1 sensor, +* Run `./ouster_client_example ` where + `` is the hostname or IP address of the OS1 sensor, and `` is the IP to which the sensor should send lidar data diff --git a/ouster_ros/README.md b/ouster_ros/README.md index 473f0708..17822f01 100644 --- a/ouster_ros/README.md +++ b/ouster_ros/README.md @@ -1,35 +1,45 @@ -# OS-1 Example ROS Node +# OS1 Example ROS Node ## Contents -* `ouster_ros/` contains sample code for publishing OS-1 data as standard ROS - topics -* Tested with ROS Kinetic on Ubuntu 16.04 +* `ouster_ros/` contains sample code for publishing OS1 data as standard + ROS topics + +## Operating System Support +* The visualizer has been tested on [ROS Kinetic](http://wiki.ros.org/kinetic/Installation/Ubuntu) on Ubuntu 16.04 + * additionally requires `ros-kinetic-pcl-ros`, `ros-kinetic-tf2-geometry-msgs` + and, optionally, `ros-kinetic-rviz` for visualization using ROS +* The visualizer has been tested on [ROS Melodic](http://wiki.ros.org/melodic/Installation/Ubuntu) on Ubuntu 18.04 + * additionally requires `ros-melodic-pcl-ros`, `ros-melodic-tf2-geometry-msgs` + and, optionally, `ros-melodic-rviz` for visualization using ROS ## Building the Sample ROS Node -* Supports Ubuntu 16.04 with ROS Kinetic (for ouster_ros) -* ROS installation instructions can be found - [here](http://wiki.ros.org/kinetic/Installation/Ubuntu) -* Additionally requires `ros-kinetic-pcl-ros`, `ros-kinetic-tf2-geometry-msgs` - and, optionally, `ros-kinetic-rviz` for visualization using ROS -* Be sure to source the ROS setup script before building. For example:`source - /opt/ros/kinetic/setup.bash` +* In the following instruction steps, `/path/to/ouster_example` is where you've cloned the repository +* Run the following command `export CMAKE_PREFIX_PATH=/path/to/ouster_example` +* Be sure to source the ROS setup script before building. For example: +`source /opt/ros/[kinetic_or_melodic]/setup.bash` * Build with `mkdir -p myworkspace/src && cd myworkspace && ln -s /path/to/ouster_example ./src/ && catkin_make -DCMAKE_BUILD_TYPE=Release` ## Running the Sample ROS Nodes -* Make sure to set up the ROS environment with `source - /path/to/myworkspace/devel/setup.bash` in a new terminal for each command - below -* To publish ROS topics from a running sensor: - - Run `roslaunch ouster_ros os1.launch os1_hostname:= - os1_udp_dest:= lidar_mode:=` where - `` can be the hostname or IP of the OS-1 device, - `` is the IP to which the sensor should send data, and - `` is one of 512x10, 512x20, 1024x10, 1024x20, or 2048x10 - - To record raw sensor output, run `rosbag record /os1_node/imu_packets - /os1_node/lidar_packets` in another terminal -* To publish ROS topics from recorded data: - - Run `roslaunch ouster_ros os1.launch replay:=true +* Make sure the OS1 is connected to the network and has obtained a DHCP lease. See section 3.1 in the accompanying [software user guide](https://www.ouster.io/downloads) for more details +* In each new terminal for each command below: + - Make sure to source ROS environment with `source + /path/to/myworkspace/devel/setup.bash` where `/path/to/myworkspace` is where the path to the workspace directory that was created + when building the ROS nodes +* To publish ROS topics from a running sensor from within the `ouster_ros` directory: + - Run `roslaunch os1.launch os1_hostname:= + os1_udp_dest:= lidar_mode:= viz:=`where: + - `` can be the hostname (os1-991xxxxxxxxx) or IP of the OS1 + - `` is the IP to which the sensor should send data + - `` is one of `512x10`, `512x20`, `1024x10`, `1024x20`, or `2048x10` + - `` is either `true` or `false`. If true, a window should open and start + displaying data after a few seconds +* To record raw sensor output + - In another terminal instance, run `rosbag record /os1_node/imu_packets + /os1_node/lidar_packets` + - This will save a .bag file of recorded data in that directory +* To publish ROS topics from recorded data from withint the `ouster_ros` directory: + - Run `roslaunch os1.launch replay:=true os1_hostname:=` - In a second terminal run `rosbag play --clock ` - Note: `os1_node` reads and writes metadata to `${ROS_HOME}` to enable @@ -40,13 +50,6 @@ 1024x10. This can be overridden with the `lidar_mode` parameter. Visualizer output will only be correct if the same `lidar_mode` parameter is used for both recording and replay -* To display sensor output using the provided visualizer: - - To visualize the published OS-1 point cloud data using the provided - visualizer, add `viz:=true` to either of the `roslaunch` commands above - - A window should open and start displaying data after a few seconds. This - should work with a running sensor or replayed data - - See the [README.md](../ouster_viz/README.md) in the `ouster_viz` directory - for details on keyboard and mouse controls * To display sensor output using ROS tools (rviz): - Follow the instructions above for running the example ROS code with a sensor or recorded data @@ -54,3 +57,22 @@ in another terminal - To view lidar intensity/noise/range images, add `image:=true` to either of the `roslaunch` commands above + +## Key bindings +| key | what it does | +| ----| ------------ | +| `o` | Increase point size | +| `p` | Decrease point size | +| `m` | Cycle point cloud coloring by z-height / intensity / z-height plus intensity / range | +| `c` | Cycle color scheme for range image | +| `shift c` | Cycle color scheme for point cloud | +| `v` | Toggle color cycling in range image | +| `n` | Display ambient image from the sensor| +| `r` | Reset camera position +| `0` (zero) | Toggle parallel projection and reset camera | +| `d` | Cycle through fraction of the window height used for displaying range and intensity image + +## Mouse control +* Click and drag rotates the view +* Middle click and drag pans the view +* Scroll adjusts how far away the camera is from the vehicle diff --git a/ouster_viz/README.md b/ouster_viz/README.md index 6db21629..93548b68 100644 --- a/ouster_viz/README.md +++ b/ouster_viz/README.md @@ -1,10 +1,10 @@ -# OS-1 Example Visualizer +# OS1 Example Visualizer ## Contents -* 'ouster_viz/' contains a basic visualizer that can be used to +* `ouster_viz/` contains a basic visualizer that can be used to display point clouds and range/intensity/ambient images -* can be built both with and without ROS. See the instructions in - `ouster_ros` for building in a ROS environment +* Can be built both with and without ROS. See the instructions in + [ouster_ros](../ouster_ros/README.md) for building in a ROS environment ## Operating System Support * The visualizer has been tested on: Ubuntu 16.04, 17.1, and 18.04, as @@ -20,21 +20,23 @@ eigen3-devel.noarch ## Building the Visualizer: -* Build with 'cd /path/to/ouster_example/ouster_viz && mkdir build && - cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make' +* In the following instruction steps, `/path/to/ouster_example` is where you've cloned the repository +* Run the following command `export CMAKE_PREFIX_PATH=/path/to/ouster_example` +* Build with `cd /path/to/ouster_example/ouster_viz && mkdir build && + cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make` ## Running the Visualizer -* An executable called "viz" is generated in the build directory +* An executable called `simple_viz` is generated in the build directory * Note: if compiling in an environment with ROS, the location of the executable will be different -* To run: `./viz ` -* For help, run ./viz -h +* To run: `./simple_viz ` +* For help, run `./simple_viz -h` ## Command Line Arguments -* `` the hostname or IP address of the OS-1 sensor +* `` the hostname or IP address of the OS1 sensor * `` the IP to which the sensor should send data * `-m <512x10 | 512x20 | 1024x10 | 1024x20 | 2048x10>` flag to set the lidar - mode (horizontal resolution and rate). Defaults to 1024x10. + mode (horizontal resolution x rotation rate). Defaults to 1024x10. ## Key bindings | key | what it does | From 4a0cc273d1711421f24da2495d90143fd7684883 Mon Sep 17 00:00:00 2001 From: DangitBen <30333928+DangitBen@users.noreply.github.com> Date: Thu, 19 Sep 2019 12:09:24 -0500 Subject: [PATCH 07/11] Change dependency from jsoncpp to match rosdep --- ouster_client/package.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ouster_client/package.xml b/ouster_client/package.xml index d5933f47..e956f413 100644 --- a/ouster_client/package.xml +++ b/ouster_client/package.xml @@ -5,9 +5,9 @@ The os1_client package ouster developers BSD - jsoncpp + libjsoncpp catkin - jsoncpp + libjsoncpp From 68ad03c18c99b536a31ad67ccfb2e2d4aeb9b61c Mon Sep 17 00:00:00 2001 From: Dima Garbuzov Date: Tue, 14 May 2019 03:19:39 +0000 Subject: [PATCH 08/11] Update for fw 1.13. See changelog for details * Use random udp ports by default to simplify running multiple clients * Dynamically adjust ambient and intensity exposure in visualizer * Fix crash on failed udp socket call --- CHANGELOG.md | 16 +++ README.md | 2 +- ouster_client/include/ouster/os1.h | 13 ++- ouster_client/src/os1.cpp | 54 ++++++++--- ouster_ros/os1.launch | 4 +- ouster_ros/src/os1_node.cpp | 4 +- ouster_viz/README.md | 11 +-- ouster_viz/include/ouster/autoexposure.h | 52 ++++++++++ ouster_viz/include/ouster/beam_uniformity.h | 84 ++++++++++++++++ ouster_viz/include/ouster/lidar_scan.h | 1 + ouster_viz/src/main.cpp | 29 ++++-- ouster_viz/src/viz.cpp | 102 ++++++++++++-------- 12 files changed, 295 insertions(+), 77 deletions(-) create mode 100644 ouster_viz/include/ouster/autoexposure.h create mode 100644 ouster_viz/include/ouster/beam_uniformity.h diff --git a/CHANGELOG.md b/CHANGELOG.md index c78a6fbb..395870be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Changelog +## [1.13.0] - 2020-03-16 +### Added +- post-processing to improve ambient image uniformity in visualizer +- make timestamp mode configurable via the client (PR #97) + +### Changed +- turn on position-independent code by default to make using code in libraries + easier (PR #65) +- use random ports for lidar and imu data by default when unspecified + +### Fixed +- prevent legacy tf prefix from making invalid frame names (PR #56) +- use `iterator_traits` to make `batch_to_iter` work with more types (PR #70) +- use correct name for json dependency in `package.xml` (PR #116) +- handle udp socket creation error gracefully in client + ## [1.12.0] - 2019-05-02 ### Added - install directives for `ouster_ros` build (addresses #50) diff --git a/README.md b/README.md index a8e8c1a6..ecb1e61c 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,4 @@ See the `README.md` in each subdirectory for details. ## Sample Data * Sample sensor output usable with the provided ROS code is available - [here](https://data.ouster.io/sample-data-1.12) + [here](https://data.ouster.io/sample-data-1.13) diff --git a/ouster_client/include/ouster/os1.h b/ouster_client/include/ouster/os1.h index 12de828c..63f63783 100644 --- a/ouster_client/include/ouster/os1.h +++ b/ouster_client/include/ouster/os1.h @@ -132,7 +132,7 @@ timestamp_mode timestamp_mode_of_string(const std::string& s); * @param imu_port port on which the sensor will send imu data * @return pointer owning the resources associated with the connection */ -std::shared_ptr init_client(int lidar_port = 7502, int imu_port = 7503); +std::shared_ptr init_client(int lidar_port = 0, int imu_port = 0); /** * Connect to and configure the sensor and start listening for data @@ -146,10 +146,10 @@ std::shared_ptr init_client(const std::string& hostname, const std::string& udp_dest_host, lidar_mode mode = MODE_1024x10, timestamp_mode ts_mode = TIME_FROM_INTERNAL_OSC, - int lidar_port = 7502, int imu_port = 7503); + int lidar_port = 0, int imu_port = 0); /** - * Block for up to timeout_sec until either data is ready or an error occurs. + * Block for up to timeout_sec until either data is ready or an error occurs * @param cli client returned by init_client associated with the connection * @param timeout_sec seconds to block while waiting for data * @return client_state s where (s & ERROR) is true if an error occured, (s & @@ -159,7 +159,7 @@ std::shared_ptr init_client(const std::string& hostname, client_state poll_client(const client& cli, int timeout_sec = 1); /** - * Read lidar data from the sensor. Will not block. + * Read lidar data from the sensor. Will not block * @param cli client returned by init_client associated with the connection * @param buf buffer to which to write lidar data. Must be at least * lidar_packet_bytes + 1 bytes @@ -168,7 +168,7 @@ client_state poll_client(const client& cli, int timeout_sec = 1); bool read_lidar_packet(const client& cli, uint8_t* buf); /** - * Read imu data from the sensor. Will not block. + * Read imu data from the sensor. Will not block * @param cli client returned by init_client associated with the connection * @param buf buffer to which to write imu data. Must be at least * imu_packet_bytes + 1 bytes @@ -186,8 +186,7 @@ std::string get_metadata(const client& cli); /** * Parse metadata text blob from the sensor into a sensor_info struct. String * and vector fields will have size 0 if the parameter cannot be found or - * parsed, - * while lidar_mode will be set to 0 (invalid). + * parsed, while lidar_mode will be set to 0 (invalid) * @throw runtime_error if the text is not valid json * @param metadata a text blob returned by get_metadata above * @return a sensor_info struct populated with a subset of the metadata diff --git a/ouster_client/src/os1.cpp b/ouster_client/src/os1.cpp index 60a43285..164d6ebc 100644 --- a/ouster_client/src/os1.cpp +++ b/ouster_client/src/os1.cpp @@ -52,6 +52,23 @@ const std::array, 3> {TIME_FROM_SYNC_PULSE_IN, "TIME_FROM_SYNC_PULSE_IN"}, {TIME_FROM_PTP_1588, "TIME_FROM_PTP_1588"}}}; +int32_t get_sock_port(int sock_fd) { + struct sockaddr_storage ss; + socklen_t addrlen = sizeof ss; + + if (getsockname(sock_fd, (struct sockaddr*)&ss, &addrlen) < 0) { + std::cerr << "udp getsockname(): " << std::strerror(errno) << std::endl; + return -1; + } + + if (ss.ss_family == AF_INET) + return ntohs(((struct sockaddr_in*)&ss)->sin_port); + else if (ss.ss_family == AF_INET6) + return ntohs(((struct sockaddr_in6*)&ss)->sin6_port); + else + return -1; +} + int udp_data_socket(int port) { struct addrinfo hints, *info_start, *ai; @@ -97,6 +114,7 @@ int udp_data_socket(int port) { if (fcntl(sock_fd, F_SETFL, fcntl(sock_fd, F_GETFL, 0) | O_NONBLOCK) < 0) { std::cerr << "udp fcntl(): " << std::strerror(errno) << std::endl; + close(sock_fd); return -1; } @@ -179,7 +197,7 @@ bool do_tcp_cmd(int sock_fd, const std::vector& cmd_tokens, void update_json_obj(Json::Value& dst, const Json::Value& src) { for (const auto& key : src.getMemberNames()) dst[key] = src[key]; } -} +} // namespace std::string to_string(version v) { if (v == invalid_version) return "UNKNOWN"; @@ -313,10 +331,12 @@ sensor_info parse_metadata(const std::string& meta) { std::shared_ptr init_client(int lidar_port, int imu_port) { auto cli = std::make_shared(); - int lidar_fd = udp_data_socket(lidar_port); - int imu_fd = udp_data_socket(imu_port); - cli->lidar_fd = lidar_fd; - cli->imu_fd = imu_fd; + cli->lidar_fd = udp_data_socket(lidar_port); + cli->imu_fd = udp_data_socket(imu_port); + + if (cli->lidar_fd < 0 || cli->imu_fd < 0) + return std::shared_ptr(); + return cli; } @@ -325,6 +345,12 @@ std::shared_ptr init_client(const std::string& hostname, lidar_mode mode, timestamp_mode ts_mode, int lidar_port, int imu_port) { auto cli = init_client(lidar_port, imu_port); + if (!cli) return std::shared_ptr(); + + // update requested ports to actual bound ports + lidar_port = get_sock_port(cli->lidar_fd); + imu_port = get_sock_port(cli->imu_fd); + if (lidar_port == -1 || imu_port == -1) return std::shared_ptr(); int sock_fd = cfg_socket(hostname.c_str()); @@ -342,9 +368,10 @@ std::shared_ptr init_client(const std::string& hostname, do_tcp_cmd(sock_fd, {"set_config_param", "udp_ip", udp_dest_host}, res); success &= res == "set_config_param"; - success &= do_tcp_cmd(sock_fd, {"set_config_param", "udp_port_lidar", - std::to_string(lidar_port)}, - res); + success &= do_tcp_cmd( + sock_fd, + {"set_config_param", "udp_port_lidar", std::to_string(lidar_port)}, + res); success &= res == "set_config_param"; success &= do_tcp_cmd( @@ -419,9 +446,9 @@ client_state poll_client(const client& c, const int timeout_sec) { return res; } -static bool recv_fixed(int fd, void* buf, size_t len) { - ssize_t n = recvfrom(fd, buf, len + 1, 0, NULL, NULL); - if (n == (ssize_t)len) +static bool recv_fixed(int fd, void* buf, ssize_t len) { + ssize_t n = recv(fd, (char*)buf, len + 1, 0); + if (n == len) return true; else if (n == -1) std::cerr << "recvfrom: " << std::strerror(errno) << std::endl; @@ -437,5 +464,6 @@ bool read_lidar_packet(const client& cli, uint8_t* buf) { bool read_imu_packet(const client& cli, uint8_t* buf) { return recv_fixed(cli.imu_fd, buf, imu_packet_bytes); } -} -} + +} // namespace OS1 +} // namespace ouster diff --git a/ouster_ros/os1.launch b/ouster_ros/os1.launch index 0c098a89..2eb50cf6 100644 --- a/ouster_ros/os1.launch +++ b/ouster_ros/os1.launch @@ -2,8 +2,8 @@ - - + + diff --git a/ouster_ros/src/os1_node.cpp b/ouster_ros/src/os1_node.cpp index 824a96d4..faca163a 100644 --- a/ouster_ros/src/os1_node.cpp +++ b/ouster_ros/src/os1_node.cpp @@ -147,8 +147,8 @@ int main(int argc, char** argv) { // empty indicates "not set" since roslaunch xml can't optionally set params auto hostname = nh.param("os1_hostname", std::string{}); auto udp_dest = nh.param("os1_udp_dest", std::string{}); - auto lidar_port = nh.param("os1_lidar_port", 7501); - auto imu_port = nh.param("os1_imu_port", 7502); + auto lidar_port = nh.param("os1_lidar_port", 0); + auto imu_port = nh.param("os1_imu_port", 0); auto replay = nh.param("replay", false); auto lidar_mode = nh.param("lidar_mode", std::string{}); auto timestamp_mode = nh.param("timestamp_mode", std::string{}); diff --git a/ouster_viz/README.md b/ouster_viz/README.md index 93548b68..703eaf06 100644 --- a/ouster_viz/README.md +++ b/ouster_viz/README.md @@ -16,21 +16,20 @@ and CMake 3.1 or newer * Requires VTK6 and Eigen3 libraries * Using Ubuntu: sudo apt-get install libvtk6-dev libeigen3-dev -* Using Fedora: sudo apt-get update yum install vtk-devel.x86_64 - eigen3-devel.noarch +* Using Fedora: sudo yum install vtk-devel.x86_64 eigen3-devel.noarch ## Building the Visualizer: -* In the following instruction steps, `/path/to/ouster_example` is where you've cloned the repository +* In the following instruction steps, `/path/to/ouster_example` is where you've cloned the repository * Run the following command `export CMAKE_PREFIX_PATH=/path/to/ouster_example` * Build with `cd /path/to/ouster_example/ouster_viz && mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make` ## Running the Visualizer -* An executable called `simple_viz` is generated in the build directory +* An executable called `viz` is generated in the build directory * Note: if compiling in an environment with ROS, the location of the executable will be different -* To run: `./simple_viz ` -* For help, run `./simple_viz -h` +* To run: `./viz ` +* For help, run `./viz -h` ## Command Line Arguments * `` the hostname or IP address of the OS1 sensor diff --git a/ouster_viz/include/ouster/autoexposure.h b/ouster_viz/include/ouster/autoexposure.h new file mode 100644 index 00000000..f56123db --- /dev/null +++ b/ouster_viz/include/ouster/autoexposure.h @@ -0,0 +1,52 @@ +/** + * @file + * @brief Adjust brightness image brightness and apply gamma correction + * + * Functor that adjusts brightness so that 1st percentile pixel is black + * and 99th percentile pixel is white, while applying basic gamma correction + * of 2.0. + * Stores state of the black and white points so that it does not flicker + * rapidly. + */ + +#pragma once + +#include +#include +#include + +struct AutoExposure { + private: + double lo_state = -1.0; + double hi_state = -1.0; + + public: + void operator()(Eigen::Ref key_eigen) { + const size_t n = key_eigen.rows(); + const size_t kth_extreme = n / 100; + std::vector indices(n); + for (size_t i = 0; i < n; i++) { + indices[i] = i; + } + auto cmp = [&](const size_t a, const size_t b) { + return key_eigen(a) < key_eigen(b); + }; + std::nth_element(indices.begin(), indices.begin() + kth_extreme, + indices.end(), cmp); + const double lo = key_eigen[*(indices.begin() + kth_extreme)]; + std::nth_element(indices.begin() + kth_extreme, + indices.end() - kth_extreme, indices.end(), cmp); + const double hi = key_eigen[*(indices.end() - kth_extreme)]; + if (lo_state < 0) { + lo_state = lo; + hi_state = hi; + } + lo_state = 0.9 * lo_state + 0.1 * lo; + hi_state = 0.9 * hi_state + 0.1 * hi; + key_eigen -= lo; + key_eigen *= 1.0 / (hi - lo); + + // gamma correction + key_eigen = key_eigen.max(0.0).sqrt().min(1.0); + } +}; diff --git a/ouster_viz/include/ouster/beam_uniformity.h b/ouster_viz/include/ouster/beam_uniformity.h new file mode 100644 index 00000000..3159d7e3 --- /dev/null +++ b/ouster_viz/include/ouster/beam_uniformity.h @@ -0,0 +1,84 @@ +/** + * @file + * @brief Corrects beam uniformity by minimizing median difference between rows + * + */ + +#pragma once + +#include +#include +#include + +class BeamUniformityCorrector { + private: + std::vector dark_count; + + std::vector compute_dark_count( + const Eigen::Ref image) { + const size_t image_h = image.rows(); + const size_t image_w = image.cols(); + + std::vector tmp(image_w); + std::vector new_dark_count(image_h, 0); + + Eigen::ArrayXXd row_diffs = + image.bottomRows(image_h - 1) - image.topRows(image_h - 1); + + // compute the median of differences between rows + for (size_t i = 1; i < image_h; i++) { + Eigen::Map> tmp_map(tmp.data(), + image_w); + tmp_map = row_diffs.row(i - 1); + std::nth_element(tmp.begin(), tmp.begin() + image_w / 2, tmp.end()); + new_dark_count[i] = new_dark_count[i - 1] + tmp[image_w / 2]; + } + + // remove gradients in the entire height of image by doing linear fit + Eigen::Matrix A(image_h, 2); + for (size_t i = 0; i < image_h; i++) { + A(i, 0) = 1; + A(i, 1) = i; + } + + Eigen::Vector2d x = A.fullPivLu().solve( + Eigen::Map(new_dark_count.data(), image_h, 1)); + + Eigen::Map(new_dark_count.data(), image_h, 1) -= + (A * x).array(); + + // subtract minimum value + double min_el = + *std::min_element(new_dark_count.begin(), new_dark_count.end()); + Eigen::Map(new_dark_count.data(), image_h, 1) -= min_el; + return new_dark_count; + } + + public: + void correct(Eigen::Ref image) { + const size_t image_h = image.rows(); + + if (dark_count.size() == 0) { + dark_count = compute_dark_count(image); + } else { + // update dark_count with a decaying weighted average + const auto new_dark_count = compute_dark_count(image); + Eigen::Map(dark_count.data(), image_h) *= 0.95; + Eigen::Map(dark_count.data(), image_h) += + Eigen::Map(new_dark_count.data(), + image_h) * + 0.05; + } + + // apply the dark count correction row by row + for (size_t i = 0; i < image_h; i++) { + // contains a view of the current row + image.row(i) -= dark_count[i]; + image.row(i) = image.row(i).unaryExpr([](double x) { + x = std::max(x, 0.0); + x = std::min(x, (double)UINT32_MAX); + return x; + }); + } + } +}; diff --git a/ouster_viz/include/ouster/lidar_scan.h b/ouster_viz/include/ouster/lidar_scan.h index b8bf3bce..2e292d66 100644 --- a/ouster_viz/include/ouster/lidar_scan.h +++ b/ouster_viz/include/ouster/lidar_scan.h @@ -9,6 +9,7 @@ #include #include #include +#include namespace ouster { diff --git a/ouster_viz/src/main.cpp b/ouster_viz/src/main.cpp index df3e444e..13245725 100644 --- a/ouster_viz/src/main.cpp +++ b/ouster_viz/src/main.cpp @@ -31,6 +31,8 @@ void print_help() { << "Options:\n" << " -m <512x10 | 512x20 | 1024x10 | 1024x20 | 2048x10> : lidar mode, " "default 1024x10\n" + << " -l : use specified port for lidar data\n" + << " -i : use specified port for imu data \n" << " -f : use provided metadata file; do not configure via TCP" << std::endl; } @@ -57,10 +59,12 @@ int main(int argc, char** argv) { OS1::lidar_mode mode = OS1::MODE_1024x10; bool do_config = true; // send tcp commands to configure sensor std::string metadata{}; + int lidar_port = 0; + int imu_port = 0; try { int c = 0; - while ((c = getopt(argc, argv, "hm:f:")) != -1) { + while ((c = getopt(argc, argv, "hm:l:i:f:")) != -1) { switch (c) { case 'h': print_help(); @@ -78,6 +82,12 @@ int main(int argc, char** argv) { std::exit(EXIT_FAILURE); } break; + case 'l': + lidar_port = std::stoi(optarg); + break; + case 'i': + imu_port = std::stoi(optarg); + break; case 'f': do_config = false; metadata = read_metadata(optarg); @@ -103,12 +113,19 @@ int main(int argc, char** argv) { std::shared_ptr cli; if (do_config) { - std::cout << "Configuring sensor: " << argv[optind] - << " UDP Destination:" << argv[optind + 1] << std::endl; - cli = OS1::init_client(argv[optind], argv[optind + 1], mode); + std::string os1_host = argv[optind]; + std::string os1_udp_dest = argv[optind + 1]; + std::cout << "Configuring sensor: " << os1_host + << " UDP Destination:" << os1_udp_dest << std::endl; + cli = + OS1::init_client(os1_host, os1_udp_dest, mode, + OS1::TIME_FROM_INTERNAL_OSC, lidar_port, imu_port); } else { - std::cout << "Listening for sensor data" << std::endl; - cli = OS1::init_client(); + if (lidar_port == 0) lidar_port = 7502; + if (imu_port == 0) imu_port = 7503; + std::cout << "Listening for sensor data on udp ports " << lidar_port + << " and " << imu_port << std::endl; + cli = OS1::init_client(lidar_port, imu_port); } if (!cli) { diff --git a/ouster_viz/src/viz.cpp b/ouster_viz/src/viz.cpp index 89b745b1..cadf8400 100644 --- a/ouster_viz/src/viz.cpp +++ b/ouster_viz/src/viz.cpp @@ -39,6 +39,8 @@ #include #include "colormaps.h" +#include "ouster/autoexposure.h" +#include "ouster/beam_uniformity.h" #include "ouster/lidar_scan.h" #include "ouster/os1_util.h" #include "ouster/viz.h" @@ -70,12 +72,19 @@ const std::vector>> /** * Specify what quantity to color in the point cloud visualization **/ -enum ColorMode { COLOR_Z, COLOR_INTENSITY, COLOR_ZINTENSITY, COLOR_RANGE }; +enum ColorMode { + COLOR_Z, + COLOR_INTENSITY, + COLOR_ZINTENSITY, + COLOR_RINTENSITY, + COLOR_RANGE +}; const std::vector> color_modes = { {"Z", COLOR_Z}, {"INTENSITY", COLOR_INTENSITY}, {"Z+INTENSITY", COLOR_ZINTENSITY}, + {"INTENSITY_TIMES_RANGE", COLOR_RINTENSITY}, {"RANGE", COLOR_RANGE}}; /** @@ -90,13 +99,22 @@ struct VisualizerConfig { int palette; // image color palette bool image_noise; // display noise image - double intensity_scale; double range_scale; - double noise_scale; int fraction_3d; // percent of window displaying cloud }; +/** + * Mutable state for visualizer + */ +struct VisualizerState { + AutoExposure color_intensity; + AutoExposure color_zintensity; + AutoExposure color_rintensity; + AutoExposure color_noise; + BeamUniformityCorrector buc; +}; + struct LidarScanBuffer { std::mutex ls_mtx; bool ls_dirty = true; // false if the 'back' scan is new @@ -109,6 +127,7 @@ struct LidarScanBuffer { **/ struct VizHandle { VisualizerConfig config; + VisualizerState state; LidarScanBuffer lsb; int W; int H; @@ -127,16 +146,6 @@ void update(viz::VizHandle& vh, std::unique_ptr& ls) { ls_guard.unlock(); } -/** - * Applies filter for scaling the intensity scaling factor based on their - * intensity - **/ -void color_intensity(Eigen::Ref key_eigen, - const VisualizerConfig& config) { - key_eigen *= config.intensity_scale; - key_eigen = key_eigen.max(0.0).sqrt(); -} - /** * Applies filter for scaling the intensity scaling factor based on their range **/ @@ -151,13 +160,6 @@ void color_range(Eigen::Ref range, } } -void color_noise(Eigen::Ref key_eigen, - const VisualizerConfig& config) { - double noise_scale = config.image_noise ? config.noise_scale : 0.0; - key_eigen *= noise_scale * 0.002; - key_eigen = key_eigen.max(0.0).sqrt(); -} - /** * Generates a point cloud from a lidar scan, by multiplying each pixel in the * lidar scan by a vector pointing radially outward @@ -174,8 +176,8 @@ void lidar_scan_to_point_cloud(ouster::LidarScan& ls, Points& xyz) { /** * Update scalars used to color points **/ -void update_color_key(const VisualizerConfig& config, const Points& xyz, - Eigen::Ref intensity, +void update_color_key(const VisualizerConfig& config, VisualizerState& state, + const Points& xyz, Eigen::Ref intensity, Eigen::Ref range, std::vector& color_key) { const int n = xyz.rows(); @@ -191,12 +193,18 @@ void update_color_key(const VisualizerConfig& config, const Points& xyz, break; case COLOR_INTENSITY: key_eigen = Eigen::Map(intensity.data(), n); - color_intensity(key_eigen, config); + state.color_intensity(key_eigen); break; case COLOR_ZINTENSITY: key_eigen = Eigen::Map(intensity.data(), n); - color_intensity(key_eigen, config); key_eigen += ((1.5 + xyz.col(2)) * 0.05).abs().sqrt(); + state.color_zintensity(key_eigen); + break; + case COLOR_RINTENSITY: + key_eigen = + (Eigen::Map(range.data(), n) + 3.0) * + Eigen::Map(intensity.data(), n); + state.color_rintensity(key_eigen); break; case COLOR_RANGE: key_eigen = Eigen::Map(range.data(), n); @@ -213,7 +221,8 @@ void update_color_key(const VisualizerConfig& config, const Points& xyz, void update_images( ouster::LidarScan& ls, Eigen::Array& arr, - const std::vector& px_offset, const VisualizerConfig& config) { + const std::vector& px_offset, const VisualizerConfig& config, + VisualizerState& state) { using MapXXd = Eigen::Map; using MapXXdr = Eigen::Map< Eigen::Array>; @@ -235,10 +244,16 @@ void update_images( n.row(u).head(ofs); } + Eigen::ArrayXXd noise_image = dst.bottomRows(ls.H); + state.buc.correct(noise_image); + const int N = ls.W * ls.H; color_range(Eigen::Map{arr.data(), N}, config); - color_intensity(Eigen::Map{arr.data() + N, N}, config); - color_noise(Eigen::Map{arr.data() + 2 * N, N}, config); + state.color_intensity(Eigen::Map{arr.data() + N, N}); + if (config.image_noise) { + state.color_noise(Eigen::Map{noise_image.data(), N}); + dst.bottomRows(ls.H) = noise_image; + } }; class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera { @@ -342,7 +357,8 @@ vtkSmartPointer init_cloud_actor( } void fill_viewport(vtkSmartPointer renderer, - vtkSmartPointer image) { + vtkSmartPointer image, + const VisualizerConfig& config) { auto camera = renderer->GetActiveCamera(); double* origin = image->GetOrigin(); @@ -351,8 +367,13 @@ void fill_viewport(vtkSmartPointer renderer, double xc = origin[0] + 0.5 * (extent[0] + extent[1]) * spacing[0]; double yc = origin[1] + 0.5 * (extent[2] + extent[3]) * spacing[1]; - // double s = (extent[1] - extent[0] + 1) * spacing[0] * 0.5; double s = (extent[3] - extent[2] + 1) * spacing[1] * 0.5; + + // if the noise image is turned off, we only show the bottom two thirds + if (!config.image_noise) { + yc = origin[1] + 1.0 / 3 * (extent[2] + extent[3]) * spacing[1]; + s = (extent[3] - extent[2] + 1) * spacing[1] / 3.0; + } double d = camera->GetDistance(); camera->ParallelProjectionOn(); @@ -425,7 +446,7 @@ void run_viz(VizHandle& vh) { render_window->AddRenderer(renderer_2d); // fit image to viewport - fill_viewport(renderer_2d, image_change->GetOutput()); + fill_viewport(renderer_2d, image_change->GetOutput(), vh.config); // vtk callback that calls a std::function in client data auto fn_cb = [](vtkObject*, long unsigned int, void* clientData, void*) { @@ -436,7 +457,6 @@ void run_viz(VizHandle& vh) { // render callback std::function on_render = [&]() { - // check if we're exiting if (vh.exit) render_window_interactor->ExitCallback(); @@ -451,9 +471,11 @@ void run_viz(VizHandle& vh) { // update data backing visualization: pc_render, color_key, image_data lidar_scan_to_point_cloud(*vh.lsb.front, pc_render); - update_color_key(vh.config, pc_render, vh.lsb.front->intensity(), - vh.lsb.front->range(), color_key); - update_images(*vh.lsb.front, image_data, px_offset, vh.config); + update_color_key(vh.config, vh.state, pc_render, + vh.lsb.front->intensity(), vh.lsb.front->range(), + color_key); + update_images(*vh.lsb.front, image_data, px_offset, vh.config, + vh.state); points->Modified(); color->Modified(); @@ -481,6 +503,8 @@ void run_viz(VizHandle& vh) { renderer_2d->SetViewport(0, vh.config.fraction_3d / 100.0, 1, 1); renderer->SetViewport(0, 0, 1, vh.config.fraction_3d / 100.0); + fill_viewport(renderer_2d, image_change->GetOutput(), vh.config); + if (camera->GetParallelProjection() != vh.config.parallel) { camera->SetParallelProjection(vh.config.parallel); renderer->ResetCamera(); @@ -521,17 +545,15 @@ std::shared_ptr init_viz(int W, int H) { vh->W = W; vh->exit = false; - vh->config.palette = 1; + vh->config.palette = 5; vh->config.c_palette = 1; vh->config.point_size = 2; vh->config.color_mode = 2; vh->config.cycle_range = false; vh->config.parallel = false; - vh->config.image_noise = false; - vh->config.intensity_scale = 0.002; + vh->config.image_noise = true; vh->config.range_scale = 0.005; - vh->config.noise_scale = 1.0; vh->lsb.back = std::unique_ptr(new ouster::LidarScan(W, H)); @@ -541,5 +563,5 @@ std::shared_ptr init_viz(int W, int H) { return vh; } -} -} +} // namespace viz +} // namespace ouster From 8b6c2b5962a35a09231454662626ca44e6ac683c Mon Sep 17 00:00:00 2001 From: Alex Millane Date: Tue, 26 May 2020 13:05:00 +0200 Subject: [PATCH 09/11] Fixed a couple of things to get it compiling --- ouster_client/src/os1.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ouster_client/src/os1.cpp b/ouster_client/src/os1.cpp index a10efd8a..a4f93fb0 100644 --- a/ouster_client/src/os1.cpp +++ b/ouster_client/src/os1.cpp @@ -46,6 +46,12 @@ const std::array, 5> lidar_mode_strings = { {lidar_mode::MODE_1024x20, "1024x20"}, {lidar_mode::MODE_2048x10, "2048x10"}}}; +const std::array, 3> + timestamp_mode_strings = { + {{TIME_FROM_INTERNAL_OSC, "TIME_FROM_INTERNAL_OSC"}, + {TIME_FROM_SYNC_PULSE_IN, "TIME_FROM_SYNC_PULSE_IN"}, + {TIME_FROM_PTP_1588, "TIME_FROM_PTP_1588"}}}; + int32_t get_sock_port(int sock_fd) { struct sockaddr_storage ss; socklen_t addrlen = sizeof ss; @@ -337,7 +343,7 @@ std::shared_ptr init_client(int lidar_port, int imu_port) { std::shared_ptr init_client(const std::string& hostname, const std::string& udp_dest_host, lidar_mode mode, timestamp_mode ts_mode, - const uint16_t lidar_port, uint16_t imu_port) { + int lidar_port, int imu_port) { auto cli = init_client(lidar_port, imu_port); if (!cli) return std::shared_ptr(); From 594e300bb5672fb519ab191176a10ac70bd1a34a Mon Sep 17 00:00:00 2001 From: Alex Millane Date: Tue, 26 May 2020 13:07:59 +0200 Subject: [PATCH 10/11] Strongly typed timestamp mode enum --- ouster_client/include/ouster/os1.h | 4 ++-- ouster_client/src/os1.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ouster_client/include/ouster/os1.h b/ouster_client/include/ouster/os1.h index ca2b3df6..5b7cc098 100644 --- a/ouster_client/include/ouster/os1.h +++ b/ouster_client/include/ouster/os1.h @@ -35,7 +35,7 @@ enum class lidar_mode { MODE_INVALID }; -enum timestamp_mode { +enum class timestamp_mode { TIME_FROM_INTERNAL_OSC = 1, TIME_FROM_SYNC_PULSE_IN, TIME_FROM_PTP_1588 @@ -146,7 +146,7 @@ std::shared_ptr init_client(int lidar_port = 7502, int imu_port = 7503); std::shared_ptr init_client(const std::string& hostname, const std::string& udp_dest_host, lidar_mode mode = lidar_mode::MODE_1024x10, - timestamp_mode ts_mode = TIME_FROM_INTERNAL_OSC, + timestamp_mode ts_mode = timestamp_mode::TIME_FROM_INTERNAL_OSC, int lidar_port = 7502u, int imu_port = 7503u); /** diff --git a/ouster_client/src/os1.cpp b/ouster_client/src/os1.cpp index a4f93fb0..25604658 100644 --- a/ouster_client/src/os1.cpp +++ b/ouster_client/src/os1.cpp @@ -48,9 +48,9 @@ const std::array, 5> lidar_mode_strings = { const std::array, 3> timestamp_mode_strings = { - {{TIME_FROM_INTERNAL_OSC, "TIME_FROM_INTERNAL_OSC"}, - {TIME_FROM_SYNC_PULSE_IN, "TIME_FROM_SYNC_PULSE_IN"}, - {TIME_FROM_PTP_1588, "TIME_FROM_PTP_1588"}}}; + {{timestamp_mode::TIME_FROM_INTERNAL_OSC, "TIME_FROM_INTERNAL_OSC"}, + {timestamp_mode::TIME_FROM_SYNC_PULSE_IN, "TIME_FROM_SYNC_PULSE_IN"}, + {timestamp_mode::TIME_FROM_PTP_1588, "TIME_FROM_PTP_1588"}}}; int32_t get_sock_port(int sock_fd) { struct sockaddr_storage ss; From dbc9271fd5b549e02a03d04cdb055f1ce7aa06d2 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 29 May 2020 10:46:30 +0200 Subject: [PATCH 11/11] Fix some unclassed enum conversion hackery. --- ouster_client/include/ouster/os1.h | 3 ++- ouster_client/src/os1.cpp | 2 +- ouster_ros/src/os1_node.cpp | 4 ++-- ouster_viz/src/main.cpp | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ouster_client/include/ouster/os1.h b/ouster_client/include/ouster/os1.h index 5b7cc098..da5eba80 100644 --- a/ouster_client/include/ouster/os1.h +++ b/ouster_client/include/ouster/os1.h @@ -38,7 +38,8 @@ enum class lidar_mode { enum class timestamp_mode { TIME_FROM_INTERNAL_OSC = 1, TIME_FROM_SYNC_PULSE_IN, - TIME_FROM_PTP_1588 + TIME_FROM_PTP_1588, + MODE_INVALID }; struct version { diff --git a/ouster_client/src/os1.cpp b/ouster_client/src/os1.cpp index 25604658..e6fbaebc 100644 --- a/ouster_client/src/os1.cpp +++ b/ouster_client/src/os1.cpp @@ -275,7 +275,7 @@ timestamp_mode timestamp_mode_of_string(const std::string& s) { return p.second == s; }); - return res == end ? timestamp_mode(0) : res->first; + return res == end ? timestamp_mode::MODE_INVALID : res->first; } std::string get_metadata(const client& cli) { diff --git a/ouster_ros/src/os1_node.cpp b/ouster_ros/src/os1_node.cpp index 9550f331..c3be6d3b 100644 --- a/ouster_ros/src/os1_node.cpp +++ b/ouster_ros/src/os1_node.cpp @@ -199,10 +199,10 @@ int main(int argc, char** argv) { } if (not timestamp_mode.size()) { - timestamp_mode = OS1::to_string(OS1::TIME_FROM_INTERNAL_OSC); + timestamp_mode = OS1::to_string(OS1::timestamp_mode::TIME_FROM_INTERNAL_OSC); } - if (!OS1::timestamp_mode_of_string(timestamp_mode)) { + if (OS1::timestamp_mode_of_string(timestamp_mode) == OS1::timestamp_mode::MODE_INVALID) { ROS_ERROR("Invalid timestamp mode %s", timestamp_mode.c_str()); return EXIT_FAILURE; } diff --git a/ouster_viz/src/main.cpp b/ouster_viz/src/main.cpp index 24a1f6b3..d0ce0ab4 100644 --- a/ouster_viz/src/main.cpp +++ b/ouster_viz/src/main.cpp @@ -120,7 +120,7 @@ int main(int argc, char** argv) { << " UDP Destination:" << os1_udp_dest << std::endl; cli = OS1::init_client(os1_host, os1_udp_dest, mode, - OS1::TIME_FROM_INTERNAL_OSC, lidar_port, imu_port); + OS1::timestamp_mode::TIME_FROM_INTERNAL_OSC, lidar_port, imu_port); } else { if (lidar_port == 0) lidar_port = 7502; if (imu_port == 0) imu_port = 7503;