genesys: Regenerate motor table total duration when it is updated

merge-requests/455/head
Povilas Kanapickas 2020-05-18 03:53:08 +03:00
rodzic 9c4f84f91a
commit 253bd0ffe4
4 zmienionych plików z 34 dodań i 21 usunięć

Wyświetl plik

@ -753,11 +753,11 @@ static void gl841_init_motor_regs_scan(Genesys_Device* dev, const Genesys_Sensor
fast_exposure / 4 *
(feed_steps - fast_table.table.size()*2 -
(slow_table.table.size() >> static_cast<unsigned>(motor_profile.step_type)))
+ fast_table.pixeltime_sum*2 + slow_table.pixeltime_sum;
+ fast_table.pixeltime_sum() * 2 + slow_table.pixeltime_sum();
slow_time =
(scan_exposure_time * scan_yres) / dev->motor.base_ydpi *
(feed_steps - (slow_table.table.size() >> static_cast<unsigned>(motor_profile.step_type)))
+ slow_table.pixeltime_sum;
+ slow_table.pixeltime_sum();
use_fast_fed = fast_time < slow_time;
}

Wyświetl plik

@ -46,6 +46,7 @@
#include "motor.h"
#include "utilities.h"
#include <cmath>
#include <numeric>
namespace genesys {
@ -86,6 +87,7 @@ void MotorSlopeTable::slice_steps(unsigned count)
throw SaneException("Excessive steps count");
}
table.resize(count);
generate_pixeltime_sum();
}
void MotorSlopeTable::expand_table(unsigned count)
@ -94,6 +96,13 @@ void MotorSlopeTable::expand_table(unsigned count)
throw SaneException("Can't expand empty table");
}
table.resize(table.size() + count, table.back());
generate_pixeltime_sum();
}
void MotorSlopeTable::generate_pixeltime_sum()
{
pixeltime_sum_ = std::accumulate(table.begin(), table.end(),
std::size_t{0}, std::plus<std::size_t>());
}
unsigned get_slope_table_max_size(AsicType asic_type)
@ -139,22 +148,21 @@ MotorSlopeTable create_slope_table_for_speed(const MotorSlope& slope, unsigned t
break;
}
table.table.push_back(current);
table.pixeltime_sum += current;
}
// make sure the target speed (or the max speed if target speed is too high) is present in
// the table
table.table.push_back(final_speed);
table.pixeltime_sum += table.table.back();
// fill the table up to the specified size
while (table.table.size() < max_size - 1 &&
(table.table.size() % steps_alignment != 0 || table.table.size() < min_size))
{
table.table.push_back(table.table.back());
table.pixeltime_sum += table.table.back();
}
table.generate_pixeltime_sum();
return table;
}

Wyświetl plik

@ -126,12 +126,17 @@ struct MotorSlope
struct MotorSlopeTable
{
std::vector<std::uint16_t> table;
unsigned pixeltime_sum = 0;
void slice_steps(unsigned count);
// expands the table by the given number of steps
void expand_table(unsigned count);
std::uint64_t pixeltime_sum() const { return pixeltime_sum_; }
void generate_pixeltime_sum();
private:
std::uint64_t pixeltime_sum_ = 0;
};
unsigned get_slope_table_max_size(AsicType asic_type);

Wyświetl plik

