diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2012-08-13 22:10:03 +0200 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2012-08-13 22:10:03 +0200 |
commit | 1d029b01fe466b67969d650accf911a75fd620ab (patch) | |
tree | 314df263c4f706552a41be54c2aa2e978a2f5b66 /apps/px4/tests | |
parent | 6fb3bbb5da23454cc9b56cc502b2689572f94a4c (diff) | |
download | px4-firmware-1d029b01fe466b67969d650accf911a75fd620ab.tar.gz px4-firmware-1d029b01fe466b67969d650accf911a75fd620ab.tar.bz2 px4-firmware-1d029b01fe466b67969d650accf911a75fd620ab.zip |
First initial revision of ACC driver and gyro
Diffstat (limited to 'apps/px4/tests')
-rw-r--r-- | apps/px4/tests/test_float.c | 29 | ||||
-rw-r--r-- | apps/px4/tests/test_sensors.c | 40 |
2 files changed, 39 insertions, 30 deletions
diff --git a/apps/px4/tests/test_float.c b/apps/px4/tests/test_float.c index 0439476e6..4922d06b1 100644 --- a/apps/px4/tests/test_float.c +++ b/apps/px4/tests/test_float.c @@ -62,7 +62,7 @@ int test_float(int argc, char *argv[]) int ret = 0; printf("\n--- SINGLE PRECISION TESTS ---\n"); - printf("The single precision test involves calls to fabs(),\nif test fails check this function as well.\n\n"); + printf("The single precision test involves calls to fabsf(),\nif test fails check this function as well.\n\n"); float f1 = 1.55f; @@ -80,7 +80,7 @@ int test_float(int argc, char *argv[]) fflush(stdout); - if (fabs((sinf_one - 0.841470956802368164062500000000f)) < FLT_EPSILON) { + if (fabsf((sinf_one - 0.841470956802368164062500000000f)) < FLT_EPSILON) { printf("\t success: sinf(1.0f) == 0.84147f\n"); } else { @@ -92,7 +92,7 @@ int test_float(int argc, char *argv[]) float asinf_one = asinf(1.0f); - if (fabs((asinf_one - 1.570796251296997070312500000000f)) < FLT_EPSILON * 1.5f) { + if (fabsf((asinf_one - 1.570796251296997070312500000000f)) < FLT_EPSILON * 1.5f) { printf("\t success: asinf(1.0f) == 1.57079f\n"); } else { @@ -104,7 +104,7 @@ int test_float(int argc, char *argv[]) float cosf_one = cosf(1.0f); - if (fabs((cosf_one - 0.540302336215972900390625000000f)) < FLT_EPSILON) { + if (fabsf((cosf_one - 0.540302336215972900390625000000f)) < FLT_EPSILON) { printf("\t success: cosf(1.0f) == 0.54030f\n"); } else { @@ -117,7 +117,7 @@ int test_float(int argc, char *argv[]) float acosf_one = acosf(1.0f); - if (fabs((acosf_one - 0.000000000000000000000000000000f)) < FLT_EPSILON) { + if (fabsf((acosf_one - 0.000000000000000000000000000000f)) < FLT_EPSILON) { printf("\t success: acosf(1.0f) == 0.0f\n"); } else { @@ -162,9 +162,9 @@ int test_float(int argc, char *argv[]) if (sbuf[0] == ' ' && sbuf[1] == ' ' && sbuf[2] == '0' && sbuf[3] == '.' && sbuf[4] == '5' && sbuf[5] == '5' && sbuf[6] == '3' && sbuf[7] == '4' && sbuf[8] == '\0') { - printf("\t success: printf(\"%8.4f\", 0.553415f) == %8.4f\n", 0.553415f); + printf("\t success: printf(\"%%8.4f\", 0.553415f) == %8.4f\n", 0.553415f); } else { - printf("\t FAIL: printf(\"%8.4f\", 0.553415f) != \" 0.5534\", result: %s\n", sbuf); + printf("\t FAIL: printf(\"%%8.4f\", 0.553415f) != \" 0.5534\", result: %s\n", sbuf); ret = -5; } @@ -230,15 +230,24 @@ int test_float(int argc, char *argv[]) ret = -7; } - printf("\t testing printing: printf(0.553415): %8.4f\n", 0.553415); - printf("\t testing pow() with magic value\n"); - printf("\t (44330.0 * (1.0 - pow((96286LL / 101325.0), 0.190295)));\n"); + printf("\t (44330.0 * (1.0 - pow((96286LL / 101325.0), 0.190295)));\n"); fflush(stdout); usleep(20000); double powres = (44330.0 * (1.0 - pow((96286LL / 101325.0), 0.190295))); printf("\t success: result: %8.4f\n", (double)powres); + sprintf(sbuf, "%8.4f", 0.553415); + + if (sbuf[0] == ' ' && sbuf[1] == ' ' && sbuf[2] == '0' && + sbuf[3] == '.' && sbuf[4] == '5' && sbuf[5] == '5' + && sbuf[6] == '3' && sbuf[7] == '4' && sbuf[8] == '\0') { + printf("\t success: printf(\"%%8.4f\", 0.553415) == %8.4f\n", 0.553415); + } else { + printf("\t FAIL: printf(\"%%8.4f\", 0.553415) != \" 0.5534\", result: %s\n", sbuf); + ret = -8; + } + if (ret == 0) { printf("\n SUCCESS: All float and double tests passed.\n"); diff --git a/apps/px4/tests/test_sensors.c b/apps/px4/tests/test_sensors.c index 1a7ebcc7a..af1213711 100644 --- a/apps/px4/tests/test_sensors.c +++ b/apps/px4/tests/test_sensors.c @@ -331,7 +331,7 @@ mpu6000(int argc, char *argv[]) fflush(stdout); int fd; - int16_t buf[5] = { -1, 0, -1, 0, -1, 0}; + int16_t buf[6] = { -1, 0, -1, 0, -1, 0}; int ret; fd = open("/dev/mpu6000", O_RDONLY); @@ -341,32 +341,32 @@ mpu6000(int argc, char *argv[]) return ERROR; } - // /* wait at least 100ms, sensor should have data after no more than 20ms */ - // usleep(100000); + /* wait at least 100ms, sensor should have data after no more than 20ms */ + usleep(100000); - // /* read data - expect samples */ - // ret = read(fd, buf, sizeof(buf)); + /* read data - expect samples */ + ret = read(fd, buf, sizeof(buf)); - // if (ret != sizeof(buf)) { - // printf("\tMPU-6000: read1 fail (%d)\n", ret); - // return ERROR; + if (ret != sizeof(buf)) { + printf("\tMPU-6000: read1 fail (%d)\n", ret); + return ERROR; - // } else { - // printf("\tMPU-6000 values: acc: x:%d\ty:%d\tz:%d\tgyro: r:%d\tp:%d\ty:%d\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); - // } + } else { + printf("\tMPU-6000 values: acc: x:%d\ty:%d\tz:%d\tgyro: r:%d\tp:%d\ty:%d\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); + } - // /* wait at least 10ms, sensor should have data after no more than 2ms */ - // usleep(100000); + /* wait at least 10ms, sensor should have data after no more than 2ms */ + usleep(100000); - // ret = read(fd, buf, sizeof(buf)); + ret = read(fd, buf, sizeof(buf)); - // if (ret != sizeof(buf)) { - // printf("\tMPU-6000: read2 fail (%d)\n", ret); - // return ERROR; + if (ret != sizeof(buf)) { + printf("\tMPU-6000: read2 fail (%d)\n", ret); + return ERROR; - // } else { - // printf("\tMPU-6000 values: acc: x:%d\ty:%d\tz:%d\tgyro: r:%d\tp:%d\ty:%d\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); - // } + } else { + printf("\tMPU-6000 values: acc: x:%d\ty:%d\tz:%d\tgyro: r:%d\tp:%d\ty:%d\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); + } /* XXX more tests here */ |