OpenAstroTech / OpenAstroTracker-Firmware

Official firmware for the OpenAstroTracker.
https://wiki.openastrotech.com
MIT License
89 stars 61 forks source link

#define NEW_STEPPER_LIB compiler FAILS - both Arduino IDE and Platform.IO #246

Closed illigtr closed 1 month ago

illigtr commented 1 month ago

For some reason, I have NEVER been able to compile using the NEW_STEPPER_LIB definition. Always get a pack of errors. Why won't this work?

My Configuration:

Here is my Configuration_local.hpp

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// This configuration file was generated by the OAT/OAM Configurator at https://config.openastrotech.com
// and is for firmware to be used on a OpenAstroTracker.
// Save this as Configuration_local.hpp in the folder where you placed the firmware code.
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Unique ConfigKey: TR:OAT,FWT:L,SL:N,HS:N,BD:M21,RST:N8,RDO:TU,RATP900:O90:A3000:V1800:S16:T256:,RTR:Y,RT:1,DS:N8,DDT:TU,DATP900:O90:A3000:V1800:S16:T256:,DT:1,DLIN90:D45:,STL:S,DY:NO,GP:N,LM:N,FC:Y,FS:BY,FD:TU,FAP150:O100:S1:H10:,FMSA600:V400:,APT:N,RAH:N
/////////////////////////////////////////////////////////////////////////////////////////////////////////

// Use the much higher performance stepper library.
//#define NEW_STEPPER_LIB

// We live in the Northern Hemisphere
#define NORTHERN_HEMISPHERE 1

// We are using the MKS GEN L V2.1 board
#if defined(BOARD) && BOARD != BOARD_AVR_MKS_GEN_L_V21
    #error Selected PIO environment does not match this configuration
#else
    #define BOARD BOARD_AVR_MKS_GEN_L_V21
#endif

////////////////////////////////
// RA Stepper configuration (OAT)
// See supported stepper values. Change according to the steppers you are using
// Using the NEMA 17, 1.8°/step stepper for RA
#define RA_STEPPER_TYPE STEPPER_TYPE_ENABLED
#define RA_STEPPER_SPR 200.0f

// Using the TMC2209-UART driver for RA stepper motor
#define RA_DRIVER_TYPE DRIVER_TYPE_TMC2209_UART

// Define some RA stepper motor settings
#define RA_MOTOR_CURRENT_RATING        900 // mA
#define RA_OPERATING_CURRENT_SETTING   90 // %
#define RA_STEPPER_ACCELERATION        3000
#define RA_STEPPER_SPEED               1800
#define RA_SLEW_MICROSTEPPING          16
#define RA_TRACKING_MICROSTEPPING      256

// Is it going the wrong way?
#define RA_INVERT_DIR  0

#ifdef NEW_STEPPER_LIB
  #define RA_SLEWING_ACCELERATION_DEG   2.0  // deg/s/s
  #define RA_SLEWING_SPEED_DEG          2.0  // deg/s
#endif

// Track immediately after boot
#define TRACK_ON_BOOT 0

// Define limits for RA... 
#define RA_LIMIT_LEFT     5.5f
#define RA_LIMIT_RIGHT    6.5f
#define RA_TRACKING_LIMIT 6.75f // can't quite get to 7h...

// Using the 16 tooth gear (recommended) for RA belt
#define RA_PULLEY_TEETH 16

////////////////////////////////
// DEC Stepper configuration 
// See supported stepper values. Change according to the steppers you are using
// Using the NEMA 17, 1.8°/step stepper for DEC
#define DEC_STEPPER_TYPE STEPPER_TYPE_ENABLED
#define DEC_STEPPER_SPR 200.0f

// Using the TMC2209-UART driver for DEC stepper
#define DEC_DRIVER_TYPE DRIVER_TYPE_TMC2209_UART

// Define some DEC stepper motor settings
#define DEC_MOTOR_CURRENT_RATING       800 // mA
#define DEC_OPERATING_CURRENT_SETTING  90 // %
#define DEC_STEPPER_ACCELERATION       3000
#define DEC_STEPPER_SPEED              1800
#define DEC_SLEW_MICROSTEPPING         16
#define DEC_GUIDE_MICROSTEPPING        256

// Is it going the wrong way?
#define DEC_INVERT_DIR  0

