Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write & Read BNO055 Calibration and heel/pitch offsets to/from EEPROM #110

Merged
merged 88 commits into from
Jan 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
bd9cb0c
Netbeans project folder added
ronzeiller Dec 9, 2017
ab7ccfb
initial commit with some settings for IMUService & IMUMonitorPage
ronzeiller Dec 9, 2017
9fc5355
initial commit with some settings for IMUService & IMUMonitorPage
ronzeiller Dec 9, 2017
9cc6d2e
Start of simplified IMUMonitorPage
ronzeiller Dec 9, 2017
1e183f4
Start of simplified IMUMonitorPage
ronzeiller Dec 9, 2017
e9ad204
include KBoxConfig, IMUMonitorPage, settings for service intervals
ronzeiller Dec 9, 2017
14a7546
MagHdg and heel/pitch update separated to diff. calibration settings
ronzeiller Dec 9, 2017
7898cb9
Some functions added for IMUMonitorPage
ronzeiller Dec 11, 2017
e9b4cea
Some functions added for the IMUMonitorPage
ronzeiller Dec 11, 2017
b67754c
more defines, passing a reference to IMUService for IMUMonitorPage
ronzeiller Dec 11, 2017
f041061
reference to IMUService added
ronzeiller Dec 11, 2017
de083c1
getLastValues from IMUService added
ronzeiller Dec 11, 2017
d11d220
KBoxConfig moved to src/common/config, 2 more service-defines added
ronzeiller Dec 11, 2017
db7fa77
extended with button long click for offset-to-zero of heel/pitch
ronzeiller Dec 11, 2017
100a6d4
extended with button long click for offset-to-zero of heel/pitch
ronzeiller Dec 11, 2017
24b5ec4
make write8() public to access from IMUService
ronzeiller Dec 11, 2017
1229eb4
axis- and sign remapping cancelled here as made on start of IMUService
ronzeiller Dec 11, 2017
f45d445
ButtonEvent LongClick added, default for switch page is Click now
ronzeiller Dec 11, 2017
91f52d2
changed to ButtonEventTypeClick for switching patches
ronzeiller Dec 11, 2017
a58f66e
Long Button press for setOffset in IMUService implemented
ronzeiller Dec 11, 2017
0f883bd
Long button click added
ronzeiller Dec 11, 2017
65add4f
Long button click added
ronzeiller Dec 11, 2017
6948ccf
setOffset, recall and saveCalibration, axis & sign setting added
ronzeiller Dec 11, 2017
7b61c06
setOffset, recall and saveCalibration, axis & sign setting added
ronzeiller Dec 11, 2017
48fe0a3
debug msg commented out
ronzeiller Dec 11, 2017
1bcc7a3
Merge remote-tracking branch 'upstream/master' into rz_imu-page
ronzeiller Dec 11, 2017
644643a
put back to original + overload begin function for KBox mounting
ronzeiller Dec 14, 2017
f67950a
restore original + overload begin function for KBox mounting
ronzeiller Dec 14, 2017
b1b4552
Axis & Sign config now in bno055.begin function
ronzeiller Dec 14, 2017
0eb4e27
restore to original (w/o config) just new IMUPage added
ronzeiller Dec 14, 2017
dd57cd3
original restored w/o config settings, just IMUPage added
ronzeiller Dec 14, 2017
098756f
settings now private, w/o config file, all angle values radians
ronzeiller Dec 14, 2017
1e23958
settings now private, w/o config file, all angle values radians
ronzeiller Dec 14, 2017
841c3de
settings now private, w/o config file, all angle values radians
ronzeiller Dec 14, 2017
94e5f17
settings now private, w/o config file, all angle values radians
ronzeiller Dec 14, 2017
0e0f54e
KBoxConfig deleted as it will come in another PR
ronzeiller Dec 14, 2017
35e1662
back to Sarfatas BNO055 library but with extended begin() function
ronzeiller Dec 14, 2017
55f0e11
back to Sarfatas BNO055 library but with extended begin() function
ronzeiller Dec 14, 2017
6f3652c
removed unnecessary include
ronzeiller Dec 14, 2017
7c7f608
extra lines removed
ronzeiller Dec 14, 2017
406aee7
moved #include here
ronzeiller Dec 14, 2017
add7009
Removed bug in calculating offset, some comments added
ronzeiller Dec 14, 2017
16d732a
NaN for not available values in N2k and SKUpdate
ronzeiller Dec 27, 2017
7ff16fc
TODO deleted as SDIO has no sdcard_cs
ronzeiller Dec 29, 2017
ab61dcc
more config for IMU-sensor added
ronzeiller Dec 29, 2017
51247f0
more IMU-sensor config settings
ronzeiller Dec 29, 2017
ab5b665
netbeans added
ronzeiller Dec 29, 2017
ef4e46a
some corrections for new config
ronzeiller Dec 29, 2017
d9311b5
correction for new config
ronzeiller Dec 29, 2017
5082ee0
Merge branch 'rz_more-config' into rz_imu-page
ronzeiller Dec 29, 2017
fe6c5cf
IMUMonitorPage if IMU enabled, imuConfig added
ronzeiller Dec 29, 2017
f37782a
IMUConfig for settings of IMU-cal values added
ronzeiller Dec 29, 2017
8e03c94
IMUConfig for settings of IMU-cal values added
ronzeiller Dec 29, 2017
2c0b16f
IMUConfig for settings of IMU-cal values added
ronzeiller Dec 29, 2017
d68ec3d
IMUConfig for settings of IMU-cal values added
ronzeiller Dec 29, 2017
cc71273
config for different KBox mounting positions added
ronzeiller Dec 30, 2017
621c5d0
ident to tab 2
ronzeiller Dec 31, 2017
a818895
small corrections, config for mounting
ronzeiller Dec 31, 2017
4edf570
indent corrected
ronzeiller Jan 1, 2018
fe3ee96
Merge branch 'rz_imu-page' of https://github.com/ronzeiller/kbox-firm…
ronzeiller Jan 1, 2018
cb01893
indention corrected
ronzeiller Jan 1, 2018
f2aa14d
indent corrected, not used function deleted
ronzeiller Jan 1, 2018
333242e
indent corrected, not used function deleted
ronzeiller Jan 1, 2018
69007d2
IMU calibration values deleted from config
ronzeiller Jan 1, 2018
03c048c
IMU calibration values deleted from config
ronzeiller Jan 1, 2018
dc36c58
IMU calibration values deleted from config
ronzeiller Jan 1, 2018
2c87d62
IMU calibration values deleted from config
ronzeiller Jan 1, 2018
019d7e7
put back updateReceived due to error message....
ronzeiller Jan 1, 2018
2be63c3
put back updateReceived due to error message....
ronzeiller Jan 1, 2018
2abe954
not needed debug msg deleted
ronzeiller Jan 1, 2018
9b18505
prevent overflow by setOffset
ronzeiller Jan 1, 2018
e1c285a
read/write BNO055 Calibration and heel/pitch offset from/to EEPROM
ronzeiller Jan 2, 2018
d36937e
correction to 3 digits for heel/pitch values
ronzeiller Jan 2, 2018
179fcb5
indent corrected
ronzeiller Jan 2, 2018
b442fc7
fixing some indent issues
sarfata Jan 3, 2018
4a3ef35
Add missing struct keywords
sarfata Jan 3, 2018
a786f35
Fix phantom button event at startup
sarfata Jan 3, 2018
368f6fb
Fix name of function called to read heel/pitch offset
sarfata Jan 3, 2018
ca5fe38
KBox default mounting position: vertical, Port Hull
ronzeiller Jan 3, 2018
61ca6e5
mounting positions switch statements, default position port hull
ronzeiller Jan 3, 2018
b419214
fix my if/else codestyle
sarfata Jan 4, 2018
860f447
Few changes to IMUService and calibration
sarfata Jan 4, 2018
4127387
Merge pull request #6 from sarfata/rz-imu-more-stuff-changes
ronzeiller Jan 5, 2018
5463472
Update IMUService.h
ronzeiller Jan 5, 2018
7b4e9a3
Copyright changed
ronzeiller Jan 5, 2018
17ce680
Copyright changed
ronzeiller Jan 5, 2018
efc610b
Merge branch 'master' into rz_imu-more-stuff
ronzeiller Jan 5, 2018
60a2fe2
Merge branch 'master' into rz_imu-more-stuff
ronzeiller Jan 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Network Trash Folder
Temporary Items
.apdisk

