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
123 while (written < count) {
124 ssize_t n = write(
fd, buf + written, count - written);
126 if (errno == EAGAIN || errno == EWOULDBLOCK) {
144 while (readed < count) {
145 ssize_t n = read(
fd, buf + readed, count - readed);
147 if (errno == EAGAIN || errno == EWOULDBLOCK) {
157 #if PERIODIC_TELEMETRY
162 #pragma GCC diagnostic push
163 #pragma GCC diagnostic ignored "-Wpragmas"
164 #pragma GCC diagnostic ignored "-Waddress-of-packed-member"
165 pprz_msg_send_ARDRONE_NAVDATA(trans,
dev, AC_ID,
195 #pragma GCC diagnostic pop
208 navdata.
fd = open(
"/dev/ttyO1", O_RDWR | O_NOCTTY);
211 printf(
"[navdata] Unable to open navdata board connection(/dev/ttyO1)\n");
218 struct termios options;
222 cfsetispeed(&options,
B460800);
223 cfsetospeed(&options,
B460800);
225 options.c_cflag |= (CLOCAL | CREAD);
228 options.c_oflag &= ~OPOST;
231 tcsetattr(
navdata.
fd, TCSANOW, &options);
252 printf(
"[navdata] Could not acquire baro calibration!\n");
270 pthread_t navdata_thread;
271 if (pthread_create(&navdata_thread, NULL,
navdata_read, NULL) != 0) {
272 printf(
"[navdata] Could not create navdata reading thread!\n");
275 pthread_setname_np(navdata_thread,
"pprz_navdata_thread");
277 #if PERIODIC_TELEMETRY
311 buffer_idx += newbytes;
325 fprintf(stderr,
"[navdata] sync error, startbyte not found, resetting...\n");
345 fprintf(stderr,
"[navdata] Checksum error [calculated: %d] [packet: %d] [diff: %d]\n",
415 fprintf(stderr,
"[navdata] Lost frame: %d should have been %d\n",
473 printf(
"[navdata] Could not read calibration data.");
500 static int16_t LastMagValue = 0;
501 static int MagFreezeCounter = 0;
507 if (MagFreezeCounter > 30) {
508 fprintf(stderr,
"mag freeze detected, resetting!\n");
527 MagFreezeCounter = 0;
532 MagFreezeCounter = 0;
545 static int32_t lastpressval = 0;
547 static int32_t lastpressval_nospike = 0;
548 static uint16_t lasttempval_nospike = 0;
549 static uint8_t temp_or_press_was_updated_last =
552 static int sync_errors = 0;
553 static int spike_detected = 0;
555 if (temp_or_press_was_updated_last == 0) {
557 temp_or_press_was_updated_last =
true;
560 if (lastpressval != 0) {
564 temp_or_press_was_updated_last =
false;
571 temp_or_press_was_updated_last =
false;
574 if (lasttempval != 0) {
578 temp_or_press_was_updated_last =
true;
590 if (lastpressval != 0 && lasttempval != 0
596 if (lastpressval != 0 && lasttempval != 0
650 if (spike_detected > 0) {
Main include for ABI (AirBorneInterface).
#define AGL_SONAR_ARDRONE2_ID
Dispatcher to register actual AHRS implementations.
#define ARDRONE_GPIO_PORT
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
static void gpio_set(ioportid_t port, uint16_t pin)
Set a gpio output to high level.
static void gpio_clear(ioportid_t port, uint16_t pin)
Clear a gpio output to low level.
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Some architecture independent helper functions for GPIOs.
void imu_set_defaults_mag(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Vect3 *neutral, const struct Int32Vect3 *scale)
Set the defaults for a mag sensor WARNING: Should be called before sensor is publishing messages to e...
void imu_set_defaults_accel(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Vect3 *neutral, const struct Int32Vect3 *scale)
Set the defaults for a accel sensor WARNING: Should be called before sensor is publishing messages to...
void imu_set_defaults_gyro(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Rates *neutral, const struct Int32Rates *scale)
Set the defaults for a gyro sensor WARNING: Should be called before sensor is publishing messages to ...
Inertial Measurement Unit interface.
Integrated Navigation System interface.
static void mag_freeze_check(void)
Check if the magneto is frozen Unknown why this bug happens.
static bool navdata_baro_calib(void)
Try to receive the baro calibration from the navdata board.
static void send_navdata(struct transport_tx *trans, struct link_device *dev)
ssize_t full_write(int fd, const uint8_t *buf, size_t count)
Write to fd even while being interrupted.
static void * navdata_read(void *data)
Main reading thread This is done asynchronous because the navdata board doesn't support NON_BLOCKING.
static void baro_update_logic(void)
Handle the baro(pressure/temperature) logic Sometimes the temperature and pressure are switched becau...
void navdata_update()
Update the navdata (event loop)
static const struct Int32Vect3 accel_neutral
static void navdata_cmd_send(uint8_t cmd)
Sends a one byte command.
static uint8_t navdata_buffer[NAVDATA_PACKET_SIZE]
Buffer filled in the thread (maximum one navdata packet)
#define SONAR_SCALE
Sonar scale.
static pthread_mutex_t navdata_mutex
static const struct Int32Vect3 mag_scale[2]
Default mag scale.
bool navdata_init()
Initialize the navdata board.
static const struct Int32Rates gyro_scale[2]
Default gyro scale.
static bool navdata_available
flag to indicate new packet is available in buffer
#define SONAR_OFFSET
Sonar offset.
static void navdata_publish_imu(void)
static const struct Int32Vect3 accel_scale[2]
Default accel scale/neutral.
ssize_t full_read(int fd, uint8_t *buf, size_t count)
Read from fd even while being interrupted.
static pthread_cond_t navdata_cond
ardrone2 navdata aquisition driver.
struct bmp180_calib_t bmp180_calib
BMP180 calibration receieved from navboard.
uint16_t temperature_gyro
struct navdata_measure_t measure
Main navdata packet receieved from navboard.
bool imu_lost
Whenever the imu is lost.
bool baro_calibrated
Whenever the baro is calibrated.
#define NAVDATA_START_BYTE
#define ARDRONE_GPIO_PIN_NAVDATA
int fd
The navdata file pointer.
bool baro_available
Whenever the baro is available.
uint16_t us_distance_echo
#define NAVDATA_CMD_START
#define NAVDATA_CMD_BARO_CALIB
uint16_t last_packet_number
#define NAVDATA_PACKET_SIZE
bool is_initialized
Check if the navdata board is initialized.
uint16_t us_association_echo
uint16_t temperature_pressure
Main navdata structure from the navdata board This is received from the navdata board at ~200Hz.
static const struct usb_device_descriptor dev
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.