Skip to content

Commit

Permalink
PR #7551 from Eran: Pick K_th fixes from 52 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel authored Oct 13, 2020
2 parents 2ef61da + 0737b79 commit 296d104
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 27 deletions.
15 changes: 8 additions & 7 deletions src/algo/thermal-loop/l500-thermal-loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ thermal_calibration_table::thermal_calibration_table( const std::vector< byte >
int resolution )
: _resolution( resolution )
{
float const * header_ptr = (float *)( data.data() + sizeof( ivcam2::table_header ) );

auto expected_size = sizeof( ivcam2::table_header ) + sizeof( thermal_table_header )
auto expected_size = sizeof( thermal_table_header )
+ sizeof( thermal_bin ) * resolution;

if( data.size() != expected_size )
throw std::runtime_error( librealsense::to_string()
<< "data size (" << data.size()
<< ") does not meet expected size " << expected_size );

_header = *(thermal_table_header *)( header_ptr );
_header = *(thermal_table_header *)data.data();

// The table may be invalid if the unit has not gone thru calibration
if( ! _header.valid )
throw std::runtime_error( "thermal calibration table is not valid" );

auto data_ptr = (thermal_bin *)( data.data() + sizeof( ivcam2::table_header )
+ sizeof( thermal_table_header ) );
auto data_ptr = (thermal_bin *)( data.data() + sizeof( thermal_table_header ));
bins.assign( data_ptr, data_ptr + resolution );
}

Expand Down Expand Up @@ -86,7 +87,7 @@ double thermal_calibration_table::get_thermal_scale( double hum_temp ) const
std::vector< byte > thermal_calibration_table::build_raw_data() const
{
std::vector< float > data;
data.resize( sizeof( ivcam2::table_header ) / sizeof( float ), 0 );

data.push_back( _header.min_temp );
data.push_back( _header.max_temp );
data.push_back( _header.reference_temp );
Expand Down
6 changes: 4 additions & 2 deletions src/algo/thermal-loop/l500-thermal-loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class thermal_calibration_table : public thermal_calibration_table_interface
{
float min_temp;
float max_temp;
float reference_temp; // not used
float valid; // not used
float reference_temp; // Reference calibration temperature (humidity sensor)
float valid; // Valid table (Created in ATC && Updated in ACC)
};

// Each bin data, as it's written in the actual raw table
Expand All @@ -63,6 +63,8 @@ class thermal_calibration_table : public thermal_calibration_table_interface
double get_thermal_scale( double hum_temp ) const override;

std::vector< byte > build_raw_data() const override;

bool is_valid() const override { return ( bool ) _header.valid; }
};
#pragma pack( pop )

