From 59892df74f1c2e1008fd4b3552b13dad591c1fb7 Mon Sep 17 00:00:00 2001 From: Anthony Good Date: Thu, 25 Jan 2018 21:49:33 -0500 Subject: [PATCH] 2018.01.25.01 FEATURE_AZ_POSITION_HMC5883L_USING_JARZEBSKI_LIBRARY --- .../k3ng_rotator_controller.ino | 88 +++++++++++++++++-- .../rotator_dependencies.h | 2 +- k3ng_rotator_controller/rotator_features.h | 1 + .../rotator_features_m0upu.h | 1 + .../rotator_features_test.h | 21 ++--- .../rotator_features_wb6kcn.h | 1 + 6 files changed, 97 insertions(+), 17 deletions(-) diff --git a/k3ng_rotator_controller/k3ng_rotator_controller.ino b/k3ng_rotator_controller/k3ng_rotator_controller.ino index 483f815..307b011 100644 --- a/k3ng_rotator_controller/k3ng_rotator_controller.ino +++ b/k3ng_rotator_controller/k3ng_rotator_controller.ino @@ -319,6 +319,9 @@ 2017.11.14.01 Merged pulled request #42 - allowing functions to return their calculated values https://github.com/k3ng/k3ng_rotator_controller/pull/42 (Thanks, SQ6EMM) + 2018.01.25.01 + FEATURE_AZ_POSITION_HMC5883L_USING_JARZEBSKI_LIBRARY + {need to document in wiki after someone tests} All library files should be placed in directories likes \sketchbook\libraries\library1\ , \sketchbook\libraries\library2\ , etc. Anything rotator_*.* should be in the ino directory! @@ -329,7 +332,7 @@ */ -#define CODE_VERSION "2017.11.14.01" +#define CODE_VERSION "2018.01.25.01" #include #include @@ -382,7 +385,7 @@ #include // required for FEATURE_I2C_LCD, any ADXL345 feature, FEATURE_AZ_POSITION_HMC5883L, FEATURE_EL_POSITION_ADAFRUIT_LSM303 #endif -#if defined(FEATURE_AZ_POSITION_HMC5883L) +#if defined(FEATURE_AZ_POSITION_HMC5883L) || defined(FEATURE_AZ_POSITION_HMC5883L_USING_JARZEBSKI_LIBRARY) #include // required for HMC5883L digital compass support #endif @@ -471,7 +474,7 @@ #endif #ifdef FEATURE_STEPPER_MOTOR - #include +// #include #endif #include "rotator_language.h" @@ -874,7 +877,7 @@ DebugClass debug; K3NGdisplay k3ngdisplay(LCD_COLUMNS,LCD_ROWS,LCD_UPDATE_TIME); #endif -#ifdef FEATURE_AZ_POSITION_HMC5883L +#if defined(FEATURE_AZ_POSITION_HMC5883L) || defined(FEATURE_AZ_POSITION_HMC5883L_USING_JARZEBSKI_LIBRARY) HMC5883L compass; #endif //FEATURE_AZ_POSITION_HMC5883L @@ -4708,6 +4711,50 @@ void read_azimuth(byte force_read){ azimuth = raw_azimuth; #endif // FEATURE_AZ_POSITION_HMC5883L + #ifdef FEATURE_AZ_POSITION_HMC5883L_USING_JARZEBSKI_LIBRARY + Vector norm = compass.readNormalize(); + + // Calculate heading + float heading = atan2(norm.YAxis, norm.XAxis); + + #ifdef DEBUG_HMC5883L + debug.print("read_azimuth: HMC5883L x:"); + debug.print(norm.XAxis,4); + debug.print(" y:"); + debug.print(norm.YAxis,4); + debug.println(""); + #endif //DEBUG_HMC5883L + + // Set declination angle on your location and fix heading + // You can find your declination on: http://magnetic-declination.com/ + // (+) Positive or (-) for negative + // For Bytom / Poland declination angle is 4'26E (positive) + // Formula: (deg + (min / 60.0)) / (180 / M_PI); + //float declinationAngle = (4.0 + (26.0 / 60.0)) / (180 / M_PI); + //heading += declinationAngle; + + // Correct for heading < 0deg and heading > 360deg + if (heading < 0){ + heading += 2 * PI; + } + + if (heading > 2 * PI){ + heading -= 2 * PI; + } + + // Convert to degrees + raw_azimuth = heading * 180 / M_PI; + + if (AZIMUTH_SMOOTHING_FACTOR > 0) { + raw_azimuth = (raw_azimuth * (1 - (AZIMUTH_SMOOTHING_FACTOR / 100))) + (previous_raw_azimuth * (AZIMUTH_SMOOTHING_FACTOR / 100)); + } + #ifdef FEATURE_AZIMUTH_CORRECTION + raw_azimuth = (correct_azimuth(raw_azimuth / (float) HEADING_MULTIPLIER) * HEADING_MULTIPLIER); + #endif // FEATURE_AZIMUTH_CORRECTION + raw_azimuth = raw_azimuth + (configuration.azimuth_offset * HEADING_MULTIPLIER); + azimuth = raw_azimuth; + #endif FEATURE_AZ_POSITION_HMC5883L_USING_JARZEBSKI_LIBRARY + #ifdef FEATURE_AZ_POSITION_ADAFRUIT_LSM303 lsm.read(); @@ -6994,7 +7041,7 @@ void initialize_peripherals(){ #ifndef OPTION_DISABLE_HMC5883L_ERROR_CHECKING if (error != 0) { #if defined(FEATURE_REMOTE_UNIT_SLAVE) || defined(FEATURE_YAESU_EMULATION) || defined(FEATURE_EASYCOM_EMULATION) - control_port->print(F("setup: compass error:")); + control_port->print(F("initialize_peripherals: compass error:")); control_port->println(compass.GetErrorText(error)); // check if there is an error, and print if so #endif } @@ -7003,13 +7050,42 @@ void initialize_peripherals(){ #ifndef OPTION_DISABLE_HMC5883L_ERROR_CHECKING if (error != 0) { #if defined(FEATURE_REMOTE_UNIT_SLAVE) || defined(FEATURE_YAESU_EMULATION) || defined(FEATURE_EASYCOM_EMULATION) - control_port->print(F("setup: compass error:")); + control_port->print(F("initialize_peripherals: compass error:")); control_port->println(compass.GetErrorText(error)); // check if there is an error, and print if so #endif } #endif //OPTION_DISABLE_HMC5883L_ERROR_CHECKING #endif // FEATURE_AZ_POSITION_HMC5883L + #if defined(FEATURE_AZ_POSITION_HMC5883L_USING_JARZEBSKI_LIBRARY) + while (!compass.begin()) + { + #if defined(FEATURE_REMOTE_UNIT_SLAVE) || defined(FEATURE_YAESU_EMULATION) || defined(FEATURE_EASYCOM_EMULATION) + control_port->println("initialize_peripherals: could not find a valid HMC5883L sensor"); + #endif + delay(500); + } + + // Set measurement range + compass.setRange(HMC5883L_RANGE_1_3GA); + + // Set measurement mode + compass.setMeasurementMode(HMC5883L_CONTINOUS); + + // Set data rate + compass.setDataRate(HMC5883L_DATARATE_30HZ); + + // Set number of samples averaged + compass.setSamples(HMC5883L_SAMPLES_8); + + // Set calibration offset. See HMC5883L_calibration.ino + compass.setOffset(0, 0); + + + #endif //FEATURE_AZ_POSITION_HMC5883L_USING_JARZEBSKI_LIBRARY + + + #ifdef FEATURE_EL_POSITION_ADXL345_USING_LOVE_ELECTRON_LIB accel = ADXL345(); accel.SetRange(2, true); diff --git a/k3ng_rotator_controller/rotator_dependencies.h b/k3ng_rotator_controller/rotator_dependencies.h index b0ba31d..6840a0f 100755 --- a/k3ng_rotator_controller/rotator_dependencies.h +++ b/k3ng_rotator_controller/rotator_dependencies.h @@ -46,7 +46,7 @@ #undef FEATURE_EL_PRESET_ENCODER #endif -#if !defined(FEATURE_AZ_POSITION_POTENTIOMETER) && !defined(FEATURE_AZ_POSITION_ROTARY_ENCODER) && !defined(FEATURE_AZ_POSITION_PULSE_INPUT) && !defined(FEATURE_AZ_POSITION_GET_FROM_REMOTE_UNIT) && !defined(FEATURE_AZ_POSITION_HMC5883L) && !defined(FEATURE_AZ_POSITION_ADAFRUIT_LSM303) && !defined(FEATURE_AZ_POSITION_HH12_AS5045_SSI) &&!defined(FEATURE_AZ_POSITION_INCREMENTAL_ENCODER) &&!defined(FEATURE_AZ_POSITION_POLOLU_LSM303) &&!defined(FEATURE_AZ_POSITION_A2_ABSOLUTE_ENCODER) &&!defined(FEATURE_AZ_POSITION_ROTARY_ENCODER_USE_PJRC_LIBRARY) +#if !defined(FEATURE_AZ_POSITION_POTENTIOMETER) && !defined(FEATURE_AZ_POSITION_ROTARY_ENCODER) && !defined(FEATURE_AZ_POSITION_PULSE_INPUT) && !defined(FEATURE_AZ_POSITION_GET_FROM_REMOTE_UNIT) && !defined(FEATURE_AZ_POSITION_HMC5883L) && !defined(FEATURE_AZ_POSITION_ADAFRUIT_LSM303) && !defined(FEATURE_AZ_POSITION_HH12_AS5045_SSI) &&!defined(FEATURE_AZ_POSITION_INCREMENTAL_ENCODER) &&!defined(FEATURE_AZ_POSITION_POLOLU_LSM303) &&!defined(FEATURE_AZ_POSITION_A2_ABSOLUTE_ENCODER) &&!defined(FEATURE_AZ_POSITION_ROTARY_ENCODER_USE_PJRC_LIBRARY) && !defined(FEATURE_AZ_POSITION_HMC5883L_USING_JARZEBSKI_LIBRARY) #error "You must specify one AZ position sensor feature" #endif diff --git a/k3ng_rotator_controller/rotator_features.h b/k3ng_rotator_controller/rotator_features.h index e68b6cb..5f0db96 100755 --- a/k3ng_rotator_controller/rotator_features.h +++ b/k3ng_rotator_controller/rotator_features.h @@ -43,6 +43,7 @@ // #define FEATURE_AZ_POSITION_ROTARY_ENCODER_USE_PJRC_LIBRARY // library @ http://www.pjrc.com/teensy/td_libs_Encoder.html // #define FEATURE_AZ_POSITION_PULSE_INPUT // #define FEATURE_AZ_POSITION_HMC5883L // HMC5883L digital compass support +// #define FEATURE_AZ_POSITION_HMC5883L_USING_JARZEBSKI_LIBRARY // HMC5883L digital compass support using Jarzebski library at https://github.com/jarzebski/Arduino-HMC5883L // #define FEATURE_AZ_POSITION_GET_FROM_REMOTE_UNIT // requires FEATURE_MASTER_WITH_SERIAL_SLAVE or FEATURE_MASTER_WITH_ETHERNET_SLAVE // #define FEATURE_AZ_POSITION_ADAFRUIT_LSM303 // Uncomment for azimuth using LSM303 compass and Adafruit library (https://github.com/adafruit/Adafruit_LSM303) (also uncomment object declaration below) // #define FEATURE_AZ_POSITION_POLOLU_LSM303 // Uncomment for azimuth using LSM303 compass and Polulu library diff --git a/k3ng_rotator_controller/rotator_features_m0upu.h b/k3ng_rotator_controller/rotator_features_m0upu.h index c53d42d..15bac46 100755 --- a/k3ng_rotator_controller/rotator_features_m0upu.h +++ b/k3ng_rotator_controller/rotator_features_m0upu.h @@ -43,6 +43,7 @@ // #define FEATURE_AZ_POSITION_ROTARY_ENCODER_USE_PJRC_LIBRARY // library @ http://www.pjrc.com/teensy/td_libs_Encoder.html //#define FEATURE_AZ_POSITION_PULSE_INPUT //#define FEATURE_AZ_POSITION_HMC5883L // HMC5883L digital compass support +//#define FEATURE_AZ_POSITION_HMC5883L_USING_JARZEBSKI_LIBRARY // HMC5883L digital compass support using Jarzebski library at https://github.com/jarzebski/Arduino-HMC5883L //#define FEATURE_AZ_POSITION_GET_FROM_REMOTE_UNIT // requires FEATURE_MASTER_WITH_SERIAL_SLAVE or FEATURE_MASTER_WITH_ETHERNET_SLAVE //#define FEATURE_AZ_POSITION_ADAFRUIT_LSM303 // Uncomment for azimuth using LSM303 compass and Adafruit library (https://github.com/adafruit/Adafruit_LSM303) (also uncomment object declaration below) //#define FEATURE_AZ_POSITION_POLOLU_LSM303 // Uncomment for azimuth using LSM303 compass and Polulu library diff --git a/k3ng_rotator_controller/rotator_features_test.h b/k3ng_rotator_controller/rotator_features_test.h index 5c03011..9d61119 100755 --- a/k3ng_rotator_controller/rotator_features_test.h +++ b/k3ng_rotator_controller/rotator_features_test.h @@ -13,14 +13,14 @@ */ #define FEATURE_ELEVATION_CONTROL // uncomment this for AZ/EL rotators -#define FEATURE_YAESU_EMULATION // uncomment this for Yaesu GS-232 emulation on control port +// #define FEATURE_YAESU_EMULATION // uncomment this for Yaesu GS-232 emulation on control port // #define FEATURE_EASYCOM_EMULATION // Easycom protocol emulation on control port (undefine FEATURE_YAESU_EMULATION above) -#define FEATURE_MOON_TRACKING -#define FEATURE_SUN_TRACKING -#define FEATURE_CLOCK -#define FEATURE_GPS -#define FEATURE_RTC_DS1307 +// #define FEATURE_MOON_TRACKING +// #define FEATURE_SUN_TRACKING +// #define FEATURE_CLOCK +// #define FEATURE_GPS +// #define FEATURE_RTC_DS1307 // #define FEATURE_RTC_PCF8583 // #define FEATURE_ETHERNET // #define FEATURE_STEPPER_MOTOR // requires Mega or an AVR with Timer 5 support @@ -36,22 +36,23 @@ // #define LANGUAGE_DUTCH /* master and remote slave unit functionality */ -// #define FEATURE_REMOTE_UNIT_SLAVE // uncomment this to make this unit a remote unit controlled by a host unit +#define FEATURE_REMOTE_UNIT_SLAVE // uncomment this to make this unit a remote unit controlled by a host unit // #define FEATURE_MASTER_WITH_SERIAL_SLAVE // [master]{remote_port}<-------serial-------->{control_port}[slave] // #define FEATURE_MASTER_WITH_ETHERNET_SLAVE // [master]<-------------------ethernet--------------------->[slave] /* position sensors - pick one for azimuth and one for elevation if using an az/el rotator */ - // #define FEATURE_AZ_POSITION_POTENTIOMETER //this is used for both a voltage from a rotator control or a homebrew rotator with a potentiometer + #define FEATURE_AZ_POSITION_POTENTIOMETER //this is used for both a voltage from a rotator control or a homebrew rotator with a potentiometer // #define FEATURE_AZ_POSITION_ROTARY_ENCODER // #define FEATURE_AZ_POSITION_ROTARY_ENCODER_USE_PJRC_LIBRARY // library @ http://www.pjrc.com/teensy/td_libs_Encoder.html // #define FEATURE_AZ_POSITION_PULSE_INPUT // #define FEATURE_AZ_POSITION_HMC5883L // HMC5883L digital compass support +// #define FEATURE_AZ_POSITION_HMC5883L_USING_JARZEBSKI_LIBRARY // HMC5883L digital compass support using Jarzebski library at https://github.com/jarzebski/Arduino-HMC5883L // #define FEATURE_AZ_POSITION_GET_FROM_REMOTE_UNIT // requires FEATURE_MASTER_WITH_SERIAL_SLAVE or FEATURE_MASTER_WITH_ETHERNET_SLAVE // #define FEATURE_AZ_POSITION_ADAFRUIT_LSM303 // Uncomment for azimuth using LSM303 compass and Adafruit library (https://github.com/adafruit/Adafruit_LSM303) (also uncomment object declaration below) // #define FEATURE_AZ_POSITION_POLOLU_LSM303 // Uncomment for azimuth using LSM303 compass and Polulu library -#define FEATURE_AZ_POSITION_HH12_AS5045_SSI +// #define FEATURE_AZ_POSITION_HH12_AS5045_SSI // #define FEATURE_AZ_POSITION_INCREMENTAL_ENCODER // #define FEATURE_AZ_POSITION_A2_ABSOLUTE_ENCODER @@ -70,7 +71,7 @@ // #define FEATURE_EL_POSITION_A2_ABSOLUTE_ENCODER // And if you are using an Adafruit, Yourduino, RFRobot, YWRobot, or SainSmart display, you must also change the feature setting in rotator_k3ngdisplay.h!!!! -#define FEATURE_4_BIT_LCD_DISPLAY // Uncomment for classic 4 bit LCD display (most common) +// #define FEATURE_4_BIT_LCD_DISPLAY // Uncomment for classic 4 bit LCD display (most common) // #define FEATURE_ADAFRUIT_I2C_LCD // #define FEATURE_ADAFRUIT_BUTTONS // Uncomment this to use Adafruit I2C LCD buttons for manual AZ/EL instead of normal buttons (also set this feature in rotator_k3ngdisplay.h) // #define FEATURE_YOURDUINO_I2C_LCD diff --git a/k3ng_rotator_controller/rotator_features_wb6kcn.h b/k3ng_rotator_controller/rotator_features_wb6kcn.h index 0116463..22ec962 100755 --- a/k3ng_rotator_controller/rotator_features_wb6kcn.h +++ b/k3ng_rotator_controller/rotator_features_wb6kcn.h @@ -44,6 +44,7 @@ // #define FEATURE_AZ_POSITION_ROTARY_ENCODER_USE_PJRC_LIBRARY // library @ http://www.pjrc.com/teensy/td_libs_Encoder.html //#define FEATURE_AZ_POSITION_PULSE_INPUT //#define FEATURE_AZ_POSITION_HMC5883L // HMC5883L digital compass support +//#define FEATURE_AZ_POSITION_HMC5883L_USING_JARZEBSKI_LIBRARY // HMC5883L digital compass support using Jarzebski library at https://github.com/jarzebski/Arduino-HMC5883L //#define FEATURE_AZ_POSITION_GET_FROM_REMOTE_UNIT // requires FEATURE_MASTER_WITH_SERIAL_SLAVE or FEATURE_MASTER_WITH_ETHERNET_SLAVE //#define FEATURE_AZ_POSITION_ADAFRUIT_LSM303 // Uncomment for azimuth using LSM303 compass and Adafruit library (https://github.com/adafruit/Adafruit_LSM303) (also uncomment object declaration below) //#define FEATURE_AZ_POSITION_POLOLU_LSM303 // Uncomment for azimuth using LSM303 compass and Polulu library