Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Extend analog dial processing with correction factors for offset and parallax #2727

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,18 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph)
neuroi->deltax = std::stoi(splitted[3]);
neuroi->deltay = std::stoi(splitted[4]);
neuroi->CCW = false;
neuroi->calibrate = false;
if (splitted.size() >= 6)
{
neuroi->CCW = toUpper(splitted[5]) == "TRUE";
}
if (splitted.size() >= 9)
{
neuroi->calibrate = true;
neuroi->parallax_x = std::stof(splitted[6]);
neuroi->parallax_y = std::stof(splitted[7]);
neuroi->value_offset = std::stof(splitted[8]);
}
neuroi->result_float = -1;
neuroi->image = NULL;
neuroi->image_org = NULL;
Expand Down Expand Up @@ -692,8 +700,24 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time)
GENERAL[n]->ROI[roi]->result_float = 10 - (result * 10);
else
GENERAL[n]->ROI[roi]->result_float = result * 10;

ESP_LOGD(TAG, "General result (Analog)%i - CCW: %d - %f", roi, GENERAL[n]->ROI[roi]->CCW, GENERAL[n]->ROI[roi]->result_float);

if(GENERAL[n]->ROI[roi]->calibrate)
{
float cw = GENERAL[n]->ROI[roi]->CCW ? 1 : -1;
float dx = GENERAL[n]->ROI[roi]->parallax_x;
float dy = GENERAL[n]->ROI[roi]->parallax_y;
float dval = GENERAL[n]->ROI[roi]->value_offset;
float value = GENERAL[n]->ROI[roi]->result_float;
float angle = cw * value / 10 * (2 * M_PI);
float corrected_angle = atan2(sin(angle) + dx, cos(angle) + dy);
float corrected_value = cw * corrected_angle / (2 * M_PI) * 10 + dval;
GENERAL[n]->ROI[roi]->result_float = fmod(corrected_value + 10, 10);

ESP_LOGD(TAG, "General result (Analog)%i - Calibrated: %f (%f, %f, %f)", roi, GENERAL[n]->ROI[roi]->result_float, dx, dy, dval);
}

if (isLogImage)
LogImage(logPath, GENERAL[n]->ROI[roi]->name, &GENERAL[n]->ROI[roi]->result_float, NULL, time, GENERAL[n]->ROI[roi]->image_org);
} break;
Expand Down
2 changes: 2 additions & 0 deletions code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ struct roi {
float result_float;
int result_klasse;
bool isReject, CCW;
bool calibrate;
float value_offset, parallax_x, parallax_y;
string name;
CImageBasis *image, *image_org;
};
Expand Down