Voss Connection Detection  1
Detect a connector click using realtime code on Bela hardware
gyro.cpp
Go to the documentation of this file.
1 #include "gyro.h"
2 #include "SimpleGPIO.h"
3 #include "ICM20948.h"
4 
5 void raw_gyro_auxtask_callback(void* gyro_ptr) {
6  Gyro* gyro = static_cast<Gyro*>(gyro_ptr);
7  gyro->loop();
8 }
9 
10 Gyro::Gyro(BelaContext* ctx) {
11  // 0x69 is the address of I2C of the Gyro. 1 is the bus.
12  _gyro = new ICM20948(1, 0x69);
13  _gyro->ResetChip();
14  _gyro->WakeUp();
15 
16  _task = Bela_createAuxiliaryTask(raw_gyro_auxtask_callback,
17  50, "Gyro_task", this);
18  Bela_scheduleAuxiliaryTask(_task);
19 }
20 
21 std::array<float, 6> Gyro::get_raw() const {
22  Bela_scheduleAuxiliaryTask(_task);
23  return {
24  _gyro->getGyroX(),
25  _gyro->getGyroY(),
26  _gyro->getGyroZ(),
27  _gyro->getAccX(),
28  _gyro->getAccY(),
29  _gyro->getAccZ()
30  };
31 }
32 
33 std::array<float, 2> Gyro::get_abs() const {
34  Bela_scheduleAuxiliaryTask(_task);
35  return {
36  _gyro->getGyroAbs(),
37  _gyro->getAccAbs(),
38  };
39 
40 }
41 
42 void Gyro::loop() {
43 
44  _gyro->readFullSensorState();
45 
46 }
47 
48 
49 bool Gyro::error() const {
50  return _gyro->error();
51 }
53  _gyro->resetError();
54 }
ICM20948::WakeUp
void WakeUp()
Definition: ICM20948.cpp:127
Gyro::error
bool error() const
Returns whether an error occured during the last readout of the IMU sensor.
Definition: gyro.cpp:49
ICM20948::getGyroAbs
float getGyroAbs()
Definition: ICM20948.h:71
SimpleGPIO.h
ICM20948.h
Gyro::get_abs
std::array< float, 2 > get_abs() const
Get the absolute values of the acceleration and rotation speed. Scaled such that the value is always ...
Definition: gyro.cpp:33
Gyro::get_raw
std::array< float, 6 > get_raw() const
Get the current values of the gyroscope, the first three are the angular velocities,...
Definition: gyro.cpp:21
raw_gyro_auxtask_callback
void raw_gyro_auxtask_callback(void *gyro_ptr)
Definition: gyro.cpp:5
ICM20948::getAccZ
float getAccZ() const
Definition: ICM20948.h:76
ICM20948::readFullSensorState
int readFullSensorState()
Definition: ICM20948.cpp:50
ICM20948::getAccX
float getAccX() const
Definition: ICM20948.h:74
Gyro
Readout of IMU sensor data.
Definition: gyro.h:9
ICM20948::ResetChip
void ResetChip()
Definition: ICM20948.cpp:183
Gyro::raw_gyro_auxtask_callback
friend void raw_gyro_auxtask_callback(void *gyro_ptr)
Definition: gyro.cpp:5
ICM20948::error
bool error() const
Definition: ICM20948.h:78
Gyro::resetError
void resetError()
Reset a previous found error in the sensor.
Definition: gyro.cpp:52
ICM20948::getAccY
float getAccY() const
Definition: ICM20948.h:75
ICM20948::getGyroX
float getGyroX() const
Definition: ICM20948.h:67
Gyro::Gyro
Gyro(BelaContext *ctx)
Initialze Gyro class.
Definition: gyro.cpp:10
ICM20948
Definition: ICM20948.h:31
ICM20948::getGyroY
float getGyroY() const
Definition: ICM20948.h:68
ICM20948::getGyroZ
float getGyroZ() const
Definition: ICM20948.h:69
ICM20948::getAccAbs
float getAccAbs()
Definition: ICM20948.h:72
gyro.h
ICM20948::resetError
void resetError()
Definition: ICM20948.h:79