I am making a robot that has a lidar in his head.
I made a command that has the head panning over 450 micro steps and I am collecting distance and angle of the head in 2 variables.
tfmP.getData( tfDist);
Fr_Clear [i_Dist] = tfDist; // frontal clearance (CM) array from the Lidar
Fr_ClearDeg[i_Dist] = Mot_Ang_Read [6]; // Angle reading from the panning motor encoder.
Serial.printf( "%u %03icm %.2f° \n", i_Dist, Fr_Clear[i_Dist], Fr_ClearDeg[i_Dist]);
I would like to call myself a better programmer and be able to have an 2 dimensional array that collect distance and angle.
How to write that?
Rather than using a two dimensional array, consider using an array of struct.
struct Reading {
float distance;
float angle;
};
const int STEPS= 450;
Reading Fr_Clear[STEPS];
void foo() {
tfmP.getData( tfDist);
Fr_Clear[i_Dist].distance = tfDist; // frontal clearance (CM) array from the Lidar
Fr_Clear[i_Dist].angle = Mot_Ang_Read [6]; // Angle reading from the panning motor encoder.
}
[code]
You might also want to consider checking out naming conventions for variables in C++.
The array of struct is your best answer. Gives you flexibility in case the data types ever change and allows grouping together items of different data types in a logical manner.