50 static void *
navdata_read(
void *data __attribute__((unused)));
68 #ifndef NAVDATA_FILTER_ID
69 #define NAVDATA_FILTER_ID 2
77 #define SONAR_OFFSET 880
84 #define SONAR_SCALE 0.00047
94 while (written < count) {
95 ssize_t n = write(fd, buf + written, count - written);
97 if (errno == EAGAIN || errno == EWOULDBLOCK) {
115 while (readed < count) {
116 ssize_t n = read(fd, buf + readed, count - readed);
118 if (errno == EAGAIN || errno == EWOULDBLOCK) {
128 #if PERIODIC_TELEMETRY
133 pprz_msg_send_ARDRONE_NAVDATA(trans, dev, AC_ID,
175 navdata.
fd = open(
"/dev/ttyO1", O_RDWR | O_NOCTTY);
178 printf(
"[navdata] Unable to open navdata board connection(/dev/ttyO1)\n");
185 struct termios options;
189 cfsetispeed(&options, B460800);
190 cfsetospeed(&options, B460800);
192 options.c_cflag |= (CLOCAL | CREAD);
195 options.c_oflag &= ~OPOST;
198 tcsetattr(
navdata.
fd, TCSANOW, &options);
202 navdata_available =
FALSE;
219 printf(
"[navdata] Could not acquire baro calibration!\n");
232 pthread_t navdata_thread;
233 if (pthread_create(&navdata_thread, NULL,
navdata_read, NULL) != 0) {
234 printf(
"[navdata] Could not create navdata reading thread!\n");
238 #if PERIODIC_TELEMETRY
261 pthread_mutex_lock(&navdata_mutex);
262 while (navdata_available) {
263 pthread_cond_wait(&navdata_cond, &navdata_mutex);
265 pthread_mutex_unlock(&navdata_mutex);
272 buffer_idx += newbytes;
286 fprintf(stderr,
"[navdata] sync error, startbyte not found, resetting...\n");
299 checksum += navdata_buffer[i] + (navdata_buffer[i + 1] << 8);
305 if (new_measurement->
chksum != checksum) {
306 fprintf(stderr,
"[navdata] Checksum error [calculated: %d] [packet: %d] [diff: %d]\n",
307 checksum, new_measurement->
chksum, checksum - new_measurement->
chksum);
313 pthread_mutex_lock(&navdata_mutex);
314 navdata_available =
TRUE;
315 pthread_mutex_unlock(&navdata_mutex);
349 pthread_mutex_lock(&navdata_mutex);
351 if (navdata_available) {
357 navdata_available =
FALSE;
359 pthread_cond_signal(&navdata_cond);
360 pthread_mutex_unlock(&navdata_mutex);
365 fprintf(stderr,
"[navdata] Lost frame: %d should have been %d\n",
398 pthread_mutex_unlock(&navdata_mutex);
422 printf(
"[navdata] Could not read calibration data.");
449 static int16_t LastMagValue = 0;
450 static int MagFreezeCounter = 0;
456 if (MagFreezeCounter > 30) {
457 fprintf(stderr,
"mag freeze detected, resetting!\n");
476 MagFreezeCounter = 0;
481 MagFreezeCounter = 0;
494 static int32_t lastpressval = 0;
496 static int32_t lastpressval_nospike = 0;
497 static uint16_t lasttempval_nospike = 0;
498 static uint8_t temp_or_press_was_updated_last =
501 static int sync_errors = 0;
502 static int spike_detected = 0;
504 if (temp_or_press_was_updated_last == 0) {
506 temp_or_press_was_updated_last =
TRUE;
509 if (lastpressval != 0) {
513 temp_or_press_was_updated_last =
FALSE;
520 temp_or_press_was_updated_last =
FALSE;
523 if (lasttempval != 0) {
527 temp_or_press_was_updated_last =
TRUE;
539 if (lastpressval != 0 && lasttempval != 0
545 if (lastpressval != 0 && lasttempval != 0
599 if (spike_detected > 0) {
static void * navdata_read(void *data)
Main reading thread This is done asynchronous because the navdata board doesn't support NON_BLOCKING...
bool_t baro_calibrated
Whenever the baro is calibrated.
Dispatcher to register actual AHRS implementations.
static pthread_cond_t navdata_cond
void navdata_update()
Update the navdata (event loop)
Generic transmission transport header.
bool_t baro_available
Whenever the baro is available.
void imu_scale_gyro(struct Imu *_imu)
bool_t navdata_init()
Initialize the navdata board.
struct bmp180_calib_t bmp180_calib
BMP180 calibration receieved from navboard.
Periodic telemetry system header (includes downlink utility and generated code).
void imu_scale_accel(struct Imu *_imu)
#define NAVDATA_START_BYTE
Some architecture independent helper functions for GPIOs.
#define VECT3_ASSIGN(_a, _x, _y, _z)
#define RATES_ASSIGN(_ra, _p, _q, _r)
struct navdata_measure_t measure
Main navdata packet receieved from navboard.
Main include for ABI (AirBorneInterface).
#define SONAR_SCALE
Sonar scale.
#define NAVDATA_CMD_BARO_CALIB
Integrated Navigation System interface.
static bool_t navdata_baro_calib(void)
Try to receive the baro calibration from the navdata board.
bool_t imu_lost
Whenever the imu is lost.
uint16_t temperature_gyro
static void baro_update_logic(void)
Handle the baro(pressure/temperature) logic Sometimes the temperature and pressure are switched becau...
uint16_t temperature_pressure
static uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
struct Int32Vect3 mag_unscaled
unscaled magnetometer measurements
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
struct Int32Vect3 accel
accelerometer measurements in m/s^2 in BFP with INT32_ACCEL_FRAC
ssize_t full_read(int fd, uint8_t *buf, size_t count)
Read from fd even while being interrupted.
void gpio_set(uint32_t port, uint16_t pin)
Set a gpio output to high level.
struct Imu imu
global IMU state
void gpio_clear(uint32_t port, uint16_t pin)
Clear a gpio output to low level.
static void navdata_cmd_send(uint8_t cmd)
Sends a one byte command.
#define DefaultPeriodic
Set default periodic telemetry.
Main navdata structure from the navdata board This is received from the navdata board at ~200Hz...
struct Int32Vect3 mag
magnetometer measurements scaled to 1 in BFP with INT32_MAG_FRAC
ardrone2 navdata aquisition driver.
Inertial Measurement Unit interface.
static void navdata_publish_imu(void)
static bool_t navdata_available
flag to indicate new packet is available in buffer
static const struct usb_device_descriptor dev
#define ARDRONE_GPIO_PIN_NAVDATA
void imu_scale_mag(struct Imu *_imu)
bool_t is_initialized
Check if the navdata board is initialized.
#define NAVDATA_PACKET_SIZE
static pthread_mutex_t navdata_mutex
#define ARDRONE_GPIO_PORT
uint16_t us_association_echo
ssize_t full_write(int fd, const uint8_t *buf, size_t count)
Write to fd even while being interrupted.
#define AGL_SONAR_ARDRONE2_ID
int fd
The navdata file pointer.
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
uint16_t us_distance_echo
static void mag_freeze_check(void)
Check if the magneto is frozen Unknown why this bug happens.
#define NAVDATA_CMD_START
#define SONAR_OFFSET
Sonar offset.
void gpio_setup_output(uint32_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
struct Int32Rates gyro
gyroscope measurements in rad/s in BFP with INT32_RATE_FRAC
uint16_t last_packet_number
static uint8_t navdata_buffer[NAVDATA_PACKET_SIZE]
Buffer filled in the thread (maximum one navdata packet)