#ifdef NEW_STEPPER_LIB
  #define DEC_SLEWING_ACCELERATION_DEG   2.0  // degs/s/s
  #define DEC_SLEWING_SPEED_DEG          2.0  // deg/s
#endif

// Using the 16 tooth gear (recommended) for DEC belt
#define DEC_PULLEY_TEETH 16

// Define DEC limits
#define DEC_LIMIT_UP   90 // degrees from Home
#define DEC_LIMIT_DOWN 55 // degrees from Home

// TMC2209 Stealth Mode (spreadCycle) - When set to 0, tracking is more precise, but noisy (high-pitched hissing sound). When set to 1, they are silent.
#define RA_UART_STEALTH_MODE      1
#define DEC_UART_STEALTH_MODE     1

////////////////////////////////
// Display configuration 
// Define the type of display we are using. Currently: No display
#define DISPLAY_TYPE DISPLAY_TYPE_LCD_KEYPAD

////////////////////////////////
// GPS Addon configuration 
// Define whether we have the GPS addon or not. Currently: No GPS
#define USE_GPS 1

////////////////////////////////
// Digital Level Addon configuration 
// Define whether we have the Digital Level or not. Currently: No Digital Level
#define USE_GYRO_LEVEL 1
#define GYRO_AXIS_SWAP 0 
// MKS uses software I2C library. Define the SCL and SDA pins you wired (recommended are 11 and 21) 
#define USE_GYRO_WITH_SOFTWAREI2C 1 
#define GYRO_SOFTWARE_SCL_PIN 11 
#define GYRO_SOFTWARE_SDA_PIN 21 efine USE_GYRO_LEVEL 1

////////////////////////////////
// Focuser configuration 
// Define whether to support a focusing stepper motor on E1 or not. Currently: Focuser stepper

// Using the Modded 28BYJ-48 (Bipolar) stepper for FOC
#define FOCUS_STEPPER_TYPE STEPPER_TYPE_ENABLED
#define FOCUS_STEPPER_SPR 2048.0f

// Using the TMC2209-UART driver for focuser stepper
#define FOCUS_DRIVER_TYPE DRIVER_TYPE_TMC2209_UART

// Define Focus stepper motor power settings
#define FOCUS_MOTOR_CURRENT_RATING       150 // mA
#define FOCUS_OPERATING_CURRENT_SETTING  100 // %
#define FOCUS_MICROSTEPPING              1 // steps
#define FOCUSER_MOTOR_HOLD_SETTING       10 // %
#define FOCUS_UART_STEALTH_MODE          1 // silent?
#define FOCUSER_ALWAYS_ON                1

// Define some focuser stepper motor settings
#define FOCUS_STEPPER_ACCELERATION 600
#define FOCUS_STEPPER_SPEED 400

////////////////////////////////
// AutoPA Addon configuration 
// Define whether we have the AutoPA add on or not. Currently: No AutoPA
// No AutoPA settings

//////////////////////////////// 
// Auto Homing addons 
#define USE_HALL_SENSOR_RA_AUTOHOME 1 
#define RA_HOMING_SENSOR_SEARCH_DEGREES 30
#define RA_HOMING_SENSOR_ACTIVE_STATE HIGH
#define USE_HALL_SENSOR_DEC_AUTOHOME 1 
#define DEC_HOMING_SENSOR_SEARCH_DEGREES 50
#define DEC_HOMING_SENSOR_ACTIVE_STATE HIGH

///////////////////////
// Debug settings
// DEBUG_NONE
// DEBUG_WIFI
// DEBUG_MOUNT 
// DEBUG_FOCUS         
//|DEBUG_EEPROM|DEBUG_GYRO|DEBUG_GPS|DEBUG_COORD_CALC| DEBUG_GPS
// DEBUG_MEADE|DEBUG_SERIAL|DEBUG_INFO|DEBUG_MOUNT_VERBOSE|DEBUG_GENERAL|DEBUG_MEADE|DEBUG_VERBOSE|DEBUG_STEPPERS|DEBUG_ANY
//#define DEBUG_LEVEL (DEBUG_NONE)
//#define DEBUG_LEVEL (DEBUG_MEADE|DEBUG_ANY)
//#define DEBUG_LEVEL (DEBUG_NONE)
#define DEBUG_LEVEL (DEBUG_INFO)