@ -46,7 +46,7 @@ void test_create_slope_table3()
auto table = sanei_genesys_create_slope_table3(asic_type, motor, StepType::FULL, 10000,
motor.base_ydpi);
ASSERT_EQ(table.pixeltime_sum, 10000u);
ASSERT_EQ(table.pixeltime_sum(), 10000u);
ASSERT_EQ(table.table.size(), 1u);
std::vector<std::uint16_t> expected_steps = {
@ -57,7 +57,7 @@ void test_create_slope_table3()
table = sanei_genesys_create_slope_table3(asic_type, motor, StepType::FULL, 2000,
motor.base_ydpi);
ASSERT_EQ(table.pixeltime_sum, 33830u);
ASSERT_EQ(table.pixeltime_sum(), 33830u);
ASSERT_EQ(table.table.size(), 7u);
expected_steps = {
@ -68,7 +68,7 @@ void test_create_slope_table3()
table = sanei_genesys_create_slope_table3(asic_type, motor, StepType::HALF, 10000,
motor.base_ydpi);
ASSERT_EQ(table.pixeltime_sum, 5000u);
ASSERT_EQ(table.pixeltime_sum(), 5000u);
ASSERT_EQ(table.table.size(), 1u);
expected_steps = {
@ -79,7 +79,7 @@ void test_create_slope_table3()
table = sanei_genesys_create_slope_table3(asic_type, motor, StepType::HALF, 2000,
motor.base_ydpi);
ASSERT_EQ(table.pixeltime_sum, 16914u);
ASSERT_EQ(table.pixeltime_sum(), 16914u);
ASSERT_EQ(table.table.size(), 7u);
expected_steps = {
@ -90,7 +90,7 @@ void test_create_slope_table3()
table = sanei_genesys_create_slope_table3(asic_type, motor, StepType::QUARTER, 10000,
motor.base_ydpi);
ASSERT_EQ(table.pixeltime_sum, 2500u);
ASSERT_EQ(table.pixeltime_sum(), 2500u);
ASSERT_EQ(table.table.size(), 1u);
expected_steps = {
@ -101,7 +101,7 @@ void test_create_slope_table3()
table = sanei_genesys_create_slope_table3(asic_type, motor, StepType::QUARTER, 2000,
motor.base_ydpi);
ASSERT_EQ(table.pixeltime_sum, 7680u);
ASSERT_EQ(table.pixeltime_sum(), 7680u);
ASSERT_EQ(table.table.size(), 6u);
expected_steps = {
@ -127,7 +127,7 @@ void test_create_slope_table_small_full_step()
};
ASSERT_EQ(table.table, expected_table);
ASSERT_EQ(table.table.size(), 8u);
ASSERT_EQ(table.pixeltime_sum, 156348u);
ASSERT_EQ(table.pixeltime_sum(), 156348u);
table = create_slope_table_for_speed(slope, 3000, StepType::FULL, 4, 8, max_table_size);
@ -137,7 +137,7 @@ void test_create_slope_table_small_full_step()
};
ASSERT_EQ(table.table, expected_table);
ASSERT_EQ(table.table.size(), 8u);
ASSERT_EQ(table.pixeltime_sum, 148843u);
ASSERT_EQ(table.pixeltime_sum(), 148843u);
}
void test_create_slope_table_small_full_step_target_speed_too_high()
@ -157,7 +157,7 @@ void test_create_slope_table_small_full_step_target_speed_too_high()
};
ASSERT_EQ(table.table, expected_table);
ASSERT_EQ(table.table.size(), 8u);
ASSERT_EQ(table.pixeltime_sum, 148358u);
ASSERT_EQ(table.pixeltime_sum(), 148358u);
}
void test_create_slope_table_small_half_step()
@ -177,7 +177,7 @@ void test_create_slope_table_small_half_step()
};
ASSERT_EQ(table.table, expected_table);
ASSERT_EQ(table.table.size(), 8u);
ASSERT_EQ(table.pixeltime_sum, 78174u);
ASSERT_EQ(table.pixeltime_sum(), 78174u);
table = create_slope_table_for_speed(slope, 3000, StepType::HALF, 4, 8, max_table_size);
@ -187,7 +187,7 @@ void test_create_slope_table_small_half_step()
};
ASSERT_EQ(table.table, expected_table);
ASSERT_EQ(table.table.size(), 8u);
ASSERT_EQ(table.pixeltime_sum, 74421u);
ASSERT_EQ(table.pixeltime_sum(), 74421u);
}
void test_create_slope_table_large_full_step()
@ -235,7 +235,7 @@ void test_create_slope_table_large_full_step()
};
ASSERT_EQ(table.table, expected_table);
ASSERT_EQ(table.table.size(), 60u);
ASSERT_EQ(table.pixeltime_sum, 412616u);
ASSERT_EQ(table.pixeltime_sum(), 412616u);
table = create_slope_table_for_speed(slope, 1500, StepType::FULL, 4, 8, max_table_size);
@ -267,7 +267,7 @@ void test_create_slope_table_large_full_step()
};
ASSERT_EQ(table.table, expected_table);
ASSERT_EQ(table.table.size(), 224u);
ASSERT_EQ(table.pixeltime_sum, 734910u);
ASSERT_EQ(table.pixeltime_sum(), 734910u);
}
void test_create_slope_table_large_half_step()
@ -293,7 +293,7 @@ void test_create_slope_table_large_half_step()
};
ASSERT_EQ(table.table, expected_table);
ASSERT_EQ(table.table.size(), 60u);
ASSERT_EQ(table.pixeltime_sum, 206294u);
ASSERT_EQ(table.pixeltime_sum(), 206294u);
table = create_slope_table_for_speed(slope, 1500, StepType::HALF, 4, 8, max_table_size);
@ -325,7 +325,7 @@ void test_create_slope_table_large_half_step()
};
ASSERT_EQ(table.table, expected_table);
ASSERT_EQ(table.table.size(), 224u);
ASSERT_EQ(table.pixeltime_sum, 367399u);
ASSERT_EQ(table.pixeltime_sum(), 367399u);
}
void test_motor()