Merged master into cmake-2

This commit is contained in:
Lorenz Meier
2015-09-20 10:33:39 +02:00
45 changed files with 1858 additions and 985 deletions
+48 -12
View File
@@ -65,6 +65,7 @@
#include <drivers/drv_accel.h>
#include <drivers/drv_mag.h>
#include <drivers/device/ringbuffer.h>
#include <drivers/device/integrator.h>
#include <drivers/drv_tone_alarm.h>
#include <board_config.h>
@@ -206,6 +207,7 @@ static const int ERROR = -1;
#define LSM303D_ACCEL_DEFAULT_RATE 800
#define LSM303D_ACCEL_DEFAULT_ONCHIP_FILTER_FREQ 50
#define LSM303D_ACCEL_DEFAULT_DRIVER_FILTER_FREQ 30
#define LSM303D_ACCEL_MAX_OUTPUT_RATE 280
#define LSM303D_MAG_DEFAULT_RANGE_GA 2
#define LSM303D_MAG_DEFAULT_RATE 100
@@ -308,6 +310,8 @@ private:
math::LowPassFilter2p _accel_filter_y;
math::LowPassFilter2p _accel_filter_z;
Integrator _accel_int;
enum Rotation _rotation;
// values used to
@@ -577,6 +581,7 @@ LSM303D::LSM303D(int bus, const char* path, spi_dev_e device, enum Rotation rota
_accel_filter_x(LSM303D_ACCEL_DEFAULT_RATE, LSM303D_ACCEL_DEFAULT_DRIVER_FILTER_FREQ),
_accel_filter_y(LSM303D_ACCEL_DEFAULT_RATE, LSM303D_ACCEL_DEFAULT_DRIVER_FILTER_FREQ),
_accel_filter_z(LSM303D_ACCEL_DEFAULT_RATE, LSM303D_ACCEL_DEFAULT_DRIVER_FILTER_FREQ),
_accel_int(1000000 / LSM303D_ACCEL_MAX_OUTPUT_RATE, true),
_rotation(rotation),
_constant_accel_count(0),
_last_temperature(0),
@@ -1411,6 +1416,13 @@ LSM303D::stop()
{
hrt_cancel(&_accel_call);
hrt_cancel(&_mag_call);
/* reset internal states */
memset(_last_accel, 0, sizeof(_last_accel));
/* discard unread data in the buffers */
_accel_reports->flush();
_mag_reports->flush();
}
void
@@ -1575,17 +1587,27 @@ LSM303D::measure()
accel_report.y = _accel_filter_y.apply(y_in_new);
accel_report.z = _accel_filter_z.apply(z_in_new);
math::Vector<3> aval(x_in_new, y_in_new, z_in_new);
math::Vector<3> aval_integrated;
bool accel_notify = _accel_int.put(accel_report.timestamp, aval, aval_integrated, accel_report.integral_dt);
accel_report.x_integral = aval_integrated(0);
accel_report.y_integral = aval_integrated(1);
accel_report.z_integral = aval_integrated(2);
accel_report.scaling = _accel_range_scale;
accel_report.range_m_s2 = _accel_range_m_s2;
_accel_reports->force(&accel_report);
/* notify anyone waiting for data */
poll_notify(POLLIN);
if (accel_notify) {
poll_notify(POLLIN);
if (!(_pub_blocked)) {
/* publish it */
orb_publish(ORB_ID(sensor_accel), _accel_topic, &accel_report);
if (!(_pub_blocked)) {
/* publish it */
orb_publish(ORB_ID(sensor_accel), _accel_topic, &accel_report);
}
}
_accel_read++;
@@ -1841,7 +1863,7 @@ namespace lsm303d
LSM303D *g_dev;
void start(bool external_bus, enum Rotation rotation);
void start(bool external_bus, enum Rotation rotation, unsigned range);
void test();
void reset();
void info();
@@ -1856,11 +1878,12 @@ void test_error();
* up and running or failed to detect the sensor.
*/
void
start(bool external_bus, enum Rotation rotation)
start(bool external_bus, enum Rotation rotation, unsigned range)
{
int fd, fd_mag;
if (g_dev != nullptr)
if (g_dev != nullptr) {
errx(0, "already started");
}
/* create the driver */
if (external_bus) {
@@ -1884,11 +1907,17 @@ start(bool external_bus, enum Rotation rotation)
/* set the poll rate to default, starts automatic data collection */
fd = open(LSM303D_DEVICE_PATH_ACCEL, O_RDONLY);
if (fd < 0)
if (fd < 0) {
goto fail;
}
if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0)
if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
goto fail;
}
if (ioctl(fd, ACCELIOCSRANGE, range) < 0) {
goto fail;
}
fd_mag = open(LSM303D_DEVICE_PATH_MAG, O_RDONLY);
@@ -1980,7 +2009,10 @@ test()
warnx("mag z: \t%d\traw", (int)m_report.z_raw);
warnx("mag range: %8.4f ga", (double)m_report.range_ga);
/* XXX add poll-rate tests here too */
/* reset to default polling */
if (ioctl(fd_accel, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
err(1, "reset to default polling");
}
close(fd_accel);
close(fd_mag);
@@ -2084,9 +2116,10 @@ lsm303d_main(int argc, char *argv[])
bool external_bus = false;
int ch;
enum Rotation rotation = ROTATION_NONE;
int accel_range = 8;
/* jump over start/off/etc and look at options first */
while ((ch = getopt(argc, argv, "XR:")) != EOF) {
while ((ch = getopt(argc, argv, "XR:a:")) != EOF) {
switch (ch) {
case 'X':
external_bus = true;
@@ -2094,6 +2127,9 @@ lsm303d_main(int argc, char *argv[])
case 'R':
rotation = (enum Rotation)atoi(optarg);
break;
case 'a':
accel_range = atoi(optarg);
break;
default:
lsm303d::usage();
exit(0);
@@ -2107,7 +2143,7 @@ lsm303d_main(int argc, char *argv[])
*/
if (!strcmp(verb, "start"))
lsm303d::start(external_bus, rotation);
lsm303d::start(external_bus, rotation, accel_range);
/*
* Test the driver/device.