// UART CONNECTION TEST - USE only TX or TXRX at the same time
//#define UART_CONNECTION_TEST_TX 1   // this one contains a 5 degree self-test in both motors
//#define UART_CONNECTION_TEST_TXRX 1
// define debug commands to Serial1

#define DEBUG_SEPARATE_SERIAL 1
#define DEBUG_SERIAL_PORT Serial2
#define DEBUG_SERIAL_BAUDRATE 115200

Here is my modified pins_MKS_GEN_L_V21.h

#pragma once

// DRIVER_TYPE_TMC2209_UART requires 4 digital pins in Arduino pin numbering
#ifndef RA_STEP_PIN
    #define RA_STEP_PIN 54  // STEP
#endif
#ifndef RA_DIR_PIN
    #define RA_DIR_PIN 55  // DIR
#endif
#ifndef RA_EN_PIN
    #define RA_EN_PIN 38  // Enable
#endif
#ifndef RA_DIAG_PIN
    #define RA_DIAG_PIN 3  // only needed for autohome function
#endif
#ifndef RA_MS0_PIN
    #define RA_MS0_PIN 51
#endif
#ifndef RA_MS1_PIN
    #define RA_MS1_PIN 52
#endif
#ifndef RA_MS2_PIN
    #define RA_MS2_PIN 63
#endif
// DRIVER_TYPE_TMC2209_UART requires 2 additional digital pins for SoftwareSerial, can be shared across all drivers
#ifndef RA_SERIAL_PORT_TX
    #define RA_SERIAL_PORT_TX 40  // SoftwareSerial TX port
#endif
#ifndef RA_SERIAL_PORT_RX
    #define RA_SERIAL_PORT_RX 63  // SoftwareSerial RX port
#endif
#ifndef RA_DRIVER_ADDRESS
    #define RA_DRIVER_ADDRESS 0b00
#endif
// DRIVER_TYPE_TMC2209_UART requires 4 digital pins in Arduino pin numbering
#ifndef DEC_STEP_PIN
    #define DEC_STEP_PIN 60  // STEP
#endif
#ifndef DEC_DIR_PIN
    #define DEC_DIR_PIN 61  // DIR
#endif
#ifndef DEC_EN_PIN
    #define DEC_EN_PIN 56  // Enable
#endif
#ifndef DEC_DIAG_PIN
    #define DEC_DIAG_PIN 14  // only needed for autohome function
    //#define DEC_DIAG_PIN -1
#endif
#ifndef DEC_MS0_PIN
    #define DEC_MS0_PIN 51
#endif
#ifndef DEC_MS1_PIN
    #define DEC_MS1_PIN 52
#endif
#ifndef DEC_MS2_PIN
    #define DEC_MS2_PIN 64
#endif
// DRIVER_TYPE_TMC2209_UART requires 2 additional digital pins for SoftwareSerial, can be shared across all drivers
#ifndef DEC_SERIAL_PORT_TX
    #define DEC_SERIAL_PORT_TX 59  // SoftwareSerial TX port
#endif
#ifndef DEC_SERIAL_PORT_RX
    #define DEC_SERIAL_PORT_RX 64  // SoftwareSerial RX port
#endif
#ifndef DEC_DRIVER_ADDRESS
    #define DEC_DRIVER_ADDRESS 0b00
#endif

#define SW_SERIAL_UART 1
#ifndef UART_CONNECTION_TEST_TXRX
    #define UART_CONNECTION_TEST_TXRX 1
#endif

// DRIVER_TYPE_TMC2209_UART requires 4 digital pins in Arduino pin numbering
#ifndef AZ_STEP_PIN
    #define AZ_STEP_PIN 46  // STEP
#endif
#ifndef AZ_DIR_PIN
    #define AZ_DIR_PIN 48  // DIR
#endif
#ifndef AZ_EN_PIN
    #define AZ_EN_PIN 62  // Enable
#endif
#ifndef AZ_DIAG_PIN
    #define AZ_DIAG_PIN 18  // only needed for autohome function
#endif
// DRIVER_TYPE_TMC2209_UART requires 2 additional digital pins for SoftwareSerial, can be shared across all drivers
#ifndef AZ_SERIAL_PORT_TX
    #define AZ_SERIAL_PORT_TX 42  // SoftwareSerial TX port
#endif
#ifndef AZ_SERIAL_PORT_RX
    #define AZ_SERIAL_PORT_RX 65  // SoftwareSerial RX port
