Skip to content

Commit 632d1b2

Browse files
authored
PR realsenseai#14316 from AviaAv: sensor start after open, other simplifications
2 parents 5d68d16 + d107870 commit 632d1b2

2 files changed

Lines changed: 20 additions & 21 deletions

File tree

tools/data-collect/rs-data-collect.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ void data_collector::save_data_to_file(const string& out_filename)
141141
}
142142
}
143143

144-
void data_collector::collect_frame_attributes(rs2::frame f, std::chrono::time_point<std::chrono::high_resolution_clock> start_time)
144+
void data_collector::collect_frame_attributes(rs2::frame f)
145145
{
146-
auto arrival_time = std::chrono::duration<double, std::milli>(chrono::high_resolution_clock::now() - start_time);
146+
auto arrival_time = std::chrono::duration<double, std::milli>(chrono::high_resolution_clock::now() - _start_time);
147147
auto stream_uid = std::make_pair(f.get_profile().stream_type(), f.get_profile().stream_index());
148148

149149
if (data_collection[stream_uid].size() < _max_frames)
@@ -173,13 +173,13 @@ void data_collector::collect_frame_attributes(rs2::frame f, std::chrono::time_po
173173
}
174174
}
175175

176-
bool data_collector::collecting(std::chrono::time_point<std::chrono::high_resolution_clock> start_time)
176+
bool data_collector::collecting()
177177
{
178178
bool timed_out = false;
179179

180180
if (_time_out_sec > 0)
181181
{
182-
timed_out = (chrono::high_resolution_clock::now() - start_time) > std::chrono::seconds(_time_out_sec);
182+
timed_out = (chrono::high_resolution_clock::now() - _start_time) > std::chrono::seconds(_time_out_sec);
183183
// When the timeout is the only option is specified, disregard frame number
184184
if (stop_on_timeout == _stop_cond)
185185
return !timed_out;
@@ -234,6 +234,7 @@ bool data_collector::parse_configuration(const std::string& line, const std::vec
234234
// Assign the user configuration to the selected device
235235
bool data_collector::configure_sensors()
236236
{
237+
_start_time = chrono::high_resolution_clock::now();
237238
bool succeed = false;
238239
requests_to_go = user_requests;
239240
std::vector<rs2::stream_profile> matches;
@@ -278,6 +279,7 @@ bool data_collector::configure_sensors()
278279
{
279280
std::copy(matches.begin(), matches.end(), std::back_inserter(selected_stream_profiles));
280281
sensor.open(matches);
282+
sensor.start([this](rs2::frame f) { collect_frame_attributes(f); }); // start right after open sensor, required on DDS to avoid reverting to default
281283
active_sensors.emplace_back(sensor);
282284
matches.clear();
283285
}
@@ -361,28 +363,18 @@ int main(int argc, char** argv) try
361363

362364
dc.parse_and_configure(config_file);
363365

364-
//data_collection buffer;
365-
auto start_time = chrono::high_resolution_clock::now();
366-
367-
// Start streaming
368-
for (auto&& sensor : dc.selected_sensors())
369-
sensor.start([&dc,&start_time](rs2::frame f)
370-
{
371-
dc.collect_frame_attributes(f,start_time);
372-
});
373-
374366
std::cout << "\nData collection started.... \n" << std::endl;
375367

376-
while (dc.collecting(start_time))
368+
while (dc.collecting())
377369
{
378370
std::this_thread::sleep_for(std::chrono::seconds(1));
379371
std::cout << "Collecting data for "
380-
<< chrono::duration_cast<chrono::seconds>(chrono::high_resolution_clock::now() - start_time).count()
372+
<< dc.time_passed()
381373
<< " sec" << std::endl;
382374
}
383375

384376
// Stop & flush all active sensors
385-
for (auto&& sensor : dc.selected_sensors())
377+
for (auto&& sensor : dc.active_sensors)
386378
{
387379
sensor.stop();
388380
sensor.close();

tools/data-collect/rs-data-collect.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,17 @@ namespace rs_data_collect
183183

184184
void parse_and_configure(rs2::cli::value<string>& config_file);
185185
void save_data_to_file(const string& out_filename);
186-
void collect_frame_attributes(rs2::frame f, std::chrono::time_point<std::chrono::high_resolution_clock> start_time);
187-
bool collecting(std::chrono::time_point<std::chrono::high_resolution_clock> start_time);
186+
void collect_frame_attributes(rs2::frame f);
187+
bool collecting();
188+
auto time_passed() const
189+
{
190+
return std::chrono::duration_cast< std::chrono::seconds >(
191+
std::chrono::high_resolution_clock::now() - _start_time )
192+
.count();
193+
}
194+
188195

189-
const std::vector<rs2::sensor>& selected_sensors() const { return active_sensors; };
196+
std::vector<rs2::sensor> active_sensors;
190197

191198
struct frame_record
192199
{
@@ -238,11 +245,11 @@ namespace rs_data_collect
238245
std::shared_ptr<rs2::device> _dev;
239246
std::map<std::pair<rs2_stream, int>, std::vector<frame_record>> data_collection;
240247
std::vector<stream_request> requests_to_go, user_requests;
241-
std::vector<rs2::sensor> active_sensors;
242248
std::vector<rs2::stream_profile> selected_stream_profiles;
243249
uint64_t _max_frames;
244250
int64_t _time_out_sec;
245251
application_stop _stop_cond;
252+
std::chrono::high_resolution_clock::time_point _start_time;
246253

247254
bool parse_configuration(const std::string& line, const std::vector<std::string>& tokens,
248255
rs2_stream& type, int& width, int& height, rs2_format& format, int& fps, int& index);

0 commit comments

Comments
 (0)