diff --git a/src/BaselineOfPharoThings.package/BaselineOfPharoThings.class/instance/devices.st b/src/BaselineOfPharoThings.package/BaselineOfPharoThings.class/instance/devices.st index 3c1634e..73facd8 100644 --- a/src/BaselineOfPharoThings.package/BaselineOfPharoThings.class/instance/devices.st +++ b/src/BaselineOfPharoThings.package/BaselineOfPharoThings.class/instance/devices.st @@ -9,5 +9,6 @@ devices #'PharoThings-Devices-ADXL345' -> #(#'PharoThings-Devices-I2C'). #'PharoThings-Devices-MCP9808' -> #(#'PharoThings-Devices-I2C'). #'PharoThings-Devices-BME280' -> #(#'PharoThings-Devices-I2C'). - #'PharoThings-Devices-HD44780' -> #(#'PharoThings-Devices-I2C') + #'PharoThings-Devices-HD44780' -> #(#'PharoThings-Devices-I2C'). + #'PharoThings-Devices-MPU6050' -> #(#'PharoThings-Devices-I2C') } \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/.filetree b/src/PharoThings-Devices-MPU6050.package/.filetree new file mode 100644 index 0000000..57a6797 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/.filetree @@ -0,0 +1,5 @@ +{ + "separateMethodMetaAndSource" : false, + "noMethodMetaData" : true, + "useCypressPropertiesFile" : true +} \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/README.md b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/README.md new file mode 100644 index 0000000..d354b58 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/README.md @@ -0,0 +1,24 @@ +I provide implementation of Gyroscope/Accelerator I2C sensor MPU6050. + +The code for initialization and sensors reading is based from example: + https://tutorials-raspberrypi.com/measuring-rotation-and-acceleration-raspberry-pi/ + +Register map: + https://www.i2cdevlib.com/devices/mpu6050#registers + +To use it: +sensor := (RpiBoard3B current) installDevice: PotMPU6050Device new. +or on inspector: +sensor := board installDevice: PotMPU6050Device new. + +API: +readGyroscope. "#(1540 -9 -211)" +readGyroscopeSkaliert. "#(13.526718 -1.916031 -1.526718)" +readAccelerometer. "#(748 -892 15676)" +readAccelerometerSkaliert. "#(0.033691 -0.051025 0.974121)" +readRotationXY. "#(-3.224775339993247 -2.4755961852044157)" + +sensor := (RpiBoard3B current) installDevice: PotMPU6050Device new. +sensor readRollPitchYaw +sensor printRollPitchYaw. +sensor finishRollPitchYaw. \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/class/defaultI2CAddress.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/class/defaultI2CAddress.st new file mode 100644 index 0000000..7e7c828 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/class/defaultI2CAddress.st @@ -0,0 +1,3 @@ +instance creation +defaultI2CAddress + ^16r68 \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateDistanceA.B..st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateDistanceA.B..st new file mode 100644 index 0000000..8a1ba48 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateDistanceA.B..st @@ -0,0 +1,3 @@ +controlling +calculateDistanceA: anAccelerometerScaledA B: anAccelerometerScaledB + ^ ((anAccelerometerScaledA*anAccelerometerScaledA)+(anAccelerometerScaledB*anAccelerometerScaledB)) sqrt \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateRotationX.Y.Z..st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateRotationX.Y.Z..st new file mode 100644 index 0000000..28edfdd --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateRotationX.Y.Z..st @@ -0,0 +1,8 @@ +controlling +calculateRotationX: anAccelerometerScaledX Y: anAccelerometerScaledY Z: anAccelerometerScaledZ + | radiansX radiansY rotationX rotationY | + radiansX := anAccelerometerScaledY arcTan: (self calculateDistanceA: anAccelerometerScaledX B: anAccelerometerScaledZ). + radiansY := anAccelerometerScaledX arcTan: (self calculateDistanceA: anAccelerometerScaledY B: anAccelerometerScaledZ). + rotationX := radiansX radiansToDegrees. + rotationY := radiansY radiansToDegrees * -1. + ^ { rotationX . rotationY } \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/connect.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/connect.st new file mode 100644 index 0000000..7da32b0 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/connect.st @@ -0,0 +1,5 @@ +controlling +connect + super connect. + self wakeUpSensor + diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometer.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometer.st new file mode 100644 index 0000000..c6a110f --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometer.st @@ -0,0 +1,7 @@ +controlling +readAccelerometer + | accX accY accZ | + accX := self readRegisters2C: 16r3b. + accY := self readRegisters2C: 16r3d. + accZ := self readRegisters2C: 16r3f. + ^ { accX . accY . accZ } \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometerScaled.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometerScaled.st new file mode 100644 index 0000000..6b15381 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometerScaled.st @@ -0,0 +1,8 @@ +controlling +readAccelerometerScaled + | acc accX accY accZ | + acc := self readAccelerometer. + accX := ((acc at: 1)/16384) asFloat round: 6. + accY := ((acc at: 2)/16384) asFloat round: 6. + accZ := ((acc at: 3)/16384) asFloat round: 6. + ^ { accX . accY . accZ } \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscope.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscope.st new file mode 100644 index 0000000..904c66f --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscope.st @@ -0,0 +1,7 @@ +controlling +readGyroscope + | gyroX gyroY gyroZ | + gyroX := self readRegisters2C: 16r43. + gyroY := self readRegisters2C: 16r45. + gyroZ := self readRegisters2C: 16r47. + ^ { gyroX . gyroY . gyroZ } \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscopeScaled.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscopeScaled.st new file mode 100644 index 0000000..ec8b617 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscopeScaled.st @@ -0,0 +1,8 @@ +controlling +readGyroscopeScaled + | gyro gyroX gyroY gyroZ | + gyro := self readGyroscope. + gyroX := (gyro at: 1)/131 asFloat round: 6. + gyroY := (gyro at: 2)/131 asFloat round: 6. + gyroZ := (gyro at: 3)/131 asFloat round: 6. + ^ { gyroX . gyroY . gyroZ } \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters..st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters..st new file mode 100644 index 0000000..cac92b7 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters..st @@ -0,0 +1,11 @@ +controlling +readRegisters: anHex + | h l value | + h := i2cConnection read8BitsAt: anHex. + l := i2cConnection read8BitsAt: anHex + 1. + (h == 0 & l == 0) + ifTrue: [ self wakeUpSensor. 1 milliSeconds wait. + h := i2cConnection read8BitsAt: anHex. + l := i2cConnection read8BitsAt: anHex + 1 ]. + value := (h bitShift: 8) + l. + ^ value \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters2C..st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters2C..st new file mode 100644 index 0000000..6415e7f --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters2C..st @@ -0,0 +1,7 @@ +controlling +readRegisters2C: anHex + | value | + value := self readRegisters: anHex. + value >= 16r8000 + ifTrue: [ ^ ((65535 - value) + 1) * -1] + ifFalse: [^ value ] \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRotationXY.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRotationXY.st new file mode 100644 index 0000000..35b8ea4 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRotationXY.st @@ -0,0 +1,8 @@ +controlling +readRotationXY + | accelerometerScaled rotation rotationX rotationY | + accelerometerScaled := self readAccelerometerScaled. + rotation := self calculateRotationX: (accelerometerScaled at: 1) Y: (accelerometerScaled at: 2) Z: (accelerometerScaled at: 3). + rotationX := rotation at: 1. + rotationY := rotation at: 2. + ^ { rotationX . rotationY } \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/wakeUpSensor.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/wakeUpSensor.st new file mode 100644 index 0000000..73cc413 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/wakeUpSensor.st @@ -0,0 +1,3 @@ +controlling +wakeUpSensor + i2cConnection write8BitsAt: 16r6b data: 0 \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/properties.json b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/properties.json new file mode 100644 index 0000000..f7f8722 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/properties.json @@ -0,0 +1,13 @@ +{ + "commentStamp" : "AllexOliveira 8/7/2019 18:28", + "super" : "PotI2CDevice", + "category" : "PharoThings-Devices-MPU6050", + "classinstvars" : [ ], + "pools" : [ ], + "classvars" : [ ], + "instvars" : [ + "readProcess" + ], + "name" : "PotMPU6050Device", + "type" : "normal" +} \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/monticello.meta/categories.st b/src/PharoThings-Devices-MPU6050.package/monticello.meta/categories.st new file mode 100644 index 0000000..66e7f4c --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/monticello.meta/categories.st @@ -0,0 +1 @@ +SystemOrganization addCategory: #'PharoThings-Devices-MPU6050'! diff --git a/src/PharoThings-Devices-MPU6050.package/monticello.meta/initializers.st b/src/PharoThings-Devices-MPU6050.package/monticello.meta/initializers.st new file mode 100644 index 0000000..e69de29 diff --git a/src/PharoThings-Devices-MPU6050.package/monticello.meta/package b/src/PharoThings-Devices-MPU6050.package/monticello.meta/package new file mode 100644 index 0000000..b84f9fd --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/monticello.meta/package @@ -0,0 +1 @@ +(name 'PharoThings-Devices-MPU6050') \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/properties.json b/src/PharoThings-Devices-MPU6050.package/properties.json new file mode 100644 index 0000000..6f31cf5 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/properties.json @@ -0,0 +1 @@ +{ } \ No newline at end of file