sonar angle calibration

This commit is contained in:
e5l
2016-08-22 16:09:58 +03:00
parent d368fd0c9b
commit fd529b384f
+9 -7
View File
@@ -7,15 +7,17 @@
* http://www.dfrobot.com/wiki/index.php?title=URM37_V4.0_Ultrasonic_Sensor_(SKU:SEN0001) * http://www.dfrobot.com/wiki/index.php?title=URM37_V4.0_Ultrasonic_Sensor_(SKU:SEN0001)
*/ */
#define FRONT_ANGLE 1
#define BACK_ANGLE 40
#define MAX_DEGREE 180
static uint8_t sonar_degree(uint8_t degree) static uint8_t sonar_degree(uint8_t degree)
{ {
// urm37 accepts values [0;46] if (degree > MAX_DEGREE)
// so we have 47 steps. degree = MAX_DEGREE;
// But we don't use the last 46 value.
// It gives us angle > 180. float factor = 1.0 * (BACK_ANGLE - FRONT_ANGLE) / MAX_DEGREE;
if (degree > 180) return factor * degree + FRONT_ANGLE;
degree = 180;
return degree / 4;
} }
#define SONAR_CMD_GET_DIST 0x22 #define SONAR_CMD_GET_DIST 0x22