Below is part of a sample code for a 3D Lidar sensor and when the code runs, it outputs a live recording of what the sensor sees in front with the shortest measurement being 0.25 meters. When the sensor sees the object at a very close range, it will cover that object in '0' as stated below in the code.
What I need help with is creating a cout for when the sensor detects an object between 0.25 and 0.35 meters to output a line saying 'Too close, Stop!' and another line for when it's between 0.35 and 0.45 meters to output a line saying 'Getting close'. Please let me know if you need additional lines of code and I can email the whole file to you and highlight the key points.
char asciiPoint(const royale::DepthData* data, std::size_t x, std::size_t y)
{
// Using a bounds-check here is inefficient, but allows the scale-to-max-width-or-height
// loop in onNewData to be simpler.
if (x >= data->width || y >= data->height)
{
return ' ';
}
auto depth = data->points[y * data->width + x];
if (depth.depthConfidence < 128)
{
return ' ';
}
const royale::Vector<royale::Pair<float, char>> DEPTH_LETTER
{
{0.25f, 'O'}, //goes up to 25cm = 0.25 meters
{0.35f, '1'}, //goes from 25 to 35cm = 0.35 meters
{0.45f, '2'}, //goes from 35 to 45cm = 0.45 meters
{0.55f, '3'}, //goes from 45 to 55cm = 0.55 meters
{1.50f, '.'}, //goes up to 1.5 meters but max is 4 meters
};
for (auto x : DEPTH_LETTER)
{
if (depth.z < x.first)
{
return x.second;
}
}
return ' ';
i fail to see the point of your {O, 1, 2, 3, .} translation, but you may apply the same idea
traverse the matrix and count the amount of each class, then check if you have at least one
(of course, you need to check from nearest to farthest)