imu.c
/*******************************************************************************
* examples/imu.c *
* ============== *
* *
* Version: 1.2.0 *
* Date : 05.11.18 *
* Author : Peter Weissig *
* *
* If you are changing this file, you may also consider to update *
* demos/diagnosticTool/diagnosticTool.c *
*******************************************************************************/
//*********************************<Included files>*****************************
#include <tucbot/tucbot.h>
//*********************************<Methods>************************************
void testImu_print(int16_t value, uint8_t digits);
void testImu(void);
int main(void);
//*********************************[testImu_print]******************************
void testImu_print(int16_t value, uint8_t digits) {
int16_t temp_value = value ;
uint8_t temp_digits = digits;
if ((temp_value < 0) && temp_digits) {
temp_digits--;
temp_value = -temp_value;
}
while (temp_digits) {
temp_value/= 10;
temp_digits--;
}
if (temp_value == 0) {
int16tostr(lcdout, value, digits);
} else if (value >= 0) {
while (digits) {
lcdout('+');
digits--;
}
} else {
while (digits) {
lcdout('-');
digits--;
}
}
}
//*********************************[testImu]************************************
void testImu(void) {
uint8_t resolution;
int16_t orientation;
int16_t orientation_display;
uint8_t countdown = 0;
uint8_t flag_redraw_menu = 0xFF;
lcdclr();
lcdxy(0,1);
lcdstr_p(PSTR("x####y#### Z####"));
while (1) {
if (flag_redraw_menu) {
flag_redraw_menu = 0x00;
orientation_display = 0x7FFF; // force update on new data
lcdxy(0,0);
// "Imu ###°C ####°"
lcdstr_p(PSTR("Imu ###" "\xDF" "C ####" "\xDF"));
}
mdelay(100);
lcdxy(4,0);
lcdstr_p(PSTR(" calibrating")); // "Imu calibrating"
mdelay(250);
flag_redraw_menu = 0xFF;
countdown = 0;
} else if (buttons_get(kButtonRight)) {
mdelay(100);
lcdxy(4,0);
lcdstr_p(PSTR("setRes. ")); // "Imu setRes. "
mdelay(100);
// get current resolution
// setup and print next resolution
switch (resolution) {
resolution = kImuGyroResolution500;
lcdstr_p(PSTR(" 500")); // "Imu setRes. 500"
break;
resolution = kImuGyroResolution1000;
lcdstr_p(PSTR("1000")); // "Imu setRes. 1000"
break;
resolution = kImuGyroResolution2000;
lcdstr_p(PSTR("2000")); // "Imu setRes. 2000"
break;
resolution = kImuGyroResolution250;
lcdstr_p(PSTR(" 250")); // "Imu setRes. 250"
break;
default:
resolution = kImuGyroResolution500;
lcdstr_p(PSTR("500!")); // "Imu setRes. 500!"
break;
}
// switch to next resolution
// check for errors
if (imu_get(kImuGetGyroResolution) != resolution) {
lcdxy(12,0);
lcdstr_p(PSTR(" ERR")); // "Imu setRes. ERR"
}
// wait a bit
mdelay(1000);
// reset absolute orientation
flag_redraw_menu = 0xFF;
countdown = 0;
}
if (countdown) {
countdown--;
} else {
countdown = 5;
lcdxy(5,0);
testImu_print((imu_get(kImuGetTemperature) + 5)/ 10,3);
}
if (orientation != orientation_display) {
orientation_display = orientation;
lcdxy(11,0); testImu_print(orientation,4);
}
lcdxy( 1,1); testImu_print(imu_get(kImuGetAccelX),4);
lcdxy( 6,1); testImu_print(imu_get(kImuGetAccelY),4);
}
lcdxy(12,1); testImu_print(imu_get(kImuGetGyroZ),4);
}
}
mdelay(100);
}
}
//*********************************[main]***************************************
int main (void) {
init_tucbot(0xFF);
testImu();
return (0);
}
leds_set
void leds_set(eLedMask bitmask, uint8_t bool)
Sets the selected leds on or off.
kImuGetAccelX
@ kImuGetAccelX
Definition: imu.h:289
buttons_get
eButtonMask buttons_get(eButtonMask bitmask)
Returns the last stored value of the selected buttons.
kImuSetGyroResolution
@ kImuSetGyroResolution
Definition: imu.h:373
kButtonMiddle
@ kButtonMiddle
bit mask (0x08): middle button
Definition: buttons.h:35
kImuGyroResolution250
@ kImuGyroResolution250
Definition: imu.h:128
imu_calibrate
uint8_t imu_calibrate(void)
Sets the three offsets through simple bias estimation.
kImuGetGyroZ
@ kImuGetGyroZ
Definition: imu.h:299
kImuGetAccelY
@ kImuGetAccelY
Definition: imu.h:294
kLedOn
@ kLedOn
constant (0xFF): turn leds on
Definition: leds.h:63
kLedRight
@ kLedRight
bit mask (0x04): right led
Definition: leds.h:46
kImuSetOrientation
@ kImuSetOrientation
Definition: imu.h:364
kButtonRight
@ kButtonRight
bit mask (0x10): right button
Definition: buttons.h:37
kImuSelectGyroscope
@ kImuSelectGyroscope
bit mask (0x04): angular velocities (16-bit)
Definition: imu.h:273
imu_changed
eImuSelectMask imu_changed(eImuSelectMask bitmask)
Indicates if new data changed the selected data blocks.
buttons_request
void buttons_request(eRequestType request)
Requests new data from the buttons.
int16tostr
void int16tostr(void *out, int16_t number, uint8_t digits)
Converts an integer to a string and passes it to an output function.
kImuSelectAccelerometer
@ kImuSelectAccelerometer
Definition: imu.h:267
kImuGetTemperature
@ kImuGetTemperature
Definition: imu.h:305
kImuGetGyroResolution
@ kImuGetGyroResolution
Definition: imu.h:322
kRequestContinuous
@ kRequestContinuous
constant (3): request continuous updates
Definition: update.h:37
kLedMiddle
@ kLedMiddle
bit mask (0x08): middle led
Definition: leds.h:44
kLedOff
@ kLedOff
constant (0x00): turn leds off
Definition: leds.h:61
kImuGyroResolution500
@ kImuGyroResolution500
Definition: imu.h:131
kImuGyroResolution1000
@ kImuGyroResolution1000
Definition: imu.h:134
imu_set
void imu_set(eImuSet select, int16_t value)
Sets the selected value of the imu sensors.
lcdclr
void lcdclr(void)
Clears the display.
lcdxy
void lcdxy(uint8_t x, uint8_t y)
Moves the cursor to a postion on the display.
imu_request
void imu_request(eImuSelectMask bitmask, eRequestType request)
Requests new data from the imu.
orientation
#define orientation
deprecated constant: see kLausTrackerGetSelfOrientation
Definition: backward.h:880
imu_get
int16_t imu_get(eImuGet select)
Returns the last stored version of the selected value.
kImuGetOrientation
@ kImuGetOrientation
Definition: imu.h:285
lcdstr_p
void lcdstr_p(const char *send_data)
Writes a string located in the flash to the display.
lcdout
void lcdout(uint8_t data)
Writes one byte to the display.
init_tucbot
void init_tucbot(uint8_t enable_interrupts)
Initiates the TUC-Bot.
mdelay
void mdelay(uint16_t mseconds)
Waits for the given time in milliseconds.
kImuSelectAll
@ kImuSelectAll
bit mask (0x07): select all data blocks
Definition: imu.h:275
kImuGyroResolution2000
@ kImuGyroResolution2000
Definition: imu.h:137
kImuSelectTemperature
@ kImuSelectTemperature
Definition: imu.h:270