# Netbeans project folder
nbproject

# Platformio likes to auto-create this
lib/readme.txt
CMakeListsPrivate.txt
Expand Down
6 changes: 4 additions & 2 deletions extras/config/default-config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"imu": {
"enabled": true,
"frequency": 20
"frequency": 20,
"enableHdg": true,
"enableHeelPitch": true,
"mounting": "verticalPortHull"
},
"barometer": {
"enabled": true,
Expand Down Expand Up @@ -49,4 +52,3 @@
"rxEnabled": true
}
}

23 changes: 9 additions & 14 deletions lib/Adafruit_BNO055/Adafruit_BNO055.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,14 @@ Adafruit_BNO055::Adafruit_BNO055(int32_t sensorID, uint8_t address)
PUBLIC FUNCTIONS
***************************************************************************/


/**************************************************************************/
/*!
@brief Sets up the HW
Sets up the IMU Sensor for KBox, including axis- and sign mapping
*/
/**************************************************************************/
bool Adafruit_BNO055::begin(adafruit_bno055_opmode_t mode)
bool Adafruit_BNO055::begin(adafruit_bno055_opmode_t mode, uint8_t axis_remap_orientation, uint8_t axis_remap_sign)
{
/* Enable I2C */
//Wire.begin();

/* Make sure we have the right device */
uint8_t id = read8(BNO055_CHIP_ID_ADDR);
if(id != BNO055_ID)
Expand Down Expand Up @@ -90,8 +88,7 @@ bool Adafruit_BNO055::begin(adafruit_bno055_opmode_t mode)
//delay(100);
//}
//delay(50);

DEBUG("rebooted");
//DEBUG("rebooted");

/* Set to normal power mode */
DEBUG("going into normal power mode");
Expand All @@ -111,14 +108,12 @@ bool Adafruit_BNO055::begin(adafruit_bno055_opmode_t mode)
write8(BNO055_UNIT_SEL_ADDR, unitsel);
*/

/* Configure axis mapping (see section 3.4) */
//write8(BNO055_AXIS_MAP_CONFIG_ADDR, REMAP_CONFIG_P2); // P0-P7, Default is P1
write8(BNO055_AXIS_MAP_CONFIG_ADDR, 0b00001001); // P0-P7, Default is P1
/* Configure axis mapping (see section 3.4 Bosch manual) */
write8(BNO055_AXIS_MAP_CONFIG_ADDR, axis_remap_orientation);
delay(10);
//write8(BNO055_AXIS_MAP_SIGN_ADDR, REMAP_SIGN_P2); // P0-P7, Default is P1
write8(BNO055_AXIS_MAP_SIGN_ADDR, 0b00000000); // P0-P7, Default is P1
write8(BNO055_AXIS_MAP_SIGN_ADDR, axis_remap_sign);
delay(10);

write8(BNO055_SYS_TRIGGER_ADDR, 0x0);
delay(10);
/* Set the requested operating mode (see section 3.3) */
Expand Down Expand Up @@ -612,7 +607,7 @@ byte Adafruit_BNO055::read8(adafruit_bno055_reg_t reg )
#else
value = Wire.receive();
#endif

//DEBUG("read => %x", value);

return value;
Expand Down
5 changes: 4 additions & 1 deletion lib/Adafruit_BNO055/Adafruit_BNO055.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,11 @@ class Adafruit_BNO055 : public Adafruit_Sensor
} adafruit_vector_type_t;

