27#include "sensesp/sensors/sensor.h"
28#include "sensesp/signalk/signalk_output.h"
29#include "sensesp/system/lambda_consumer.h"
30#include "sensesp_app_builder.h"
36#include "sensesp/sensors/digital_input.h"
37#include "sensesp/transforms/debounce.h"
46#include "sensesp/transforms/angle_correction.h"
47#include "sensesp/transforms/curveinterpolator.h"
53#include "sensesp/signalk/signalk_types.h"
59#include "sensesp/transforms/linear.h"
69#define BOARD_ACCEL_MAG_I2C_ADDR (0x1F)
70#define BOARD_GYRO_I2C_ADDR (0x21)
71#define PIN_I2C_SDA (23)
72#define PIN_I2C_SCL (25)
73#define PIN_SWITCH_CAL_SAVE (32)
74#define SWITCH_ACTIVE_STATE (0)
79#define ORIENTATION_REPORTING_INTERVAL_MS (100)
81using namespace sensesp;
90 : CurveInterpolator( NULL, config_path) {
124 SetupLogging(ESP_LOG_INFO);
133 SensESPAppBuilder builder;
134 sensesp_app = (&builder)
136 ->set_hostname(
"eCompass")
144 ->enable_uptime_sensor()
145 ->enable_ip_address_sensor()
146 ->enable_free_mem_sensor()
147 ->enable_system_hz_sensor()
173 const char* kSKPathHeadingCompass =
"navigation.headingCompass";
174 const char* kSKPathHeadingMagnetic =
"navigation.headingMagnetic";
175 const char* kSKPathAttitude =
"navigation.attitude";
182 const char* kSKPathTurnRate =
"navigation.rateOfTurn";
183 const char* kSKPathRollRate =
"navigation.rateOfRoll";
184 const char* kSKPathPitchRate =
"navigation.rateOfPitch";
189 const char* kSKPathTemperature =
190 "environment.inside.ecompass.temperature";
194 const char* kSKPathAccelX =
"sensors.accelerometer.accel_x";
195 const char* kSKPathAccelY =
"sensors.accelerometer.accel_y";
196 const char* kSKPathAccelZ =
"sensors.accelerometer.accel_z";
207 const char* kSKPathMagFit =
"orientation.calibration.magfit";
208 const char* kSKPathMagFitTrial =
"orientation.calibration.magfittrial";
209 const char* kSKPathMagSolver =
"orientation.calibration.magsolver";
210 const char* kSKPathMagInclination =
"orientation.calibration.maginclination";
211 const char* kSKPathMagBValue =
"orientation.calibration.magmagnitude";
212 const char* kSKPathMagBValueTrial =
"orientation.calibration.magmagnitudetrial";
213 const char* kSKPathMagNoise =
"orientation.calibration.magnoise";
214 const char* kSKPathMagCalValues =
"orientation.calibration.magvalues";
236 const char* kConfigPathNone =
"";
256 PIN_I2C_SDA, PIN_I2C_SCL, BOARD_ACCEL_MAG_I2C_ADDR, BOARD_GYRO_I2C_ADDR);
257 const int fusionIntervalMs = 1000 / orientation_sensor->GetFusionRateHz();
258 event_loop()->onRepeat( fusionIntervalMs,
259 [orientation_sensor]() { orientation_sensor->ReadAndProcessSensors(); }
303 auto compass_heading = std::make_shared<RepeatSensor<float>>(
304 ORIENTATION_REPORTING_INTERVAL_MS,
305 [sensor_heading]() {
return sensor_heading->ReportValue(); }
315 auto compass_sk_output = std::make_shared<SKOutput<float>>(
316 kSKPathHeadingCompass,
325 auto magneticheading_sk_output = std::make_shared<SKOutput<float>>(
326 kSKPathHeadingMagnetic,
339 const char* kConfigPathDeviation =
"/sensors/hdg/deviation";
341 ConfigItem(deviationInterpolator)
342 ->set_title(
"Deviation Table")
343 ->set_description(
"Interpolation Values")
344 ->set_sort_order(1001);
348 const char* kConfigPathHeadingOffset =
"/sensors/hdg/offset";
349 auto* mountingOffset =
new AngleCorrection((PI/2.0), 0.0, kConfigPathHeadingOffset);
350 ConfigItem(mountingOffset)
351 ->set_title(
"Mounting Offset")
352 ->set_description(
"Enter any adjustment to be applied to all headings (e.g. from mounting offsets)")
353 ->set_sort_order(400);
357 ->connect_to(mountingOffset)
358 ->connect_to(compass_sk_output)
359 ->connect_to(deviationInterpolator)
360 ->connect_to(
new AngleCorrection(0.0, 0.0, kConfigPathNone))
361 ->connect_to(magneticheading_sk_output);
715void loop() { event_loop()->tick(); }
DeviationInterpolator(String config_path="")
OrientationSensor represents a 9-Degrees-of-Freedom sensor (magnetometer, accelerometer,...
OrientationValues reads and outputs orientation parameters.
@ kCompassHeading
compass heading, also called yaw
Orientation sensor interface to SensESP.
Vessel orientation data structures definition file.