diff --git a/docs/api.md b/docs/api.md index 5ced974..7c463c0 100644 --- a/docs/api.md +++ b/docs/api.md @@ -116,6 +116,15 @@ Represents a Modulino Movement module. - **`float getZ()`** Returns the Z-axis acceleration. +- **`float getRoll()`** + Returns the angular velocity around X-axis. + +- **`float getPitch()`** + Returns the angular velocity around Y-axis. + +- **`float getYaw()`** + Returns the angular velocity around Z-axis. + --- ### ModulinoThermo diff --git a/examples/Modulino_Movement/Movement_Basic/Movement_Basic.ino b/examples/Modulino_Movement/Movement_Basic/Movement_Basic.ino index 8de9a97..4868dca 100644 --- a/examples/Modulino_Movement/Movement_Basic/Movement_Basic.ino +++ b/examples/Modulino_Movement/Movement_Basic/Movement_Basic.ino @@ -11,9 +11,10 @@ // Create a ModulinoMovement ModulinoMovement movement; -float x; -float y; -float z; + +float x, y, z; +float roll, pitch, yaw; + void setup() { Serial.begin(9600); @@ -24,19 +25,34 @@ void setup() { } void loop() { - // Read new acceleration data from the sensor + // Read new movement data from the sensor movement.update(); - // Get the acceleration values for each axis (in Gs) + // Get acceleration and gyroscope values x = movement.getX(); y = movement.getY(); z = movement.getZ(); + roll = movement.getRoll(); + pitch = movement.getPitch(); + yaw = movement.getYaw(); - Serial.print("Movement data: "); - Serial.print("x "); + // Print acceleration values + Serial.print("A: "); Serial.print(x, 3); - Serial.print(" y "); + Serial.print(", "); Serial.print(y, 3); - Serial.print(" z "); - Serial.println(z, 3); + Serial.print(", "); + Serial.print(z, 3); + + // Print divider between acceleration and gyroscope + Serial.print(" | G: "); + + // Print gyroscope values + Serial.print(roll, 1); + Serial.print(", "); + Serial.print(pitch, 1); + Serial.print(", "); + Serial.println(yaw, 1); + + delay(200); } \ No newline at end of file diff --git a/src/Modulino.h b/src/Modulino.h index aa259da..6f62aaf 100644 --- a/src/Modulino.h +++ b/src/Modulino.h @@ -313,13 +313,15 @@ class ModulinoMovement : public Module { } int update() { if (initialized) { - return _imu->readAcceleration(x, y, z); + int accel = _imu->readAcceleration(x, y, z); + int gyro = _imu->readGyroscope(roll, pitch, yaw); + return accel && gyro; } return 0; } int available() { if (initialized) { - return _imu->accelerationAvailable(); + return _imu->accelerationAvailable() && _imu->gyroscopeAvailable(); } return 0; } @@ -332,9 +334,19 @@ class ModulinoMovement : public Module { float getZ() { return z; } + float getRoll() { + return roll; + } + float getPitch() { + return pitch; + } + float getYaw() { + return yaw; + } private: LSM6DSOXClass* _imu = nullptr; float x,y,z; + float roll,pitch,yaw; //gx, gy, gz int initialized = 0; };