Adafruit_BNO055 ( int32_t sensorID = -1, uint8_t address = BNO055_ADDRESS_A );
// MOD for KBox to set axis and sign
bool begin ( adafruit_bno055_opmode_t mode = OPERATION_MODE_NDOF,
uint8_t axis_remap_orientation = REMAP_CONFIG_P1,
uint8_t axis_remap_sign = REMAP_SIGN_P1);

bool begin ( adafruit_bno055_opmode_t mode = OPERATION_MODE_NDOF );
void setMode ( adafruit_bno055_opmode_t mode );
void getRevInfo ( adafruit_bno055_rev_info_t* );
void displayRevInfo ( void );
Expand Down
1 change: 0 additions & 1 deletion lib/KBoxHardware/src/KBoxHardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ void KBoxHardware::espRebootInProgram() {
}

bool KBoxHardware::sdCardInit() {
//TODO: check if sdcard_cs is working with SdFatSdio
#if defined(__MK66FX1M0__)
// SDIO support for Builtin SD-Card in Teensy 3.6
if (!_sd.begin()){
Expand Down
12 changes: 9 additions & 3 deletions src/common/ui/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ class Event {
};

enum ButtonEventType {
// Those two events are always sent when button goes up/down
ButtonEventTypePressed,
ButtonEventTypeReleased
ButtonEventTypeReleased,

// Those events are also sent when a single click, or a double click happen
ButtonEventTypeClick,
ButtonEventTypeLongClick,

// This event is sent multiple times, as long as button is maintained
ButtonEventTypeMaintained,
};
class ButtonEvent : public Event {
private:
Expand All @@ -68,5 +76,3 @@ class TickEvent : public Event {
TickEvent(unsigned long int millis) : Event(EventTypeTick), millis(millis) {};
time_ms_t getMillis() const { return millis; };
};


9 changes: 6 additions & 3 deletions src/common/ui/Page.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "Event.h"
#include "Layer.h"

#include <KBoxLogging.h>

/* A page is one simple app available on the MFD.
*
* - Only one page can be active at a time.
Expand All @@ -44,7 +46,9 @@ class BasePage {

virtual bool processEvent(const ButtonEvent &e) {
// By default button down will force switching to the next page.
return !(e.clickType == ButtonEventTypePressed);
DEBUG("EventTypeButton: %i", e.clickType);
// false -> next page
return !(e.clickType == ButtonEventTypeClick);
}
virtual bool processEvent(const EncoderEvent &e) {
// By default this will be ignored.
Expand All @@ -59,7 +63,7 @@ class BasePage {
virtual ~BasePage() {};
};

/* BasePage offers a very generic paint implementation.
/* BasePage offers a very generic paint implementation.
* Page assumes the use of Layers.
*
* Adding a layer via addLayer() will transfer ownership to the Page who will
Expand All @@ -76,4 +80,3 @@ class Page : public BasePage {
void addLayer(Layer *l);
void paint(GC &context);
};

13 changes: 12 additions & 1 deletion src/host/config/IMUConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,19 @@

#pragma once

enum IMUMounting {
VerticalStbHull,
VerticalPortHull,
VerticalTopToBow,
//VerticalTopToStern,
HorizontalLeftSideToBow,
//HorizontalRightSideToBow
};

struct IMUConfig {
bool enabled;
int frequency;
bool enableHdg;
bool enableHeelPitch;
enum IMUMounting mounting = VerticalPortHull;
};

26 changes: 25 additions & 1 deletion src/host/config/KBoxConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ void KBoxConfigParser::defaultConfig(KBoxConfig &config) {

config.imuConfig.enabled = true;
config.imuConfig.frequency = 20;
config.imuConfig.enabled = true; // enable internal IMU sensor
config.imuConfig.enableHdg = true; // true if values taken from internal sensor
config.imuConfig.enableHeelPitch = true; // true if values taken from internal sensor
config.imuConfig.mounting = VerticalStbHull;

config.barometerConfig.enabled = true;
config.barometerConfig.frequency = 1;
Expand All @@ -75,6 +79,9 @@ void KBoxConfigParser::parseKBoxConfig(const JsonObject &json, KBoxConfig &confi
void KBoxConfigParser::parseIMUConfig(const JsonObject &json, IMUConfig &config) {
READ_BOOL_VALUE(enabled);
READ_INT_VALUE_WRANGE(frequency, 1, 100);
READ_BOOL_VALUE(enableHdg);
READ_BOOL_VALUE(enableHeelPitch);
READ_ENUM_VALUE(mounting, convertIMUMounting);
}

void KBoxConfigParser::parseBarometerConfig(const JsonObject &json, BarometerConfig &config){
Expand Down Expand Up @@ -131,4 +138,21 @@ enum SerialMode KBoxConfigParser::convertSerialMode(const String &s) {
return SerialModeNMEA;
}
return SerialModeDisabled;
}
}

enum IMUMounting KBoxConfigParser::convertIMUMounting(const String &s) {
if (s == "verticalPortHull") {
return VerticalPortHull;
}
if (s == "verticalStarboardHull") {
return VerticalStbHull;
}
if (s == "verticalTopToBow") {
return VerticalTopToBow;
}
if (s == "horizontalLeftSideToBow") {
return HorizontalLeftSideToBow;
}
// default
return VerticalPortHull;
}
1 change: 1 addition & 0 deletions src/host/config/KBoxConfigParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
class KBoxConfigParser {
private:
SerialMode convertSerialMode(const String &s);
IMUMounting convertIMUMounting(const String &s);

public:
/**
Expand Down
9 changes: 8 additions & 1 deletion src/host/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "host/services/ADCService.h"
#include "host/services/BarometerService.h"
#include "host/services/IMUService.h"
#include "host/pages/IMUMonitorPage.h"
#include "host/services/NMEA2000Service.h"
#include "host/services/SerialService.h"
#include "host/services/RunningLightService.h"
Expand Down Expand Up @@ -98,7 +99,7 @@ void setup() {

ADCService *adcService = new ADCService(skHub, KBox.getADC());
BarometerService *baroService = new BarometerService(skHub);
IMUService *imuService = new IMUService(skHub);
IMUService *imuService = new IMUService(config.imuConfig, skHub);

NMEA2000Service *n2kService = new NMEA2000Service(config.nmea2000Config,
skHub);
Expand Down Expand Up @@ -134,6 +135,12 @@ void setup() {
BatteryMonitorPage *batPage = new BatteryMonitorPage(skHub);
mfd.addPage(batPage);

if (config.imuConfig.enabled) {
// At the moment the IMUMonitorPage is working with built-in sensor only
IMUMonitorPage *imuPage = new IMUMonitorPage(config.imuConfig, skHub, *imuService);
mfd.addPage(imuPage);
}

StatsPage *statsPage = new StatsPage();
statsPage->setSDCardTask(sdcardTask);

Expand Down
99 changes: 99 additions & 0 deletions src/host/pages/IMUMonitorPage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
__ __ ______ ______ __ __
/\ \/ / /\ == \ /\ __ \ /\_\_\_\
\ \ _"-. \ \ __< \ \ \/\ \ \/_/\_\/_
\ \_\ \_\ \ \_____\ \ \_____\ /\_\/\_\
\/_/\/_/ \/_____/ \/_____/ \/_/\/_/

The MIT License

Copyright (c) 2018 Thomas Sarlandie [email protected]
Copyright (c) 2018 Ronnie Zeiller [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/


#include "IMUMonitorPage.h"

#include "common/signalk/SKUpdate.h"
#include "common/signalk/SKUnits.h"

IMUMonitorPage::IMUMonitorPage(IMUConfig &config, SKHub& hub, IMUService &imuService) : _config(config), _imuService(imuService) {
static const int col1 = 5;
static const int col2 = 200;
static const int row1 = 26;
static const int row2 = 50;
static const int row3 = 152;
static const int row4 = 182;

addLayer(new TextLayer(Point(col1, row1), Size(20, 20), "HDG ° Mag", ColorWhite, ColorBlack, FontDefault));
addLayer(new TextLayer(Point(col2, row1), Size(20, 20), "Sys/Mag/Acc", ColorWhite, ColorBlack, FontDefault));
addLayer(new TextLayer(Point(col1, row3), Size(20, 20), "Heel °", ColorWhite, ColorBlack, FontDefault));
addLayer(new TextLayer(Point(col2, row3), Size(20, 20), "Pitch °", ColorWhite, ColorBlack, FontDefault));

_hdgTL = new TextLayer(Point(col1, row2), Size(20, 20), "--", ColorWhite, ColorBlack, FontLarge);
_calTL = new TextLayer(Point(col2, row2), Size(20, 20), "--", ColorWhite, ColorBlack, FontLarge);
_rollTL = new TextLayer(Point(col1, row4), Size(20, 20), "--", ColorWhite, ColorBlack, FontLarge);
_pitchTL = new TextLayer(Point(col2, row4), Size(20, 20), "--", ColorWhite, ColorBlack, FontLarge);

addLayer(_hdgTL);
addLayer(_calTL);
addLayer(_rollTL);
addLayer(_pitchTL);

hub.subscribe(this);
}

bool IMUMonitorPage::processEvent(const ButtonEvent &be){
if (be.clickType == ButtonEventTypeClick) {
// Change page on single click.
return false;
}
if (be.clickType == ButtonEventTypeLongClick) {
_imuService.setRollPitchOffset();
}
return true;
}

bool IMUMonitorPage::processEvent(const TickEvent &te){
_imuService.getLastValues(_sysCalibration, _accelCalibration, _pitch, _roll, _magCalibration, _heading);

// TODO: Some damping for the display
_hdgTL->setText(String( SKRadToDeg(_heading), 1) + "° ");
_calTL->setText(String( _sysCalibration) + "/" + String( _magCalibration) + "/" + String( _accelCalibration) + " ");
_pitchTL->setText(String( SKRadToDeg(_pitch), 1) + "° ");
_rollTL->setText(String( SKRadToDeg(_roll), 1) + "° ");

// Always show Hdg from IMU-sensor, but if the value is not trusted (which means
// calibrationData below default setting, change color to red
if ( ! _imuService.isMagCalibrated() || ! _imuService.isRollAndPitchCalibrated()) {
_hdgTL->setColor(ColorRed);
_calTL->setColor(ColorRed);
} else {
_hdgTL->setColor(ColorWhite);
_calTL->setColor(ColorWhite);
};

return true;
}

void IMUMonitorPage::updateReceived(const SKUpdate& up) {
// may be needed for something....
}
Loading