-
Notifications
You must be signed in to change notification settings - Fork 20
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
IMUMonitorPage added #89
Changes from 55 commits
bd9cb0c
ab7ccfb
9fc5355
9cc6d2e
1e183f4
e9ad204
14a7546
7898cb9
e9b4cea
b67754c
f041061
de083c1
d11d220
db7fa77
100a6d4
24b5ec4
1229eb4
f45d445
91f52d2
a58f66e
0f883bd
65add4f
6948ccf
7b61c06
48fe0a3
1bcc7a3
644643a
f67950a
b1b4552
0eb4e27
dd57cd3
098756f
1e23958
841c3de
94e5f17
0e0f54e
35e1662
55f0e11
6f3652c
7c7f608
406aee7
add7009
16d732a
7ff16fc
ab61dcc
51247f0
ab5b665
ef4e46a
d9311b5
5082ee0
fe6c5cf
f37782a
8e03c94
2c0b16f
d68ec3d
cc71273
621c5d0
a818895
4edf570
fe3ee96
cb01893
f2aa14d
333242e
69007d2
03c048c
dc36c58
2c87d62
019d7e7
2be63c3
2abe954
9b18505
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -90,8 +88,7 @@ bool Adafruit_BNO055::begin(adafruit_bno055_opmode_t mode) | |
//delay(100); | ||
//} | ||
//delay(50); | ||
|
||
DEBUG("rebooted"); | ||
//DEBUG("rebooted"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should just remove this I think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you do not need your remarks anymore, I can delete them. |
||
|
||
/* Set to normal power mode */ | ||
DEBUG("going into normal power mode"); | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should eventually try to remove any modifications from 3rd party libraries. Would make it a lot easier to upgrade them. Is this what you did here? Are we back to the original file? All those comments confuse me. I don't remember what was part of the library and what I added. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi,
The rest was by done by you. Then you did some corrections to wire at the beginning of the Adafruit_BNO055.cpp |
||
/* 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) */ | ||
|
@@ -612,7 +607,7 @@ byte Adafruit_BNO055::read8(adafruit_bno055_reg_t reg ) | |
#else | ||
value = Wire.receive(); | ||
#endif | ||
|
||
//DEBUG("read => %x", value); | ||
|
||
return value; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,4 +57,4 @@ inline double SKNormalizeAngle(double x) { | |
return x - M_PI; | ||
} | ||
|
||
|
||
const double SKDoubleNAN = -1e9; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very very nice 👍 |
||
ButtonEventTypeLongClick, | ||
|
||
// This event is sent multiple times, as long as button is maintained | ||
ButtonEventTypeMaintained, | ||
}; | ||
class ButtonEvent : public Event { | ||
private: | ||
|
@@ -68,5 +76,3 @@ class TickEvent : public Event { | |
TickEvent(unsigned long int millis) : Event(EventTypeTick), millis(millis) {}; | ||
time_ms_t getMillis() const { return millis; }; | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,11 @@ 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.calHdg = 3; // hdg valid, if calibration value greater equal | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am still not convinced we need this. Besides you, and to a lesser extent me, nobody is going to understand what those values mean. If I agree to make 3 and 2 the defaults, are you ok removing this? ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :-)) I have to delete it then in the config too. But would prefer to do it in a separate PR after merging, if it is ok for you. |
||
config.imuConfig.calHeelPitch = 2; // heel (roll) & pitch valid, if calibration value greater equal | ||
|
||
config.barometerConfig.enabled = true; | ||
config.barometerConfig.frequency = 1; | ||
|
@@ -75,6 +80,10 @@ 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_INT_VALUE_WRANGE(calHdg, 0, 3); | ||
READ_INT_VALUE_WRANGE(calHeelPitch, 0, 3); | ||
} | ||
|
||
void KBoxConfigParser::parseBarometerConfig(const JsonObject &json, BarometerConfig &config){ | ||
|
@@ -131,4 +140,4 @@ enum SerialMode KBoxConfigParser::convertSerialMode(const String &s) { | |
return SerialModeNMEA; | ||
} | ||
return SerialModeDisabled; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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); | ||
|
@@ -134,6 +135,12 @@ void setup() { | |
BatteryMonitorPage *batPage = new BatteryMonitorPage(skHub); | ||
mfd.addPage(batPage); | ||
|
||
if (config.imuConfig.enabled) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 great idea. |
||
// 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); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
__ __ ______ ______ __ __ | ||
/\ \/ / /\ == \ /\ __ \ /\_\_\_\ | ||
\ \ _"-. \ \ __< \ \ \/\ \ \/_/\_\/_ | ||
\ \_\ \_\ \ \_____\ \ \_____\ /\_\/\_\ | ||
\/_/\/_/ \/_____/ \/_____/ \/_/\/_/ | ||
|
||
The MIT License | ||
|
||
Copyright (c) 2017 Thomas Sarlandie [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 <stdio.h> | ||
#include "common/signalk/SKUpdate.h" | ||
#include "IMUMonitorPage.h" | ||
#include <KBoxLogging.h> | ||
#include "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), "Cal: 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){ | ||
// DEBUG("EventTypeButton: %i", be.clickType); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to come up with a better way to disable logging for just one class. Commenting DEBUG is really not ideal, and removing them is also not great. I need to come up with something! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A lot of this DEBUG I just need during inventing of code. Then, when I think it works as I expect, I think it is a pity to delete them.... |
||
if (be.clickType == ButtonEventTypeClick) { | ||
DEBUG("Button ButtonEventTypeClick !!!"); | ||
// Change page on single click. | ||
return false; | ||
} | ||
if (be.clickType == ButtonEventTypeLongClick) { | ||
_imuService.setOffset(); | ||
} | ||
return true; | ||
} | ||
|
||
bool IMUMonitorPage::processEvent(const TickEvent &te){ | ||
_imuService.getLastValues(_accelCalibration, _pitch, _roll, _magCalibration, _heading); | ||
//DEBUG("AccelCalibration: %i | MagCalibration: %i", _accelCalibration, _magCalibration); | ||
|
||
// TODO: Some damping for the display | ||
_hdgTL->setText(String( SKRadToDeg(_heading), 1) + "° "); | ||
_calTL->setText(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 | ||
// calibration below config setting, change color to red | ||
if ((_magCalibration <= _config.calHdg)||(_accelCalibration <= _config.calHeelPitch)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: indentation problem here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the IMUService should expose a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I do not know how to get rid of ident-problem. In every editor I have it shows a 2-ident tab.
Good idea!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re-Indent: this article might help: https://stackoverflow.com/questions/4119872/netbeans-removing-trailing-whitespace-on-save-and-tabs-to-spaces I think your editor is configured to show tabs as 2 spaces. this is why it looks good to you. But since they are actually tabs, it does not look good in github (they do this on purpose to make it easier to detect). I can push a commit to fix it if needed. |
||
_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.... | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
__ __ ______ ______ __ __ | ||
/\ \/ / /\ == \ /\ __ \ /\_\_\_\ | ||
\ \ _"-. \ \ __< \ \ \/\ \ \/_/\_\/_ | ||
\ \_\ \_\ \ \_____\ \ \_____\ /\_\/\_\ | ||
\/_/\/_/ \/_____/ \/_____/ \/_/\/_/ | ||
|
||
The MIT License | ||
|
||
Copyright (c) 2017 Thomas Sarlandie [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 "common/ui/Page.h" | ||
#include "common/ui/TextLayer.h" | ||
#include "common/signalk/SKHub.h" | ||
#include "common/signalk/SKSubscriber.h" | ||
#include "services/IMUService.h" | ||
#include "host/config/IMUConfig.h" | ||
|
||
class IMUMonitorPage : public Page, public SKSubscriber { | ||
private: | ||
TextLayer *_hdgTL, *_rollTL, *_pitchTL, *_calTL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indentation is wrong here. Should 2 space for private and then 4 for the properties and methods. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. repaired There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indent issues here too (tabs instead of spaces) |
||
IMUConfig &_config; | ||
IMUService &_imuService; | ||
|
||
int _magCalibration, _accelCalibration; | ||
double _pitch, _roll, _heading; | ||
|
||
public: | ||
IMUMonitorPage(IMUConfig &config, SKHub& hub, IMUService &imuService); | ||
virtual void updateReceived(const SKUpdate& up); | ||
|
||
bool processEvent(const TickEvent &te); | ||
bool processEvent(const ButtonEvent &be); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