l500-thermal-loop.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2020 Intel Corporation. All Rights Reserved.
3 
4 #include "l500-thermal-loop.h"
5 #include "../../l500/l500-private.h"
6 
7 namespace librealsense {
8 namespace algo {
9 namespace thermal_loop {
10 namespace l500 {
11 
12 
13 const int thermal_calibration_table::id = 0x317;
14 
16 {
17  _header.max_temp = 0;
18  _header.min_temp = 0;
20  _header.valid = 0;
21 }
22 
24  int resolution )
25  : _resolution( resolution )
26 {
27  auto expected_size = sizeof( thermal_table_header )
28  + sizeof( thermal_bin ) * resolution;
29 
30  _header.valid = 0;
31 
32  if( data.size() != expected_size )
33  throw std::runtime_error( librealsense::to_string()
34  << "data size (" << data.size()
35  << ") does not meet expected size " << expected_size );
36 
37  _header = *(thermal_table_header *)data.data();
38 
39  // The table may be invalid if the unit has not gone thru calibration
40  if( ! _header.valid )
41  throw std::runtime_error( "thermal calibration table is not valid" );
42 
43  auto data_ptr = (thermal_bin *)( data.data() + sizeof( thermal_table_header ));
44  bins.assign( data_ptr, data_ptr + resolution );
45 }
46 
47 
49 {
50  if( lhs.bins.size() != rhs.bins.size() )
51  return false;
52 
53  if( lhs._header.max_temp != rhs._header.max_temp || lhs._header.min_temp != rhs._header.min_temp
55  || lhs._header.valid != rhs._header.valid )
56  return false;
57 
58  for( auto i = 0; i < rhs.bins.size(); i++ )
59  {
60  if( lhs.bins[i].scale != rhs.bins[i].scale || lhs.bins[i].sheer != rhs.bins[i].sheer
61  || lhs.bins[i].tx != rhs.bins[i].tx || lhs.bins[i].ty != rhs.bins[i].ty )
62  return false;
63  }
64  return true;
65 }
66 
67 
68 double thermal_calibration_table::get_thermal_scale( double hum_temp ) const
69 {
70  auto scale = bins[_resolution - 1].scale;
71 
72  auto temp_range = _header.max_temp - _header.min_temp;
73  // there are 29 bins between min and max temps so 30 equal intervals
74  auto const interval = temp_range / ( _resolution + 1 );
75  // T: |---|---|---| ... |---|
76  // min 0 1 2 ... 28 max
77  size_t index = 0;
78  for( double temp = _header.min_temp; index < _resolution;
79  ++index, temp += interval )
80  {
81  auto interval_max = temp + interval;
82  if( hum_temp <= interval_max )
83  {
84  scale = bins[index].scale;
85  break;
86  }
87  }
88 
89  // The "scale" is meant to be divided by, but we want something to multiply with!
90  if( scale == 0 )
91  throw std::runtime_error( "invalid 0 scale in thermal table" );
92  return 1. / scale;
93 }
94 
95 
96 std::vector< byte > thermal_calibration_table::build_raw_data() const
97 {
98  std::vector< float > data;
99 
100  data.push_back( _header.min_temp );
101  data.push_back( _header.max_temp );
102  data.push_back( _header.reference_temp );
103  data.push_back( _header.valid );
104 
105  for( auto i = 0; i < bins.size(); i++ )
106  {
107  data.push_back( bins[i].scale );
108  data.push_back( bins[i].sheer );
109  data.push_back( bins[i].tx );
110  data.push_back( bins[i].ty );
111  }
112 
113  std::vector< byte > res;
114  res.assign( (byte *)( data.data() ), (byte *)( data.data() + data.size() ) );
115  return res;
116 }
117 
118 
119 }
120 }
121 }
122 }
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:10806
bool operator==(const thermal_calibration_table &lhs, const thermal_calibration_table &rhs)
GLuint index
GLbyte ty
Definition: glext.h:6694
unsigned char byte
Definition: src/types.h:52
int i
GLuint res
Definition: glext.h:8856
GLboolean * data
YYCODETYPE lhs
Definition: sqlite3.c:132469
Definition: parser.hpp:150


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:21