From 127ae329978940bd5e1944bc08bc5d7a65dc3361 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sat, 10 Nov 2012 11:43:05 +0100 Subject: [PATCH 1/3] Completed sensors test, WIP on ADC test --- apps/px4/tests/test_adc.c | 175 +++++++++++----------------------- apps/px4/tests/test_sensors.c | 141 ++++++++++++++++++++++++--- 2 files changed, 186 insertions(+), 130 deletions(-) diff --git a/apps/px4/tests/test_adc.c b/apps/px4/tests/test_adc.c index 7795f07acf..4ffa9374f1 100644 --- a/apps/px4/tests/test_adc.c +++ b/apps/px4/tests/test_adc.c @@ -1,7 +1,6 @@ /**************************************************************************** - * px4/sensors/test_gpio.c * - * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Copyright (C) 2012 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -13,7 +12,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be + * 3. Neither the name PX4 nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * @@ -32,9 +31,10 @@ * ****************************************************************************/ -/**************************************************************************** - * Included Files - ****************************************************************************/ +/** + * @file test_adc.c + * Test for the analog to digital converter. + */ #include #include @@ -54,91 +54,46 @@ #include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: test_gpio - ****************************************************************************/ - int test_adc(int argc, char *argv[]) { - int fd0; + int fd0 = 0; int ret = 0; - //struct adc_msg_s sample[4],sample2[4],sample3[4],sample4[4],sample5[4],sample6[4],sample7[4],sample8[4],sample9[4]; + #pragma pack(push,1) struct adc_msg4_s { - uint8_t am_channel1; /* The 8-bit ADC Channel */ - int32_t am_data1; /* ADC convert result (4 bytes) */ - uint8_t am_channel2; /* The 8-bit ADC Channel */ - int32_t am_data2; /* ADC convert result (4 bytes) */ - uint8_t am_channel3; /* The 8-bit ADC Channel */ - int32_t am_data3; /* ADC convert result (4 bytes) */ - uint8_t am_channel4; /* The 8-bit ADC Channel */ - int32_t am_data4; /* ADC convert result (4 bytes) */ - } __attribute__((__packed__));; - - struct adc_msg4_s sample1[4], sample2[4]; - - size_t readsize; - ssize_t nbytes, nbytes2; - int i; + uint8_t am_channel1; /**< The 8-bit ADC Channel 1 */ + int32_t am_data1; /**< ADC convert result 1 (4 bytes) */ + uint8_t am_channel2; /**< The 8-bit ADC Channel 2 */ + int32_t am_data2; /**< ADC convert result 2 (4 bytes) */ + uint8_t am_channel3; /**< The 8-bit ADC Channel 3 */ + int32_t am_data3; /**< ADC convert result 3 (4 bytes) */ + uint8_t am_channel4; /**< The 8-bit ADC Channel 4 */ + int32_t am_data4; /**< ADC convert result 4 (4 bytes) */ + }; + #pragma pack(pop) + + struct adc_msg4_s sample1; + + ssize_t nbytes; int j; int errval; - for (j = 0; j < 1; j++) { - char name[11]; - sprintf(name, "/dev/adc%d", j); - fd0 = open(name, O_RDONLY | O_NONBLOCK); + fd0 = open("/dev/adc0", O_RDONLY | O_NONBLOCK); - if (fd0 < 0) { - printf("ADC: %s open fail\n", name); - return ERROR; + if (fd0 <= 0) { + message("/dev/adc0 open fail: %d", errno); + return ERROR; - } else { - printf("Opened %s successfully\n", name); - } + } else { + message("opened /dev/adc0 successfully"); + } + usleep(10000); - /* first adc read round */ - readsize = 4 * sizeof(struct adc_msg_s); - up_udelay(10000);//microseconds - nbytes = read(fd0, sample1, readsize); - up_udelay(10000);//microseconds - nbytes2 = read(fd0, sample2, readsize); -// nbytes2 = read(fd0, sample3, readsize); -// nbytes2 = read(fd0, sample4, readsize); -// nbytes2 = read(fd0, sample5, readsize); -// nbytes2 = read(fd0, sample6, readsize); -// nbytes2 = read(fd0, sample7, readsize); -// nbytes2 = read(fd0, sample8, readsize); - //nbytes2 = read(fd0, sample9, readsize); + for (j = 0; j < 10; j++) { + + /* sleep 1 millisecond */ + usleep(1000); + nbytes = read(fd0, &sample1, sizeof(sample1)); /* Handle unexpected return values */ @@ -146,62 +101,44 @@ int test_adc(int argc, char *argv[]) errval = errno; if (errval != EINTR) { - message("read %s failed: %d\n", - name, errval); + message("reading /dev/adc0 failed: %d", errval); errval = 3; goto errout_with_dev; } - message("\tInterrupted read...\n"); + message("\tinterrupted read.."); } else if (nbytes == 0) { - message("\tNo data read, Ignoring\n"); + message("\tno data read, ignoring."); + ret = ERROR; } /* Print the sample data on successful return */ else { - int nsamples = nbytes / sizeof(struct adc_msg_s); - - if (nsamples * sizeof(struct adc_msg_s) != nbytes) { - message("\tread size=%d is not a multiple of sample size=%d, Ignoring\n", - nbytes, sizeof(struct adc_msg_s)); + if (nbytes != sizeof(sample1)) { + message("\tsample 1 size %d is not matching struct size %d, ignoring", + nbytes, sizeof(sample1)); + ret = ERROR; } else { - message("Sample:"); - - for (i = 0; i < 1 ; i++) { - message("%d: channel: %d value: %d\n", - i, sample1[i].am_channel1, sample1[i].am_data1); - message("Sample:"); - message("%d: channel: %d value: %d\n", - i, sample1[i].am_channel2, sample1[i].am_data2); - message("Sample:"); - message("%d: channel: %d value: %d\n", - i, sample1[i].am_channel3, sample1[i].am_data3); - message("Sample:"); - message("%d: channel: %d value: %d\n", - i, sample1[i].am_channel4, sample1[i].am_data4); - message("Sample:"); - message("%d: channel: %d value: %d\n", - i + 1, sample2[i].am_channel1, sample2[i].am_data1); - message("Sample:"); - message("%d: channel: %d value: %d\n", - i + 1, sample2[i].am_channel2, sample2[i].am_data2); - message("Sample:"); - message("%d: channel: %d value: %d\n", - i + 1, sample2[i].am_channel3, sample2[i].am_data3); - message("Sample:"); - message("%d: channel: %d value: %d\n", - i + 1, sample2[i].am_channel4, sample2[i].am_data4); -// message("%d: channel: %d value: %d\n", -// i, sample9[i].am_channel, sample9[i].am_data); - } + + message("CYCLE %d:", j); + + message("channel: %d value: %d", + sample1.am_channel1, sample1.am_data1); + message("channel: %d value: %d", + sample1.am_channel2, sample1.am_data2); + message("channel: %d value: %d", + sample1.am_channel3, sample1.am_data3); + message("channel: %d value: %d", + sample1.am_channel4, sample1.am_data4); } } + fflush(stdout); } - printf("\t ADC test successful.\n"); + message("\t ADC test successful."); errout_with_dev: diff --git a/apps/px4/tests/test_sensors.c b/apps/px4/tests/test_sensors.c index c801869ab6..ad7c740648 100644 --- a/apps/px4/tests/test_sensors.c +++ b/apps/px4/tests/test_sensors.c @@ -1,7 +1,7 @@ /**************************************************************************** * * Copyright (C) 2012 PX4 Development Team. All rights reserved. - * Author: @author Lorenz Meier + * Author: Lorenz Meier * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -36,7 +36,7 @@ * @file test_sensors.c * Tests the onboard sensors. * - * The sensors app must not be running when performing this test. + * @author Lorenz Meier */ #include @@ -56,7 +56,10 @@ #include "tests.h" +#include #include +#include +#include /**************************************************************************** * Pre-processor Definitions @@ -70,8 +73,10 @@ * Private Function Prototypes ****************************************************************************/ -//static int lis331(int argc, char *argv[]); -static int mpu6000(int argc, char *argv[]); +static int accel(int argc, char *argv[]); +static int gyro(int argc, char *argv[]); +static int mag(int argc, char *argv[]); +static int baro(int argc, char *argv[]); /**************************************************************************** * Private Data @@ -82,7 +87,10 @@ struct { const char *path; int (* test)(int argc, char *argv[]); } sensors[] = { - {"mpu6000", "/dev/accel", mpu6000}, + {"accel", "/dev/accel", accel}, + {"gyro", "/dev/gyro", gyro}, + {"mag", "/dev/mag", mag}, + {"baro", "/dev/baro", baro}, {NULL, NULL, NULL} }; @@ -95,9 +103,9 @@ struct { ****************************************************************************/ static int -mpu6000(int argc, char *argv[]) +accel(int argc, char *argv[]) { - printf("\tMPU-6000: test start\n"); + printf("\tACCEL: test start\n"); fflush(stdout); int fd; @@ -107,7 +115,7 @@ mpu6000(int argc, char *argv[]) fd = open("/dev/accel", O_RDONLY); if (fd < 0) { - printf("\tMPU-6000: open fail, run first.\n"); + printf("\tACCEL: open fail, run or or first.\n"); return ERROR; } @@ -118,11 +126,11 @@ mpu6000(int argc, char *argv[]) ret = read(fd, &buf, sizeof(buf)); if (ret < 3) { - printf("\tMPU-6000: read1 fail (%d)\n", ret); + printf("\tACCEL: read1 fail (%d)\n", ret); return ERROR; } else { - printf("\tMPU-6000 values: acc: x:%8.4f\ty:%8.4f\tz:%8.4f\n", (double)buf.x, (double)buf.y, (double)buf.z);//\tgyro: r:%d\tp:%d\ty:%d\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); + printf("\tACCEL values: acc: x:%8.4f\ty:%8.4f\tz:%8.4f\n", (double)buf.x, (double)buf.y, (double)buf.z); } // /* wait at least 10ms, sensor should have data after no more than 2ms */ @@ -141,7 +149,118 @@ mpu6000(int argc, char *argv[]) /* XXX more tests here */ /* Let user know everything is ok */ - printf("\tOK: MPU-6000 passed all tests successfully\n"); + printf("\tOK: ACCEL passed all tests successfully\n"); + + return OK; +} + +static int +gyro(int argc, char *argv[]) +{ + printf("\tGYRO: test start\n"); + fflush(stdout); + + int fd; + struct gyro_report buf; + int ret; + + fd = open("/dev/gyro", O_RDONLY); + + if (fd < 0) { + printf("\tGYRO: open fail, run or first.\n"); + return ERROR; + } + + /* wait at least 5 ms, sensor should have data after that */ + usleep(5000); + + /* read data - expect samples */ + ret = read(fd, &buf, sizeof(buf)); + + if (ret < 3) { + printf("\tGYRO: read fail (%d)\n", ret); + return ERROR; + + } else { + printf("\tGYRO values: rates: x:%8.4f\ty:%8.4f\tz:%8.4f\n", (double)buf.x, (double)buf.y, (double)buf.z); + } + + /* Let user know everything is ok */ + printf("\tOK: GYRO passed all tests successfully\n"); + + return OK; +} + +static int +mag(int argc, char *argv[]) +{ + printf("\tMAG: test start\n"); + fflush(stdout); + + int fd; + struct mag_report buf; + int ret; + + fd = open("/dev/mag", O_RDONLY); + + if (fd < 0) { + printf("\tMAG: open fail, run or first.\n"); + return ERROR; + } + + /* wait at least 5 ms, sensor should have data after that */ + usleep(5000); + + /* read data - expect samples */ + ret = read(fd, &buf, sizeof(buf)); + + if (ret < 3) { + printf("\tMAG: read fail (%d)\n", ret); + return ERROR; + + } else { + printf("\tMAG values: mag. field: x:%8.4f\ty:%8.4f\tz:%8.4f\n", (double)buf.x, (double)buf.y, (double)buf.z); + } + + /* Let user know everything is ok */ + printf("\tOK: MAG passed all tests successfully\n"); + + return OK; +} + +static int +baro(int argc, char *argv[]) +{ + printf("\tBARO: test start\n"); + fflush(stdout); + + int fd; + struct baro_report buf; + int ret; + + fd = open("/dev/baro", O_RDONLY); + + if (fd < 0) { + printf("\tBARO: open fail, run or first.\n"); + return ERROR; + } + + /* wait at least 5 ms, sensor should have data after that */ + usleep(5000); + + /* read data - expect samples */ + ret = read(fd, &buf, sizeof(buf)); + + if (ret < 3) { + printf("\tBARO: read fail (%d)\n", ret); + return ERROR; + + } else { + printf("\tBARO values: pressure: %8.4f mbar\taltitude: %8.4f m\ttemperature: %8.4f deg Celsius\n", (double)buf.pressure, (double)buf.altitude, (double)buf.temperature); + } + + /* Let user know everything is ok */ + printf("\tOK: BARO passed all tests successfully\n"); return OK; } From 15f43b1acc456ae47bac0575e785ed87d95db93c Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sat, 10 Nov 2012 12:13:15 +0100 Subject: [PATCH 2/3] improved ADC test, not yet stable --- apps/px4/tests/test_adc.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/apps/px4/tests/test_adc.c b/apps/px4/tests/test_adc.c index 4ffa9374f1..c33af1311d 100644 --- a/apps/px4/tests/test_adc.c +++ b/apps/px4/tests/test_adc.c @@ -81,18 +81,18 @@ int test_adc(int argc, char *argv[]) fd0 = open("/dev/adc0", O_RDONLY | O_NONBLOCK); if (fd0 <= 0) { - message("/dev/adc0 open fail: %d", errno); + message("/dev/adc0 open fail: %d\n", errno); return ERROR; } else { - message("opened /dev/adc0 successfully"); + message("opened /dev/adc0 successfully\n"); } usleep(10000); for (j = 0; j < 10; j++) { - /* sleep 1 millisecond */ - usleep(1000); + /* sleep 20 milliseconds */ + usleep(20000); nbytes = read(fd0, &sample1, sizeof(sample1)); /* Handle unexpected return values */ @@ -101,15 +101,15 @@ int test_adc(int argc, char *argv[]) errval = errno; if (errval != EINTR) { - message("reading /dev/adc0 failed: %d", errval); + message("reading /dev/adc0 failed: %d\n", errval); errval = 3; goto errout_with_dev; } - message("\tinterrupted read.."); + message("\tinterrupted read..\n"); } else if (nbytes == 0) { - message("\tno data read, ignoring."); + message("\tno data read, ignoring.\n"); ret = ERROR; } @@ -117,22 +117,22 @@ int test_adc(int argc, char *argv[]) else { if (nbytes != sizeof(sample1)) { - message("\tsample 1 size %d is not matching struct size %d, ignoring", + message("\tsample 1 size %d is not matching struct size %d, ignoring\n", nbytes, sizeof(sample1)); ret = ERROR; } else { - message("CYCLE %d:", j); + message("CYCLE %d:\n", j); + message("channel: %d value: %d\n", + (int)sample1.am_channel1, sample1.am_data1); message("channel: %d value: %d", - sample1.am_channel1, sample1.am_data1); + (int)sample1.am_channel2, sample1.am_data2); message("channel: %d value: %d", - sample1.am_channel2, sample1.am_data2); + (int)sample1.am_channel3, sample1.am_data3); message("channel: %d value: %d", - sample1.am_channel3, sample1.am_data3); - message("channel: %d value: %d", - sample1.am_channel4, sample1.am_data4); + (int)sample1.am_channel4, sample1.am_data4); } } fflush(stdout); From 90466afe05359cd5fc1d5b44b13d73912fb6571b Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sat, 10 Nov 2012 12:13:40 +0100 Subject: [PATCH 3/3] Comments cleanup / polishing --- apps/mavlink/mavlink_receiver.c | 4 +++- apps/mavlink/orb_listener.c | 4 +++- apps/multirotor_pos_control/multirotor_pos_control.c | 6 ++++-- apps/sensors/sensors.cpp | 4 ++-- apps/uORB/topics/subsystem_info.h | 12 ++++++++---- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/apps/mavlink/mavlink_receiver.c b/apps/mavlink/mavlink_receiver.c index 39e574c047..e1a4e8e8af 100644 --- a/apps/mavlink/mavlink_receiver.c +++ b/apps/mavlink/mavlink_receiver.c @@ -1,7 +1,7 @@ /**************************************************************************** * * Copyright (C) 2012 PX4 Development Team. All rights reserved. - * Author: @author Lorenz Meier + * Author: Lorenz Meier * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -35,6 +35,8 @@ /** * @file mavlink_receiver.c * MAVLink protocol message receive and dispatch + * + * @author Lorenz Meier */ /* XXX trim includes */ diff --git a/apps/mavlink/orb_listener.c b/apps/mavlink/orb_listener.c index 683964a0d9..fafc8f79c7 100644 --- a/apps/mavlink/orb_listener.c +++ b/apps/mavlink/orb_listener.c @@ -1,7 +1,7 @@ /**************************************************************************** * * Copyright (C) 2012 PX4 Development Team. All rights reserved. - * Author: @author Lorenz Meier + * Author: Lorenz Meier * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -35,6 +35,8 @@ /** * @file orb_listener.c * Monitors ORB topics and sends update messages as appropriate. + * + * @author Lorenz Meier */ // XXX trim includes diff --git a/apps/multirotor_pos_control/multirotor_pos_control.c b/apps/multirotor_pos_control/multirotor_pos_control.c index 9821fc7e5f..7b8d83aa8a 100644 --- a/apps/multirotor_pos_control/multirotor_pos_control.c +++ b/apps/multirotor_pos_control/multirotor_pos_control.c @@ -32,8 +32,10 @@ * ****************************************************************************/ -/* - * @file Implementation of AR.Drone 1.0 / 2.0 control interface +/** + * @file multirotor_pos_control.c + * + * Skeleton for multirotor position controller */ #include diff --git a/apps/sensors/sensors.cpp b/apps/sensors/sensors.cpp index 3e9f35eaf4..675a8602a4 100644 --- a/apps/sensors/sensors.cpp +++ b/apps/sensors/sensors.cpp @@ -34,9 +34,9 @@ /** * @file sensors.cpp - * @author Lorenz Meier - * * Sensor readout process. + * + * @author Lorenz Meier */ #include diff --git a/apps/uORB/topics/subsystem_info.h b/apps/uORB/topics/subsystem_info.h index 89b3974783..c3e039d66b 100644 --- a/apps/uORB/topics/subsystem_info.h +++ b/apps/uORB/topics/subsystem_info.h @@ -1,9 +1,9 @@ /**************************************************************************** * - * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. - * Author: @author Lorenz Meier - * @author Thomas Gubler - * @author Julian Oes + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Author: Lorenz Meier + * Thomas Gubler + * Julian Oes * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -37,6 +37,10 @@ /** * @file subsystem_info.h * Definition of the subsystem info topic. + * + * @author Lorenz Meier + * @author Thomas Gubler + * @author Julian Oes */ #ifndef TOPIC_SUBSYSTEM_INFO_H_