Skip to content
This repository was archived by the owner on Aug 28, 2022. It is now read-only.

Commit 848ed34

Browse files
committed
Added sensor model and firmware version validation. The driver currently only works for OS-1-64 and on firmware version 1.10 some configuration parameters disappeared.
Signed-off-by: alexandrx <[email protected]>
1 parent e05482c commit 848ed34

File tree

2 files changed

+63
-7
lines changed

2 files changed

+63
-7
lines changed

include/ouster/os1.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ typedef enum {
8181
using PulseMode = pulse_mode_t;
8282
/**
8383
* Define the pointcloud type to use
84-
* @param operation_mode defines
85-
* @param pulse_mode
86-
* @param window_rejection
87-
*
84+
* @param operation_mode defines the resolution and frame rate
85+
* @param pulse_mode is the width of the laser pulse (standard or narrow)
86+
* @param window_rejection to reject short range data (true), or to accept short range data (false)
8887
* @note This function was added to configure advanced operation modes for Autoware
8988
*/
9089
void set_advanced_params(std::string operation_mode_str, std::string pulse_mode_str, bool window_rejection);

src/os1.cpp

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <cstring>
55
#include <iostream>
66
#include <memory>
7+
#include <vector>
8+
#include <algorithm>
79

810
#include <arpa/inet.h>
911
#include <netdb.h>
@@ -119,7 +121,7 @@ std::shared_ptr<client> init_client(const std::string& hostname,
119121
std::string cmd;
120122

121123
auto do_cmd = [&](const std::string& op, const std::string& val) {
122-
const size_t max_res_len = 64;
124+
const size_t max_res_len = 4095;
123125
char read_buf[max_res_len + 1];
124126

125127
ssize_t len;
@@ -165,6 +167,20 @@ std::shared_ptr<client> init_client(const std::string& hostname,
165167
}
166168
return res;
167169
};
170+
171+
auto str_tok = [&](const std::string &str, const std::string delim) {
172+
auto start = str.find_first_not_of(delim);
173+
auto end = start;
174+
std::vector<std::string> tokens;
175+
176+
while (start != std::string::npos){
177+
end = str.find_first_of(delim, start);
178+
tokens.push_back(str.substr(start, end-start));
179+
start = str.find_first_not_of(delim, end);
180+
}
181+
182+
return tokens;
183+
};
168184

169185
bool success = true;
170186
success &= do_cmd_chk("set_udp_port_lidar", std::to_string(lidar_port));
@@ -176,9 +192,50 @@ std::shared_ptr<client> init_client(const std::string& hostname,
176192
/**
177193
* @note Added to support advanced mode parameters configuration
178194
*/
195+
//read the sensor information
196+
std::string version_str = std::string("");
197+
std::string product_str = std::string("");
198+
bool has_pulsemode = true;
199+
auto sensor_info_str = get_cmd("get_sensor_info", "");
200+
auto tokens = str_tok(sensor_info_str, std::string(",: \""));
201+
auto pos = std::find(tokens.begin(), tokens.end(), "build_rev");
202+
if (pos != tokens.end()) {
203+
version_str = *(pos+1);
204+
}
205+
pos = std::find(tokens.begin(), tokens.end(), "prod_line");
206+
if (pos != tokens.end()) {
207+
product_str = *(pos+1);
208+
}
209+
if (product_str == std::string("") || version_str == std::string("")) {
210+
std::cout << "Error: Failed to read product name and firmware version." << std::endl;
211+
return std::shared_ptr<client>();
212+
}
213+
std::cout << "Ouster model \"" << product_str << "\", firmware version \"" << version_str << "\"" << std::endl;
214+
//TODO: support OS-1-16 and OS-1-128
215+
if (product_str != std::string("OS-1-64")) {
216+
std::cout << "Error: this driver currently only supports Ouster model \"OS-1-64\"." << std::endl;
217+
return std::shared_ptr<client>();
218+
}
219+
220+
auto ver_numbers = str_tok(version_str, std::string("v."));
221+
//check the minor version
222+
auto ver_major = std::stoi(ver_numbers[0], nullptr);
223+
auto ver_minor = std::stoi(ver_numbers[1], nullptr);
224+
if (ver_major < 1 || ver_minor < 7) {
225+
std::cout << "Error: Firmware version \"" << version_str << "\" is not supported, please upgrade" << std::endl;
226+
return std::shared_ptr<client>();
227+
}
228+
if (std::stoi(ver_numbers[1], nullptr) >= 10) {
229+
std::cout << "On firmware version \"" << version_str << "\" the \"pulse_mode\" parameter is no longer available, will ignore it." << std::endl;
230+
has_pulsemode = false;
231+
}
232+
179233
//read the current settings
180234
auto curr_operation_mode_str = get_cmd("get_config_param", "active lidar_mode");
181-
auto curr_pulse_mode_str = get_cmd("get_config_param", "active pulse_mode");
235+
auto curr_pulse_mode_str = std::string("");
236+
if (has_pulsemode) {
237+
curr_pulse_mode_str = get_cmd("get_config_param", "active pulse_mode");
238+
}
182239
auto curr_window_rejection_str = get_cmd("get_config_param", "active window_rejection_enable");
183240
bool do_configure = false;
184241
success = true;
@@ -188,7 +245,7 @@ std::shared_ptr<client> init_client(const std::string& hostname,
188245
success &= do_cmd_chk("set_config_param", "lidar_mode " + _operation_mode_str);
189246
do_configure = true;
190247
}
191-
if (curr_pulse_mode_str != _pulse_mode_str) {
248+
if (has_pulsemode && (curr_pulse_mode_str != _pulse_mode_str)) {
192249
success &= do_cmd_chk("set_config_param", "pulse_mode " + _pulse_mode_str);
193250
do_configure = true;
194251
}

0 commit comments

Comments
 (0)