Skip to content

Commit 08a4fe1

Browse files
[PXCT-768] Modulino Movement Gyroscope readings (#29)
* AddedGyro * Added Gyro to Basic * Added more accurate terminology roll, pitch, yaw * Update api.md Added info on the movement modulino for angular velocity
1 parent 8441dd9 commit 08a4fe1

File tree

3 files changed

+49
-12
lines changed

3 files changed

+49
-12
lines changed

docs/api.md

+9
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ Represents a Modulino Movement module.
116116
- **`float getZ()`**
117117
Returns the Z-axis acceleration.
118118

119+
- **`float getRoll()`**
120+
Returns the angular velocity around X-axis.
121+
122+
- **`float getPitch()`**
123+
Returns the angular velocity around Y-axis.
124+
125+
- **`float getYaw()`**
126+
Returns the angular velocity around Z-axis.
127+
119128
---
120129

121130
### ModulinoThermo

examples/Modulino_Movement/Movement_Basic/Movement_Basic.ino

+26-10
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
// Create a ModulinoMovement
1212
ModulinoMovement movement;
1313

14-
float x;
15-
float y;
16-
float z;
14+
15+
float x, y, z;
16+
float roll, pitch, yaw;
17+
1718

1819
void setup() {
1920
Serial.begin(9600);
@@ -24,19 +25,34 @@ void setup() {
2425
}
2526

2627
void loop() {
27-
// Read new acceleration data from the sensor
28+
// Read new movement data from the sensor
2829
movement.update();
2930

30-
// Get the acceleration values for each axis (in Gs)
31+
// Get acceleration and gyroscope values
3132
x = movement.getX();
3233
y = movement.getY();
3334
z = movement.getZ();
35+
roll = movement.getRoll();
36+
pitch = movement.getPitch();
37+
yaw = movement.getYaw();
3438

35-
Serial.print("Movement data: ");
36-
Serial.print("x ");
39+
// Print acceleration values
40+
Serial.print("A: ");
3741
Serial.print(x, 3);
38-
Serial.print(" y ");
42+
Serial.print(", ");
3943
Serial.print(y, 3);
40-
Serial.print(" z ");
41-
Serial.println(z, 3);
44+
Serial.print(", ");
45+
Serial.print(z, 3);
46+
47+
// Print divider between acceleration and gyroscope
48+
Serial.print(" | G: ");
49+
50+
// Print gyroscope values
51+
Serial.print(roll, 1);
52+
Serial.print(", ");
53+
Serial.print(pitch, 1);
54+
Serial.print(", ");
55+
Serial.println(yaw, 1);
56+
57+
delay(200);
4258
}

src/Modulino.h

+14-2
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,15 @@ class ModulinoMovement : public Module {
313313
}
314314
int update() {
315315
if (initialized) {
316-
return _imu->readAcceleration(x, y, z);
316+
int accel = _imu->readAcceleration(x, y, z);
317+
int gyro = _imu->readGyroscope(roll, pitch, yaw);
318+
return accel && gyro;
317319
}
318320
return 0;
319321
}
320322
int available() {
321323
if (initialized) {
322-
return _imu->accelerationAvailable();
324+
return _imu->accelerationAvailable() && _imu->gyroscopeAvailable();
323325
}
324326
return 0;
325327
}
@@ -332,9 +334,19 @@ class ModulinoMovement : public Module {
332334
float getZ() {
333335
return z;
334336
}
337+
float getRoll() {
338+
return roll;
339+
}
340+
float getPitch() {
341+
return pitch;
342+
}
343+
float getYaw() {
344+
return yaw;
345+
}
335346
private:
336347
LSM6DSOXClass* _imu = nullptr;
337348
float x,y,z;
349+
float roll,pitch,yaw; //gx, gy, gz
338350
int initialized = 0;
339351
};
340352

0 commit comments

Comments
 (0)