diff --git a/experiments/bno055-rpi-test.ts b/experiments/bno055-rpi-test.ts index d8b71a3..4fd69e5 100644 --- a/experiments/bno055-rpi-test.ts +++ b/experiments/bno055-rpi-test.ts @@ -1,49 +1,54 @@ -import { - BNO055, - // Enums: - OpMode, - DeviceAddress, - PowerLevel, - } from 'bno055-imu-node'; - import delay from "../psybot-lib/delay"; - - // All BNO055 instance methods are async and return a promise - (async () => { - try { - // Start the sensor - // The begin method performs basic connection verification and resets the device - const imu = await BNO055.begin( - DeviceAddress.A, // Address enum: A = 0x28, B = 0x29 - OpMode.FullFusion, // Operation mode enum - 3 // Use this seral device: /dev/i2c-3 - ); +const { BNO055, OpMode, DeviceAddress } = require('@workshop2/bno055-imu-node'); +const fs = require('fs'); +import delay from "../psybot-lib/delay"; +const offsetsPath = "./offsets.json"; +(async () => { + try { + const imu = await BNO055.begin(DeviceAddress.A, OpMode.FullFusion, 3); await imu.resetSystem(); - const printEverything = async () => { + if(fs.existsSync(offsetsPath)) { + console.log("Reading offsets from disk,", offsetsPath); + const data = fs.readFileSync(offsetsPath, {encoding: 'utf8', flag: 'r'}); + + const data2 = JSON.parse(data.toString()); + console.log(data2); + + console.log("Running setSensorOffsets...."); + await imu.setSensorOffsets(data2); + console.log("Done?!"); + } + + let calibrated = false; + while(!calibrated) { + await delay(3333); + console.log('calibration: ', await imu.getCalibrationStatuses()); + + calibrated = await imu.isFullyCalibrated(); + console.log('is calibrated: ', calibrated); + + const offsets = await imu.getSensorOffsets(); + console.log('offsets: ', offsets); - console.log('current mode: ', await imu.getMode()); - console.log('current page: ', await imu.getPage()); - console.log('system status: ', await imu.getSystemStatus()); - console.log('system error: ', await imu.getSystemError()); - console.log('temp: ', await imu.getTemperature()); - console.log('self-test results: ', await imu.getSelfTestResults()); + if(calibrated) { + console.log("Storing offsets to disk", offsetsPath, offsets); + const data = JSON.stringify(offsets); + fs.writeFileSync(offsetsPath, data); + } + } - console.log('axis mapping: ', await imu.getAxisMapping()); - console.log('versions: ', await imu.getVersions()); - console.log('units: ', await imu.getUnits()); + while(true) { console.log('euler: ', await imu.getEuler()); console.log('quat: ', await imu.getQuat()); - console.log('calibration: ', await imu.getCalibrationStatuses()); - console.log('is calibrated: ', await imu.isFullyCalibrated()); - console.log('offsets: ', await imu.getSensorOffsets()); - - setTimeout(printEverything, 3333); - }; + console.log('temp', await imu.getTemperature()); + console.log('units', await imu.getUnits()); + console.log('--------------------------------'); - await printEverything(); + await delay(3333); + } } catch (error) { console.error('error: ', error); } - })(); \ No newline at end of file +})(); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 760e6f0..380c8d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "bno055-imu-node": "^1.4.0", + "@workshop2/bno055-imu-node": "^1.4.2", "console-stamp": "^0.2.9", "fsm-as-promised": "^0.16.0", "javascript-state-machine": "^3.1.0", @@ -187,6 +187,14 @@ "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz", "integrity": "sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==" }, + "node_modules/@workshop2/bno055-imu-node": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@workshop2/bno055-imu-node/-/bno055-imu-node-1.4.2.tgz", + "integrity": "sha512-pFbCm1mZiHN3AhGFyH4AJMVBJbsYbswpL9yaHQ8TQJrKQaVOriYHNJ7YK6DfTfe4bHQ50LmIWXmnijORPWxzhw==", + "dependencies": { + "i2c-bus": "^5.1.0" + } + }, "node_modules/ansi-regex": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", @@ -272,14 +280,6 @@ "node": ">= 6" } }, - "node_modules/bno055-imu-node": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/bno055-imu-node/-/bno055-imu-node-1.4.0.tgz", - "integrity": "sha512-ZEN+jX7f8Q5jspjq16yYN3xf4iv0UZ8ndH70QrS6aFYM40LxGWUxiH5ivMeFSJo6m5xAWSPjmoPIAMaic2CqQA==", - "dependencies": { - "i2c-bus": "^5.1.0" - } - }, "node_modules/browser-serialport": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/browser-serialport/-/browser-serialport-2.1.0.tgz", @@ -1675,6 +1675,14 @@ "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz", "integrity": "sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==" }, + "@workshop2/bno055-imu-node": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@workshop2/bno055-imu-node/-/bno055-imu-node-1.4.2.tgz", + "integrity": "sha512-pFbCm1mZiHN3AhGFyH4AJMVBJbsYbswpL9yaHQ8TQJrKQaVOriYHNJ7YK6DfTfe4bHQ50LmIWXmnijORPWxzhw==", + "requires": { + "i2c-bus": "^5.1.0" + } + }, "ansi-regex": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", @@ -1752,14 +1760,6 @@ } } }, - "bno055-imu-node": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/bno055-imu-node/-/bno055-imu-node-1.4.0.tgz", - "integrity": "sha512-ZEN+jX7f8Q5jspjq16yYN3xf4iv0UZ8ndH70QrS6aFYM40LxGWUxiH5ivMeFSJo6m5xAWSPjmoPIAMaic2CqQA==", - "requires": { - "i2c-bus": "^5.1.0" - } - }, "browser-serialport": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/browser-serialport/-/browser-serialport-2.1.0.tgz", diff --git a/package.json b/package.json index 5c80e17..f13b364 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "author": "S Colmer", "license": "ISC", "dependencies": { - "bno055-imu-node": "^1.4.0", + "@workshop2/bno055-imu-node": "^1.4.2", "console-stamp": "^0.2.9", "fsm-as-promised": "^0.16.0", "javascript-state-machine": "^3.1.0",