*******************************************************************************/
+/** @file bno055_tty.h
+ @brief BNO055 Library - TTY Interface
+*/
+
#ifndef __BNO055_TTY_H__
#define __BNO055_TTY_H__
#include <bno055.h>
-/* \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);
#include <unistd.h>
#include <bno055_tty.h>
+#include <bno055_units.h>
void usage_help(const char *name)
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;
/* TTY interface */
if(BNO055_tty_init(optarg,&bno055))
{
- perror("Error while initializing tty interface");
+ perror("Error initializing tty interface");
return -errno;
}
break;
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);