From: Walter Fetter Lages Date: Tue, 5 Feb 2019 02:04:53 +0000 (-0200) Subject: Remove the use of bno055_convert*() funtions. X-Git-Tag: f1~4 X-Git-Url: http://git.ece.ufrgs.br/?a=commitdiff_plain;h=8b8c11bbda0cd8b8c590c3251f0c1d18ffd9e52d;p=bno055.git Remove the use of bno055_convert*() funtions. Change all displayed values to SI units. Chanage display of quaternion to unit quaternion. --- diff --git a/include/bno055_delay.h b/include/bno055_delay.h index 26631e0..37799f5 100644 --- a/include/bno055_delay.h +++ b/include/bno055_delay.h @@ -19,6 +19,10 @@ *******************************************************************************/ +/** @file bno055_delay.h + @brief BNO055 Library - Delay +*/ + #ifndef __BNO055_DELAY_H__ #define __BNO055_DELAY_H__ @@ -29,8 +33,8 @@ extern "C" #include -/* Brief : Delay routine - * \param : delay in ms +/** @Brief : Delay routine + * @param : delay in ms */ extern void BNO055_delay(u32 ms); diff --git a/include/bno055_tty.h b/include/bno055_tty.h index 5a6e342..cb1d105 100644 --- a/include/bno055_tty.h +++ b/include/bno055_tty.h @@ -19,6 +19,10 @@ *******************************************************************************/ +/** @file bno055_tty.h + @brief BNO055 Library - TTY Interface +*/ + #ifndef __BNO055_TTY_H__ #define __BNO055_TTY_H__ @@ -29,36 +33,36 @@ extern "C" #include -/* \Brief: Bus read - * \Return : Status of the read - * \param dev_addr : Device address of the sensor - * \param reg_addr : Address of the first register to be read - * \param reg_data : Data read from the sensor, - * \param cnt : Number of bytes to be read +/** @Brief: Bus read + * @Return : Status of the read + * @param dev_addr : Device address of the sensor + * @param reg_addr : Address of the first register to be read + * @param reg_data : Data read from the sensor, + * @param cnt : Number of bytes to be read */ extern s8 BNO055_tty_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt); -/* \Brief: TBus write - * \Return : Status of the write - * \param dev_addr : Device address of the sensor - * \param reg_addr : Address of the first register to be written - * \param reg_data : Value to be written into the register - * \param cnt : Number of bytes to be written +/** @Brief: TBus write + * @Return : Status of the write + * @param dev_addr : Device address of the sensor + * @param reg_addr : Address of the first register to be written + * @param reg_data : Value to be written into the register + * @param cnt : Number of bytes to be written */ extern s8 BNO055_tty_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt); -/* - * \Brief: TTY initilization routine - * \Return: 0 on success, -1 on failure and set errno to indicate the error - * \param dev_name: tty device name - * \param bno055: pointer to a bno055 structure +/** + * @Brief: TTY initilization routine + * @Return: 0 on success, -1 on failure and set errno to indicate the error + * @param dev_name: tty device name + * @param bno055: pointer to a bno055 structure */ extern int BNO055_tty_init(const char *dev_name,struct bno055_t *bno055); -/* - * \Brief: TTY close routine - * \Return: 0 on success, -1 on failure and set errno to indicate the error - * \param bno055: pointer to a bno055 structure +/** + * @Brief: TTY close routine + * @Return: 0 on success, -1 on failure and set errno to indicate the error + * @param bno055: pointer to a bno055 structure */ extern int BNO055_tty_close(struct bno055_t *bno055); diff --git a/include/bno055_units.h b/include/bno055_units.h new file mode 100644 index 0000000..79ba236 --- /dev/null +++ b/include/bno055_units.h @@ -0,0 +1,44 @@ +/****************************************************************************** + BNO055 Library + Extra Units Definitions + Copyright (C) 2019 Walter Fetter Lages + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + . + +*******************************************************************************/ + +/** @file bno055_units.h + @brief BNO055 Library - Extra Units Definitions +*/ + +#ifndef __BNO055_UNITS_H__ +#define __BNO055_UNITS_H__ + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** Set Tilt unit to radians */ +#define BNO055_TILT_UNIT_RAD BNO055_EULER_UNIT_RAD + +/** Quaternion division factor */ +#define BNO055_QUATERNION_DIV 16384.0 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/test/bno055_test.c b/test/bno055_test.c index d4d7577..ce1cc42 100644 --- a/test/bno055_test.c +++ b/test/bno055_test.c @@ -24,6 +24,7 @@ #include #include +#include void usage_help(const char *name) @@ -46,16 +47,7 @@ int main(int argc,char *argv[]) struct bno055_linear_accel_t linear_accel; struct bno055_gravity_t gravity; - struct bno055_accel_double_t d_accel; - struct bno055_mag_double_t d_mag; - struct bno055_gyro_double_t d_gyro; - - struct bno055_euler_double_t d_euler; - struct bno055_linear_accel_double_t d_linear_accel; - struct bno055_gravity_double_t d_gravity; - s8 temp; - double d_temp; u8 stat_clk; u8 clk_src; @@ -74,7 +66,7 @@ int main(int argc,char *argv[]) /* TTY interface */ if(BNO055_tty_init(optarg,&bno055)) { - perror("Error while initializing tty interface"); + perror("Error initializing tty interface"); return -errno; } break; @@ -93,88 +85,96 @@ int main(int argc,char *argv[]) printf("Gyroscope id=0x%02x\n",bno055.gyro_rev_id); printf("Boot loader id=0x%02x\n",bno055.bl_rev_id); } - else fprintf(stderr,"Error while initializing bno055.\n"); + else fprintf(stderr,"Error initializing bno055.\n"); if(bno055_get_stat_main_clk(&stat_clk) != BNO055_SUCCESS) - fprintf(stderr,"Error while reading clock status.\n"); + fprintf(stderr,"Error reading clock status.\n"); else { if(stat_clk==0) { clk_src=1; - if(bno055_set_clk_src(clk_src) != BNO055_SUCCESS) fprintf(stderr,"Error while setting clock source.\n"); + if(bno055_set_clk_src(clk_src) != BNO055_SUCCESS) fprintf(stderr,"Error setting clock source.\n"); else printf("Clock source changed to external\n"); } - else printf("Clock source can't be changed.\n"); + else fprintf(stderr,"Clock source can't be changed.\n"); } - printf("Raw data:\n"); - if(bno055_set_operation_mode(BNO055_OPERATION_MODE_AMG) != BNO055_SUCCESS) - fprintf(stderr,"Error while setting operation mode.\n"); + if(bno055_set_accel_unit(BNO055_ACCEL_UNIT_MSQ) == BNO055_SUCCESS) + printf("Acceleration unit set to m/s^2.\n"); + else fprintf(stderr,"Error setting acceleration unit to m/s^2.\n"); + + if(bno055_set_gyro_unit(BNO055_GYRO_UNIT_RPS) == BNO055_SUCCESS) + printf("Gyroscope unit set to rad/s.\n"); + else fprintf(stderr,"Error setting gyroscope unit to rad/s.\n"); + + if(bno055_set_euler_unit(BNO055_EULER_UNIT_RAD) == BNO055_SUCCESS) + printf("Euler angles unit set to rad.\n"); + else fprintf(stderr,"Error setting Euler angles unit to rad.\n"); + + if(bno055_set_tilt_unit(BNO055_TILT_UNIT_RAD) == BNO055_SUCCESS) + printf("Tilt unit set to rad.\n"); + else fprintf(stderr,"Error setting tilt unit to rad.\n"); + + if(bno055_set_temp_unit(BNO055_TEMP_UNIT_CELSIUS) == BNO055_SUCCESS) + printf("Temperature unit set to Celsius.\n"); + else fprintf(stderr,"Error setting temperature unit to Celsius.\n"); + + if(bno055_set_data_output_format(0x01) == BNO055_SUCCESS) + printf("Data output format set to Android.\n"); + else fprintf(stderr,"Error setting data output format.\n"); + + if(bno055_set_operation_mode(BNO055_OPERATION_MODE_AMG) == BNO055_SUCCESS) + printf("Operation mode set to AMG: raw (uncompesated) data.\n"); + else fprintf(stderr,"Error setting operation mode t0 AMG.\n"); if(bno055_read_accel_xyz(&accel) == BNO055_SUCCESS) - printf("Acceleration=%d, %d, %d\n",accel.x,accel.y,accel.z); - else fprintf(stderr,"Error while reading acceleration.\n"); + printf("Acceleration=%G, %G, %G m/s^2\n",accel.x/BNO055_ACCEL_DIV_MSQ,accel.y/BNO055_ACCEL_DIV_MSQ,accel.z/BNO055_ACCEL_DIV_MSQ); + else fprintf(stderr,"Error reading acceleration.\n"); if(bno055_read_mag_xyz(&mag) == BNO055_SUCCESS) - printf("Magnetometer=%d, %d, %d\n",mag.x,mag.y,mag.z); - else fprintf(stderr,"Error while reading magnetometer.\n"); + printf("Magnetometer=%G, %G, %G uT\n",mag.x/BNO055_MAG_DIV_UT,mag.y/BNO055_MAG_DIV_UT,mag.z/BNO055_MAG_DIV_UT); + else fprintf(stderr,"Error reading magnetometer.\n"); if(bno055_read_gyro_xyz(&gyro) == BNO055_SUCCESS) - printf("Gyroscope=%d, %d, %d\n",gyro.x,gyro.y,gyro.z); - else fprintf(stderr,"Error while reading gyroscope.\n"); + printf("Gyroscope=%G, %G, %G rad/s\n",gyro.x/BNO055_GYRO_DIV_RPS,gyro.y/BNO055_GYRO_DIV_RPS,gyro.z/BNO055_GYRO_DIV_RPS); + else fprintf(stderr,"Error reading gyroscope.\n"); if(bno055_read_temp_data(&temp) == BNO055_SUCCESS) - printf("Temperature=%d\n",temp); - else fprintf(stderr,"Error while reading temperature.\n"); + printf("Temperature=%d Celsius\n",temp/BNO055_TEMP_DIV_CELSIUS); + else fprintf(stderr,"Error reading temperature.\n"); - if(bno055_set_operation_mode(BNO055_OPERATION_MODE_NDOF) != BNO055_SUCCESS) - fprintf(stderr,"Error while setting operation mode.\n"); + if(bno055_set_operation_mode(BNO055_OPERATION_MODE_NDOF) == BNO055_SUCCESS) + printf("Opertation mode set to NDOF: fused (offset and tilt compensated data).\n"); + else fprintf(stderr,"Error setting operation mode to NDOF.\n"); + + if(bno055_read_accel_xyz(&accel) == BNO055_SUCCESS) + printf("Acceleration=%G, %G, %G m/s^2\n",accel.x/BNO055_ACCEL_DIV_MSQ,accel.y/BNO055_ACCEL_DIV_MSQ,accel.z/BNO055_ACCEL_DIV_MSQ); + else fprintf(stderr,"Error reading acceleration.\n"); + + if(bno055_read_mag_xyz(&mag) == BNO055_SUCCESS) + printf("Magnetometer=%G, %G, %G uT\n",mag.x/BNO055_MAG_DIV_UT,mag.y/BNO055_MAG_DIV_UT,mag.z/BNO055_MAG_DIV_UT); + else fprintf(stderr,"Error reading magnetometer.\n"); + + if(bno055_read_gyro_xyz(&gyro) == BNO055_SUCCESS) + printf("Gyroscope=%G, %G, %G rad/s\n",gyro.x/BNO055_GYRO_DIV_RPS,gyro.y/BNO055_GYRO_DIV_RPS,gyro.z/BNO055_GYRO_DIV_RPS); + else fprintf(stderr,"Error reading gyroscope.\n"); - printf("Fused data:\n"); if(bno055_read_euler_hrp(&euler) == BNO055_SUCCESS) - printf("Euler angles=%d, %d, %d\n",euler.h,euler.r,euler.p); - else fprintf(stderr,"Error while reading Euler angles.\n"); + printf("Euler angles=%G, %G, %G rad\n",euler.h/BNO055_EULER_DIV_RAD,euler.r/BNO055_EULER_DIV_RAD,euler.p/BNO055_EULER_DIV_RAD); + else fprintf(stderr,"Error reading Euler angles.\n"); if(bno055_read_quaternion_wxyz(&quaternion) == BNO055_SUCCESS) - printf("Quaternion=%d, %d, %d, %d\n",quaternion.w,quaternion.x,quaternion.y,quaternion.z); - else fprintf(stderr,"Error while reading quaternion.\n"); - + printf("Quaternion=%G, %G, %G, %G\n",quaternion.w/BNO055_QUATERNION_DIV,quaternion.x/BNO055_QUATERNION_DIV,quaternion.y/BNO055_QUATERNION_DIV,quaternion.z/BNO055_QUATERNION_DIV); + else fprintf(stderr,"Error reading quaternion.\n"); + if(bno055_read_linear_accel_xyz(&linear_accel) == BNO055_SUCCESS) - printf("Linear acceleration=%d, %d, %d\n",linear_accel.x,linear_accel.y,linear_accel.z); - else fprintf(stderr,"Error while reading linear acceleration.\n"); + printf("Linear acceleration=%G, %G, %G m/s^2\n",linear_accel.x/BNO055_LINEAR_ACCEL_DIV_MSQ,linear_accel.y/BNO055_LINEAR_ACCEL_DIV_MSQ,linear_accel.z/BNO055_LINEAR_ACCEL_DIV_MSQ); + else fprintf(stderr,"Error reading linear acceleration.\n"); if(bno055_read_gravity_xyz(&gravity) == BNO055_SUCCESS) - printf("Gravity=%d, %d, %d\n",gravity.x,gravity.y,gravity.z); - else fprintf(stderr,"Error while reading gravity.\n"); - - if(bno055_convert_double_accel_xyz_msq(&d_accel) == BNO055_SUCCESS) - printf("Acceleration=%G, %G, %G m/s^2\n",d_accel.x,d_accel.y,d_accel.z); - else fprintf(stderr,"Error while reading acceleration in m/s^2.\n"); - - if(bno055_convert_double_mag_xyz_uT(&d_mag) == BNO055_SUCCESS) - printf("Magnetometer=%G, %G, %G uT\n",d_mag.x,d_mag.y,d_mag.z); - else fprintf(stderr,"Error while reading magnetometer in uT.\n"); - - if(bno055_convert_double_gyro_xyz_rps(&d_gyro) == BNO055_SUCCESS) - printf("Gyroscope=%G, %G, %G rad/s\n",d_gyro.x,d_gyro.y,d_gyro.z); - else fprintf(stderr,"Error while reading gyroscope in rad/s.\n"); - - if(bno055_convert_double_euler_hpr_rad(&d_euler) == BNO055_SUCCESS) - printf("Euler angles=%G, %G, %G rad\n",d_euler.h,d_euler.p,d_euler.r); - else fprintf(stderr,"Error while reading Euler angles in rad.\n"); - - if(bno055_convert_double_linear_accel_xyz_msq(&d_linear_accel) == BNO055_SUCCESS) - printf("Linear acceleration=%G, %G, %G m/s^2\n",d_linear_accel.x,d_linear_accel.y,d_linear_accel.z); - else fprintf(stderr,"Error while readint linear acceleration in m/s^2.\n"); - - if(bno055_convert_double_gravity_xyz_msq(&d_gravity) == BNO055_SUCCESS) - printf("Gravity=%G, %G, %G m/s^2\n",d_gravity.x,d_gravity.y,d_gravity.z); - else fprintf(stderr,"Error while reading gravity in m/s^2.\n"); - - if(bno055_convert_double_temp_celsius(&d_temp) == BNO055_SUCCESS) - printf("Temperature=%G degrees Celsius\n",d_temp); - else fprintf(stderr,"Error while reading temperature in degrees Celsius.\n"); + printf("Gravity=%G, %G, %G m/s^2\n",gravity.x/BNO055_GRAVITY_DIV_MSQ,gravity.y/BNO055_GRAVITY_DIV_MSQ,gravity.z/BNO055_GRAVITY_DIV_MSQ); + else fprintf(stderr,"Error reading gravity.\n"); BNO055_tty_close(&bno055);