rename indToMM
This commit is contained in:
@@ -115,13 +115,13 @@ void loop() {
|
|||||||
// put your main code here, to run repeatedly:
|
// put your main code here, to run repeatedly:
|
||||||
dist_raw = analogRead(indL);
|
dist_raw = analogRead(indL);
|
||||||
if (dist_raw > 870) oor = true;
|
if (dist_raw > 870) oor = true;
|
||||||
dist = ind2mm(ind0Map, dist_raw); // 189->950, 16->26
|
dist = indToMM(ind0Map, dist_raw); // 189->950, 16->26
|
||||||
Serial.print(dist);
|
Serial.print(dist);
|
||||||
Serial.print(", ");
|
Serial.print(", ");
|
||||||
|
|
||||||
dist2_raw = analogRead(indR);
|
dist2_raw = analogRead(indR);
|
||||||
if (dist2_raw > 870) oor2 = true;
|
if (dist2_raw > 870) oor2 = true;
|
||||||
dist2 = ind2mm(ind1Map, dist2_raw);
|
dist2 = indToMM(ind1Map, dist2_raw);
|
||||||
Serial.print(dist2);
|
Serial.print(dist2);
|
||||||
Serial.print(", ");
|
Serial.print(", ");
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ IndSensorMap ind2Map = {-9.824360913609562, 871.4744633266955, 0.290936623509330
|
|||||||
IndSensorMap ind3Map = {-13.891292062248292, 990.6819962477331, 0.16376045588859353, -0.074904004740735, 0.17727132893449118};
|
IndSensorMap ind3Map = {-13.891292062248292, 990.6819962477331, 0.16376045588859353, -0.074904004740735, 0.17727132893449118};
|
||||||
|
|
||||||
// Convert raw analog reading to millimeters using sensor calibration
|
// Convert raw analog reading to millimeters using sensor calibration
|
||||||
float ind2mm(IndSensorMap ind, unsigned int raw) {
|
float indToMM(IndSensorMap ind, unsigned int raw) {
|
||||||
return ind.C - (1.0 / ind.B) * log(pow((ind.K - ind.A) / ((float)raw - ind.A), ind.v) - 1.0);
|
return ind.C - (1.0 / ind.B) * log(pow((ind.K - ind.A) / ((float)raw - ind.A), ind.v) - 1.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,6 @@ extern IndSensorMap ind2Map;
|
|||||||
extern IndSensorMap ind3Map;
|
extern IndSensorMap ind3Map;
|
||||||
|
|
||||||
// Convert raw analog reading to millimeters using sensor calibration
|
// Convert raw analog reading to millimeters using sensor calibration
|
||||||
float ind2mm(IndSensorMap ind, unsigned int raw);
|
float indToMM(IndSensorMap ind, unsigned int raw);
|
||||||
|
|
||||||
#endif // IND_SENSOR_MAP_HPP
|
#endif // IND_SENSOR_MAP_HPP
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ static inline float clamp90(float x) { return clampf(x, -90.0f, 90.0f); }
|
|||||||
// prototypes (so we can keep your function layout)
|
// prototypes (so we can keep your function layout)
|
||||||
void send_pwm1(int val);
|
void send_pwm1(int val);
|
||||||
void send_pwm2(int val);
|
void send_pwm2(int val);
|
||||||
float ind2mm(IndSensorMap ind, unsigned int raw);
|
float indToMM(IndSensorMap ind, unsigned int raw);
|
||||||
int levitate(float e, float de, float ecum_local, int oor);
|
int levitate(float e, float de, float ecum_local, int oor);
|
||||||
int levitate2(float e, float de, float ecum_local, int oor);
|
int levitate2(float e, float de, float ecum_local, int oor);
|
||||||
|
|
||||||
@@ -189,7 +189,7 @@ void loop() {
|
|||||||
// Read height sensors (yours)
|
// Read height sensors (yours)
|
||||||
// ----------------------------
|
// ----------------------------
|
||||||
dist_raw = analogRead(ind0Pin);
|
dist_raw = analogRead(ind0Pin);
|
||||||
dist = ind2mm(ind0Map, dist_raw);
|
dist = indToMM(ind0Map, dist_raw);
|
||||||
Serial.print(dist);
|
Serial.print(dist);
|
||||||
Serial.print(", ");
|
Serial.print(", ");
|
||||||
|
|
||||||
@@ -376,6 +376,6 @@ void send_pwm2(int val) {
|
|||||||
// float_map() — ADC→distance mapping (yours)
|
// float_map() — ADC→distance mapping (yours)
|
||||||
// ----------------------------
|
// ----------------------------
|
||||||
// Uses John and Adi's sensor calibration to return the millimeter reading from an analog sensor value.
|
// Uses John and Adi's sensor calibration to return the millimeter reading from an analog sensor value.
|
||||||
float ind2mm(IndSensorMap ind, unsigned int raw) {
|
float indToMM(IndSensorMap ind, unsigned int raw) {
|
||||||
return ind.C - (1.0 / ind.B) * log(pow((ind.K - ind.A) / ((float)raw - ind.A), ind.v) - 1.0);
|
return ind.C - (1.0 / ind.B) * log(pow((ind.K - ind.A) / ((float)raw - ind.A), ind.v) - 1.0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user