#endif
#ifndef AZ_DRIVER_ADDRESS
    #define AZ_DRIVER_ADDRESS 0b00
#endif
// DRIVER_TYPE_TMC2209_UART requires 4 digital pins in Arduino pin numbering
#ifndef ALT_STEP_PIN
    #define ALT_STEP_PIN 26  // STEP
#endif
#ifndef ALT_DIR_PIN
    #define ALT_DIR_PIN 28  // DIR
#endif
#ifndef ALT_EN_PIN
    #define ALT_EN_PIN 24  // Enable
#endif
#ifndef ALT_DIAG_PIN
    #define ALT_DIAG_PIN 2  // only needed for autohome function
#endif
// DRIVER_TYPE_TMC2209_UART requires 2 additional digital pins for SoftwareSerial, can be shared across all drivers
#ifndef ALT_SERIAL_PORT_TX
    #define ALT_SERIAL_PORT_TX 44  // SoftwareSerial TX port
#endif
#ifndef ALT_SERIAL_PORT_RX
    #define ALT_SERIAL_PORT_RX 66  // SoftwareSerial RX port
#endif
#ifndef ALT_DRIVER_ADDRESS
    #define ALT_DRIVER_ADDRESS 0b00
#endif

// DRIVER_TYPE_TMC2209_UART requires 4 digital pins in Arduino pin numbering. This is the E1 port.
#ifndef FOCUS_STEP_PIN
    #define FOCUS_STEP_PIN 36  // STEP
#endif
#ifndef FOCUS_DIR_PIN
    #define FOCUS_DIR_PIN 34  // DIR
#endif
#ifndef FOCUS_EN_PIN
    #define FOCUS_EN_PIN 30  // Enable
#endif
#ifndef FOCUS_DIAG_PIN
    #define FOCUS_DIAG_PIN 15  // only needed for autohome function
    //#define FOCUS_DIAG_PIN -1
#endif
// DRIVER_TYPE_TMC2209_UART requires 2 additional digital pins for SoftwareSerial, can be shared across all drivers
#ifndef FOCUS_SERIAL_PORT_TX
    #define FOCUS_SERIAL_PORT_TX 20  // SoftwareSerial TX port
#endif
#ifndef FOCUS_SERIAL_PORT_RX
    #define FOCUS_SERIAL_PORT_RX 12  // SoftwareSerial RX port
#endif
#ifndef FOCUS_DRIVER_ADDRESS
    #define FOCUS_DRIVER_ADDRESS 0b00
#endif

// RA Homing pin for Hall sensor
#ifndef RA_HOMING_SENSOR_PIN
    #define RA_HOMING_SENSOR_PIN 53
#endif

// DEC Homing pin for Hall sensor
#ifndef DEC_HOMING_SENSOR_PIN
    #define DEC_HOMING_SENSOR_PIN 52
#endif

// RA End Switch East pin
#ifndef RA_ENDSWITCH_EAST_SENSOR_PIN
    #define RA_ENDSWITCH_EAST_SENSOR_PIN 19
#endif

// RA End Switch West pin
#ifndef RA_ENDSWITCH_WEST_SENSOR_PIN
    #define RA_ENDSWITCH_WEST_SENSOR_PIN 18
#endif

// DEC End Switch Up pin
#ifndef DEC_ENDSWITCH_UP_SENSOR_PIN
    #define DEC_ENDSWITCH_UP_SENSOR_PIN 3
#endif

// DEC End Switch Down pin
#ifndef DEC_ENDSWITCH_DOWN_SENSOR_PIN
    #define DEC_ENDSWITCH_DOWN_SENSOR_PIN 2
#endif

//GPS pin configuration
#ifndef GPS_SERIAL_PORT
    #define GPS_SERIAL_PORT Serial1
#endif

// DISPLAY_TYPE_LCD_KEYPAD requires 6 digital & 1 analog output in Arduino pin numbering
#ifndef LCD_PIN4
    #define LCD_PIN4 37
#endif
#ifndef LCD_PIN5
    #define LCD_PIN5 35
#endif
#ifndef LCD_PIN6
    #define LCD_PIN6 23
#endif
#ifndef LCD_PIN7
    #define LCD_PIN7 25
#endif
#ifndef LCD_PIN8
    #define LCD_PIN8 27
