Skip to content

Commit

Permalink
Avoid PPEC crash during dithering ops (#1263)
Browse files Browse the repository at this point in the history
* Cleanup of MultiStar processing and UI if subframes enabled

* Force rebuild of MultiStar list when subframes are disabled

* Add try/catch protection in gp regularize_dataset for dithering only

* PR changes.  Restore star.cpp to resolve Clang issues

* PR-requested changes, logging, 'const'

* PR request, exception pass by reference
  • Loading branch information
bwdev01 authored Dec 15, 2024
1 parent a471ca7 commit f8ecbfb
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,19 @@ double GaussianProcessGuider::result(double input, double SNR, double time_step,
{
dithering_active_ = false;
}
deduceResult(time_step); // just pretend we would do dark guiding...
try
{
deduceResult(time_step); // just pretend we would do dark guiding...
}
catch (const std::runtime_error& err)
{
reset();
std::ostringstream message;
message << "PPEC: Model reset after exception: " << err.what();
GPDebug->Write(message.str().c_str());

return parameters.control_gain_ * input;
}

GPDebug->Log("PPEC rslt(dithering): input = %.2f, final = %.2f", input, parameters.control_gain_ * input);

Expand Down Expand Up @@ -670,6 +682,7 @@ void GaussianProcessGuider::UpdatePeriodLength(double period_length)
SetGPHyperparameters(hypers); // the setter function is needed to convert parameters
}

// NOTE: Callers must be prepared to handle a thrown exception
Eigen::MatrixXd GaussianProcessGuider::regularize_dataset(const Eigen::VectorXd& timestamps, const Eigen::VectorXd& gear_error,
const Eigen::VectorXd& variances)
{
Expand All @@ -689,6 +702,7 @@ Eigen::MatrixXd GaussianProcessGuider::regularize_dataset(const Eigen::VectorXd&
int j = 0;
for (size_t i = 0; i < N - 1; ++i)
{

if (timestamps(i) < last_cell_end + grid_interval)
{
gear_error_sum += (timestamps(i) - last_timestamp) * 0.5 * (last_gear_error + gear_error(i));
Expand All @@ -699,6 +713,14 @@ Eigen::MatrixXd GaussianProcessGuider::regularize_dataset(const Eigen::VectorXd&
{
while (timestamps(i) >= last_cell_end + grid_interval)
{
if (dithering_active_) // generalizing this will require recovery in any function that calls UpdateGP
{
if (j >= reg_timestamps.size())
{
GPDebug->Log("PPDbg: Index-over-run in regularize_dataset, j = %d", j);
throw std::runtime_error("Index over-run in regularize_dataset");
}
}
double inter_timestamp = last_cell_end + grid_interval;

double proportion = (inter_timestamp - last_timestamp) / (timestamps(i) - last_timestamp);
Expand Down

0 comments on commit f8ecbfb

Please sign in to comment.