52 static void *
navdata_read(
void *data __attribute__((unused)));
70 #ifndef NAVDATA_FILTER_ID
71 #define NAVDATA_FILTER_ID 2
79 #define SONAR_OFFSET 880
86 #define SONAR_SCALE 0.00047
96 while (written < count) {
97 ssize_t n = write(fd, buf + written, count - written);
99 if (errno == EAGAIN || errno == EWOULDBLOCK) {
117 while (readed < count) {
118 ssize_t n = read(fd, buf + readed, count - readed);
120 if (errno == EAGAIN || errno == EWOULDBLOCK) {
130 #if PERIODIC_TELEMETRY
135 pprz_msg_send_ARDRONE_NAVDATA(trans, dev, AC_ID,
177 navdata.
fd = open(
"/dev/ttyO1", O_RDWR | O_NOCTTY);
180 printf(
"[navdata] Unable to open navdata board connection(/dev/ttyO1)\n");
187 struct termios options;
191 cfsetispeed(&options,
B460800);
192 cfsetospeed(&options,
B460800);
194 options.c_cflag |= (CLOCAL | CREAD);
197 options.c_oflag &= ~OPOST;
200 tcsetattr(
navdata.
fd, TCSANOW, &options);
204 navdata_available =
false;
221 printf(
"[navdata] Could not acquire baro calibration!\n");
234 pthread_t navdata_thread;
235 if (pthread_create(&navdata_thread, NULL,
navdata_read, NULL) != 0) {
236 printf(
"[navdata] Could not create navdata reading thread!\n");
239 pthread_setname_np(navdata_thread,
"pprz_navdata_thread");
241 #if PERIODIC_TELEMETRY
264 pthread_mutex_lock(&navdata_mutex);
265 while (navdata_available) {
266 pthread_cond_wait(&navdata_cond, &navdata_mutex);
268 pthread_mutex_unlock(&navdata_mutex);
275 buffer_idx += newbytes;
289 fprintf(stderr,
"[navdata] sync error, startbyte not found, resetting...\n");
302 checksum += navdata_buffer[i] + (navdata_buffer[i + 1] << 8);
308 if (new_measurement->
chksum != checksum) {
309 fprintf(stderr,
"[navdata] Checksum error [calculated: %d] [packet: %d] [diff: %d]\n",
310 checksum, new_measurement->
chksum, checksum - new_measurement->
chksum);
316 pthread_mutex_lock(&navdata_mutex);
317 navdata_available =
true;
318 pthread_mutex_unlock(&navdata_mutex);
352 pthread_mutex_lock(&navdata_mutex);
354 if (navdata_available) {
360 navdata_available =
false;
362 pthread_cond_signal(&navdata_cond);
363 pthread_mutex_unlock(&navdata_mutex);
368 fprintf(stderr,
"[navdata] Lost frame: %d should have been %d\n",
401 pthread_mutex_unlock(&navdata_mutex);
425 printf(
"[navdata] Could not read calibration data.");
452 static int16_t LastMagValue = 0;
453 static int MagFreezeCounter = 0;
459 if (MagFreezeCounter > 30) {
460 fprintf(stderr,
"mag freeze detected, resetting!\n");
479 MagFreezeCounter = 0;
484 MagFreezeCounter = 0;
497 static int32_t lastpressval = 0;
499 static int32_t lastpressval_nospike = 0;
500 static uint16_t lasttempval_nospike = 0;
501 static uint8_t temp_or_press_was_updated_last =
504 static int sync_errors = 0;
505 static int spike_detected = 0;
507 if (temp_or_press_was_updated_last == 0) {
509 temp_or_press_was_updated_last =
true;
512 if (lastpressval != 0) {
516 temp_or_press_was_updated_last =
false;
523 temp_or_press_was_updated_last =
false;
526 if (lasttempval != 0) {
530 temp_or_press_was_updated_last =
true;
542 if (lastpressval != 0 && lasttempval != 0
548 if (lastpressval != 0 && lasttempval != 0
602 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...
Dispatcher to register actual AHRS implementations.
static pthread_cond_t navdata_cond
void navdata_update()
Update the navdata (event loop)
bool is_initialized
Check if the navdata board is initialized.
static void gpio_clear(ioportid_t port, uint16_t pin)
Clear a gpio output to low level.
struct bmp180_calib_t bmp180_calib
BMP180 calibration receieved from navboard.
Periodic telemetry system header (includes downlink utility and generated code).
#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).
static bool navdata_baro_calib(void)
Try to receive the baro calibration from the navdata board.
#define SONAR_SCALE
Sonar scale.
#define NAVDATA_CMD_BARO_CALIB
Integrated Navigation System interface.
struct Imu imu
global IMU state
uint16_t temperature_gyro
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
static void baro_update_logic(void)
Handle the baro(pressure/temperature) logic Sometimes the temperature and pressure are switched becau...
uint16_t temperature_pressure
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.
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...
static void send_navdata(struct transport_tx *trans, struct link_device *dev)
struct Int32Vect3 mag
magnetometer measurements scaled to 1 in BFP with INT32_MAG_FRAC
ardrone2 navdata aquisition driver.
Inertial Measurement Unit interface.
void imu_scale_gyro(struct Imu *_imu)
static void navdata_publish_imu(void)
static const struct usb_device_descriptor dev
bool baro_calibrated
Whenever the baro is calibrated.
#define ARDRONE_GPIO_PIN_NAVDATA
static bool navdata_available
flag to indicate new packet is available in buffer
void imu_scale_mag(struct Imu *_imu)
#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.
bool imu_lost
Whenever the imu is lost.
#define AGL_SONAR_ARDRONE2_ID
int fd
The navdata file pointer.
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
void imu_scale_accel(struct Imu *_imu)
uint16_t us_distance_echo
bool baro_available
Whenever the baro is available.
static void mag_freeze_check(void)
Check if the magneto is frozen Unknown why this bug happens.
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
bool navdata_init()
Initialize the navdata board.
#define NAVDATA_CMD_START
static void gpio_set(ioportid_t port, uint16_t pin)
Set a gpio output to high level.
#define SONAR_OFFSET
Sonar offset.
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)