#endif
#ifndef LCD_PIN9
    #define LCD_PIN9 29
#endif

// DISPLAY_TYPE_LCD_KEYPAD requires 1 analog input in Arduino pin numbering
#ifndef LCD_KEY_SENSE_PIN
    #define LCD_KEY_SENSE_PIN 58
#endif

//Pin to turn on dew heater MOSFET
#ifndef DEW_HEATER_1_PIN
    #define DEW_HEATER_1_PIN 10
#endif
#ifndef DEW_HEATER_2_PIN
    #define DEW_HEATER_2_PIN 7
#endif

//Serial port for external debugging
#if DEBUG_SEPARATE_SERIAL == 1
    #ifndef DEBUG_SERIAL_PORT
        #define DEBUG_SERIAL_PORT Serial2  //D16 (LCD_RS) - TXD2 and D17 (LCD_EN) - RXD2
        // #define DEBUG_SERIAL_PORT Serial3 //D14/15
    #endif
//#else
//    #ifndef DEBUG_SERIAL_PORT
//        #define DEBUG_SERIAL_PORT Serial
//    #endif
#endif

Beyond that, the only other mod is to adjust the values for the up/down/left/right/enter of the LCD keypad. Hijacked Serial2 for debug output and moved LCD pins to new pins. All good.

ClutchplateDude commented 1 month ago

Since you didn't provide any errors themselves, there is no way for us to know what's happening. One thing that recently came to light is that the lowest RA_SLEW_MICROSTEPPING and DEC_SLEW_MICROSTEPPING need to be 32 (you have them at 16). Until you provide us actual errors to examine (the errors explain what the problem is), we can't help you.

illigtr commented 1 month ago

I inadvertantly forgot the errors from the build. Mea culpa!

In file included from .pio\libdeps\mksgenlv21\InterruptStepper\include/Stepper.h:25:0,
                 from src\StepperConfiguration.hpp:13,
                 from src\Mount.hpp:15,
                 from src\HallSensorHoming.hpp:5,
                 from src\Mount.cpp:5:
.pio\libdeps\mksgenlv21\InterruptStepper\include/AccelerationRamp.h: In instantiation of 'class AccelerationRamp<256, 16000000, 314, 314>':
.pio\libdeps\mksgenlv21\InterruptStepper\include/Stepper.h:306:65:   required from 'static uint32_t Stepper<INTERRUPT, DRIVER, RAMP>::distanceToGo() [with INTERRUPT = IntervalInterrupt<(Timer)4>; DRIVER = Driver<Pin<60>, Pin<61> >; RAMP = AccelerationRamp<256, 16000000, 314, 314>; uint32_t = long unsigned int]'
src\InterruptAccelStepper.h:89:37:   required from 'uint32_t InterruptAccelStepper<STEPPER>::distanceToGo() [with STEPPER = Stepper<IntervalInterrupt<(Timer)4>, Driver<Pin<60>, Pin<61> >, AccelerationRamp<256, 16000000, 314, 314> >; uint32_t = long unsigned int]'
src\Mount.cpp:1444:66:   required from here
.pio\libdeps\mksgenlv21\InterruptStepper\include/AccelerationRamp.h:91:5: error: static assertion failed: Amount of steps per stair has to be at most 128
     static_assert(STEPS_PER_STAIR <= 128, "Amount of steps per stair has to be at most 128");
     ^~~~~~~~~~~~~
.pio\libdeps\mksgenlv21\InterruptStepper\include/AccelerationRamp.h:92:5: error: static assertion failed: Amount of steps per stair has to be power of 2
     static_assert(is_pow2(STEPS_PER_STAIR), "Amount of steps per stair has to be power of 2");
     ^~~~~~~~~~~~~
Compiling C:\Users\tony_\AppData\Local\Temp\tmphluryn50_patched_WInterrupts.c.o
*** [.pio\build\mksgenlv21\src\Mount.cpp.o] Error 1
================================================================================= [FAILED] Took 3.89 seconds =================================================================================

Environment    Status    Duration
-------------  --------  ------------
mksgenlv21     FAILED    00:00:03.885

I changed the minium slew microstepping as suggested to 32 and the program compiled flawlessly! Thank you. It should be noted that those settings for the RA and DEC motors comes from the OTA Firmware Configurator v2.18. Perhaps this program should be updated to set the default values to 32 instead of 16...

image