d400-thermal-monitor.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2021 Intel Corporation. All Rights Reserved.
3 
4 #include <iostream>
5 #include <chrono>
6 #include "d400-color.h"
7 #include "d400-private.h"
8 #include "d400-thermal-monitor.h"
9 
10 namespace librealsense
11 {
12  d400_thermal_monitor::d400_thermal_monitor(std::shared_ptr<option> temp_option,
13  std::shared_ptr<option> tl_toggle) :
14  _monitor([this](dispatcher::cancellable_timer cancellable_timer)
15  {
16  polling(cancellable_timer);
17  }),
18  _poll_intervals_ms(2000), // Temperature check routine to be invoked every 2 sec
19  _thermal_threshold_deg(2.f),
20  _temp_base(0.f),
21  _hw_loop_on(false),
22  _temperature_sensor(temp_option),
23  _tl_activation(tl_toggle)
24  {
25  }
26 
28  {
29  _monitor.stop();
30  _temp_base = 0.f;
31  _hw_loop_on = false;
32  }
33 
35  {
36  if (on != _monitor.is_active())
37  {
38  if (!on)
39  {
40  _monitor.stop();
41  _hw_loop_on = false;
42  notify(0);
43  }
44  else
45  {
46  _monitor.start();
47  }
48  }
49  }
50 
52  {
53  if (cancellable_timer.try_sleep( std::chrono::milliseconds( _poll_intervals_ms )))
54  {
55  try
56  {
57  // Verify TL is active on FW level
58  if (auto tl_active = _tl_activation.lock())
59  {
60  bool tl_state = (std::fabs(tl_active->query()) > std::numeric_limits< float >::epsilon());
61  if (tl_state != _hw_loop_on)
62  {
63  _hw_loop_on = tl_state;
64  if (!_hw_loop_on)
65  notify(0);
66 
67  }
68 
69  if (!tl_state)
70  return;
71  }
72 
73  // Track temperature and update on temperature changes
74  auto ts = (uint64_t)std::chrono::high_resolution_clock::now().time_since_epoch().count();
75  if( auto temp = _temperature_sensor.lock() )
76  {
77  if( temp->is_enabled() )
78  {
79  auto cur_temp = temp->query();
80  if( fabs( _temp_base - cur_temp ) >= _thermal_threshold_deg )
81  {
82  LOG_DEBUG_THERMAL_LOOP( "Thermal calibration adjustment is triggered on change from "
83  << std::dec << std::setprecision( 1 ) << _temp_base << " to "
84  << cur_temp << " deg (C)" );
85 
86  notify( cur_temp );
87  }
88  }
89  }
90  else
91  {
92  LOG_ERROR("Thermal Compensation: temperature sensor option is not present");
93  }
94  }
95  catch (const std::exception& ex)
96  {
97  LOG_ERROR("Error during thermal compensation handling: " << ex.what());
98  }
99  catch (...)
100  {
101  LOG_ERROR("Unresolved error during Thermal Compensation handling");
102  }
103  }
104  else
105  {
106  LOG_DEBUG_THERMAL_LOOP("Thermal Compensation is being shut-down");
107  }
108  }
109 
110  void d400_thermal_monitor::notify(float temperature)
111  {
112  _temp_base = temperature;
113  for (auto&& cb : _thermal_changes_callbacks)
114  cb(temperature);
115  }
116 }
dispatcher::cancellable_timer::try_sleep
bool try_sleep(Duration sleep_time)
Definition: concurrency.h:296
librealsense
Definition: algo.h:18
d400-private.h
dispatcher::cancellable_timer
Definition: concurrency.h:279
librealsense::d400_thermal_monitor::_tl_activation
std::weak_ptr< option > _tl_activation
Definition: d400-thermal-monitor.h:40
active_object::start
void start()
Definition: concurrency.h:414
dispatcher
Definition: concurrency.h:272
librealsense::d400_thermal_monitor::d400_thermal_monitor
d400_thermal_monitor(std::shared_ptr< option > temp_option, std::shared_ptr< option > tl_toggle)
Definition: d400-thermal-monitor.cpp:12
librealsense::d400_thermal_monitor::polling
void polling(dispatcher::cancellable_timer cancellable_timer)
Definition: d400-thermal-monitor.cpp:51
d400-color.h
librealsense::d400_thermal_monitor::notify
void notify(float temperature)
Definition: d400-thermal-monitor.cpp:110
uint64_t
unsigned __int64 uint64_t
Definition: stdint.h:90
f
GLdouble f
Definition: glad/glad/glad.h:1517
librealsense::d400_thermal_monitor::_hw_loop_on
bool _hw_loop_on
Definition: d400-thermal-monitor.h:38
LOG_DEBUG_THERMAL_LOOP
#define LOG_DEBUG_THERMAL_LOOP(...)
Definition: ds-private.h:20
librealsense::d400_thermal_monitor::_thermal_threshold_deg
float _thermal_threshold_deg
Definition: d400-thermal-monitor.h:36
d400-thermal-monitor.h
opencv_pointcloud_viewer.now
now
Definition: opencv_pointcloud_viewer.py:314
librealsense::d400_thermal_monitor::_temperature_sensor
std::weak_ptr< option > _temperature_sensor
Definition: d400-thermal-monitor.h:39
active_object::is_active
bool is_active() const
Definition: concurrency.h:435
librealsense::d400_thermal_monitor::_poll_intervals_ms
unsigned int _poll_intervals_ms
Definition: d400-thermal-monitor.h:35
librealsense::d400_thermal_monitor::_monitor
active_object _monitor
Definition: d400-thermal-monitor.h:34
active_object::stop
void stop()
Definition: concurrency.h:422
librealsense::d400_thermal_monitor::_thermal_changes_callbacks
std::vector< std::function< void(float)> > _thermal_changes_callbacks
Definition: d400-thermal-monitor.h:41
test-color_frame_frops.cb
def cb(frame, ts)
Definition: test-color_frame_frops.py:29
librealsense::d400_thermal_monitor::~d400_thermal_monitor
~d400_thermal_monitor()
Definition: d400-thermal-monitor.cpp:27
librealsense::d400_thermal_monitor::update
void update(bool on)
Definition: d400-thermal-monitor.cpp:34
LOG_ERROR
#define LOG_ERROR(...)
Definition: easyloggingpp.h:73
librealsense::d400_thermal_monitor::_temp_base
float _temp_base
Definition: d400-thermal-monitor.h:37


librealsense2
Author(s): LibRealSense ROS Team
autogenerated on Fri Aug 2 2024 08:30:02