Expand Down
2 changes: 2 additions & 0 deletions src/algo/thermal-loop/thermal-calibration-table-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ struct thermal_calibration_table_interface
{
virtual ~thermal_calibration_table_interface() {}

virtual bool is_valid() const = 0;

virtual double get_thermal_scale( double hum_temp ) const = 0;

virtual std::vector< byte > build_raw_data() const = 0;
Expand Down
25 changes: 16 additions & 9 deletions src/depth-to-rgb-calibration.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//// License: Apache 2.0. See LICENSE file in root directory.
//// Copyright(c) 2020 Intel Corporation. All Rights Reserved.
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2020 Intel Corporation. All Rights Reserved.

#include "depth-to-rgb-calibration.h"
#include <librealsense2/rs.hpp>
Expand Down Expand Up @@ -27,7 +27,7 @@ depth_to_rgb_calibration::depth_to_rgb_calibration(
std::vector< impl::yuy_t > const & last_yuy_data,
impl::algo_calibration_info const & cal_info,
impl::algo_calibration_registers const & cal_regs,
rs2_intrinsics yuy_intrinsics,
rs2_intrinsics const & yuy_intrinsics,
thermal::thermal_calibration_table_interface const & thermal_table,
std::function<void()> should_continue
)
Expand All @@ -49,10 +49,13 @@ depth_to_rgb_calibration::depth_to_rgb_calibration(
else if( ! last_yuy_data.empty() )
AC_LOG( DEBUG, "Not using last successfully-calibrated scene: it's of a different resolution" );

auto scale = thermal_table.get_thermal_scale( settings.hum_temp );
AC_LOG( DEBUG, " scaling K_rgb by " << scale );
_thermal_intr.fx = float( _thermal_intr.fx * scale );
_thermal_intr.fy = float( _thermal_intr.fy * scale );
if( thermal_table.is_valid() )
{
auto scale = thermal_table.get_thermal_scale( settings.hum_temp );
AC_LOG( DEBUG, " scaling K_rgb by {scale}" << scale << " [TH]" );
_thermal_intr.fx = float( _thermal_intr.fx * scale );
_thermal_intr.fy = float( _thermal_intr.fy * scale );
}

impl::calib calibration( _thermal_intr, _extr );

Expand Down Expand Up @@ -107,9 +110,13 @@ void depth_to_rgb_calibration::write_data_to( std::string const & dir )
{
_algo.write_data_to( dir );

// VAL asked that we write this file even with no thermal table, so they can just make up
// something fictitious...
impl::write_to_file( &_raw_intr, sizeof( _raw_intr ), dir, "raw_rgb.intrinsics" );

impl::write_vector_to_file( _thermal_table.build_raw_data(), dir, "rgb_thermal_table" );
if( _thermal_table.is_valid() )
{
impl::write_vector_to_file( _thermal_table.build_raw_data(), dir, "rgb_thermal_table" );
}
}


Expand Down
2 changes: 1 addition & 1 deletion src/depth-to-rgb-calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace librealsense
std::vector< algo::depth_to_rgb_calibration::yuy_t > const & last_yuy_data,
algo::depth_to_rgb_calibration::algo_calibration_info const & cal_info,
algo::depth_to_rgb_calibration::algo_calibration_registers const & cal_regs,
rs2_intrinsics yuy_intrinsics,
rs2_intrinsics const & yuy_intrinsics,
algo::thermal_loop::thermal_calibration_table_interface const &,
std::function<void()> should_continue = nullptr
);
Expand Down
12 changes: 7 additions & 5 deletions src/l500/ac-trigger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,15 +975,16 @@ namespace ivcam2 {

ivcam2::read_fw_table( *hwm, cal_info.table_id, &cal_info );

// If the above throw (and they can!) then we catch below and stop...

try
{
thermal_table = _dev.get_color_sensor()->get_thermal_table();
}
catch( ... )
catch( std::exception const & e )
{
AC_LOG( WARNING, "Could not read thermal_table" );
AC_LOG( WARNING, std::string( to_string() << "Disabling thermal correction: " << e.what() << " [NO-THERMAL]" ));
}
// If the above throw (and they can!) then we catch below and stop...
}

AC_LOG( DEBUG,
Expand Down Expand Up @@ -1270,12 +1271,13 @@ namespace ivcam2 {
{
_dev.get_color_sensor()->get_thermal_table();
}
catch (...)
catch( std::exception const & e )
{
AC_LOG( DEBUG, std::string( to_string() << "Disabling thermal correction: " << e.what() << " [NO-THERMAL]" ));
thermal_table_valid = false;
}

if (!thermal_table_valid)
if( ! thermal_table_valid )
{
if( _temp < 32. )
{
Expand Down
3 changes: 3 additions & 0 deletions src/l500/l500-color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ namespace librealsense
register_stream_to_extrinsic_group(*_color_stream, 0);

_thermal_table = [this]() {

hwmon_response response;
auto data = read_fw_table_raw( *_hw_monitor,
algo::thermal_loop::l500::thermal_calibration_table::id,
Expand All @@ -211,6 +212,8 @@ namespace librealsense
<< algo::thermal_loop::l500::thermal_calibration_table::id );
}

if( data.size() > sizeof( table_header ))
data.erase( data.begin(), data.begin() + sizeof( table_header ) );
return algo::thermal_loop::l500::thermal_calibration_table{ data };
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ create_synthetic_table( const int table_size = 29, float min_temp = 0, float max
thermal::thermal_calibration_table res;
res._header.min_temp = min_temp;
res._header.max_temp = max_temp;
res._header.reference_temp = 100; // not used
res._header.valid = 1; // not used
res._header.reference_temp = 35.f;
res._header.valid = 1.f;
res._resolution = table_size;
res.bins.resize( table_size );

Expand Down
10 changes: 9 additions & 1 deletion unit-tests/algo/thermal-loop/test-table-parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ TEST_CASE("parse_thermal_table", "[thermal-loop]")
REQUIRE( original_table == table_from_raw );
}

TEST_CASE( "invalid thermal table", "[thermal-loop]" )
{
auto table = create_synthetic_table();
table._header.valid = 0.f;

auto raw_data = table.build_raw_data();
REQUIRE_THROWS( thermal_calibration_table( raw_data ));
}

TEST_CASE( "data_size_too_small", "[thermal-loop]" )
{
auto syntetic_table = create_synthetic_table();
Expand All @@ -40,7 +49,6 @@ TEST_CASE( "build_raw_data", "[thermal-loop]" )
auto raw_data = syntetic_table.build_raw_data();

std::vector< byte > raw;
raw.resize( sizeof( thermal_calibration_table::thermal_table_header ), 0 );

raw.insert( raw.end(),
(byte *)&( syntetic_table._header.min_temp ),
Expand Down

0 comments on commit 296d104

Please sign in to comment.