init
This commit is contained in:
Executable
+2
@@ -0,0 +1,2 @@
|
|||||||
|
# Auto detect text files and perform LF normalization
|
||||||
|
* text=auto
|
||||||
Executable
+13
@@ -0,0 +1,13 @@
|
|||||||
|
.vscode/settings.json
|
||||||
|
*.json
|
||||||
|
__vm/*
|
||||||
|
*.vcxproj*
|
||||||
|
.vs/*
|
||||||
|
*.sln
|
||||||
|
Debug/*
|
||||||
|
Release/*
|
||||||
|
debug.cfg
|
||||||
|
esp32.svd
|
||||||
|
src/plugins/*
|
||||||
|
debug.svd
|
||||||
|
z.*
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
# CLAUDE.md
|
||||||
|
|
||||||
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||||
|
|
||||||
|
## Project type
|
||||||
|
|
||||||
|
OnStepX is an Arduino sketch ([OnStepX.ino](OnStepX.ino)) — not a CMake / PlatformIO / Makefile project. There is no `platformio.ini`. Builds happen in the Arduino IDE or via `arduino-cli`. The MCU target is selected by which board the user picks in their IDE; the code adapts via the HAL.
|
||||||
|
|
||||||
|
There is no test suite, no linter config, and no CI. "Build" means "compile this sketch for the target board." When asked to verify a change, the realistic checks are:
|
||||||
|
- Read the relevant `Config.defaults.h` and `Validate.h` sections to confirm the change passes preprocessor validation.
|
||||||
|
- For deeper checks, run `arduino-cli compile --fqbn <fqbn> .` from the repo root if `arduino-cli` is available.
|
||||||
|
|
||||||
|
## Configuration is preprocessor-driven
|
||||||
|
|
||||||
|
User-editable controller configuration lives in three header files at the project root or in `src/plugins/`:
|
||||||
|
|
||||||
|
- [Config.h](Config.h) — the main per-installation config: pinmap, mount type, axis drivers, steps/degree, serial baud, WiFi/BT, etc. This file *will* differ between installations and is edited by the end user. Do not "tidy" it.
|
||||||
|
- [Extended.config.h](Extended.config.h) — debug/NV-wipe and other infrequently-changed knobs.
|
||||||
|
- [src/plugins/Plugins.config.h](src/plugins/Plugins.config.h) — enables PLUGIN1..PLUGIN8.
|
||||||
|
|
||||||
|
Defaults live in [src/Config.defaults.h](src/Config.defaults.h); every option `Config.h` does not set is filled in there. Validation rules live in [src/Validate.h](src/Validate.h) — `#error` and `#warning` directives there are the closest thing to a type system this codebase has. When adding a new config option, add the default AND a validation rule.
|
||||||
|
|
||||||
|
`#define FirmwareVersionConfig` in `OnStepX.ino` is bumped whenever `Config.h`'s structure changes; mismatches trigger a `#error` in `Validate.h`.
|
||||||
|
|
||||||
|
`src/plugins/*` is gitignored (except the `sample/` dir). Plugin code is expected to be dropped into that directory by the user.
|
||||||
|
|
||||||
|
## Big picture: HAL → pinmap → Telescope → subsystems
|
||||||
|
|
||||||
|
`OnStepX.ino` is intentionally tiny. It calls `HAL_INIT()`, brings up NV, starts the cooperative task scheduler, instantiates one global `Telescope telescope;`, and registers command channels. Everything else is driven from there.
|
||||||
|
|
||||||
|
Layers, from bottom up:
|
||||||
|
|
||||||
|
1. **HAL** ([src/HAL/](src/HAL/)): one subdirectory per MCU family (`atmel`, `esp`, `stm32`, `teensy`, `mbed`, `arduinoM0`, `default`). `HAL.h` does compile-time `#if defined(__AVR_…)` / `defined(ESP32)` / etc. selection and pulls in the right per-MCU header, which provides `HAL_INIT()`, `HAL_TEMP()`, fast-tick macros, and analog wrappers. Adding a new MCU means adding a HAL subfolder and a branch in `src/HAL/HAL.h`.
|
||||||
|
2. **Pinmap** ([src/pinmaps/](src/pinmaps/)): `Pins.*.h` per board. The user picks one via `#define PINMAP <board>` in `Config.h`; [src/pinmaps/Models.h](src/pinmaps/Models.h) maps that to the include. `Pins.defaults.h` fills in anything the chosen pinmap omits. If `PINMAP == OFF`, the user is expected to define `AXIS*_STEP_PIN` etc. directly in `Config.h` (see the user's current config for an example).
|
||||||
|
3. **Generic libraries** ([src/lib/](src/lib/)): hardware-independent building blocks — `tasks/` (cooperative scheduler, see below), `axis/` (motion control, motor abstraction), `nv/` (non-volatile storage over EEPROM/FRAM/Flash), `commands/` (parser + buffer), plus transports: `serial/`, `bluetooth/`, `wifi/`, `ethernet/`, `canPlus/`, `canTransport/`, and peripherals: `analog/`, `sense/`, `gpioEx/`, `tls/` (time/location source), `encoder/`, `softSpi/`, `convert/`, `math/`, `calendars/`.
|
||||||
|
4. **App-level shared services** ([src/libApp/](src/libApp/)): `commands/` (the `ProcessCmds` command channel processor and `CommandBroker` for cross-channel request/reply), `weather/`, `temperature/`.
|
||||||
|
5. **Telescope domain** ([src/telescope/](src/telescope/)): `Telescope.cpp` owns the global object; subdirs implement the four optional subsystems: `mount/`, `rotator/`, `focuser/`, `auxiliary/`. Whether each is compiled in is controlled by `*_PRESENT` macros derived in [src/Common.h](src/Common.h) from the driver-model and feature-purpose settings in `Config.h`.
|
||||||
|
|
||||||
|
A request typically flows: serial/IP byte stream → `CommandProcessor::poll()` ([src/libApp/commands/ProcessCmds.cpp](src/libApp/commands/ProcessCmds.cpp)) → `telescope.command(...)` → subsystem `*.command.cpp` files. Each subsystem has its own `Foo.command.cpp` that handles its slice of the LX200-style protocol; that's where to look when implementing or modifying a `:XX...#` command.
|
||||||
|
|
||||||
|
## Cooperative scheduler (OnTask)
|
||||||
|
|
||||||
|
There is no RTOS abstraction layer above this — everything that isn't an ISR runs through `tasks` from [src/lib/tasks/OnTask.h](src/lib/tasks/OnTask.h). New periodic work is added with `tasks.add(periodMs, durationMs, repeat, priority, function, name)`. Long-running code inside a task must call `tasks.yield()` (or the `Y;` macro) so the scheduler can run higher-priority work — including the step-pulse generator. This is critical: blocking inside a task starves stepper output.
|
||||||
|
|
||||||
|
The main `loop()` is just `tasks.yield();`.
|
||||||
|
|
||||||
|
## Command protocol
|
||||||
|
|
||||||
|
The canonical reference for the wire protocol is [docs/COMMAND_REFERENCE.md](docs/COMMAND_REFERENCE.md), and it's explicitly derived from the current `*.command.cpp` files — if behavior and the older OnStep wiki disagree, the code wins. Frame format: `:CC...#` (plain) or `;CC...CCS#` (with checksum). Error codes returned by `:GE#` are listed in that doc.
|
||||||
|
|
||||||
|
Many commands are compile-time-gated by feature defines. Code under `#ifdef MOUNT_PRESENT`, `#ifdef FOCUSER_PRESENT`, etc. only exists when the corresponding axes/drivers are configured.
|
||||||
|
|
||||||
|
## Subsystem docs (read these before changing related code)
|
||||||
|
|
||||||
|
The `docs/` directory holds the design notes that aren't otherwise discoverable from the code:
|
||||||
|
|
||||||
|
- [COMMAND_REFERENCE.md](docs/COMMAND_REFERENCE.md) — wire protocol.
|
||||||
|
- [STARTUP_AUTHORITY_NOTES.md](docs/STARTUP_AUTHORITY_NOTES.md) — when the mount trusts its coordinate basis enough to allow goto/sync/park. Important: gating logic here affects nearly every motion command.
|
||||||
|
- [GOTO_NOTES.md](docs/GOTO_NOTES.md), [HOMING_NOTES.md](docs/HOMING_NOTES.md), [PEC_NOTES.md](docs/PEC_NOTES.md), [SENSING_NOTES.md](docs/SENSING_NOTES.md) — subsystem-specific design notes.
|
||||||
|
- [SERIAL_NOTES.md](docs/SERIAL_NOTES.md) — three-layer model (platform / pinmap / feature) for understanding why a serial transport may "exist but not work" on a given board.
|
||||||
|
- [SERVO_SETUP.md](docs/SERVO_SETUP.md), [CAN_NOTES.md](docs/CAN_NOTES.md) — motor and transport specifics.
|
||||||
|
|
||||||
|
## Conventions
|
||||||
|
|
||||||
|
- Each subsystem follows the pattern `Foo.h` / `Foo.cpp` for state, `Foo.command.cpp` for the command handler, optionally `Foo.can.command.cpp` / `Foo.can.encode.cpp` / `Foo.can.decode.cpp` for the CAN-bus remote-control variant of the same surface.
|
||||||
|
- Logging uses the `V…` / `D…` macros from `src/lib/debug/Debug.h` (e.g. `VLF`, `VF`, `DLF`). Output is gated by the `DEBUG` setting in `Extended.config.h` and goes to `SERIAL_DEBUG`. Don't add raw `Serial.print` — use the macros so debug output can be compiled out.
|
||||||
|
- Commit messages follow the brief, lowercase-prefixed style shown by `git log --date=short --pretty=format:"%h %ad %<(20)%an %<(150,trunc)%s"` (per [README.md](README.md)).
|
||||||
@@ -0,0 +1,400 @@
|
|||||||
|
/* ---------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
* Configuration for OnStepX
|
||||||
|
*
|
||||||
|
* For more information on setting OnStep up see http://www.stellarjourney.com/index.php?r=site/equipment_onstep
|
||||||
|
* and join the OnStep Groups.io at https://groups.io/g/onstep
|
||||||
|
*
|
||||||
|
* *** Read the compiler warnings and errors, they are there to help guard against invalid configurations ***
|
||||||
|
*
|
||||||
|
* ---------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
* ADJUST THE FOLLOWING TO CONFIGURE YOUR CONTROLLER FEATURES ----------------------------------------------------------------------
|
||||||
|
* <-Req'd = always must set, <-Often = usually must set, Option = optional, Adjust = adjust as req'd, Infreq = infrequently changed
|
||||||
|
*/
|
||||||
|
// Parameter Name Value Default Notes Hint
|
||||||
|
|
||||||
|
// =================================================================================================================================
|
||||||
|
// CONTROLLER ======================================================================================================================
|
||||||
|
#define HOST_NAME "OnStep" // nStep", Hostname for this device up to 16 chars. Adjust
|
||||||
|
|
||||||
|
|
||||||
|
#define HOST_NAME "OnStep"
|
||||||
|
|
||||||
|
#define AXIS1_STEP_PIN 14
|
||||||
|
#define AXIS1_DIR_PIN 12
|
||||||
|
|
||||||
|
#define AXIS2_STEP_PIN 27
|
||||||
|
#define AXIS2_DIR_PIN 26
|
||||||
|
|
||||||
|
#define SHARED_ENABLE_PIN 25 // Közös láb, ahogy gyárilag tervezték!
|
||||||
|
#define STATUS_LED_PIN 2
|
||||||
|
|
||||||
|
// PINMAP ------------------------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Controller#PINMAP
|
||||||
|
#define PINMAP OFF // OFF, Choose from: MiniPCB, MiniPCB2, MaxPCB4, MaxESP4, MaxSTM3, FYSETC_E4, <-Req'd
|
||||||
|
// BTT_SKR_PRO, etc. Other boards and more info. in ~/src/Constants.h
|
||||||
|
|
||||||
|
// SERIAL PORT COMMAND CHANNELS --------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Controller#SERIAL_PORTS
|
||||||
|
#define SERIAL_A_BAUD_DEFAULT 57600 // 9600, n. Where n=9600,19200,57600,115200,230400,460800 (common baud rates.) Infreq
|
||||||
|
#define SERIAL_B_BAUD_DEFAULT OFF // 9600, n. Baud rate as above. See (src/pinmaps/) for Serial port assignments. Infreq
|
||||||
|
#define SERIAL_B_ESP_FLASHING OFF // OFF, ON Upload ESP8266 WiFi firmware through SERIAL_B with :ESPFLASH# cmd. Option
|
||||||
|
#define SERIAL_C_BAUD_DEFAULT OFF // OFF, n. Baud rate as above. See (src/pinmaps/) for Serial port assignments. Infreq
|
||||||
|
#define SERIAL_D_BAUD_DEFAULT OFF // OFF, n. Baud rate as above. See (src/pinmaps/) for Serial port assignments. Infreq
|
||||||
|
#define SERIAL_E_BAUD_DEFAULT OFF // OFF, n. Baud rate as above. See (src/pinmaps/) for Serial port assignments. Infreq
|
||||||
|
#define SERIAL_RADIO WIFI_ACCESS_POINT // OFF, Use BLUETOOTH or WIFI_ACCESS_POINT or WIFI_STATION (ESP32 only.) Option
|
||||||
|
|
||||||
|
// STATUS --------------------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Controller#STATUS_LED
|
||||||
|
#define STATUS_LED ON // OFF, Steady illumination if no error, blinks w/error code otherwise. Option
|
||||||
|
|
||||||
|
// RETICLE CONTROL ------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Controller#RETICLE_CONTROL
|
||||||
|
#define RETICLE_LED_DEFAULT OFF // OFF, n. Where n=0..255 (0..100%) activates feature sets default brightness. Option
|
||||||
|
#define RETICLE_LED_MEMORY OFF // OFF, ON Remember reticle brightness across power cycles. Option
|
||||||
|
#define RETICLE_LED_INVERT OFF // OFF, ON Inverts control for cases where 0V is max brightness. Option
|
||||||
|
|
||||||
|
// WEATHER SENSOR --------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Controller#WEATHER_SENSOR
|
||||||
|
#define WEATHER OFF // OFF, BME280 (I2C 0x77,) BME280_0x76, BME280_SPI (see pinmap for CS.) Option
|
||||||
|
// BMP280 (I2C 0x77,) BMP280_0x76, BMP280_SPI (see pinmap for CS.)
|
||||||
|
// BME280 or BMP280 for temperature, pressure. BME280 for humidity also.
|
||||||
|
|
||||||
|
// SIGNALING ------------------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Controller#SIGNALING
|
||||||
|
#define STEP_WAVE_FORM SQUARE // SQUARE, PULSE Step signal wave form faster rates. SQUARE best signal integrity. Adjust
|
||||||
|
// Applies to all axes.
|
||||||
|
|
||||||
|
// NON-VOLATILE MEMORY ---------------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Controller#NV
|
||||||
|
#define NV_DRIVER NV_DEFAULT // NV_DEF, Use platforms default non-volatile device to remember runtime settings. Option
|
||||||
|
|
||||||
|
// =================================================================================================================================
|
||||||
|
// MOUNT ===========================================================================================================================
|
||||||
|
|
||||||
|
// Driver models (Step/Dir and Servo) many have specific requirements so be sure to follow the link below to help learn about these.
|
||||||
|
// Typically: A4988, DRV8825, LV8729, S109, TMC2130, TMC5160, TMC2209, etc.
|
||||||
|
|
||||||
|
// AXIS1 RA/AZM -------------------------------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Axes
|
||||||
|
#define AXIS1_DRIVER_MODEL TMC2209S // OFF, Enter motor driver model (above) in both axes to activate the mount. <-Often
|
||||||
|
|
||||||
|
// If runtime axis settings are enabled changes in the section below will be ignored (disable in SWS or by wiping NV/EEPROM):
|
||||||
|
// \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
|
||||||
|
#define AXIS1_STEPS_PER_DEGREE 3582.2 // 12800, n. Number of steps per degree: <-Req'd
|
||||||
|
// n = (stepper_steps * micro_steps * overall_gear_reduction)/360.0
|
||||||
|
#define AXIS1_REVERSE OFF // OFF, ON Reverses movement direction, or reverse wiring instead to correct. <-Often
|
||||||
|
#define AXIS1_LIMIT_MIN -180 // -180, n. Where n= -90..-360 (degrees.) Minimum "Hour Angle" or Azimuth. Adjust
|
||||||
|
#define AXIS1_LIMIT_MAX 180 // 180, n. Where n= 90.. 360 (degrees.) Maximum "Hour Angle" or Azimuth. Adjust
|
||||||
|
#define AXIS1_LIMIT_SYNC OFF // OFF, n. Where n= 0..90 (degrees.) Allow sync/reset only within this +/-range. Option
|
||||||
|
|
||||||
|
#define AXIS1_DRIVER_MICROSTEPS 16 // OFF, n. Microstep mode when tracking. <-Req'd
|
||||||
|
#define AXIS1_DRIVER_MICROSTEPS_GOTO 4 // OFF, n. Microstep mode used during slews. OFF uses _DRIVER_MICROSTEPS. Option
|
||||||
|
|
||||||
|
// for TMC2130, TMC5160, TMC2209, TMC2226 STEP/DIR driver models:
|
||||||
|
#define AXIS1_DRIVER_IHOLD OFF // OFF, n, (mA.) Current during standstill. OFF uses IRUN/2.0 Option
|
||||||
|
#define AXIS1_DRIVER_IRUN OFF // OFF, n, (mA.) Current during tracking, appropriate for stepper/driver/etc. Option
|
||||||
|
#define AXIS1_DRIVER_IGOTO OFF // OFF, n, (mA.) Current during slews. OFF uses IRUN. Option
|
||||||
|
// /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /
|
||||||
|
|
||||||
|
#define AXIS1_DRIVER_STATUS OFF // OFF, ON, HIGH, or LOW. For driver status info/fault detection. Option
|
||||||
|
|
||||||
|
#define AXIS1_DRIVER_DECAY OFF // OFF, Tracking decay mode default override. TMC default is STEALTHCHOP. Infreq
|
||||||
|
#define AXIS1_DRIVER_DECAY_GOTO OFF // OFF, Decay mode goto default override. TMC default is SPREADCYCLE. Infreq
|
||||||
|
|
||||||
|
#define AXIS1_POWER_DOWN OFF // OFF, ON Powers off 30sec after movement stops or 10min after last<=1x guide. Infreq
|
||||||
|
|
||||||
|
#define AXIS1_SENSE_HOME OFF // OFF, HIGH or LOW enables & state clockwise home position, as seen from front. Option
|
||||||
|
#define AXIS1_SENSE_LIMIT_MIN LIMIT_SENSE // ...NSE, HIGH or LOW state on limit sense switch stops movement. Option
|
||||||
|
#define AXIS1_SENSE_LIMIT_MAX LIMIT_SENSE // ...NSE, HIGH or LOW state on limit sense switch stops movement. Option
|
||||||
|
// Digital, optionally add: |HYST(n) Where n=0..1023 stability time in ms.
|
||||||
|
// Analog capable sense inputs also allow adding:
|
||||||
|
// |THLD(n) Where n=1..1023 (ADU) for Analog threshold.
|
||||||
|
// |HYST(n) Where n=0..1023 (ADU) for +/- Hystersis range.
|
||||||
|
|
||||||
|
// AXIS2 DEC/ALT ------------------------------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Axes
|
||||||
|
#define AXIS2_DRIVER_MODEL TMC2209S // OFF, Enter motor driver model (above) in both axes to activate the mount. <-Often
|
||||||
|
|
||||||
|
// If runtime axis settings are enabled changes in the section below will be ignored (disable in SWS or by wiping NV/EEPROM):
|
||||||
|
// \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
|
||||||
|
#define AXIS2_STEPS_PER_DEGREE 3591.1 // 12800, n. Number of steps per degree: <-Req'd
|
||||||
|
// n = (stepper_steps * micro_steps * overall_gear_reduction)/360.0
|
||||||
|
#define AXIS2_REVERSE OFF // OFF, ON Reverses movement direction, or reverse wiring instead to correct. <-Often
|
||||||
|
#define AXIS2_LIMIT_MIN -90 // -90, n. Where n=-90..0 (degrees.) Minimum allowed Declination or Altitude. Infreq
|
||||||
|
#define AXIS2_LIMIT_MAX 90 // 90, n. Where n= 0..90 (degrees.) Maximum allowed Declination or Altitude. Infreq
|
||||||
|
#define AXIS2_LIMIT_SYNC OFF // OFF, n. Where n= 0..90 (degrees.) Allow sync/reset only within this +/-range. Option
|
||||||
|
|
||||||
|
#define AXIS2_DRIVER_MICROSTEPS 16 // OFF, n. Microstep mode when tracking. <-Req'd
|
||||||
|
#define AXIS2_DRIVER_MICROSTEPS_GOTO OFF // OFF, n. Microstep mode used during slews. OFF uses _DRIVER_MICROSTEPS. Option
|
||||||
|
|
||||||
|
// for TMC2130, TMC5160, TMC2209, TMC2226 STEP/DIR driver models:
|
||||||
|
#define AXIS2_DRIVER_IHOLD OFF // OFF, n, (mA.) Current during standstill. OFF uses IRUN/2.0 Option
|
||||||
|
#define AXIS2_DRIVER_IRUN OFF // OFF, n, (mA.) Current during tracking, appropriate for stepper/driver/etc. Option
|
||||||
|
#define AXIS2_DRIVER_IGOTO OFF // OFF, n, (mA.) Current during slews. OFF uses IRUN. Option
|
||||||
|
// /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /
|
||||||
|
|
||||||
|
#define AXIS2_DRIVER_STATUS OFF // OFF, ON, HIGH, or LOW. Polling for driver status info/fault detection. Option
|
||||||
|
|
||||||
|
#define AXIS2_DRIVER_DECAY OFF // OFF, Tracking decay mode default override. TMC default is STEALTHCHOP. Infreq
|
||||||
|
#define AXIS2_DRIVER_DECAY_GOTO OFF // OFF, Decay mode goto default override. TMC default is SPREADCYCLE. Infreq
|
||||||
|
|
||||||
|
#define AXIS2_POWER_DOWN OFF // OFF, ON Powers off 30sec after movement stops or 10min after last<=1x guide. Option
|
||||||
|
|
||||||
|
#define AXIS2_SENSE_HOME OFF // OFF, HIGH or LOW enables & state clockwise home position, as seen from above. Option
|
||||||
|
#define AXIS2_SENSE_LIMIT_MIN LIMIT_SENSE // ...NSE, HIGH or LOW state on limit sense switch stops movement. Option
|
||||||
|
#define AXIS2_SENSE_LIMIT_MAX LIMIT_SENSE // ...NSE, HIGH or LOW state on limit sense switch stops movement. Option
|
||||||
|
|
||||||
|
// MOUNT -------------------------------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Mount#MOUNT
|
||||||
|
#define MOUNT_TYPE GEM // GEM, GEM German Equatorial Mount, etc. that need meridian flips. <-Req'd
|
||||||
|
// GEM_TA GEM w/tangent arm Declination
|
||||||
|
// GEM_TAC GEM w/tangent arm Declination and geometry correction
|
||||||
|
// FORK Fork Mount
|
||||||
|
// FORK_TA FORK w/tangent arm Declination
|
||||||
|
// FORK_TAC FORK w/tangent arm Declination and geometry correction
|
||||||
|
// ALTAZM Altitude/Azimuth Mount, Dobsonians, etc.
|
||||||
|
// ALTAZM_UNL ALTAZM w/unlimited Azimuth motion
|
||||||
|
|
||||||
|
#define MOUNT_ALTERNATE_ORIENTATION OFF // OFF, ON Enables Meridian Flips for FORK mounts and passing through the Option
|
||||||
|
// Zenith for ALTAZM mounts. GEM mode ignores this setting.
|
||||||
|
|
||||||
|
#define MOUNT_STARTUP_MODE SA_AUTO // ..AUTO, SA_STRICT, or SA_PERMISSIVE. Controls when startup trust is granted. Option
|
||||||
|
// SA_AUTO keeps legacy immediate goto only when no absolute position source
|
||||||
|
// is present and coordinate memory is OFF.
|
||||||
|
|
||||||
|
#define MOUNT_COORDS TOPOCENTRIC // ...RIC, Applies refraction to coordinates to/from OnStep, except exactly Infreq
|
||||||
|
// at the poles. Use TOPO_STRICT to apply refraction even in that case.
|
||||||
|
// Use OBSERVED_PLACE for no refraction.
|
||||||
|
|
||||||
|
#define MOUNT_COORDS_MEMORY OFF // OFF, ON Remembers approximate mount coordinates across power cycles. Option
|
||||||
|
// Requires FRAM NV memory and the mount must not move while powered down.
|
||||||
|
|
||||||
|
#define MOUNT_ENABLE_IN_STANDBY OFF // OFF, ON Enables mount motor drivers while in standby. Infreq
|
||||||
|
|
||||||
|
// TIME AND LOCATION ---------------------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Mount#TLS
|
||||||
|
#define TIME_LOCATION_SOURCE OFF // OFF, DS3231 (I2C,) SD3031 (I2C,) TEENSY (T3.2 etc,) GPS, or NTP source. Option
|
||||||
|
// Provides Date/Time, and if available, PPS & Lat/Long also.
|
||||||
|
#define TIME_LOCATION_PPS_SENSE OFF // OFF, HIGH senses PPS (pulse per second,) signal rising edge, or use LOW for Option
|
||||||
|
// falling edge, or use BOTH for rising and falling edges.
|
||||||
|
|
||||||
|
// STATUS ------------------------------------------------------ see https://onstep.groups.io/g/main/wiki/Configuration_Mount#STATUS
|
||||||
|
#define STATUS_MOUNT_LED OFF // OFF, ON Flashes proportional to rate of movement or solid on for slews. Option
|
||||||
|
#define STATUS_BUZZER OFF // OFF, ON, n. Where n=100..6000 (Hz freq.) for speaker. ON for piezo buzzer. Option
|
||||||
|
#define STATUS_BUZZER_DEFAULT OFF // OFF, ON starts w/buzzer sound enabled. Option
|
||||||
|
#define STATUS_BUZZER_MEMORY OFF // OFF, ON to remember buzzer sound setting across power cycles. Option
|
||||||
|
|
||||||
|
// ST4 INTERFACE -------------------------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Mount#ST4
|
||||||
|
// *** It is up to you to verify the interface meets the electrical specifications of any connected device, use at your own risk ***
|
||||||
|
#define ST4_INTERFACE OFF // OFF, ON enables interface. <= 1X guides unless hand control mode. Option
|
||||||
|
// During goto btn press: aborts slew or continue meridian flip pause home
|
||||||
|
#define ST4_HAND_CONTROL ON // ON, ON for hand controller special features and SHC support. Option
|
||||||
|
// Hold [E]+[W] btns >2s: Guide rate [E]- [W]+ [N] trk on/off [S] sync
|
||||||
|
// Hold [N]+[S] btns >2s: Usr cat item [E]- [W]+ [N] goto [S] snd on/off
|
||||||
|
#define ST4_HAND_CONTROL_FOCUSER ON // ON, ON alternate to above: Focuser move [E]f1 [W]f2 [N]- [S]+ Option
|
||||||
|
|
||||||
|
// GUIDING BEHAVIOUR ------------------------------------------ see https://onstep.groups.io/g/main/wiki/Configuration_Mount#GUIDING
|
||||||
|
#define GUIDE_TIME_LIMIT 10 // 10, n. Time limit n=0..120 seconds. Use 0 to disable. Adjust
|
||||||
|
#define GUIDE_DISABLE_BACKLASH OFF // OFF, Disable backlash takeup during guiding at <= 1X. Option
|
||||||
|
|
||||||
|
// LIMITS ------------------------------------------------------ see https://onstep.groups.io/g/main/wiki/Configuration_Mount#LIMITS
|
||||||
|
#define LIMIT_SENSE OFF // OFF, HIGH or LOW state on limit sense switch stops movement. Option
|
||||||
|
#define LIMIT_STRICT OFF // OFF, disables limits until unpark goto or sync. ON enables limits at startup. Option
|
||||||
|
// note that ON also disables all motion until date/time are set.
|
||||||
|
|
||||||
|
// PARKING ---------------------------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Mount#PARKING
|
||||||
|
#define PARK_SENSE OFF // OFF, HIGH or LOW state indicates mount is in the park orientation. Option
|
||||||
|
#define PARK_SIGNAL OFF // OFF, HIGH or LOW state park input signal triggers parking. Option
|
||||||
|
#define PARK_STATUS OFF // OFF, signals with a HIGH or LOW state when successfully parked. Option
|
||||||
|
|
||||||
|
// PEC ------------------------------------------------------------ see https://onstep.groups.io/g/main/wiki/Configuration_Mount#PEC
|
||||||
|
#define PEC_STEPS_PER_WORM_ROTATION 12800 // 0, n. Steps per worm rotation (0 disables else 720 sec buffer allocated.) <-Req'd
|
||||||
|
// n = (AXIS1_STEPS_PER_DEGREE*360)/reduction_final_stage
|
||||||
|
|
||||||
|
#define PEC_SENSE OFF // OFF, HIGH. Senses the PEC signal rising edge or use LOW for falling edge. Option
|
||||||
|
// Ignored in ALTAZM mode.
|
||||||
|
#define PEC_BUFFER_SIZE_LIMIT 720 // 720, Seconds of PEC buffer allowed. Infreq
|
||||||
|
|
||||||
|
// TRACKING BEHAVIOUR ---------------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Mount#TRACKING
|
||||||
|
#define TRACK_BACKLASH_RATE 20 // 20, n. Where n=2..50 (x sidereal rate) during backlash takeup. Option
|
||||||
|
// Too fast motors stall/gears slam or too slow and sluggish in backlash.
|
||||||
|
#define TRACK_AUTOSTART OFF // OFF, ON Start with tracking enabled. Option
|
||||||
|
#define TRACK_COMPENSATION_DEFAULT OFF // OFF, No compensation or REFRACTION, REFRACTION_DUAL, MODEL, MODEL_DUAL. Option
|
||||||
|
#define TRACK_COMPENSATION_MEMORY OFF // OFF, ON Remembers refraction/pointing model compensated tracking settings. Option
|
||||||
|
|
||||||
|
// SLEWING BEHAVIOUR ------------------------------------------ see https://onstep.groups.io/g/main/wiki/Configuration_Mount#SLEWING
|
||||||
|
#define SLEW_RATE_BASE_DESIRED 2.5 // 1.0, n. Desired slew rate in deg/sec. Adjustable at run-time from <-Req'd
|
||||||
|
// 1/2 to 2x this rate, and as performace considerations require.
|
||||||
|
#define SLEW_RATE_MEMORY OFF // OFF, ON Remembers rates set across power cycles. Option
|
||||||
|
#define SLEW_ACCELERATION_DIST 5.0 // 5.0, n, (degrees.) Approx. distance for acceleration (and deceleration.) Adjust
|
||||||
|
#define SLEW_RAPID_STOP_DIST 2.0 // 2.0, n, (degrees.) Approx. distance required to stop when a slew Adjust
|
||||||
|
// is aborted or a limit is exceeded.
|
||||||
|
#define GOTO_FEATURE ON // ON, Use OFF to disable mount Goto features. Infreq
|
||||||
|
#define GOTO_OFFSET 0.25 // 0.25, Offset in deg's for goto target unidirectional approach, 0.0 disables Adjust
|
||||||
|
#define GOTO_OFFSET_ALIGN OFF // OFF, ON skips final phase of goto for align stars so user tends to approach Option
|
||||||
|
// from the correct direction when centering.
|
||||||
|
|
||||||
|
// PIER SIDE BEHAVIOUR --------------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Mount#PIERSIDE
|
||||||
|
#define MFLIP_SKIP_HOME OFF // OFF, ON Goto directly to the destination without visiting home position. Option
|
||||||
|
#define MFLIP_AUTOMATIC_DEFAULT OFF // OFF, ON Start with automatic meridian flips enabled. Option
|
||||||
|
#define MFLIP_AUTOMATIC_MEMORY OFF // OFF, ON Remember automatic meridian flip setting across power cycles. Option
|
||||||
|
#define MFLIP_PAUSE_HOME_DEFAULT OFF // OFF, ON Start with meridian flip pause at home enabed. Infreq
|
||||||
|
#define MFLIP_PAUSE_HOME_MEMORY OFF // OFF, ON Remember meridian flip pause at home setting across power cycles. Infreq
|
||||||
|
|
||||||
|
#define PIER_SIDE_SYNC_CHANGE_SIDES OFF // OFF, ON Allows sync to change pier side, for GEM mounts. Option
|
||||||
|
#define PIER_SIDE_PREFERRED_DEFAULT BEST // BEST, BEST Stays on current side if possible. EAST or WEST switch if possible. Option
|
||||||
|
// AUTOMATIC prefers west nearer the under pole meridian or east otherwise. Option
|
||||||
|
#define PIER_SIDE_PREFERRED_MEMORY OFF // OFF, ON Remember preferred pier side setting across power cycles. Option
|
||||||
|
|
||||||
|
// ALIGN -------------------------------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Mount#ALIGN
|
||||||
|
#define ALIGN_AUTO_HOME OFF // OFF, ON uses home switches to find home first when starting an align. Option
|
||||||
|
#define ALIGN_MODEL_MEMORY OFF // OFF, ON Restores any pointing model saved in NV at startup. Option
|
||||||
|
#define ALIGN_MAX_STARS AUTO // AUTO, Uses HAL specified default (either 6 or 9 stars.) Infreq
|
||||||
|
// Or use n. Where n=1 (for Sync only) or 3 to 9 (for Goto Assist.)
|
||||||
|
|
||||||
|
// =================================================================================================================================
|
||||||
|
// ROTATOR =========================================================================================================================
|
||||||
|
|
||||||
|
// Driver models (Step/Dir and Servo) many have specific requirements so be sure to follow the link below to help learn about these.
|
||||||
|
// Typically: A4988, DRV8825, LV8729, S109, TMC2130S, etc.
|
||||||
|
|
||||||
|
// AXIS3 ROTATOR ---------------------------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Rotator
|
||||||
|
#define AXIS3_DRIVER_MODEL OFF // OFF, Enter motor driver model (above) to activate the rotator. Option
|
||||||
|
#define AXIS3_SLEW_RATE_BASE_DESIRED 1.0 // 1.0, n. Desired slew rate in deg/sec. Adjustable at run-time from <-Req'd
|
||||||
|
// 1/2 to 2x this rate, and as performance considerations require.
|
||||||
|
|
||||||
|
// If runtime axis settings are enabled changes in the section below will be ignored (disable in SWS or by wiping NV/EEPROM):
|
||||||
|
// \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
|
||||||
|
#define AXIS3_STEPS_PER_DEGREE 64.0 // 64.0, n. Number of steps per degree for rotator/de-rotator. Adjust
|
||||||
|
// Alt/Az de-rotation: n = (num_circumference_pixels * 2)/360, minimum
|
||||||
|
#define AXIS3_REVERSE OFF // OFF, ON Reverses movement direction, or reverse wiring instead to correct. Option
|
||||||
|
#define AXIS3_LIMIT_MIN 0 // 0, n. Where n=-360..0 (degrees.) Minimum allowed rotator angle. Infreq
|
||||||
|
#define AXIS3_LIMIT_MAX 360 // 360, n. Where n=0..360 (degrees.) Maximum allowed rotator angle. Infreq
|
||||||
|
|
||||||
|
#define AXIS3_DRIVER_MICROSTEPS OFF // OFF, n. Microstep mode when tracking. Option
|
||||||
|
#define AXIS3_DRIVER_MICROSTEPS_GOTO OFF // OFF, n. Microstep mode used during slews. OFF uses _DRIVER_MICROSTEPS. Option
|
||||||
|
|
||||||
|
// for TMC2130, TMC5160, TMC2209, TMC2226 STEP/DIR driver models:
|
||||||
|
#define AXIS3_DRIVER_IHOLD OFF // OFF, n, (mA.) Current during standstill. OFF uses IRUN/2.0 Option
|
||||||
|
#define AXIS3_DRIVER_IRUN OFF // OFF, n, (mA.) Current during tracking, appropriate for stepper/driver/etc. Option
|
||||||
|
#define AXIS3_DRIVER_IGOTO OFF // OFF, n, (mA.) Current during slews. OFF uses IRUN. Option
|
||||||
|
// /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /
|
||||||
|
|
||||||
|
#define AXIS3_DRIVER_STATUS OFF // OFF, ON, HIGH, or LOW. For driver status info/fault detection. Option
|
||||||
|
|
||||||
|
#define AXIS3_DRIVER_DECAY OFF // OFF, Tracking decay mode default override. TMC default is STEALTHCHOP. Infreq
|
||||||
|
#define AXIS3_DRIVER_DECAY_GOTO OFF // OFF, Decay mode goto default override. TMC default is SPREADCYCLE. Infreq
|
||||||
|
|
||||||
|
#define AXIS3_POWER_DOWN OFF // OFF, ON Powers off 30 seconds after movement stops. Option
|
||||||
|
|
||||||
|
#define AXIS3_SENSE_HOME OFF // OFF, HIGH or LOW enables & state clockwise home position, as seen from above. Option
|
||||||
|
#define AXIS3_SENSE_LIMIT_MIN OFF // OFF, HIGH or LOW state on limit sense switch stops movement. Option
|
||||||
|
#define AXIS3_SENSE_LIMIT_MAX OFF // OFF, HIGH or LOW state on limit sense switch stops movement. Option
|
||||||
|
|
||||||
|
// =================================================================================================================================
|
||||||
|
// FOCUSERS ========================================================================================================================
|
||||||
|
|
||||||
|
// Driver models (Step/Dir and Servo) many have specific requirements so be sure to follow the link below to help learn about these.
|
||||||
|
// Typically: A4988, DRV8825, LV8729, S109, TMC2130S, etc.
|
||||||
|
|
||||||
|
// AXIS4 FOCUSER 1 -------------------------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Focuser
|
||||||
|
#define AXIS4_DRIVER_MODEL OFF // OFF, Enter motor driver model (above) to activate the focuser. Option
|
||||||
|
#define AXIS4_SLEW_RATE_BASE_DESIRED 500 // 500, n, Where n=200..5000 (um/s.) Adjustable at run-time from <-Req'd
|
||||||
|
// 1/2 to 2x this rate, and as performance considerations require.
|
||||||
|
#define AXIS4_SLEW_RATE_MINIMUM 20 // 20, n. Where n=5..200 (um/s.) Minimum microns/second. Adjust
|
||||||
|
|
||||||
|
// If runtime axis settings are enabled changes in the section below will be ignored (disable in SWS or by wiping NV/EEPROM):
|
||||||
|
// \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
|
||||||
|
#define AXIS4_STEPS_PER_MICRON 0.5 // 0.5, n. Steps per micrometer. Figure this out by testing or other means. Adjust
|
||||||
|
#define AXIS4_REVERSE OFF // OFF, ON Reverses movement direction, or reverse wiring instead to correct. Option
|
||||||
|
#define AXIS4_LIMIT_MIN 0 // 0, n. Where n=0..500 (millimeters.) Minimum allowed position. Adjust
|
||||||
|
#define AXIS4_LIMIT_MAX 50 // 50, n. Where n=0..500 (millimeters.) Maximum allowed position. Adjust
|
||||||
|
|
||||||
|
#define AXIS4_DRIVER_MICROSTEPS OFF // OFF, n. Microstep mode when tracking. Option
|
||||||
|
#define AXIS4_DRIVER_MICROSTEPS_GOTO OFF // OFF, n. Microstep mode used during slews. OFF uses _DRIVER_MICROSTEPS. Option
|
||||||
|
|
||||||
|
// for TMC2130, TMC5160, TMC2209, TMC2226 STEP/DIR driver models:
|
||||||
|
#define AXIS4_DRIVER_IHOLD OFF // OFF, n, (mA.) Current during standstill. OFF uses IRUN/2.0 Option
|
||||||
|
#define AXIS4_DRIVER_IRUN OFF // OFF, n, (mA.) Current during tracking, appropriate for stepper/driver/etc. Option
|
||||||
|
#define AXIS4_DRIVER_IGOTO OFF // OFF, n, (mA.) Current during slews. OFF uses IRUN. Option
|
||||||
|
// /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /
|
||||||
|
|
||||||
|
#define AXIS4_DRIVER_STATUS OFF // OFF, ON, HIGH, or LOW. For driver status info/fault detection. Option
|
||||||
|
|
||||||
|
#define AXIS4_DRIVER_DECAY OFF // OFF, Tracking decay mode default override. TMC default is STEALTHCHOP. Infreq
|
||||||
|
#define AXIS4_DRIVER_DECAY_GOTO OFF // OFF, Decay mode goto default override. TMC default is SPREADCYCLE. Infreq
|
||||||
|
|
||||||
|
#define AXIS4_POWER_DOWN OFF // OFF, ON Powers off 30 seconds after movement stops. Option
|
||||||
|
|
||||||
|
#define AXIS4_SENSE_HOME OFF // OFF, HIGH or LOW enables & state clockwise home position, as seen from above. Option
|
||||||
|
#define AXIS4_SENSE_LIMIT_MIN OFF // OFF, HIGH or LOW state on limit sense switch stops movement. Option
|
||||||
|
#define AXIS4_SENSE_LIMIT_MAX OFF // OFF, HIGH or LOW state on limit sense switch stops movement. Option
|
||||||
|
|
||||||
|
// AXIS5 FOCUSER 2 -----------------------------------------------------------------------------------------------------------------
|
||||||
|
// Up to 6 focusers can be present (AXIS4 to AXIS9) simply copy the above text for focuser 1 and rename to AXIS5_ for focuser 2, etc
|
||||||
|
|
||||||
|
// FOCUSER TEMPERATURE ---------------------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Focuser
|
||||||
|
#define FOCUSER_TEMPERATURE OFF // OFF, THERMISTOR or n. Where n is the ds18b20 s/n for focuser temp. Adjust
|
||||||
|
|
||||||
|
// =================================================================================================================================
|
||||||
|
// AUXILIARY FEATURES ==============================================================================================================
|
||||||
|
|
||||||
|
// FEATURES ------------------------------------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Aux
|
||||||
|
// Note: Temporarily set DEBUG mode to VERBOSE and use "FEATURE1_TEMP DS1820" to list the DS18B20 device serial numbers.
|
||||||
|
|
||||||
|
#define FEATURE1_PURPOSE OFF // OFF, SWITCH, MOMENTARY_SWITCH, ANALOG_OUT, DEW_HEATER, INTERVALOMETER. Option
|
||||||
|
#define FEATURE1_NAME "FEATURE1" // "FE..", Name of feature being controlled. Adjust
|
||||||
|
#define FEATURE1_TEMP OFF // OFF, THERMISTOR or n. Where n is the ds18b20 s/n. For DEW_HEATER temperature. Adjust
|
||||||
|
#define FEATURE1_PIN OFF // OFF, AUX for auxiliary pin, n. Where n is the pin#. Adjust
|
||||||
|
#define FEATURE1_VALUE_DEFAULT OFF // OFF, ON, n. Where n=0..255 for ANALOG_OUT purpose. Adjust
|
||||||
|
#define FEATURE1_VALUE_MEMORY OFF // OFF, ON remembers SWITCH, ANALOG_OUT, DEW_HEATER state across power cycles. Adjust
|
||||||
|
#define FEATURE1_ON_STATE HIGH // HIGH, LOW to invert so "ON" is 0V and "OFF" is Vcc (3.3V usually.) Adjust
|
||||||
|
|
||||||
|
#define FEATURE2_PURPOSE OFF // OFF, SWITCH, MOMENTARY_SWITCH, ANALOG_OUT, DEW_HEATER, INTERVALOMETER. Option
|
||||||
|
#define FEATURE2_NAME "FEATURE2" // "FE..", Name of feature being controlled. Adjust
|
||||||
|
#define FEATURE2_TEMP OFF // OFF, THERMISTOR or n. Where n is the ds18b20 s/n. For DEW_HEATER temperature. Adjust
|
||||||
|
#define FEATURE2_PIN OFF // OFF, AUX for auxiliary pin, n. Where n is the pin#. Adjust
|
||||||
|
#define FEATURE2_VALUE_DEFAULT OFF // OFF, ON, n. Where n=0..255 for ANALOG_OUT purpose. Adjust
|
||||||
|
#define FEATURE2_VALUE_MEMORY OFF // OFF, ON remembers SWITCH, ANALOG_OUT, DEW_HEATER state across power cycles. Adjust
|
||||||
|
#define FEATURE2_ON_STATE HIGH // HIGH, LOW to invert so "ON" is 0V and "OFF" is Vcc (3.3V usually.) Adjust
|
||||||
|
|
||||||
|
#define FEATURE3_PURPOSE OFF // OFF, SWITCH, MOMENTARY_SWITCH, ANALOG_OUT, DEW_HEATER, INTERVALOMETER. Option
|
||||||
|
#define FEATURE3_NAME "FEATURE3" // "FE..", Name of feature being controlled. Adjust
|
||||||
|
#define FEATURE3_TEMP OFF // OFF, THERMISTOR or n. Where n is the ds18b20 s/n. For DEW_HEATER temperature. Adjust
|
||||||
|
#define FEATURE3_PIN OFF // OFF, AUX for auxiliary pin, n. Where n is the pin#. Adjust
|
||||||
|
#define FEATURE3_VALUE_DEFAULT OFF // OFF, ON, n. Where n=0..255 for ANALOG_OUT purpose. Adjust
|
||||||
|
#define FEATURE3_VALUE_MEMORY OFF // OFF, ON remembers SWITCH, ANALOG_OUT, DEW_HEATER state across power cycles. Adjust
|
||||||
|
#define FEATURE3_ON_STATE HIGH // HIGH, LOW to invert so "ON" is 0V and "OFF" is Vcc (3.3V usually.) Adjust
|
||||||
|
|
||||||
|
#define FEATURE4_PURPOSE OFF // OFF, SWITCH, MOMENTARY_SWITCH, ANALOG_OUT, DEW_HEATER, INTERVALOMETER. Option
|
||||||
|
#define FEATURE4_NAME "FEATURE4" // "FE..", Name of feature being controlled. Adjust
|
||||||
|
#define FEATURE4_TEMP OFF // OFF, THERMISTOR or n. Where n is the ds18b20 s/n. For DEW_HEATER temperature. Adjust
|
||||||
|
#define FEATURE4_PIN OFF // OFF, AUX for auxiliary pin, n. Where n is the pin#. Adjust
|
||||||
|
#define FEATURE4_VALUE_DEFAULT OFF // OFF, ON, n. Where n=0..255 for ANALOG_OUT purpose. Adjust
|
||||||
|
#define FEATURE4_VALUE_MEMORY OFF // OFF, ON remembers SWITCH, ANALOG_OUT, DEW_HEATER state across power cycles. Adjust
|
||||||
|
#define FEATURE4_ON_STATE HIGH // HIGH, LOW to invert so "ON" is 0V and "OFF" is Vcc (3.3V usually.) Adjust
|
||||||
|
|
||||||
|
#define FEATURE5_PURPOSE OFF // OFF, SWITCH, MOMENTARY_SWITCH, ANALOG_OUT, DEW_HEATER, INTERVALOMETER. Option
|
||||||
|
#define FEATURE5_NAME "FEATURE5" // "FE..", Name of feature being controlled. Adjust
|
||||||
|
#define FEATURE5_TEMP OFF // OFF, THERMISTOR or n. Where n is the ds18b20 s/n. For DEW_HEATER temperature. Adjust
|
||||||
|
#define FEATURE5_PIN OFF // OFF, AUX for auxiliary pin, n. Where n is the pin#. Adjust
|
||||||
|
#define FEATURE5_VALUE_DEFAULT OFF // OFF, ON, n. Where n=0..255 for ANALOG_OUT purpose. Adjust
|
||||||
|
#define FEATURE5_VALUE_MEMORY OFF // OFF, ON remembers SWITCH, ANALOG_OUT, DEW_HEATER state across power cycles. Adjust
|
||||||
|
#define FEATURE5_ON_STATE HIGH // HIGH, LOW to invert so "ON" is 0V and "OFF" is Vcc (3.3V usually.) Adjust
|
||||||
|
|
||||||
|
#define FEATURE6_PURPOSE OFF // OFF, SWITCH, MOMENTARY_SWITCH, ANALOG_OUT, DEW_HEATER, INTERVALOMETER. Option
|
||||||
|
#define FEATURE6_NAME "FEATURE6" // "FE..", Name of feature being controlled. Adjust
|
||||||
|
#define FEATURE6_TEMP OFF // OFF, THERMISTOR or n. Where n is the ds18b20 s/n. For DEW_HEATER temperature. Adjust
|
||||||
|
#define FEATURE6_PIN OFF // OFF, AUX for auxiliary pin, n. Where n is the pin#. Adjust
|
||||||
|
#define FEATURE6_VALUE_DEFAULT OFF // OFF, ON, n. Where n=0..255 for ANALOG_OUT purpose. Adjust
|
||||||
|
#define FEATURE6_VALUE_MEMORY OFF // OFF, ON remembers SWITCH, ANALOG_OUT, DEW_HEATER state across power cycles. Adjust
|
||||||
|
#define FEATURE6_ON_STATE HIGH // HIGH, LOW to invert so "ON" is 0V and "OFF" is Vcc (3.3V usually.) Adjust
|
||||||
|
|
||||||
|
#define FEATURE7_PURPOSE OFF // OFF, SWITCH, MOMENTARY_SWITCH, ANALOG_OUT, DEW_HEATER, INTERVALOMETER. Option
|
||||||
|
#define FEATURE7_NAME "FEATURE7" // "FE..", Name of feature being controlled. Adjust
|
||||||
|
#define FEATURE7_TEMP OFF // OFF, THERMISTOR or n. Where n is the ds18b20 s/n. For DEW_HEATER temperature. Adjust
|
||||||
|
#define FEATURE7_PIN OFF // OFF, AUX for auxiliary pin, n. Where n is the pin#. Adjust
|
||||||
|
#define FEATURE7_VALUE_DEFAULT OFF // OFF, ON, n. Where n=0..255 for ANALOG_OUT purpose. Adjust
|
||||||
|
#define FEATURE7_VALUE_MEMORY OFF // OFF, ON remembers SWITCH, ANALOG_OUT, DEW_HEATER state across power cycles. Adjust
|
||||||
|
#define FEATURE7_ON_STATE HIGH // HIGH, LOW to invert so "ON" is 0V and "OFF" is Vcc (3.3V usually.) Adjust
|
||||||
|
|
||||||
|
#define FEATURE8_PURPOSE OFF // OFF, SWITCH, MOMENTARY_SWITCH, ANALOG_OUT, DEW_HEATER, INTERVALOMETER. Option
|
||||||
|
#define FEATURE8_NAME "FEATURE8" // "FE..", Name of feature being controlled. Adjust
|
||||||
|
#define FEATURE8_TEMP OFF // OFF, THERMISTOR or n. Where n is the ds18b20 s/n. For DEW_HEATER temperature. Adjust
|
||||||
|
#define FEATURE8_PIN OFF // OFF, AUX for auxiliary pin, n. Where n is the pin#. Adjust
|
||||||
|
#define FEATURE8_VALUE_DEFAULT OFF // OFF, ON, n. Where n=0..255 for ANALOG_OUT purpose. Adjust
|
||||||
|
#define FEATURE8_VALUE_MEMORY OFF // OFF, ON remembers SWITCH, ANALOG_OUT, DEW_HEATER state across power cycles. Adjust
|
||||||
|
#define FEATURE8_ON_STATE HIGH // HIGH, LOW to invert so "ON" is 0V and "OFF" is Vcc (3.3V usually.) Adjust
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
#define FileVersionConfig 6
|
||||||
|
#include "Extended.config.h"
|
||||||
Executable
+38
@@ -0,0 +1,38 @@
|
|||||||
|
/* ---------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
* Extended configuration for OnStepX INFREQUENTLY USED options
|
||||||
|
*
|
||||||
|
* For more information on setting OnStep up see http://www.stellarjourney.com/index.php?r=site/equipment_onstep
|
||||||
|
* and join the OnStep Groups.io at https://groups.io/g/onstep
|
||||||
|
*
|
||||||
|
* *** Read the compiler warnings and errors, they are there to help guard against invalid configurations ***
|
||||||
|
*
|
||||||
|
* ---------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
* ADJUST THE FOLLOWING TO CONFIGURE YOUR CONTROLLER FEATURES ----------------------------------------------------------------------
|
||||||
|
* <-Req'd = always must set, <-Often = usually must set, Option = optional, Adjust = adjust as req'd, Infreq = infrequently changed
|
||||||
|
*/
|
||||||
|
// Parameter Name Value Default Notes Hint
|
||||||
|
|
||||||
|
// =================================================================================================================================
|
||||||
|
// CONTROLLER ======================================================================================================================
|
||||||
|
|
||||||
|
// DEBUG ---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Enables additional debugging and/or status messages on the specified SERIAL_DEBUG port (be sure to disable when done!)
|
||||||
|
// Note: The SERIAL_DEBUG port is often (almost always) attached to the same SERIAL_A port so it cannot be used for normal
|
||||||
|
// LX200 protocol communications. If this is the case set both to the same (faster) baud rate specified below.
|
||||||
|
#define DEBUG OFF // OFF, Use ON for background error messages only, use VERBOSE for all Infreq
|
||||||
|
// error and status messages, use CONSOLE for VT100 debug console,
|
||||||
|
// or use PROFILER for VT100 task profiler.
|
||||||
|
#define DEBUG_AXIS OFF // OFF, n. Where n=1 to 9 as the designated axis for logging activity. Option
|
||||||
|
#define DEBUG_CAN OFF // OFF, Use ON to log CAN interface statistics. Option
|
||||||
|
#define DEBUG_ECHO_COMMANDS OFF // OFF, Use ON or ERRORS_ONLY to log commands to the debug serial port. Option
|
||||||
|
#define SERIAL_DEBUG Serial // Serial, Use any available h/w serial port. Serial1 or Serial2, etc. Option
|
||||||
|
#define SERIAL_DEBUG_BAUD 230400 // 230400, n. Where n=9600,19200,57600,115200,230400,460800 (common baud rates.) Option
|
||||||
|
|
||||||
|
// NON-VOLATILE STORAGE ------------------------------------------------------------------------------------------------------------
|
||||||
|
#define NV_WIPE OFF // OFF, Causes the defaults to be written back into NV (FLASH,EEPROM,etc.) Infreq
|
||||||
|
// *** IMPORTANT: ENABLE THIS OPTION THEN UPLOAD, WAIT A MINUTE ***
|
||||||
|
// Warning ---> // *** OR TWO THEN SET THIS OPTION TO OFF AND UPLOAD AGAIN. ***
|
||||||
|
// *** LEAVING THIS OPTION ENABLED CAN CAUSE EXCESSIVE NV ***
|
||||||
|
// *** WEAR AND DAMAGE THE MICROCONTROLLER NV SUBSYSTEM !!! ***
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
Executable
+163
@@ -0,0 +1,163 @@
|
|||||||
|
/*
|
||||||
|
* Title OnStepX
|
||||||
|
* by Howard Dutton
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021-2026 Howard Dutton
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Full featured telescope control for
|
||||||
|
* Equatorial and Alt-Az mounts
|
||||||
|
* Rotator
|
||||||
|
* Focusers
|
||||||
|
* Accessories (automatic covers, dew heaters, etc.)
|
||||||
|
*
|
||||||
|
* Author: Howard Dutton
|
||||||
|
* http://www.stellarjourney.com
|
||||||
|
* hjd1964@gmail.com
|
||||||
|
*
|
||||||
|
* Revision history, and newer versions:
|
||||||
|
* See GitHub: https://github.com/hjd1964/OnStep
|
||||||
|
*
|
||||||
|
* Documentation:
|
||||||
|
* https://groups.io/g/onstep/wiki/home
|
||||||
|
*
|
||||||
|
* Discussion, Questions, ...etc
|
||||||
|
* https://groups.io/g/onstep
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Use tabs "Config..." to configure OnStep to your requirements
|
||||||
|
|
||||||
|
// Firmware version ----------------------------------------------------------------------------------------------------------------
|
||||||
|
#define FirmwareName "On-Step"
|
||||||
|
#define FirmwareVersionMajor 10
|
||||||
|
#define FirmwareVersionMinor 28 // minor version 00 to 99
|
||||||
|
#define FirmwareVersionPatch "i" // for example major.minor patch: 10.03c
|
||||||
|
#define FirmwareVersionConfig 6 // internal, for tracking configuration file changes
|
||||||
|
|
||||||
|
#include "src/Common.h"
|
||||||
|
#include "src/Validate.h"
|
||||||
|
#include "src/lib/nv/Nv.h"
|
||||||
|
#include "src/lib/analog/Analog.h"
|
||||||
|
#include "src/lib/sense/Sense.h"
|
||||||
|
#include "src/lib/tasks/OnTask.h"
|
||||||
|
|
||||||
|
#include "src/telescope/Telescope.h"
|
||||||
|
extern Telescope telescope;
|
||||||
|
|
||||||
|
#include "src/plugins/Plugins.config.h"
|
||||||
|
|
||||||
|
#if DEBUG == PROFILER
|
||||||
|
extern void profiler();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void sensesPoll() {
|
||||||
|
sense.poll();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
//pinMode(SHARED_ENABLE_PIN, OUTPUT);
|
||||||
|
//digitalWrite(SHARED_ENABLE_PIN, HIGH);
|
||||||
|
#if ADDON_SELECT_PIN != OFF
|
||||||
|
pinMode(ADDON_SELECT_PIN, OUTPUT);
|
||||||
|
digitalWrite(ADDON_SELECT_PIN, HIGH);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEBUG != OFF
|
||||||
|
SERIAL_DEBUG.begin(SERIAL_DEBUG_BAUD);
|
||||||
|
delay(2000);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// let any special processing the pinmap needs happen
|
||||||
|
#ifdef PIN_INIT
|
||||||
|
PIN_INIT();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// say hello
|
||||||
|
VLF("");
|
||||||
|
VF("MSG: OnStepX, version "); V(FirmwareVersionMajor); V("."); V(FirmwareVersionMinor); VL(FirmwareVersionPatch);
|
||||||
|
VF("MSG: OnStepX, MCU "); VLF(MCU_STR);
|
||||||
|
VF("MSG: OnStepX, pinmap "); VLF(PINMAP_STR);
|
||||||
|
|
||||||
|
// start low level hardware
|
||||||
|
VLF("MSG: System, HAL initialize");
|
||||||
|
HAL_INIT();
|
||||||
|
WIRE_INIT();
|
||||||
|
|
||||||
|
analog.begin();
|
||||||
|
|
||||||
|
nv().setGate(&xBusy);
|
||||||
|
if (!nv().init()) {
|
||||||
|
DLF("ERR: Setup, NV (EEPROM/FRAM/Flash/etc.) device not found!");
|
||||||
|
}
|
||||||
|
delay(2000);
|
||||||
|
|
||||||
|
#if defined(NV_WIPE) && NV_WIPE == ON
|
||||||
|
nv().wipe();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// start input sense polling task
|
||||||
|
int pollingRate = round((1000.0F/HAL_FRACTIONAL_SEC)/2.0F);
|
||||||
|
if (pollingRate < 1) pollingRate = 1;
|
||||||
|
VF("MSG: System, start input sense service task (rate "); V(pollingRate); VF("ms priority 7)... ");
|
||||||
|
if (tasks.add(pollingRate, 0, true, 7, sensesPoll, "SysSens")) { VLF("success"); } else { VLF("FAILED!"); }
|
||||||
|
|
||||||
|
// start telescope object
|
||||||
|
telescope.init(FirmwareName, FirmwareVersionMajor, FirmwareVersionMinor, FirmwareVersionPatch, FirmwareVersionConfig);
|
||||||
|
|
||||||
|
// start command channel tasks
|
||||||
|
commandChannelInit();
|
||||||
|
|
||||||
|
tasks.yield(2000);
|
||||||
|
|
||||||
|
// start any plugins
|
||||||
|
#if PLUGIN1 != OFF
|
||||||
|
PLUGIN1.init();
|
||||||
|
#endif
|
||||||
|
#if PLUGIN2 != OFF
|
||||||
|
PLUGIN2.init();
|
||||||
|
#endif
|
||||||
|
#if PLUGIN3 != OFF
|
||||||
|
PLUGIN3.init();
|
||||||
|
#endif
|
||||||
|
#if PLUGIN4 != OFF
|
||||||
|
PLUGIN4.init();
|
||||||
|
#endif
|
||||||
|
#if PLUGIN5 != OFF
|
||||||
|
PLUGIN5.init();
|
||||||
|
#endif
|
||||||
|
#if PLUGIN6 != OFF
|
||||||
|
PLUGIN6.init();
|
||||||
|
#endif
|
||||||
|
#if PLUGIN7 != OFF
|
||||||
|
PLUGIN7.init();
|
||||||
|
#endif
|
||||||
|
#if PLUGIN8 != OFF
|
||||||
|
PLUGIN8.init();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// start task manager debug events
|
||||||
|
#if DEBUG == PROFILER
|
||||||
|
tasks.add(142, 0, true, 7, profiler, "Profilr");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sense.poll();
|
||||||
|
|
||||||
|
telescope.ready = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
tasks.yield();
|
||||||
|
}
|
||||||
Executable
+437
@@ -0,0 +1,437 @@
|
|||||||
|
# CAN Notes
|
||||||
|
|
||||||
|
## Purpose
|
||||||
|
|
||||||
|
These notes describe the current CAN interface in its most useful practical
|
||||||
|
role: interconnecting remote OnStepX peripheral features.
|
||||||
|
|
||||||
|
This note is mainly about using CAN so the main controller can talk to:
|
||||||
|
|
||||||
|
- a remote rotator
|
||||||
|
- one or more remote focusers
|
||||||
|
- a remote auxiliary-features node
|
||||||
|
|
||||||
|
It is not mainly about low-level motor/axis CAN protocols. Those are better
|
||||||
|
left for a later axis-oriented note.
|
||||||
|
|
||||||
|
## Quick Summary
|
||||||
|
|
||||||
|
The cleanest mental model is:
|
||||||
|
|
||||||
|
1. the main OnStepX controller runs the mount as usual
|
||||||
|
2. some peripherals can live on their own CAN-connected nodes
|
||||||
|
3. the main controller forwards the normal rotator, focuser, or auxiliary
|
||||||
|
feature operations to those remote nodes
|
||||||
|
|
||||||
|
So the current CAN feature set is best thought of as a way to distribute
|
||||||
|
peripherals around the system, not as "the whole mount over CAN."
|
||||||
|
|
||||||
|
## What CAN Is Good For Here
|
||||||
|
|
||||||
|
This design is most useful when you want the mount controller and some
|
||||||
|
peripheral functions to be physically separate.
|
||||||
|
|
||||||
|
Typical reasons include:
|
||||||
|
|
||||||
|
- keeping focuser or rotator electronics close to the OTA
|
||||||
|
- reducing long motor/sensor wiring runs
|
||||||
|
- letting one small remote node host accessory features near where they are used
|
||||||
|
- building a more modular system where peripherals can be added or moved more
|
||||||
|
easily
|
||||||
|
|
||||||
|
In this arrangement:
|
||||||
|
|
||||||
|
- the rotator, focusers, and auxiliary-feature controllers can stay with an OTA
|
||||||
|
- plugging in one CAN/power cable brings that whole peripheral set online
|
||||||
|
- the correct functionality and settings can then appear at the mount
|
||||||
|
controller immediately and work as one integrated system from Android App,
|
||||||
|
Smart Hand Controller, Smart Web Server, ASCOM, and similar clients
|
||||||
|
|
||||||
|
So the CAN link is not just carrying commands. It also helps turn an OTA
|
||||||
|
assembly into a more self-contained module that can be moved from one mount
|
||||||
|
controller to another with much less rework.
|
||||||
|
|
||||||
|
In other words, CAN is being used here as a practical interconnect between
|
||||||
|
cooperating OnStepX feature nodes.
|
||||||
|
|
||||||
|
## Connectors And Cable
|
||||||
|
|
||||||
|
For this CAN interconnect role, the preferred connector choices are:
|
||||||
|
|
||||||
|
- RJ12 as the standard light-duty connector
|
||||||
|
- GX12-6 as the standard rugged connector
|
||||||
|
|
||||||
|
The standard 6-pin wiring order is:
|
||||||
|
|
||||||
|
1. `GND`
|
||||||
|
2. `+12V`
|
||||||
|
3. `CAN_L`
|
||||||
|
4. `CAN_H`
|
||||||
|
5. `+12V`
|
||||||
|
6. `GND`
|
||||||
|
|
||||||
|
This duplicates power and ground at the outer pairs and keeps the CAN pair
|
||||||
|
together in the middle.
|
||||||
|
|
||||||
|
With quality connectors and cables, this arrangement is intended to carry:
|
||||||
|
|
||||||
|
- `12V @ 2A`
|
||||||
|
|
||||||
|
Recommended cable guidance:
|
||||||
|
|
||||||
|
- twisted-pair `24 AWG` is optimal
|
||||||
|
- straight quality RJ12 cable of `26 AWG` is acceptable for short runs of about
|
||||||
|
`2 to 3 meters`
|
||||||
|
|
||||||
|
So the practical idea is:
|
||||||
|
|
||||||
|
- use RJ12 for lighter-duty short interconnects
|
||||||
|
- use GX12-6 where a more rugged connector is needed
|
||||||
|
- keep cable quality high if you expect the same cable to carry both CAN and
|
||||||
|
accessory power
|
||||||
|
|
||||||
|
## Termination
|
||||||
|
|
||||||
|
The mount controller is treated as one terminating end of the CAN bus.
|
||||||
|
|
||||||
|
In the standard arrangement:
|
||||||
|
|
||||||
|
- the mount controller has a built-in `120 Ohm` termination resistor
|
||||||
|
- the remote nodes are daisy-chained in the normal CAN fashion
|
||||||
|
- the far end of the chain gets the second `120 Ohm` termination resistor
|
||||||
|
|
||||||
|
For this system, that far-end termination can be provided by plugging a custom
|
||||||
|
terminating modular jack or `GX12-6` connector into the last node in the chain.
|
||||||
|
|
||||||
|
So the intended layout is the normal two-ended CAN termination pattern:
|
||||||
|
|
||||||
|
- one `120 Ohm` terminator at the mount controller
|
||||||
|
- one `120 Ohm` terminator at the last node
|
||||||
|
|
||||||
|
not a terminator at every intermediate node.
|
||||||
|
|
||||||
|
## The Current Remote Peripheral Types
|
||||||
|
|
||||||
|
The current CAN remote-node support is centered on three feature families:
|
||||||
|
|
||||||
|
### Rotator
|
||||||
|
|
||||||
|
The main controller can treat a rotator as remote.
|
||||||
|
|
||||||
|
That means:
|
||||||
|
|
||||||
|
- the rotator logic still looks like rotator functionality from the user side
|
||||||
|
- but the actual rotator feature can live on a CAN-connected node
|
||||||
|
- the remote node hosts the local Axis3 rotator implementation and answers the
|
||||||
|
requests
|
||||||
|
|
||||||
|
This is a natural fit when the rotator hardware is physically mounted on the
|
||||||
|
instrument side and you do not want all of that wiring returning to the main
|
||||||
|
controller.
|
||||||
|
|
||||||
|
### Focusers
|
||||||
|
|
||||||
|
The focuser support is especially useful for distributed systems.
|
||||||
|
|
||||||
|
The current model allows:
|
||||||
|
|
||||||
|
- up to six remote focusers
|
||||||
|
- heartbeat-based discovery/presence tracking
|
||||||
|
- the main controller to proxy focuser operations over CAN
|
||||||
|
|
||||||
|
This is a good fit for:
|
||||||
|
|
||||||
|
- separate main and guide focusers
|
||||||
|
- multiple optical trains
|
||||||
|
- distributed focus hardware mounted near different instruments
|
||||||
|
|
||||||
|
From the system-design point of view, this is one of the more attractive uses
|
||||||
|
of CAN in the current tree because focusers are naturally peripheral and often
|
||||||
|
benefit from being located close to the mechanics they drive.
|
||||||
|
|
||||||
|
### Auxiliary Features
|
||||||
|
|
||||||
|
Auxiliary features can also live on a remote CAN node.
|
||||||
|
|
||||||
|
This is useful for things such as:
|
||||||
|
|
||||||
|
- switches
|
||||||
|
- dew-heater style outputs
|
||||||
|
- analog outputs
|
||||||
|
- intervalometer or related accessory functions
|
||||||
|
- other feature-board style I/O that is convenient to place away from the main
|
||||||
|
controller
|
||||||
|
|
||||||
|
So a remote auxiliary node can act like a small distributed utility board for
|
||||||
|
the telescope system.
|
||||||
|
|
||||||
|
## The Main Idea: Proxy And Remote Roles
|
||||||
|
|
||||||
|
For these feature families, CAN is used in a client/server style arrangement.
|
||||||
|
|
||||||
|
On the main controller:
|
||||||
|
|
||||||
|
- `ON` means "this feature is reached through CAN"
|
||||||
|
- the main controller becomes a client/proxy for that feature
|
||||||
|
|
||||||
|
On the remote feature node:
|
||||||
|
|
||||||
|
- `REMOTE` means "this node hosts the real implementation"
|
||||||
|
- that node answers the CAN requests for its local feature
|
||||||
|
|
||||||
|
So the usual pattern is:
|
||||||
|
|
||||||
|
- the mount/main controller proxies
|
||||||
|
- the physically-near peripheral node serves
|
||||||
|
|
||||||
|
## Example Assignments
|
||||||
|
|
||||||
|
Here is a typical main-controller configuration when the mount controller is
|
||||||
|
meant to talk to remote CAN-connected peripheral nodes:
|
||||||
|
|
||||||
|
```c
|
||||||
|
#define CAN_ROTATOR ON
|
||||||
|
#define CAN_FOCUSER ON
|
||||||
|
#define CAN_FEATURES ON
|
||||||
|
#define CAN_SEND_RATE_MS 2
|
||||||
|
#define CAN_RECV_RATE_MS 10
|
||||||
|
#define CAN_PLUS CAN2_TEENSY4
|
||||||
|
#define CAN_BAUD 250000
|
||||||
|
```
|
||||||
|
|
||||||
|
In that role:
|
||||||
|
|
||||||
|
- `CAN_ROTATOR ON` means the main controller expects the rotator to be remote
|
||||||
|
- `CAN_FOCUSER ON` means the main controller expects focuser control to be remote
|
||||||
|
- `CAN_FEATURES ON` means the main controller expects the auxiliary-features
|
||||||
|
provider to be remote
|
||||||
|
|
||||||
|
Typical remote-node assignments then look like this.
|
||||||
|
|
||||||
|
Remote rotator node:
|
||||||
|
|
||||||
|
```c
|
||||||
|
#define CAN_ROTATOR REMOTE
|
||||||
|
#define CAN_SEND_RATE_MS 2
|
||||||
|
#define CAN_RECV_RATE_MS 10
|
||||||
|
#define CAN_PLUS CAN2_TEENSY4
|
||||||
|
#define CAN_BAUD 250000
|
||||||
|
```
|
||||||
|
|
||||||
|
Remote focuser node:
|
||||||
|
|
||||||
|
```c
|
||||||
|
#define CAN_FOCUSER REMOTE
|
||||||
|
#define CAN_FOCUSER_NUMBER 1
|
||||||
|
#define CAN_SEND_RATE_MS 2
|
||||||
|
#define CAN_RECV_RATE_MS 10
|
||||||
|
#define CAN_PLUS CAN2_TEENSY4
|
||||||
|
#define CAN_BAUD 250000
|
||||||
|
```
|
||||||
|
|
||||||
|
Remote auxiliary-features node:
|
||||||
|
|
||||||
|
```c
|
||||||
|
#define CAN_FEATURES REMOTE
|
||||||
|
#define CAN_SEND_RATE_MS 2
|
||||||
|
#define CAN_RECV_RATE_MS 10
|
||||||
|
#define CAN_PLUS CAN2_TEENSY4
|
||||||
|
#define CAN_BAUD 250000
|
||||||
|
```
|
||||||
|
|
||||||
|
These examples mirror the common case where the CAN interface is on the ST4
|
||||||
|
port through `CAN2_TEENSY4`, with `250000` baud and the faster `2ms` send
|
||||||
|
pacing.
|
||||||
|
|
||||||
|
The repeated send/receive-rate lines in those examples are mainly there for
|
||||||
|
documentation clarity. They make the intended CAN setup obvious in one place,
|
||||||
|
not because every line is a special non-default requirement.
|
||||||
|
|
||||||
|
## Platform Guidance
|
||||||
|
|
||||||
|
In current practical use, a Teensy 4.1 makes a very good mount controller when
|
||||||
|
CAN is involved.
|
||||||
|
|
||||||
|
That is the preferred direction because:
|
||||||
|
|
||||||
|
- it has worked well as the main controller side
|
||||||
|
- `CAN2_TEENSY4` on the ST4 port is a natural fit for this role
|
||||||
|
|
||||||
|
ESP32 is a different story.
|
||||||
|
|
||||||
|
Using the built-in TWAI interface on ESP32:
|
||||||
|
|
||||||
|
- ESP32 can feel slow as a CAN client/proxy on the main controller side
|
||||||
|
- but ESP32 is perfectly reasonable as a remote CAN server for things like a
|
||||||
|
rotator, focuser, or auxiliary-features node
|
||||||
|
|
||||||
|
The push toward `250000` baud is intentional.
|
||||||
|
|
||||||
|
The reason is mainly practical:
|
||||||
|
|
||||||
|
- `250000` gives more wiring freedom
|
||||||
|
- it is a better fit for the kind of real-world cable runs and connectors these
|
||||||
|
distributed peripheral nodes are likely to use
|
||||||
|
|
||||||
|
This whole CAN peripheral-interconnect feature set is still fairly new and
|
||||||
|
experimental.
|
||||||
|
|
||||||
|
So the current practical guidance is:
|
||||||
|
|
||||||
|
- prefer Teensy 4.1 as the CAN mount controller
|
||||||
|
- ESP32 is fine for remote peripheral-server roles
|
||||||
|
- treat `250000` as the preferred default unless there is a clear reason to do
|
||||||
|
otherwise
|
||||||
|
- do not assume other CAN platforms are equally proven
|
||||||
|
|
||||||
|
Important reality check:
|
||||||
|
|
||||||
|
- other platforms have not really been tested in this role yet
|
||||||
|
|
||||||
|
## Important Rule: Remote Or Local, Never Both
|
||||||
|
|
||||||
|
For each feature family, a build must choose whether that feature is local or
|
||||||
|
reached through CAN.
|
||||||
|
|
||||||
|
That means:
|
||||||
|
|
||||||
|
- if `CAN_ROTATOR == ON`, do not also configure a normal local rotator in that
|
||||||
|
same build
|
||||||
|
- if `CAN_FOCUSER == ON`, do not also configure normal local focusers in that
|
||||||
|
same build
|
||||||
|
- if `CAN_FEATURES == ON`, do not also configure local auxiliary features in
|
||||||
|
that same build
|
||||||
|
|
||||||
|
`REMOTE` is the opposite role:
|
||||||
|
|
||||||
|
- a `REMOTE` rotator node must actually host the local rotator it is serving
|
||||||
|
- a `REMOTE` focuser node must actually host the local focuser it is serving
|
||||||
|
- a `REMOTE` auxiliary node must actually host the local features it is serving
|
||||||
|
|
||||||
|
So the rule is not "both local and remote at once." The rule is:
|
||||||
|
|
||||||
|
- main controller build: client/proxy
|
||||||
|
- remote peripheral build: local provider/server
|
||||||
|
|
||||||
|
## What This Feels Like In Practice
|
||||||
|
|
||||||
|
From the user-facing point of view, this is meant to feel like the feature is
|
||||||
|
still part of the overall system.
|
||||||
|
|
||||||
|
Conceptually:
|
||||||
|
|
||||||
|
- you talk to the main controller in the ordinary way
|
||||||
|
- the main controller forwards the relevant focuser/rotator/auxiliary operation
|
||||||
|
over CAN
|
||||||
|
- the remote node performs the work and reports back
|
||||||
|
|
||||||
|
So the goal is not to create a second separate user workflow. The goal is to
|
||||||
|
let the feature live somewhere else electrically and physically while still
|
||||||
|
participating in the same overall system.
|
||||||
|
|
||||||
|
## Presence And Heartbeats
|
||||||
|
|
||||||
|
The remote-node model uses simple heartbeats.
|
||||||
|
|
||||||
|
That matters because the main controller should not treat a remote feature as
|
||||||
|
available just because it was configured at compile time.
|
||||||
|
|
||||||
|
Instead:
|
||||||
|
|
||||||
|
- remote nodes emit a heartbeat about once per second
|
||||||
|
- the client side considers the feature present only while that heartbeat
|
||||||
|
remains fresh
|
||||||
|
|
||||||
|
This is especially helpful for distributed peripherals because it gives the
|
||||||
|
main controller a simple way to decide whether a remote focuser, rotator, or
|
||||||
|
feature board is really there and alive right now.
|
||||||
|
|
||||||
|
For focusers, the model is a little richer:
|
||||||
|
|
||||||
|
- each remote focuser has its own heartbeat slot
|
||||||
|
- the main controller can therefore keep track of multiple remote focusers
|
||||||
|
independently
|
||||||
|
|
||||||
|
## Typical System Layouts
|
||||||
|
|
||||||
|
Some natural ways to use the current CAN feature set are:
|
||||||
|
|
||||||
|
### Main Mount Controller Plus Remote Rotator
|
||||||
|
|
||||||
|
Use the main controller for the mount itself, and put the rotator logic on a
|
||||||
|
CAN-connected node near the camera train.
|
||||||
|
|
||||||
|
That helps when:
|
||||||
|
|
||||||
|
- the rotator is physically far from the main controller
|
||||||
|
- you want cleaner wiring through the moving instrument area
|
||||||
|
|
||||||
|
### Main Mount Controller Plus Remote Focusers
|
||||||
|
|
||||||
|
Keep the mount local, but move one or more focusers onto remote CAN nodes.
|
||||||
|
|
||||||
|
That is useful when:
|
||||||
|
|
||||||
|
- focusers are spread around the instrument package
|
||||||
|
- you have more than one focuser role
|
||||||
|
- you want each focuser controller physically near its motor and sensors
|
||||||
|
|
||||||
|
### Main Mount Controller Plus Remote Auxiliary Board
|
||||||
|
|
||||||
|
Use a CAN-connected auxiliary node as a distributed accessory board.
|
||||||
|
|
||||||
|
That is a good fit for:
|
||||||
|
|
||||||
|
- dew-heater outputs
|
||||||
|
- power or switch functions
|
||||||
|
- intervalometer or small observatory accessory control
|
||||||
|
|
||||||
|
### Mixed Peripheral Layout
|
||||||
|
|
||||||
|
These roles can be mixed.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
- main controller handles the mount
|
||||||
|
- a remote node handles the rotator
|
||||||
|
- one or more remote nodes handle focusers
|
||||||
|
- another remote node hosts accessory features
|
||||||
|
|
||||||
|
That is the real strength of this CAN feature set: it lets the system be
|
||||||
|
physically distributed while still acting like one coordinated instrument.
|
||||||
|
|
||||||
|
## What This Note Is Not Trying To Cover
|
||||||
|
|
||||||
|
This note is intentionally not trying to go deep into:
|
||||||
|
|
||||||
|
- low-level frame packing details
|
||||||
|
- backend-specific controller quirks
|
||||||
|
- direct CAN motor/encoder protocols
|
||||||
|
- a future "axis over CAN" design
|
||||||
|
|
||||||
|
Those are all real topics, but they are different topics.
|
||||||
|
|
||||||
|
For this note, the important point is simply:
|
||||||
|
|
||||||
|
- CAN is currently a practical interconnect for remote rotator, focuser, and
|
||||||
|
auxiliary-feature nodes
|
||||||
|
|
||||||
|
## Related Notes
|
||||||
|
|
||||||
|
For the current command-family coverage, see
|
||||||
|
[COMMAND_REFERENCE.md](COMMAND_REFERENCE.md).
|
||||||
|
|
||||||
|
For serial transport/background comparison, see
|
||||||
|
[SERIAL_NOTES.md](SERIAL_NOTES.md).
|
||||||
|
|
||||||
|
## Good Mental Summary
|
||||||
|
|
||||||
|
The cleanest way to think about the current CAN feature set in OnStepX is:
|
||||||
|
|
||||||
|
- the mount controller stays central
|
||||||
|
- selected peripherals can live on their own CAN-connected nodes
|
||||||
|
- rotator, focusers, and auxiliary features are the current distributed-feature
|
||||||
|
sweet spot
|
||||||
|
|
||||||
|
So CAN is best understood here as a practical peripheral-interconnect feature
|
||||||
|
for building a cleaner, more modular telescope system.
|
||||||
Executable
+861
@@ -0,0 +1,861 @@
|
|||||||
|
# OnStepX Command Reference
|
||||||
|
|
||||||
|
This reference is derived from the current command handlers in the source tree, primarily the `*.command.cpp` files plus the shared command processor in `src/libApp/commands/ProcessCmds.cpp`.
|
||||||
|
|
||||||
|
Scope notes:
|
||||||
|
|
||||||
|
- This covers the command families implemented in the current tree, not older wiki pages.
|
||||||
|
- Many commands are compile-time feature gated. If a subsystem is not enabled in the build, its commands will not exist.
|
||||||
|
- Plugin-defined commands are not documented here because they come from the active plugin set, not the core command handlers.
|
||||||
|
- A few command comments in source are stale. Where the code and comment disagree, this document follows the code path.
|
||||||
|
|
||||||
|
## Protocol Basics
|
||||||
|
|
||||||
|
### Frames
|
||||||
|
|
||||||
|
- Normal ASCII command frame: `:CC...#`
|
||||||
|
- Checksummed frame: `;CC...CCS#`
|
||||||
|
- `;` starts a checksummed command.
|
||||||
|
- The command processor validates the checksum and sequence character before dispatch.
|
||||||
|
- The parser ignores ASCII space, LF, and CR.
|
||||||
|
- Internal command buffer size is 80 bytes including framing, so current implementations are not limited to the older 40-character LX200 convention.
|
||||||
|
|
||||||
|
### Command Parsing
|
||||||
|
|
||||||
|
- `CC` is effectively a 1- or 2-character command family. The rest of the payload is the parameter string.
|
||||||
|
- Replies are either:
|
||||||
|
- payload replies, usually terminated with `#`
|
||||||
|
- numeric/boolean replies, returned as `1` for success and `0` for failure
|
||||||
|
- Some commands suppress the trailing `#` on purpose.
|
||||||
|
|
||||||
|
### Global Reply/Error Behavior
|
||||||
|
|
||||||
|
- Commands that leave `numericReply=true` return:
|
||||||
|
- `1` for `CE_NONE` or `CE_1`
|
||||||
|
- `0` for any other error
|
||||||
|
- `:GE#` returns the last command error code as a 2-digit payload.
|
||||||
|
|
||||||
|
### Command Error Codes
|
||||||
|
|
||||||
|
These are the codes returned by `:GE#`:
|
||||||
|
|
||||||
|
| Code | Symbol | Meaning |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 00 | `CE_NONE` | No error |
|
||||||
|
| 01 | `CE_0` | False/fail without a protocol error |
|
||||||
|
| 02 | `CE_CMD_UNKNOWN` | Unknown command |
|
||||||
|
| 03 | `CE_REPLY_UNKNOWN` | Invalid reply |
|
||||||
|
| 04 | `CE_PARAM_RANGE` | Parameter out of range |
|
||||||
|
| 05 | `CE_PARAM_FORM` | Bad parameter format |
|
||||||
|
| 06 | `CE_ALIGN_FAIL` | Align failed |
|
||||||
|
| 07 | `CE_ALIGN_NOT_ACTIVE` | Align not active |
|
||||||
|
| 08 | `CE_NOT_PARKED_OR_AT_HOME` | Not parked or at home |
|
||||||
|
| 09 | `CE_PARKED` | Already parked |
|
||||||
|
| 10 | `CE_PARK_FAILED` | Park failed |
|
||||||
|
| 11 | `CE_NOT_PARKED` | Not parked |
|
||||||
|
| 12 | `CE_NO_PARK_POSITION_SET` | No park position set |
|
||||||
|
| 13 | `CE_GOTO_FAIL` | Goto failed |
|
||||||
|
| 14 | `CE_LIBRARY_FULL` | Library full |
|
||||||
|
| 15 | `CE_SLEW_ERR_BELOW_HORIZON` | Target below horizon limit |
|
||||||
|
| 16 | `CE_SLEW_ERR_ABOVE_OVERHEAD` | Target above overhead limit |
|
||||||
|
| 17 | `CE_SLEW_ERR_IN_STANDBY` | Controller in standby |
|
||||||
|
| 18 | `CE_SLEW_ERR_IN_PARK` | Mount parked |
|
||||||
|
| 19 | `CE_SLEW_IN_SLEW` | Goto already active |
|
||||||
|
| 20 | `CE_SLEW_ERR_OUTSIDE_LIMITS` | Outside configured limits |
|
||||||
|
| 21 | `CE_SLEW_ERR_HARDWARE_FAULT` | Hardware fault |
|
||||||
|
| 22 | `CE_SLEW_IN_MOTION` | Mount already in motion |
|
||||||
|
| 23 | `CE_SLEW_ERR_UNSPECIFIED` | Other slew error |
|
||||||
|
| 25 | `CE_1` | Explicit true/success |
|
||||||
|
|
||||||
|
## Global Processor Commands
|
||||||
|
|
||||||
|
These come from `ProcessCmds.cpp`, not from a subsystem `*.command.cpp`.
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:SBB#` | `1` then switches to 460800 baud | Set serial baud rate |
|
||||||
|
| `:SBA#` | `1` then switches to 230400 baud | Set serial baud rate |
|
||||||
|
| `:SB0#` | `1` then switches to 115200 baud | Set serial baud rate |
|
||||||
|
| `:SB1#` | `1` then switches to 56700 baud | Set serial baud rate |
|
||||||
|
| `:SB2#` | `1` then switches to 38400 baud | Set serial baud rate |
|
||||||
|
| `:SB3#` | `1` then switches to 28800 baud | Set serial baud rate |
|
||||||
|
| `:SB4#` | `1` then switches to 19200 baud | Set serial baud rate |
|
||||||
|
| `:SB5#` | `1` then switches to 14400 baud | Set serial baud rate |
|
||||||
|
| `:SB6#` | `1` then switches to 9600 baud | Set serial baud rate |
|
||||||
|
| `:SB7#` | `1` then switches to 4800 baud | Set serial baud rate |
|
||||||
|
| `:SB8#` | `1` then switches to 2400 baud | Set serial baud rate |
|
||||||
|
| `:SB9#` | `1` then switches to 1200 baud | Set serial baud rate |
|
||||||
|
| `:GE#` | `CC#` | Get last command error code |
|
||||||
|
| `<0x06>` | `A`, `P`, or `CK_FAIL` style response | Special LX200 status query/checksum-fail path handled by the buffer/processor |
|
||||||
|
|
||||||
|
## Dispatcher Notes
|
||||||
|
|
||||||
|
In the full telescope build, command dispatch order is:
|
||||||
|
|
||||||
|
1. mount
|
||||||
|
2. guide
|
||||||
|
3. GPIO/plugin status helpers
|
||||||
|
4. goto
|
||||||
|
5. park
|
||||||
|
6. library
|
||||||
|
7. site
|
||||||
|
8. limits
|
||||||
|
9. home
|
||||||
|
10. PEC
|
||||||
|
11. axis 1 / axis 2
|
||||||
|
12. rotator
|
||||||
|
13. focuser
|
||||||
|
14. auxiliary features
|
||||||
|
|
||||||
|
That matters because some command names are reused by different subsystems, especially `:hP#` and `:hR#`. In an integrated mount build, mount park/unpark wins before the rotator/focuser handlers ever see those frames. The rotator/focuser `h*` commands are still valid for standalone or remote-node builds.
|
||||||
|
|
||||||
|
## Core Telescope / Firmware / Environment
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:B+#` | none | Increase reticle brightness |
|
||||||
|
| `:B-#` | none | Decrease reticle brightness |
|
||||||
|
| `:ECtext#` | none | Echo text to debug output. `_` becomes space, trailing `&` becomes newline. |
|
||||||
|
| `:ERESET#` | none | Reset the MCU |
|
||||||
|
| `:ENVRESET#` | text | Mark NV storage to be cleared on next boot |
|
||||||
|
| `:ESPFLASH#` | `1`/none depending on build path | Put addon/ESP device into firmware flashing mode when supported |
|
||||||
|
| `:GVD#` | `MTH DD YYYY#` | Firmware build date |
|
||||||
|
| `:GVM#` | `name version#` | Firmware name plus version |
|
||||||
|
| `:GVN#` | `M.mm...#` | Firmware version number |
|
||||||
|
| `:GVP#` | `name#` | Product name |
|
||||||
|
| `:GVT#` | `HH:MM:SS#` | Firmware build time |
|
||||||
|
| `:GVC#` | `string#` | Firmware config/product description |
|
||||||
|
| `:GVH#` | `string#` | Firmware hardware/pinmap string |
|
||||||
|
| `:GX9A#` | `sn.n#` | Ambient temperature in C |
|
||||||
|
| `:GX9B#` | `n.n#` | Pressure in mbar |
|
||||||
|
| `:GX9C#` | `n.n#` | Relative humidity in percent |
|
||||||
|
| `:GX9E#` | `sn.n#` | Dew point in C |
|
||||||
|
| `:GX9F#` | `n#` or `0` | MCU temperature in C |
|
||||||
|
| `:SX9A,sn.n#` | `0/1` | Set ambient temperature |
|
||||||
|
| `:SX9B,n.n#` | `0/1` | Set pressure |
|
||||||
|
| `:SX9C,n.n#` | `0/1` | Set humidity |
|
||||||
|
|
||||||
|
## Time / Date / Site
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:Ga#` | `HH:MM:SS#` | Local standard time, 12-hour format |
|
||||||
|
| `:GC#` | `MM/DD/YY#` | Local standard calendar date |
|
||||||
|
| `:Gc#` | `24#` | Local time format indicator |
|
||||||
|
| `:GG#` | `sHH:MM#` | UTC offset to add to local time to get UT1 |
|
||||||
|
| `:Gg#` | `sDDD*MM#` | Current longitude |
|
||||||
|
| `:GgH#` | `sDDD*MM:SS.SSS#` | Longitude, highest precision |
|
||||||
|
| `:GL#` | `HH:MM:SS#` | Local standard time, 24-hour format |
|
||||||
|
| `:GLH#` | `HH:MM:SS.SSSS#` | Local standard time, highest precision |
|
||||||
|
| `:GM#` | `string#` | Site 1 name |
|
||||||
|
| `:GN#` | `string#` | Site 2 name |
|
||||||
|
| `:GO#` | `string#` | Site 3 name |
|
||||||
|
| `:GP#` | `string#` | Site 4 name |
|
||||||
|
| `:GS#` | `HH:MM:SS#` | Sidereal time |
|
||||||
|
| `:GSH#` | `HH:MM:SS.ss#` | Sidereal time, highest precision |
|
||||||
|
| `:Gt#` | `sDD*MM#` | Current latitude |
|
||||||
|
| `:GtH#` | `sDD*MM:SS.SSS#` | Latitude, highest precision |
|
||||||
|
| `:Gv#` | `sn.n#` | Elevation in meters |
|
||||||
|
| `:GX80#` | `HH:MM:SS.ss#` | UT1 time |
|
||||||
|
| `:GX81#` | `MM/DD/YY#` | UT1 date |
|
||||||
|
| `:GX89#` | `0` or `1` | Date/time ready status. `0` means ready, `1` means not ready. |
|
||||||
|
| `:SCMM/DD/YY#` | `0/1` | Set local date |
|
||||||
|
| `:SCMM/DD/YYYY#` | `0/1` | Set local date |
|
||||||
|
| `:SGsHH#` | `0/1` | Set UTC offset |
|
||||||
|
| `:SGsHH:MM#` | `0/1` | Set UTC offset. Comments indicate `MM` should be `00`, `30`, or `45`. |
|
||||||
|
| `:Sg(s)DDD*MM#` | `0/1` | Set longitude |
|
||||||
|
| `:Sg(s)DDD*MM:SS#` | `0/1` | Set longitude |
|
||||||
|
| `:Sg(s)DDD*MM:SS.SSS#` | `0/1` | Set longitude |
|
||||||
|
| `:SLHH:MM:SS#` | `0/1` | Set local time |
|
||||||
|
| `:SLHH:MM:SS.SSS#` | `0/1` | Set local time |
|
||||||
|
| `:SMname#` | `0/1` | Set site 1 name, max 15 chars |
|
||||||
|
| `:SNname#` | `0/1` | Set site 2 name, max 15 chars |
|
||||||
|
| `:SOname#` | `0/1` | Set site 3 name, max 15 chars |
|
||||||
|
| `:SPname#` | `0/1` | Set site 4 name, max 15 chars |
|
||||||
|
| `:StsDD*MM#` | `0/1` | Set latitude |
|
||||||
|
| `:StsDD*MM:SS#` | `0/1` | Set latitude |
|
||||||
|
| `:StsDD*MM:SS.SSS#` | `0/1` | Set latitude |
|
||||||
|
| `:SUs.s#` | `0/1` | Set DUT1 correction in seconds, nominally `-0.9` to `+0.9` |
|
||||||
|
| `:Svsn.n#` | `0/1` | Set elevation in meters |
|
||||||
|
| `:W0#` .. `:W3#` | none | Select active site slot |
|
||||||
|
| `:W?#` | `n#` | Query active site slot |
|
||||||
|
|
||||||
|
## Mount Position / Tracking / Rates
|
||||||
|
|
||||||
|
Available when `MOUNT_PRESENT` is enabled.
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:GA#` | `sDD*MM#` or `sDD*MM'SS#` | Current mount altitude |
|
||||||
|
| `:GAH#` | `sDD*MM'SS.SSS#` | Current mount altitude, highest precision |
|
||||||
|
| `:GD#` | `sDD*MM#` or `sDD*MM:SS#` | Current declination |
|
||||||
|
| `:GDH#` | `sDD*MM:SS.SSS#` | Current declination, highest precision |
|
||||||
|
| `:GR#` | `HH:MM.T#` or `HH:MM:SS#` | Current right ascension |
|
||||||
|
| `:GRH#` | `HH:MM:SS.SSSS#` | Current right ascension, highest precision |
|
||||||
|
| `:GT#` | `n.nnnnn#` or `0#` | Tracking rate in Hz, `0` if not tracking |
|
||||||
|
| `:GZ#` | `DDD*MM#` or `DDD*MM'SS#` | Current azimuth |
|
||||||
|
| `:GZH#` | `DDD*MM'SS.SSS#` | Current azimuth, highest precision |
|
||||||
|
| `:GXTD#` | `n.nnnnnnnn#` | Tracking rate offset, Dec, arcsec per sidereal second |
|
||||||
|
| `:GXTR#` | `n.nnnnnnnn#` | Tracking rate offset, RA, arcsec per sidereal second |
|
||||||
|
| `:GX40#` | `DDD*MM:SS#` | Axis1 instrument angle |
|
||||||
|
| `:GX41#` | `DDD*MM:SS#` | Axis2 instrument angle |
|
||||||
|
| `:GX42#` | `n.nnnnnn#` | Axis1 instrument angle in decimal degrees |
|
||||||
|
| `:GX43#` | `n.nnnnnn#` | Axis2 instrument angle in decimal degrees |
|
||||||
|
| `:GX44#` | `n#` | Axis1 encoder count |
|
||||||
|
| `:GX45#` | `n#` | Axis2 encoder count |
|
||||||
|
| `:GXE4#` | `n#` | Axis1 steps per degree |
|
||||||
|
| `:GXE5#` | `n#` | Axis2 steps per degree |
|
||||||
|
| `:GXEE#` | `0#`, `1#`, ... | Mount coordinate mode (`MOUNT_COORDS - 1`) |
|
||||||
|
| `:GXEF#` | `1` or `0` | Axis2 tangent-arm presence flag |
|
||||||
|
| `:GXEG#` | `1` or `0` | Axis1 sector-gear presence flag |
|
||||||
|
| `:GXEM#` | `n#` | Current mount type |
|
||||||
|
| `:GXF3#` | `sn.nnnnnn#` | Axis1 step frequency |
|
||||||
|
| `:GXF4#` | `sn.nnnnnn#` | Axis2 step frequency |
|
||||||
|
| `:GXFA#` | `50%#` | Reported workload placeholder |
|
||||||
|
| `:GXFF#` | `n.nnnnnn#` | Axis1 index position |
|
||||||
|
| `:GXFG#` | `n.nnnnnn#` | Axis2 index position |
|
||||||
|
| `:STn.n#` | `0/1` | Set tracking rate in Hz. `0` stops tracking. |
|
||||||
|
| `:SEO#` | `0/1` | Save absolute encoder origin, or initialize mount coordinate memory at home, when supported |
|
||||||
|
| `:SX40,n#` | `0/1` | Stage encoder axis1 angle in degrees |
|
||||||
|
| `:SX41,n#` | `0/1` | Stage encoder axis2 angle in degrees |
|
||||||
|
| `:SX42,1#` | `0/1` | Sync mount from staged encoder axis values |
|
||||||
|
| `:SX43,0#` | `0/1` | Allow SWS to control sync mode |
|
||||||
|
| `:SX44,deg1,deg2[a]#` | `0/1` | Stage and sync both encoder axes, append `a` when both SWS encoder values are absolute and trusted |
|
||||||
|
| `:SXEM,n#` | `0/1` | Set mount type for next restart |
|
||||||
|
| `:SXTD,n.n#` | `0/1` | Set Dec tracking rate offset, arcsec per sidereal second |
|
||||||
|
| `:SXTR,n.n#` | `0/1` | Set RA tracking rate offset, arcsec per sidereal second |
|
||||||
|
| `:TS#` | none | Solar tracking rate |
|
||||||
|
| `:TK#` | none | King tracking rate |
|
||||||
|
| `:TL#` | none | Lunar tracking rate |
|
||||||
|
| `:TQ#` | none | Sidereal tracking rate |
|
||||||
|
| `:T+#` | none | Increase master sidereal clock by 0.02 Hz |
|
||||||
|
| `:T-#` | none | Decrease master sidereal clock by 0.02 Hz |
|
||||||
|
| `:TR#` | none | Reset master sidereal clock |
|
||||||
|
| `:Te#` | `0/1` | Enable tracking |
|
||||||
|
| `:Td#` | `0/1` | Disable tracking |
|
||||||
|
| `:To#` | `0/1` | Enable full compensation model |
|
||||||
|
| `:Tr#` | `0/1` | Enable refraction compensation |
|
||||||
|
| `:Tn#` | `0/1` | Disable compensation |
|
||||||
|
| `:T1#` | `0/1` | Single-axis tracking mode |
|
||||||
|
| `:T2#` | `0/1` | Dual-axis tracking mode |
|
||||||
|
| `:$BDn#` | `0/1` | Set Dec/Alt backlash in arcsec |
|
||||||
|
| `:$BRn#` | `0/1` | Set RA/Azm backlash in arcsec |
|
||||||
|
| `:%BD#` | `n#` | Get Dec/Alt backlash in arcsec |
|
||||||
|
| `:%BR#` | `n#` | Get RA/Azm backlash in arcsec |
|
||||||
|
|
||||||
|
### Mount Type Values
|
||||||
|
|
||||||
|
Current core constants are:
|
||||||
|
|
||||||
|
| Value | Mount type |
|
||||||
|
| --- | --- |
|
||||||
|
| `1` | GEM |
|
||||||
|
| `2` | FORK |
|
||||||
|
| `3` | ALTAZM |
|
||||||
|
| `4` | ALTALT |
|
||||||
|
| `5` | GEM_TA |
|
||||||
|
| `6` | GEM_TAC |
|
||||||
|
| `7` | FORK_TA |
|
||||||
|
| `8` | FORK_TAC |
|
||||||
|
| `9` | ALTAZM_UNL |
|
||||||
|
|
||||||
|
## Goto / Sync / Alignment
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:AW#` | `1` | Write alignment model to NV |
|
||||||
|
| `:A?#` | `mno#` | Alignment status: max stars, current star, last required star |
|
||||||
|
| `:A1#` .. `:A9#` | `0/1` | Start manual alignment with that many stars |
|
||||||
|
| `:A+#` | `0/1` | Accept current align point |
|
||||||
|
| `:CS#` | none | Sync to current target coordinates |
|
||||||
|
| `:CM#` | `N/A#` or `E1#`..`E9#` | Sync to current catalog/database object |
|
||||||
|
| `:D#` | `0x7f#` while moving, otherwise raw `#` | LX200 distance-bar style motion indicator |
|
||||||
|
| `:Gr#` | `HH:MM.T#` or `HH:MM:SS#` | Get target RA |
|
||||||
|
| `:GrH#` | `HH:MM:SS.SSSS#` | Get target RA, highest precision |
|
||||||
|
| `:Gd#` | `sDD*MM#` or `sDD*MM:SS#` | Get target Dec |
|
||||||
|
| `:GdH#` | `sDD*MM:SS.SSS#` | Get target Dec, highest precision |
|
||||||
|
| `:Gal#` | `sDD*MM#` or `sDD*MM'SS#` | Get target altitude |
|
||||||
|
| `:GaH#` | `sDD*MM'SS.SSS#` | Get target altitude, highest precision |
|
||||||
|
| `:Gz#` | `DDD*MM#` or `DDD*MM'SS#` | Get target azimuth |
|
||||||
|
| `:GzH#` | `DDD*MM'SS.SSS#` | Get target azimuth, highest precision |
|
||||||
|
| `:MA#` | `0`..`9` | Goto target Alt/Az |
|
||||||
|
| `:MD#` | `0`, `1`, or `2` | Destination pier side for current target |
|
||||||
|
| `:MN#` | `0`..`9` | Goto current position on opposite pier side |
|
||||||
|
| `:MNe#` | `0`..`9` | Force same-position goto to east pier side |
|
||||||
|
| `:MNw#` | `0`..`9` | Force same-position goto to west pier side |
|
||||||
|
| `:MP#` | `0`..`9` | Polar-align goto |
|
||||||
|
| `:MS#` | `0`..`9` | Goto current target |
|
||||||
|
| `:SrHH:MM.T#` | `0/1` | Set target RA |
|
||||||
|
| `:SrHH:MM:SS#` | `0/1` | Set target RA |
|
||||||
|
| `:SrHH:MM:SS.SSSS#` | `0/1` | Set target RA |
|
||||||
|
| `:SdsDD*MM#` | `0/1` | Set target Dec |
|
||||||
|
| `:SdsDD*MM:SS#` | `0/1` | Set target Dec |
|
||||||
|
| `:SdsDD*MM:SS.SSS#` | `0/1` | Set target Dec |
|
||||||
|
| `:SasDD*MM#` | `0/1` | Set target altitude |
|
||||||
|
| `:SasDD*MM'SS#` | `0/1` | Set target altitude |
|
||||||
|
| `:SasDD*MM'SS.SSS#` | `0/1` | Set target altitude |
|
||||||
|
| `:SzDDD*MM#` | `0/1` | Set target azimuth |
|
||||||
|
| `:SzDDD*MM'SS#` | `0/1` | Set target azimuth |
|
||||||
|
| `:SzDDD*MM'SS.SSS#` | `0/1` | Set target azimuth |
|
||||||
|
|
||||||
|
### `:MS#` / `:MA#` / `:MN#` / `:MP#` Return Codes
|
||||||
|
|
||||||
|
| Value | Meaning |
|
||||||
|
| --- | --- |
|
||||||
|
| `0` | Goto accepted |
|
||||||
|
| `1` | Below horizon limit |
|
||||||
|
| `2` | Above overhead limit |
|
||||||
|
| `3` | Controller in standby |
|
||||||
|
| `4` | Mount parked |
|
||||||
|
| `5` | Goto already in progress |
|
||||||
|
| `6` | Outside limits |
|
||||||
|
| `7` | Hardware fault |
|
||||||
|
| `8` | Already in motion |
|
||||||
|
| `9` | Unspecified error |
|
||||||
|
|
||||||
|
### Alignment Model Extended Commands
|
||||||
|
|
||||||
|
`ALIGN_MAX_NUM_STARS > 1` builds expose:
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:GX00#` | `n#` | `ax1Cor` in arcsec |
|
||||||
|
| `:GX01#` | `n#` | `ax2Cor` in arcsec |
|
||||||
|
| `:GX02#` | `n#` | `altCor` in arcsec |
|
||||||
|
| `:GX03#` | `n#` | `azmCor` in arcsec |
|
||||||
|
| `:GX04#` | `n#` | `doCor` in arcsec |
|
||||||
|
| `:GX05#` | `n#` | `pdCor` in arcsec |
|
||||||
|
| `:GX06#` | `n#` | `ffCor` for FORK/ALTAZM, else `0` |
|
||||||
|
| `:GX07#` | `n#` | `dfCor` for GEM-style mounts, else `0` |
|
||||||
|
| `:GX08#` | `n#` | `tfCor` in arcsec |
|
||||||
|
| `:GX0a#` | `n#` | `hcp` in degrees |
|
||||||
|
| `:GX0b#` | `n#` | `hca` in arcsec |
|
||||||
|
| `:GX0c#` | `n#` | `dcp` in degrees |
|
||||||
|
| `:GX0d#` | `n#` | `dca` in arcsec |
|
||||||
|
| `:GX09#` | `n#` | Number of uploaded stars, then resets internal star index |
|
||||||
|
| `:GX0A#` | `HH:MM:SS#` | Uploaded star actual HA |
|
||||||
|
| `:GX0B#` | `sDD*MM:SS#` | Uploaded star actual Dec |
|
||||||
|
| `:GX0C#` | `HH:MM:SS#` | Uploaded star mount HA |
|
||||||
|
| `:GX0D#` | `sDD*MM:SS#` | Uploaded star mount Dec |
|
||||||
|
| `:GX0E#` | `n#` | Uploaded star pier side, then advances star index |
|
||||||
|
| `:SX00,n#` .. `:SX0d,n#` | `0/1` | Set alignment model coefficients listed above |
|
||||||
|
| `:SX09,0#` | `0/1` | Reset alignment upload state |
|
||||||
|
| `:SX09,1#` | `0/1` | Build model from uploaded stars |
|
||||||
|
| `:SX09,2#` | `0/1` | Force model active |
|
||||||
|
| `:SX0A,HH:MM:SS#` | `0/1` | Upload actual HA for current star |
|
||||||
|
| `:SX0B,sDD*MM:SS#` | `0/1` | Upload actual Dec for current star |
|
||||||
|
| `:SX0C,HH:MM:SS#` | `0/1` | Upload mount HA for current star |
|
||||||
|
| `:SX0D,sDD*MM:SS#` | `0/1` | Upload mount Dec for current star |
|
||||||
|
| `:SX0E,n#` | `0/1` | Upload pier side and advance to next star |
|
||||||
|
|
||||||
|
### Goto Extended Settings
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:GX92#` | `n.nnn#` | Current slew period in us/step |
|
||||||
|
| `:GX93#` | `n.nnn#` | Base/default slew period in us/step |
|
||||||
|
| `:GX94#` | `n` plus optional ` N` | Current pier side: `0` none, `1` east, `2` west |
|
||||||
|
| `:GX95#` | `0` or `1` | Auto meridian flip enabled |
|
||||||
|
| `:GX96#` | `E`, `W`, `B`, or `A` | Preferred pier side |
|
||||||
|
| `:GX97#` | `n.n#` | Current step rate in deg/s |
|
||||||
|
| `:GX99#` | `n.nnn#` | Fastest allowed slew period in us/step |
|
||||||
|
| `:SX92,n.nnn#` | `0/1` | Set current slew period in us/step |
|
||||||
|
| `:SX93,[1-5]#` | none | Slew preset: `5`=50%, `4`=66.7%, `3`=100%, `2`=150%, `1`=200% |
|
||||||
|
| `:SX95,0#` or `:SX95,1#` | `0/1` | Disable/enable automatic meridian flip |
|
||||||
|
| `:SX96,E#` | `0/1` | Preferred pier side east |
|
||||||
|
| `:SX96,W#` | `0/1` | Preferred pier side west |
|
||||||
|
| `:SX96,B#` | `0/1` | Preferred pier side best |
|
||||||
|
| `:SX96,A#` | `0/1` | Preferred pier side automatic |
|
||||||
|
| `:SX98,0#` or `:SX98,1#` | `0/1` | Disable/enable pause at home during meridian flip |
|
||||||
|
| `:SX99,1#` | `0/1` | Continue after pause at home |
|
||||||
|
|
||||||
|
## Guide / Manual Motion
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:GX90#` | `n.nn#` | Pulse guide rate |
|
||||||
|
| `:Mgdn#` | none | Pulse guide for `n` ms in direction `d` where `d` is `w`, `e`, `n`, or `s` |
|
||||||
|
| `:MGdn#` | `0/1` | Same as `:Mgdn#`, numeric form |
|
||||||
|
| `:Mw#` | none | Move west at current guide rate |
|
||||||
|
| `:Me#` | none | Move east at current guide rate |
|
||||||
|
| `:Mn#` | none | Move north at current guide rate |
|
||||||
|
| `:Ms#` | none | Move south at current guide rate |
|
||||||
|
| `:Mp#` | none | Spiral-search motion |
|
||||||
|
| `:Q#` | none | Stop all slews, abort goto |
|
||||||
|
| `:Qe#` / `:Qw#` | none | Stop east/west motion |
|
||||||
|
| `:Qn#` / `:Qs#` | none | Stop north/south motion |
|
||||||
|
| `:RAn.n#` | none | Set axis1 custom guide rate in deg/s |
|
||||||
|
| `:REn.n#` | none | Set axis2 custom guide rate in deg/s |
|
||||||
|
| `:RG#` | none | Guide rate preset 1x |
|
||||||
|
| `:RC#` | none | Centering rate preset 8x |
|
||||||
|
| `:RM#` | none | Find rate preset 20x |
|
||||||
|
| `:RF#` | none | Fast rate preset 48x |
|
||||||
|
| `:RS#` | none | Slew rate preset, half current goto rate |
|
||||||
|
| `:R0#` .. `:R9#` | none | Numeric guide-rate preset |
|
||||||
|
|
||||||
|
## Park / Home / Limits / Status
|
||||||
|
|
||||||
|
### Park
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:hP#` | `0/1` | Park mount |
|
||||||
|
| `:hQ#` | `0/1` | Set current position as park |
|
||||||
|
| `:hR#` | `0/1` | Unpark mount |
|
||||||
|
|
||||||
|
### Home
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:h?#` | `hasSense,axis1Offset,axis2Offset#` | Home status. Source comment mentions auto-home, but current code returns 3 fields only. |
|
||||||
|
| `:hA0#` / `:hA1#` | none | Disable/enable automatic home at boot |
|
||||||
|
| `:hC#` | none | Move to home |
|
||||||
|
| `:hC1,R#` | none | Toggle axis1 home-sense reversal |
|
||||||
|
| `:hC1,n#` | none | Set axis1 home offset in arcsec |
|
||||||
|
| `:hC2,R#` | none | Toggle axis2 home-sense reversal |
|
||||||
|
| `:hC2,n#` | none | Set axis2 home offset in arcsec |
|
||||||
|
| `:hF#` | none | Reset mount at home/cold-start position |
|
||||||
|
|
||||||
|
### Limits
|
||||||
|
|
||||||
|
For a visual explanation of confusing GEM east/west pier-side limit geometry,
|
||||||
|
see [GOTO_NOTES.md](GOTO_NOTES.md#workflow-4-reachability-and-target-unwinding).
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:Gh#` | `sDD*#` | Horizon limit |
|
||||||
|
| `:Go#` | `DD*#` | Overhead limit |
|
||||||
|
| `:GXE9#` | `n#` | East meridian limit in minutes |
|
||||||
|
| `:GXEA#` | `n#` | West meridian limit in minutes |
|
||||||
|
| `:GXEe#` | `n#` | Axis1 minimum limit in degrees |
|
||||||
|
| `:GXEw#` | `n#` | Axis1 maximum limit in degrees |
|
||||||
|
| `:GXEB#` | `n#` | Axis1 maximum limit in hours |
|
||||||
|
| `:GXEC#` | `n#` | Axis2 minimum limit in degrees |
|
||||||
|
| `:GXED#` | `n#` | Axis2 maximum limit in degrees |
|
||||||
|
| `:ShsDD#` | `0/1` | Set lower altitude limit |
|
||||||
|
| `:SoDD#` | `0/1` | Set overhead altitude limit |
|
||||||
|
| `:SXE9,n#` | `0/1` | Set east meridian limit in minutes |
|
||||||
|
| `:SXEA,n#` | `0/1` | Set west meridian limit in minutes |
|
||||||
|
|
||||||
|
### Status
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:Gm#` | `E#`, `W#`, or `N#` | Meridian pier side |
|
||||||
|
| `:GU#` | status string | Human-readable packed status |
|
||||||
|
| `:Gu#` | packed bytes | Bit-packed status |
|
||||||
|
| `:GW#` | 4-char status | Mount type, tracking, parked/home, align-done |
|
||||||
|
| `:SX97,0#` | `0/1` | Disable buzzer |
|
||||||
|
| `:SX97,1#` | `0/1` | Enable buzzer |
|
||||||
|
| `:SX97,2#` | `0/1` | Beep |
|
||||||
|
| `:SX97,3#` | `0/1` | Alert tone |
|
||||||
|
| `:SX97,4#` | `0/1` | Click |
|
||||||
|
|
||||||
|
#### `:GU#` Status Characters
|
||||||
|
|
||||||
|
The reply is an ordered string assembled from active conditions. Characters currently used by the code include:
|
||||||
|
|
||||||
|
| Char | Meaning |
|
||||||
|
| --- | --- |
|
||||||
|
| `n` | Not tracking |
|
||||||
|
| `N` | No goto active |
|
||||||
|
| `p` | Not parked |
|
||||||
|
| `I` | Parking in progress |
|
||||||
|
| `P` | Parked |
|
||||||
|
| `F` | Park failed |
|
||||||
|
| `e` | Sync-to-encoders-only mode |
|
||||||
|
| `H` | At home |
|
||||||
|
| `h` | Homing |
|
||||||
|
| `B` | Auto-home at boot |
|
||||||
|
| `S` | PPS synced |
|
||||||
|
| `G` | Pulse guide active |
|
||||||
|
| `g` | Guide active |
|
||||||
|
| `r` | Refraction compensation enabled |
|
||||||
|
| `s` | Single-axis compensation mode |
|
||||||
|
| `t` | Full compensation model enabled |
|
||||||
|
| `(` | Lunar tracking rate selected |
|
||||||
|
| `O` | Solar tracking rate selected |
|
||||||
|
| `k` | King tracking rate selected |
|
||||||
|
| `w` | Meridian flip paused at home |
|
||||||
|
| `u` | Pause-at-home enabled |
|
||||||
|
| `z` | Buzzer enabled |
|
||||||
|
| `a` | Automatic meridian flip enabled |
|
||||||
|
| `R` | PEC data recorded |
|
||||||
|
| `/`, `,`, `~`, `;`, `^` | PEC state |
|
||||||
|
| `E`, `K`, `A`, `L` | GEM, FORK, ALTAZM, ALTALT |
|
||||||
|
| `o`, `T`, `W` | Pier side none, east, west |
|
||||||
|
| final digits | pulse-guide rate, guide rate, general error code |
|
||||||
|
|
||||||
|
#### `:Gu#` Packed Status Layout
|
||||||
|
|
||||||
|
`Gu` is the binary/pseudo-binary status form. The current implementation fills bytes as:
|
||||||
|
|
||||||
|
| Byte | Contents |
|
||||||
|
| --- | --- |
|
||||||
|
| `0` | tracking/goto/PPS/pulse-guide plus compensation mode |
|
||||||
|
| `1` | tracking-rate selection plus sync-to-encoders and guide-active |
|
||||||
|
| `2` | home/homing/auto-home/home-pause/buzzer/auto-flip |
|
||||||
|
| `3` | mount type plus pier side |
|
||||||
|
| `4` | PEC state and PEC-recorded flag |
|
||||||
|
| `5` | park state |
|
||||||
|
| `6` | pulse-guide selection |
|
||||||
|
| `7` | guide-rate selection |
|
||||||
|
| `8` | general limits/error code |
|
||||||
|
|
||||||
|
## Object Library
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:LB#` | none | Previous object matching current constraints |
|
||||||
|
| `:LCn#` | none | Select record number `n` |
|
||||||
|
| `:LI#` | `name,type#` | Current object name and type |
|
||||||
|
| `:LIG#` | none | Load current object into goto target |
|
||||||
|
| `:LR#` | `name,type,ra,dec#` | Current object info, then advance to next record |
|
||||||
|
| `:LWname,type#` | `0/1` | Write current target RA/Dec to next free record |
|
||||||
|
| `:LN#` | none | Next object matching current constraints |
|
||||||
|
| `:L$#` | `1` | Move to catalog name record |
|
||||||
|
| `:LD#` | none | Clear current record |
|
||||||
|
| `:LL#` | none | Clear current catalog |
|
||||||
|
| `:L!#` | none | Clear all catalogs |
|
||||||
|
| `:L?#` | `n#` | Free records across all catalogs |
|
||||||
|
| `:Lon#` | `0/1` | Select catalog `0..14` |
|
||||||
|
|
||||||
|
Object type codes written/read by library commands are:
|
||||||
|
|
||||||
|
`UNK`, `OC`, `GC`, `PN`, `DN`, `SG`, `EG`, `IG`, `KNT`, `SNR`, `GAL`, `CN`, `STR`, `PLA`, `CMT`, `AST`
|
||||||
|
|
||||||
|
## PEC
|
||||||
|
|
||||||
|
Available when PEC support is enabled for axis 1.
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:GX91#` | `n#` | PEC analog value |
|
||||||
|
| `:GXE6#` | `n.nnnnnn#` | Steps per sidereal second |
|
||||||
|
| `:GXE7#` | `n#` | Worm rotation steps from NV |
|
||||||
|
| `:GXE8#` | `n#` | PEC buffer size in seconds |
|
||||||
|
| `:SXE7,n#` | `0/1` | Set worm rotation steps |
|
||||||
|
| `:VH#` | `nnnnn#` | PEC index sense position in sidereal seconds |
|
||||||
|
| `:VR#` | `snnn,nnn#` | Current PEC segment correction plus segment index |
|
||||||
|
| `:VRn#` | `snnn#` | PEC correction for segment `n` |
|
||||||
|
| `:Vrn#` | `x0x1...x9#` | Ten-byte hex frame of PEC data starting at segment `n` |
|
||||||
|
| `:VS#` | `n.nnnnnn#` | Steps per sidereal second of worm rotation |
|
||||||
|
| `:VW#` | `nnnnnn#` | Worm rotation steps |
|
||||||
|
| `:WR+#` | `0/1` | Rotate PEC table forward one second |
|
||||||
|
| `:WR-#` | `0/1` | Rotate PEC table backward one second |
|
||||||
|
| `:WRn,sn#` | none | Write PEC correction for segment `n` |
|
||||||
|
| `:$QZ+#` | none | Enable PEC playback |
|
||||||
|
| `:$QZ-#` | none | Disable PEC |
|
||||||
|
| `:$QZ/#` | none | Arm PEC recording |
|
||||||
|
| `:$QZZ#` | none | Clear PEC buffer |
|
||||||
|
| `:$QZ!#` | none | Save PEC data to NV |
|
||||||
|
| `:$QZ?#` | `I#`, `p#`, `P#`, `r#`, `R#`, optionally with `.#` | PEC status |
|
||||||
|
|
||||||
|
PEC status characters from `:$QZ?#`:
|
||||||
|
|
||||||
|
| Char | Meaning |
|
||||||
|
| --- | --- |
|
||||||
|
| `I` | Ignore/off |
|
||||||
|
| `p` | Ready to play |
|
||||||
|
| `P` | Playing |
|
||||||
|
| `r` | Ready to record |
|
||||||
|
| `R` | Recording |
|
||||||
|
| `.` | Index detected this second |
|
||||||
|
|
||||||
|
### `:GXUa#` Driver Status Flags
|
||||||
|
|
||||||
|
Local ASCII replies are comma-separated flag mnemonics:
|
||||||
|
|
||||||
|
| Flag | Meaning |
|
||||||
|
| --- | --- |
|
||||||
|
| `ST` | Standstill |
|
||||||
|
| `OA` | Output A open load |
|
||||||
|
| `OB` | Output B open load |
|
||||||
|
| `GA` | Output A short to ground |
|
||||||
|
| `GB` | Output B short to ground |
|
||||||
|
| `OT` | Over-temperature |
|
||||||
|
| `PW` | Over-temperature warning |
|
||||||
|
| `GF` | Driver fault |
|
||||||
|
|
||||||
|
## Focuser
|
||||||
|
|
||||||
|
Available in focuser-enabled or remote-focuser builds.
|
||||||
|
|
||||||
|
Addressing rules:
|
||||||
|
|
||||||
|
- `:FA#` returns the currently selected focuser number.
|
||||||
|
- `:FA1#` .. `:FA6#` selects the active focuser.
|
||||||
|
- `:F...#` uses the active focuser.
|
||||||
|
- `:F1...#` .. `:F6...#` directs a command to a specific focuser immediately.
|
||||||
|
|
||||||
|
Unit rules for local ASCII focuser commands:
|
||||||
|
|
||||||
|
- Uppercase `B`, `D`, `G`, `I`, `M`, `R`, `S` use microns.
|
||||||
|
- Lowercase `b`, `d`, `g`, `i`, `m`, `r`, `s` use raw steps.
|
||||||
|
- Other focuser commands are unitless or fixed-unit as noted below.
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:FA#` | `n` | Get active focuser number |
|
||||||
|
| `:FA1#` .. `:FA6#` | `0/1` | Select active focuser |
|
||||||
|
| `:hP#` | `0/1` | Park all focusers in standalone/remote focuser builds |
|
||||||
|
| `:hR#` | `0/1` | Unpark all focusers in standalone/remote focuser builds |
|
||||||
|
| `:Fa#` | `1` | Primary focuser present/selected |
|
||||||
|
| `:FT#` | `M1#`, `S3#`, etc. | Focuser status plus goto-rate digit |
|
||||||
|
| `:Fp#` | `0` or `1` | Mode. Current implementation returns `1` for DC/pseudo-absolute, `0` otherwise. |
|
||||||
|
| `:FI#` / `:Fi#` | `n#` | Full-in/min position |
|
||||||
|
| `:FM#` / `:Fm#` | `n#` | Maximum position |
|
||||||
|
| `:Fe#` | `n.n#` | Temperature delta from TCF baseline |
|
||||||
|
| `:Ft#` | `n.n#` | Focuser temperature in C |
|
||||||
|
| `:Fu#` | `n.nnnnn#` | Microns per step |
|
||||||
|
| `:FB#` / `:Fb#` | `n#` | Backlash |
|
||||||
|
| `:FBn#` / `:Fbn#` | `0/1` | Set backlash |
|
||||||
|
| `:FC#` | `n.nnnnn#` | TCF coefficient in microns per C |
|
||||||
|
| `:FCsn.n#` | `0/1` | Set TCF coefficient |
|
||||||
|
| `:Fc#` | `0` or `1` | TCF enabled status |
|
||||||
|
| `:Fc0#` / `:Fc1#` | `0/1` | Disable/enable TCF |
|
||||||
|
| `:FD#` / `:Fd#` | `n#` | TCF deadband |
|
||||||
|
| `:FDn#` / `:Fdn#` | `0/1` | Set TCF deadband |
|
||||||
|
| `:FP#` | `n#` | DC motor power percent |
|
||||||
|
| `:FPn#` | `0/1` | Set DC motor power percent |
|
||||||
|
| `:FQ#` | none | Stop focuser |
|
||||||
|
| `:F1#` .. `:F9#` | none | Set move/goto rate preset |
|
||||||
|
| `:FW#` | `n#` | Working goto rate in um/s |
|
||||||
|
| `:F+#` | none | Move inward |
|
||||||
|
| `:F-#` | none | Move outward |
|
||||||
|
| `:FG#` / `:Fg#` | `sn#` | Current position |
|
||||||
|
| `:FRsn#` / `:Frsn#` | none | Relative goto |
|
||||||
|
| `:FSn#` / `:Fsn#` | `0/1` | Absolute goto |
|
||||||
|
| `:FZ#` | none | Zero current position |
|
||||||
|
| `:FH#` | none | Set current position as home |
|
||||||
|
| `:Fh#` | none | Move to home |
|
||||||
|
| `:GXU4#` .. `:GXU9#` | flags | Driver status for focuser axes that expose `Axis.command.cpp` |
|
||||||
|
|
||||||
|
Rate preset meaning:
|
||||||
|
|
||||||
|
| Preset | Meaning |
|
||||||
|
| --- | --- |
|
||||||
|
| `1` | 1 um/s move rate |
|
||||||
|
| `2` | 10 um/s move rate |
|
||||||
|
| `3` | 100 um/s move rate |
|
||||||
|
| `4` | 0.5x goto rate, move mode |
|
||||||
|
| `5` | 0.5x goto rate |
|
||||||
|
| `6` | 0.66x goto rate |
|
||||||
|
| `7` | 1x goto rate |
|
||||||
|
| `8` | 1.5x goto rate |
|
||||||
|
| `9` | 2x goto rate |
|
||||||
|
|
||||||
|
## Rotator
|
||||||
|
|
||||||
|
Available in rotator-enabled or remote-rotator builds.
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:rA#` | `0/1` | Rotator active |
|
||||||
|
| `:hP#` | `0/1` | Park rotator in standalone/remote rotator builds |
|
||||||
|
| `:hR#` | `0/1` | Unpark rotator in standalone/remote rotator builds |
|
||||||
|
| `:rT#` | `M1#`, `SD3#`, etc. | Status string plus rate digit |
|
||||||
|
| `:rI#` | `n#` | Minimum angle in degrees |
|
||||||
|
| `:rM#` | `n#` | Maximum angle in degrees |
|
||||||
|
| `:rD#` | `n.n#` | Degrees per step |
|
||||||
|
| `:rb#` | `n#` | Backlash in steps |
|
||||||
|
| `:rbn#` | `0/1` | Set backlash |
|
||||||
|
| `:rQ#` | none | Stop motion |
|
||||||
|
| `:r1#` .. `:r9#` | none | Set move/goto rate preset |
|
||||||
|
| `:rW#` | `n.n#` | Working slew rate in deg/s |
|
||||||
|
| `:rc#` | none | Continuous-move no-op, accepted for compatibility |
|
||||||
|
| `:r>#` | none | Move clockwise |
|
||||||
|
| `:r<#` | none | Move counter-clockwise |
|
||||||
|
| `:rG#` | `sDDD*MM#` | Current angle |
|
||||||
|
| `:rrsDDD*MM#` | none | Relative goto |
|
||||||
|
| `:rSsDDD*MM#` | `0/1` | Absolute goto |
|
||||||
|
| `:rZ#` | none | Zero position |
|
||||||
|
| `:rF#` | none | Set current position to half travel |
|
||||||
|
| `:rC#` | none | Move to half-travel / home target |
|
||||||
|
| `:r+#` | none | Enable derotation |
|
||||||
|
| `:r-#` | none | Disable derotation |
|
||||||
|
| `:rP#` | none | Move to parallactic angle |
|
||||||
|
| `:rR#` | none | Toggle derotator reverse direction |
|
||||||
|
| `:GX98#` | `D#`, `R#`, or `N#` | Rotator capability: derotate, rotate-only, or none |
|
||||||
|
| `:GXU3#` | flags | Driver status for rotator axis in standalone/remote builds |
|
||||||
|
|
||||||
|
Rotator rate presets:
|
||||||
|
|
||||||
|
| Preset | Meaning |
|
||||||
|
| --- | --- |
|
||||||
|
| `1` | 0.01 deg/s move rate |
|
||||||
|
| `2` | 0.1 deg/s move rate |
|
||||||
|
| `3` | 1.0 deg/s move rate |
|
||||||
|
| `4` | 0.5x goto rate used as move rate |
|
||||||
|
| `5` | 0.5x goto rate |
|
||||||
|
| `6` | 0.66x goto rate |
|
||||||
|
| `7` | 1x goto rate |
|
||||||
|
| `8` | 1.5x goto rate |
|
||||||
|
| `9` | 2x goto rate |
|
||||||
|
|
||||||
|
## Auxiliary Features
|
||||||
|
|
||||||
|
Available when auxiliary features are enabled.
|
||||||
|
|
||||||
|
Feature slots are numbered `1..8`.
|
||||||
|
|
||||||
|
### Discovery
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:GXY0#` | `xxxxxxxx#` | Eight-character bitmap of active feature slots, `1` = present |
|
||||||
|
| `:GXYn#` | `name,purpose#` | Slot name plus purpose code |
|
||||||
|
|
||||||
|
### Slot State
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:GXXn#` | purpose-specific payload | Get current state for slot `n` |
|
||||||
|
| `:SXXn,Vv#` | `0/1` | Generic value set |
|
||||||
|
| `:SXXn,Zf#` | `0/1` | Dew-heater zero temperature |
|
||||||
|
| `:SXXn,Sf#` | `0/1` | Dew-heater span temperature |
|
||||||
|
| `:SXXn,Ef#` | `0/1` | Intervalometer exposure seconds |
|
||||||
|
| `:SXXn,Df#` | `0/1` | Intervalometer delay seconds |
|
||||||
|
| `:SXXn,Cf#` | `0/1` | Intervalometer count |
|
||||||
|
|
||||||
|
### `:GXXn#` Reply Shapes
|
||||||
|
|
||||||
|
The payload depends on the slot purpose:
|
||||||
|
|
||||||
|
| Purpose | Reply shape |
|
||||||
|
| --- | --- |
|
||||||
|
| Switch / momentary switch / cover switch | `value` plus optional power telemetry |
|
||||||
|
| Analog output | `value` plus optional power telemetry |
|
||||||
|
| Dew heater | `enabled,zero,span,deltaT` plus optional power telemetry |
|
||||||
|
| Intervalometer | `currentCount,exposure,delay,count` |
|
||||||
|
|
||||||
|
When power monitoring is compiled in, the local ASCII implementation appends:
|
||||||
|
|
||||||
|
`;<volts>,<amps>,<flags>`
|
||||||
|
|
||||||
|
Where flags are a five-character string using `P`, `C`, `U`, `V`, `T` or `!`.
|
||||||
|
|
||||||
|
## Axis / Motor / Driver Service Commands
|
||||||
|
|
||||||
|
Axis service commands are implemented by `Axis.command.cpp`. For the main telescope/mount build these are reachable for axis 1 and axis 2, if present. The rotator exposes axis3, if present. The focuser(s) expose any of axis 4 to axis 9, if present.
|
||||||
|
|
||||||
|
| Command | Reply | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `:GXAa,p#` | `value,min,max,type,name#` | Get axis parameter `p` for axis `a` (`1..9`) |
|
||||||
|
| `:GXAa,M#` | `name#` | Motor/driver name for axis `a` |
|
||||||
|
| `:GXAa,0#` | `n#` | Parameter count for axis `a` |
|
||||||
|
| `:GXSa#` | `delta,velocity#` | Servo-only delta and velocity for axis `a` |
|
||||||
|
| `:GXUa#` | `flags#` | Stepper driver status for axis `a` |
|
||||||
|
| `:SXAC,0#` | `0/1` | Use runtime NV axis settings |
|
||||||
|
| `:SXAC,1#` | `0/1` | Use compile-time `Config.h` axis settings |
|
||||||
|
| `:SXAa,R#` | `0/1` | Revert axis `a` settings to defaults on next boot |
|
||||||
|
| `:SXAa,p,value#` | `0/1` | Set axis parameter `p` for axis `a` |
|
||||||
|
|
||||||
|
### `:GXAa,p#` Reply Format
|
||||||
|
|
||||||
|
The reply is:
|
||||||
|
|
||||||
|
`value,min,max,type,name#`
|
||||||
|
|
||||||
|
Where:
|
||||||
|
|
||||||
|
- `value` is the current NV value
|
||||||
|
- `min` and `max` are the documented range
|
||||||
|
- `type` is the axis parameter type code returned by firmware
|
||||||
|
- `name` is the parameter name from the axis parameter table
|
||||||
|
- some `name` values are locale tokens such as `$1` or `$12` rather than literal English labels
|
||||||
|
|
||||||
|
Axis parameter type codes:
|
||||||
|
|
||||||
|
| Code | Symbol | Meaning |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `0` | `AXP_INVALID` | Invalid / placeholder entry |
|
||||||
|
| `1` | `AXP_BOOLEAN` | Boolean value stored in NV and applied on restart/reinit |
|
||||||
|
| `2` | `AXP_BOOLEAN_IMMEDIATE` | Boolean value applied immediately when set |
|
||||||
|
| `3` | `AXP_INTEGER` | Integer value stored in NV and applied on restart/reinit |
|
||||||
|
| `4` | `AXP_INTEGER_IMMEDIATE` | Integer value applied immediately when set |
|
||||||
|
| `5` | `AXP_FLOAT` | Floating-point value stored in NV and reported as a plain numeric field |
|
||||||
|
| `6` | `AXP_FLOAT_IMMEDIATE` | Floating-point value applied immediately when set |
|
||||||
|
| `7` | `AXP_FLOAT_RAD` | Angular float stored internally in radians |
|
||||||
|
| `8` | `AXP_FLOAT_RAD_INV` | Inverse angular float stored internally with radian/degree conversion |
|
||||||
|
| `9` | `AXP_POW2` | Power-of-two constrained integer-like value |
|
||||||
|
| `10` | `AXP_DECAY` | Driver decay-mode selector |
|
||||||
|
|
||||||
|
Protocol note:
|
||||||
|
|
||||||
|
- `:GXAa,p#` normalizes `AXP_FLOAT_RAD` and `AXP_FLOAT_RAD_INV` to reply type code `5` and converts the value/range to degree-based units for transport.
|
||||||
|
- Axis parameter values are float-backed in firmware; values are always float even when the logical type is boolean or integer so the UI can show the appropriate controls.
|
||||||
|
- Boolean parameters: some use logical `0`/`1`, while others use the firmware constants `OFF = -1` and `ON = -2`; so any UI can show 'True'/'False' or 'On'/'Off'.
|
||||||
|
- For `AXP_DECAY`, the UI shows the matching decay-mode text for the numeric value `1=MIXED`, `2=FAST`, `3=SLOW`, `4=SPREADCYCLE`, `5=STEALTHCHOP`.
|
||||||
|
|
||||||
|
Locale-backed axis parameter name tokens currently used by firmware:
|
||||||
|
|
||||||
|
| Token | Meaning |
|
||||||
|
| --- | --- |
|
||||||
|
| `$1` | Steps/degree |
|
||||||
|
| `$2` | Min limit, degs |
|
||||||
|
| `$3` | Max limit, degs |
|
||||||
|
| `$4` | Steps/um |
|
||||||
|
| `$5` | Min limit, um |
|
||||||
|
| `$6` | Max limit, um |
|
||||||
|
| `$7` | Reverse |
|
||||||
|
| `$8` | Microsteps |
|
||||||
|
| `$9` | Microsteps Goto |
|
||||||
|
| `$10` | Decay mode |
|
||||||
|
| `$11` | Decay mode Goto |
|
||||||
|
| `$12` | mA Hold |
|
||||||
|
| `$13` | mA Run |
|
||||||
|
| `$14` | mA Goto |
|
||||||
|
| `$15` | 256x Interpolate |
|
||||||
|
| `$16` | P tracking |
|
||||||
|
| `$17` | I tracking |
|
||||||
|
| `$18` | D tracking |
|
||||||
|
| `$19` | P slewing |
|
||||||
|
| `$20` | I slewing |
|
||||||
|
| `$21` | D slewing |
|
||||||
|
| `$22` | Rads/count |
|
||||||
|
| `$23` | Steps/count ratio |
|
||||||
|
| `$24` | Max accel, %/s/s |
|
||||||
|
| `$25` | Min power, % |
|
||||||
|
| `$26` | Max power, % |
|
||||||
|
|
||||||
|
## CAN Remote-Node Variants
|
||||||
|
|
||||||
|
For architecture, configuration, and current scope, see
|
||||||
|
[CAN_NOTES.md](CAN_NOTES.md).
|
||||||
|
|
||||||
|
The following files implement the same logical command families over packed CAN messages rather than the ASCII LX200-style transport:
|
||||||
|
|
||||||
|
- `src/telescope/focuser/local/Focuser.can.command.cpp`
|
||||||
|
- `src/telescope/rotator/local/Rotator.can.command.cpp`
|
||||||
|
- `src/telescope/auxiliary/local/Features.can.command.cpp`
|
||||||
|
|
||||||
|
These are not separate end-user command names. They are binary transport implementations of the same focuser, rotator, and auxiliary-feature command sets above.
|
||||||
|
|
||||||
|
Notable transport differences:
|
||||||
|
|
||||||
|
- CAN replies are binary-packed, not ASCII text.
|
||||||
|
- `:GXY0#` for CAN features returns a single bitmask byte rather than an eight-character ASCII bitmap.
|
||||||
|
- CAN focuser/rotator driver-status replies are packed bitfields rather than comma-separated text flags.
|
||||||
|
|
||||||
|
## Source Coverage
|
||||||
|
|
||||||
|
This document was built from the current handlers in:
|
||||||
|
|
||||||
|
- `src/telescope/Telescope.command.cpp`
|
||||||
|
- `src/telescope/mount/Mount.command.cpp`
|
||||||
|
- `src/telescope/mount/goto/Goto.command.cpp`
|
||||||
|
- `src/telescope/mount/guide/Guide.command.cpp`
|
||||||
|
- `src/telescope/mount/home/Home.command.cpp`
|
||||||
|
- `src/telescope/mount/library/Library.command.cpp`
|
||||||
|
- `src/telescope/mount/limits/Limits.command.cpp`
|
||||||
|
- `src/telescope/mount/park/Park.command.cpp`
|
||||||
|
- `src/telescope/mount/pec/Pec.command.cpp`
|
||||||
|
- `src/telescope/mount/site/Site.command.cpp`
|
||||||
|
- `src/telescope/mount/status/Status.command.cpp`
|
||||||
|
- `src/lib/axis/Axis.command.cpp`
|
||||||
|
- `src/telescope/focuser/local/Focuser.command.cpp`
|
||||||
|
- `src/telescope/rotator/local/Rotator.command.cpp`
|
||||||
|
- `src/telescope/auxiliary/local/Features.command.cpp`
|
||||||
|
- plus the corresponding CAN transport handlers
|
||||||
|
- plus `src/libApp/commands/ProcessCmds.cpp`
|
||||||
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 48 KiB |
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
Executable
+514
@@ -0,0 +1,514 @@
|
|||||||
|
# Goto Notes
|
||||||
|
|
||||||
|
## Purpose
|
||||||
|
|
||||||
|
These notes describe how goto, sync, orientation choice, and target-limit
|
||||||
|
planning currently work in OnStepX.
|
||||||
|
|
||||||
|
This is a workflow note. It is meant to help explain how the system decides on
|
||||||
|
a sensible motion plan, not to document every goto command.
|
||||||
|
|
||||||
|
## For related topics also see
|
||||||
|
|
||||||
|
- [STARTUP_AUTHORITY_NOTES.md](STARTUP_AUTHORITY_NOTES.md)
|
||||||
|
- [HOMING_NOTES.md](HOMING_NOTES.md)
|
||||||
|
- [COMMAND_REFERENCE.md](COMMAND_REFERENCE.md)
|
||||||
|
|
||||||
|
## Quick Summary
|
||||||
|
|
||||||
|
## The cleanest mental model is
|
||||||
|
|
||||||
|
1. a user target is turned into mount coordinates
|
||||||
|
2. the system checks whether that target is reachable in one or more valid
|
||||||
|
orientations
|
||||||
|
3. the system chooses a sensible branch and motion plan
|
||||||
|
4. goto executes that plan, possibly with waypoints or alternate orientation
|
||||||
|
handling
|
||||||
|
5. runtime limits continue watching during the motion
|
||||||
|
|
||||||
|
## So goto in OnStepX is not just
|
||||||
|
|
||||||
|
- convert coordinates
|
||||||
|
- slew there
|
||||||
|
|
||||||
|
It is more like a small decision engine.
|
||||||
|
|
||||||
|
## The Main Distinction: Goto vs Sync
|
||||||
|
|
||||||
|
`goTo.setTarget(...)` is the common decision point for both goto and sync.
|
||||||
|
|
||||||
|
## That means both operations share
|
||||||
|
|
||||||
|
- target conversion
|
||||||
|
- orientation selection
|
||||||
|
- reachability checks
|
||||||
|
- axis1 wrap/unwind correction
|
||||||
|
|
||||||
|
## Then they diverge
|
||||||
|
|
||||||
|
- goto moves the mount to the chosen target
|
||||||
|
- sync keeps the current physical mount orientation and reassigns coordinates to
|
||||||
|
match the chosen target
|
||||||
|
|
||||||
|
So sync is not a separate simpler target model. It reuses most of the same
|
||||||
|
target-planning logic, then applies it as a coordinate reassignment instead of
|
||||||
|
motion.
|
||||||
|
|
||||||
|
## What A Goto Request Really Does
|
||||||
|
|
||||||
|
## At a high level a goto request goes through these steps
|
||||||
|
|
||||||
|
1. make sure goto is allowed right now
|
||||||
|
2. convert the request into mount coordinates
|
||||||
|
3. decide which orientation options are valid
|
||||||
|
4. choose the actual target branch and pier side
|
||||||
|
5. add a waypoint/home step if needed
|
||||||
|
6. start the slew
|
||||||
|
7. continue monitoring limits and refine near the destination
|
||||||
|
|
||||||
|
The important thing is that the target may have more than one valid
|
||||||
|
representation.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
- east-side vs west-side orientation on a GEM
|
||||||
|
- axis1 target plus or minus 360 degrees when wrapping/unlimited motion exists
|
||||||
|
- alternate orientation choices on mounts such as `ALTALT`
|
||||||
|
|
||||||
|
## Workflow 1: Entry Conditions
|
||||||
|
|
||||||
|
Before goto or sync can proceed, the mount checks a number of ordinary
|
||||||
|
conditions:
|
||||||
|
|
||||||
|
- startup authority must already be trusted
|
||||||
|
- both axes must be enabled
|
||||||
|
- the mount must not be parked
|
||||||
|
- no other goto/guide/motion operation can already be active
|
||||||
|
- no goto-blocking limit/sense error can already exist
|
||||||
|
- no motor fault can already exist
|
||||||
|
|
||||||
|
For goto specifically, date/time readiness matters through the ordinary mount
|
||||||
|
and limit logic as well.
|
||||||
|
|
||||||
|
In other words, goto is not treated as a way to escape unknown state.
|
||||||
|
|
||||||
|
## Workflow 2: Converting The Target
|
||||||
|
|
||||||
|
## The incoming target may start life in
|
||||||
|
|
||||||
|
- native coordinates
|
||||||
|
- mount coordinates
|
||||||
|
- equatorial, horizontal, or `ALTALT` forms depending on mount type
|
||||||
|
|
||||||
|
## The goto code converts as needed so the mount can reason about
|
||||||
|
|
||||||
|
- target hour angle / declination where applicable
|
||||||
|
- target altitude for horizon checks
|
||||||
|
- target instrument coordinates for each orientation choice
|
||||||
|
|
||||||
|
This is why the same sky target can still lead to more than one valid motion
|
||||||
|
plan.
|
||||||
|
|
||||||
|
## Workflow 3: Choosing Orientation
|
||||||
|
|
||||||
|
This is one of the core pieces.
|
||||||
|
|
||||||
|
## OnStepX supports a family of orientation-selection policies
|
||||||
|
|
||||||
|
- `PSS_EAST_ONLY`
|
||||||
|
- `PSS_WEST_ONLY`
|
||||||
|
- `PSS_EAST`
|
||||||
|
- `PSS_WEST`
|
||||||
|
- `PSS_BEST`
|
||||||
|
- `PSS_AUTO`
|
||||||
|
- `PSS_SAME_ONLY`
|
||||||
|
|
||||||
|
## What these really mean
|
||||||
|
|
||||||
|
- some insist on one side only
|
||||||
|
- some prefer one side but can fall back to the other if needed
|
||||||
|
- some try to stay on the current side
|
||||||
|
- some ask the planner to choose what seems best
|
||||||
|
|
||||||
|
## `PSS_AUTO`
|
||||||
|
|
||||||
|
This was added mainly to support automatic meridian-flip style behavior when the
|
||||||
|
mount is in the meridian-overlap region and can legitimately continue tracking
|
||||||
|
on the other side without interruption.
|
||||||
|
|
||||||
|
In that sense, `AUTO` is not just "pick something convenient." It is meant to
|
||||||
|
prefer the side/orientation that keeps the mount on a sensible continuing
|
||||||
|
tracking path when overlap allows it.
|
||||||
|
|
||||||
|
This is still not the same thing on every mount type.
|
||||||
|
|
||||||
|
## For ordinary equatorial cases
|
||||||
|
|
||||||
|
- it usually picks a preferred side from current hour angle
|
||||||
|
- in overlap cases, that helps place the target on the side where tracking can
|
||||||
|
continue unimpeded after the orientation change
|
||||||
|
|
||||||
|
## For `ALTAZM` and `ALTALT`
|
||||||
|
|
||||||
|
- it falls back to `PSS_BEST`
|
||||||
|
|
||||||
|
So `AUTO` is really an automatic orientation policy, not one fixed algorithm.
|
||||||
|
|
||||||
|
In practical terms, it is most at home on GEMs, especially imaging setups where
|
||||||
|
automatic meridian-flip style behavior is desirable. Compared with a fixed
|
||||||
|
preference such as `PSS_EAST`, `PSS_AUTO` is better at using meridian-overlap
|
||||||
|
freedom to end up on the side where tracking can keep going cleanly after the
|
||||||
|
change.
|
||||||
|
|
||||||
|
On fork mounts, the usual practical approach is often different. Users commonly
|
||||||
|
widen the meridian limits to allow much more freedom, then keep a fixed side
|
||||||
|
preference such as `PSS_EAST` or `PSS_WEST` for normal operation. If they want
|
||||||
|
the mount to use the other orientation, they typically change that preferred
|
||||||
|
side. Forks often do not need, and often should not do, automatic flip-style
|
||||||
|
behavior in the first place. So wide limits help create freedom, but the
|
||||||
|
selected side policy still drives whether the planner stays put or flips.
|
||||||
|
|
||||||
|
## `PSS_BEST`
|
||||||
|
|
||||||
|
`BEST` is distance-aware.
|
||||||
|
|
||||||
|
It compares the reachable east- and west-orientation targets in instrument
|
||||||
|
space and may choose the alternate orientation if that target is closer.
|
||||||
|
|
||||||
|
## This is why OnStepX can sometimes choose what looks like a shortcut
|
||||||
|
|
||||||
|
- through the pole
|
||||||
|
- through an alternate valid orientation
|
||||||
|
- through a less-obvious wrapped branch
|
||||||
|
|
||||||
|
That behavior can look surprising, but it is intentional.
|
||||||
|
|
||||||
|
In practical terms, `PSS_BEST` is often attractive for visual use because it
|
||||||
|
can reduce unnecessary flips and choose the shorter or less awkward path. That
|
||||||
|
can make the mount feel nicer at the eyepiece even when it is not the same
|
||||||
|
choice an imaging workflow would prefer.
|
||||||
|
|
||||||
|
## Workflow 4: Reachability And Target Unwinding
|
||||||
|
|
||||||
|
After a tentative target exists, `Limits::validateTarget(...)` checks whether
|
||||||
|
the target is reachable.
|
||||||
|
|
||||||
|
## This includes
|
||||||
|
|
||||||
|
- altitude min/max
|
||||||
|
- east-side axis1 window
|
||||||
|
- west-side axis1 window
|
||||||
|
- meridian overlap limits for GEMs
|
||||||
|
- axis2 limits
|
||||||
|
|
||||||
|
These sketches help visualize why the same configured GEM limits can look
|
||||||
|
different depending on which side of the pier the mount is currently using:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
When east of the pier, the active limit window is interpreted against the
|
||||||
|
east-side geometry shown above.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
When west of the pier, the same ideas map onto the mirrored west-side geometry.
|
||||||
|
|
||||||
|
## But there is another subtle step
|
||||||
|
|
||||||
|
- axis1 may be normalized by plus or minus 360 degrees to find a sensible
|
||||||
|
branch
|
||||||
|
|
||||||
|
That means the planner does not necessarily use the raw first axis1 value that
|
||||||
|
falls out of the transform.
|
||||||
|
|
||||||
|
## Instead it may
|
||||||
|
|
||||||
|
- keep the current branch if it is already best
|
||||||
|
- unwind to a nearby branch if that is closer
|
||||||
|
- shift by `+360` or `-360` to make the target fit the valid motion window
|
||||||
|
|
||||||
|
This is why a coordinate that "looks outside range" on first glance may still
|
||||||
|
be reachable after normalization.
|
||||||
|
|
||||||
|
It is also why wrapped or effectively unlimited axes feel smarter than a simple
|
||||||
|
"move to exactly this number" implementation.
|
||||||
|
|
||||||
|
## What `AXIS1_WRAP` Changes
|
||||||
|
|
||||||
|
## If `AXIS1_WRAP == ON`
|
||||||
|
|
||||||
|
- axis1 is configured with a 360-degree wrap
|
||||||
|
- its configured range becomes `-360 .. +360`
|
||||||
|
- sync-threshold style coordinate-jump checks are bypassed
|
||||||
|
|
||||||
|
That does not mean the mount ignores all planning.
|
||||||
|
|
||||||
|
## It means
|
||||||
|
|
||||||
|
- axis1 has a broader wrapped coordinate space to work in
|
||||||
|
- goto can choose a sensible branch in that larger space
|
||||||
|
|
||||||
|
This is most relevant on azimuth-like axes and other mounts where bounded
|
||||||
|
`-180 .. +180` thinking is too restrictive.
|
||||||
|
|
||||||
|
## Workflow 5: Waypoints And Home During Orientation Change
|
||||||
|
|
||||||
|
If an equatorial goto changes pier side and `MFLIP_SKIP_HOME == OFF`, OnStepX
|
||||||
|
does not always go straight to the final destination.
|
||||||
|
|
||||||
|
## Instead it may
|
||||||
|
|
||||||
|
- insert a waypoint at home
|
||||||
|
- or insert an avoid waypoint first, then go to home, then continue
|
||||||
|
|
||||||
|
## That is why the goto stage machine includes
|
||||||
|
|
||||||
|
- `GG_WAYPOINT_AVOID`
|
||||||
|
- `GG_WAYPOINT_HOME`
|
||||||
|
- near-destination refine stages
|
||||||
|
- final destination
|
||||||
|
|
||||||
|
So a meridian flip or alternate-orientation goto is often a multi-stage motion,
|
||||||
|
not one direct straight-line idea.
|
||||||
|
|
||||||
|
## Horizon Avoidance
|
||||||
|
|
||||||
|
There are two different horizon-avoidance ideas in the goto system.
|
||||||
|
|
||||||
|
The first is path-shaping during side/orientation changes.
|
||||||
|
|
||||||
|
## When a pier-side change is involved, goto may first route through
|
||||||
|
|
||||||
|
- about 4 hours HA
|
||||||
|
- or about 3 hours HA
|
||||||
|
|
||||||
|
before going home and then heading to the final target.
|
||||||
|
|
||||||
|
## The reason is practical horizon avoidance
|
||||||
|
|
||||||
|
- some otherwise valid geometry would pass too low near the horizon during a
|
||||||
|
flip or alternate-orientation transition
|
||||||
|
- low-latitude cases can make that especially awkward
|
||||||
|
|
||||||
|
So the planner uses a small detour heuristic rather than pretending all valid
|
||||||
|
math paths are equally safe in practice.
|
||||||
|
|
||||||
|
The second is runtime rate shaping based on distance from the altitude limit.
|
||||||
|
|
||||||
|
## There is a runtime slowdown heuristic
|
||||||
|
|
||||||
|
- in equatorial mode with `MOUNT_HORIZON_AVOIDANCE == ON`
|
||||||
|
- the axis frequencies are scaled down near the minimum altitude limit
|
||||||
|
- the amount of slowdown varies with distance from that limit
|
||||||
|
- the code decides whether to slow RA-like or Dec-like motion depending on
|
||||||
|
whether declination is increasing or decreasing
|
||||||
|
|
||||||
|
This is best thought of as practical protective behavior, not pure geometry.
|
||||||
|
|
||||||
|
## Workflow 6: Near Destination Refinement
|
||||||
|
|
||||||
|
Goto does not always drive directly to the literal final target at full intent.
|
||||||
|
|
||||||
|
## Depending on encoder/tolerance context, it may
|
||||||
|
|
||||||
|
- slew to a near-destination first
|
||||||
|
- wait to settle
|
||||||
|
- refine in one or more additional stages
|
||||||
|
- then finish at the final destination
|
||||||
|
|
||||||
|
That final approach is not only about positional refinement. In practice, the
|
||||||
|
near-destination exit can also be used to normalize backlash on arrival by
|
||||||
|
finishing with a consistent last-direction approach instead of simply accepting
|
||||||
|
whatever direction the earlier slew happened to end with.
|
||||||
|
|
||||||
|
## This is why the code carries
|
||||||
|
|
||||||
|
- `GG_NEAR_DESTINATION_START`
|
||||||
|
- `GG_NEAR_DESTINATION_WAIT`
|
||||||
|
- `GG_NEAR_DESTINATION`
|
||||||
|
- `GG_DESTINATION`
|
||||||
|
|
||||||
|
## It is also why encoder presence changes behavior
|
||||||
|
|
||||||
|
- with suitable encoder/tolerance support, more refined near-target behavior is
|
||||||
|
allowed
|
||||||
|
- during homing/parking or on simpler cases, that refinement can be reduced or
|
||||||
|
skipped
|
||||||
|
|
||||||
|
## Runtime Limits Are Not The Same As Target Validation
|
||||||
|
|
||||||
|
This is another important distinction.
|
||||||
|
|
||||||
|
## Target validation answers
|
||||||
|
|
||||||
|
- "is this planned target/orientation allowed?"
|
||||||
|
|
||||||
|
## Runtime limit monitoring answers
|
||||||
|
|
||||||
|
- "while the mount is moving or tracking, have we crossed something dangerous?"
|
||||||
|
|
||||||
|
## Runtime checks include
|
||||||
|
|
||||||
|
- horizon / overhead limits
|
||||||
|
- meridian east/west limits
|
||||||
|
- axis min/max limits
|
||||||
|
- sensed min/max limits
|
||||||
|
|
||||||
|
## Those runtime checks can
|
||||||
|
|
||||||
|
- stop one axis
|
||||||
|
- stop the whole mount
|
||||||
|
- abort goto
|
||||||
|
- trigger automatic meridian flip in some GEM tracking cases
|
||||||
|
|
||||||
|
## So there are really two layers
|
||||||
|
|
||||||
|
- planned target acceptance
|
||||||
|
- live motion policing
|
||||||
|
|
||||||
|
## Automatic Meridian Flip
|
||||||
|
|
||||||
|
If automatic meridian flip is enabled and the mount is tracking, some runtime
|
||||||
|
limit crossings do not simply stop motion.
|
||||||
|
|
||||||
|
Instead the limit code may request a new goto to the current sky position on
|
||||||
|
the opposite side:
|
||||||
|
|
||||||
|
- east-side request if currently west and beyond the west meridian limit
|
||||||
|
- west-side request if currently east and beyond the axis1 max side
|
||||||
|
|
||||||
|
## So automatic meridian flip is implemented as
|
||||||
|
|
||||||
|
- a limit-triggered alternate-orientation goto
|
||||||
|
|
||||||
|
not as a separate completely different motion engine.
|
||||||
|
|
||||||
|
## How Non-GEM Mounts Differ
|
||||||
|
|
||||||
|
For fork and alt/az style mounts, some axis-limit reasoning is based on shaft
|
||||||
|
angles rather than GEM-style pier-side interpretation.
|
||||||
|
|
||||||
|
The limit code therefore sometimes normalizes the current axis1 position back
|
||||||
|
into a "normal east-like" coordinate form before checking limits.
|
||||||
|
|
||||||
|
That is one reason the same target can feel simpler on some mounts and much
|
||||||
|
more orientation-sensitive on others.
|
||||||
|
|
||||||
|
For fork mode specifically, this is why wide meridian limits are often used as
|
||||||
|
a practical way to increase motion freedom without constantly tripping a
|
||||||
|
side-change style decision. But wide limits are not the whole story. Orientation
|
||||||
|
selection still matters. In typical fork use, that usually means keeping
|
||||||
|
`PSS_EAST` or `PSS_WEST` fixed until the user intentionally changes it to get
|
||||||
|
the opposite orientation, even though the generous limit window would allow
|
||||||
|
more than one valid branch.
|
||||||
|
|
||||||
|
## `ALTALT` And Other Less Common Modes
|
||||||
|
|
||||||
|
`ALTALT` is one of the modes that can seem obscure from the outside.
|
||||||
|
|
||||||
|
One useful way to picture it is by re-aiming the primary axis of a familiar
|
||||||
|
equatorial mount.
|
||||||
|
|
||||||
|
- on a GEM, that axis points parallel to Earth's rotation axis
|
||||||
|
- on an `ALTAZM`, that same idea would point the primary axis at the zenith
|
||||||
|
- on an `ALTALT`, the primary axis points north on the horizon at `ALT = 0`
|
||||||
|
|
||||||
|
That is why `ALTALT` is not just "equatorial with funny numbers." It is a
|
||||||
|
different mount geometry with its own natural strengths and weak spots.
|
||||||
|
|
||||||
|
## In practice this means
|
||||||
|
|
||||||
|
- target conversion differs
|
||||||
|
- `PSS_AUTO` falls back to `PSS_BEST`
|
||||||
|
- tracking and motion behavior are not identical to GEM or ordinary alt/az
|
||||||
|
- the mount can move naturally through the zenith and celestial-pole regions
|
||||||
|
- it is therefore one of the most natural mount geometries for satellite
|
||||||
|
tracking
|
||||||
|
- the field will still rotate even if the mount is otherwise tracking the
|
||||||
|
general sky motion correctly
|
||||||
|
- the geometry is weakest for targets near due north or due south on the
|
||||||
|
horizon
|
||||||
|
|
||||||
|
So it is better to think of `ALTALT` as another consumer of the same decision
|
||||||
|
framework, but with a different singularity pattern and a different relationship
|
||||||
|
between its primary axis and Earth's rotation.
|
||||||
|
|
||||||
|
## Special Geometry: Sector Gear And Tangent Arm
|
||||||
|
|
||||||
|
Sector gear axis1 and tangent-arm axis2 are special enough that ordinary full
|
||||||
|
range goto thinking does not always apply.
|
||||||
|
|
||||||
|
## For these mounts
|
||||||
|
|
||||||
|
- target reachability is influenced by limited physical travel
|
||||||
|
- some checks are relaxed or specialized
|
||||||
|
- origin handling can matter more than wide-range coordinate elegance
|
||||||
|
|
||||||
|
## So goto on these mounts is partly about
|
||||||
|
|
||||||
|
- choosing a useful target in a constrained motion envelope
|
||||||
|
|
||||||
|
not simply navigating a wide continuous axis range.
|
||||||
|
|
||||||
|
## No-Goto Builds
|
||||||
|
|
||||||
|
## If `GOTO_FEATURE == OFF`
|
||||||
|
|
||||||
|
- real automatic goto motion does not exist
|
||||||
|
- sync still reuses the target-selection logic
|
||||||
|
- the old fake-completion paths for home/park are intentionally gone
|
||||||
|
|
||||||
|
## So this mode still benefits from
|
||||||
|
|
||||||
|
- coordinate planning
|
||||||
|
- orientation choice for sync-like operations
|
||||||
|
|
||||||
|
But it is not pretending to offer the full automatic motion planner.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
## Example 1: Ordinary GEM goto
|
||||||
|
|
||||||
|
- user asks for a sky target
|
||||||
|
- planner computes east and west solutions
|
||||||
|
- both may be reachable
|
||||||
|
- preferred side or best-distance logic chooses one
|
||||||
|
- goto may go directly, or through home if the side changes
|
||||||
|
|
||||||
|
## Example 2: `PIER_SIDE_BEST`
|
||||||
|
|
||||||
|
- both orientations are valid
|
||||||
|
- alternate orientation is closer in instrument space
|
||||||
|
- planner chooses the alternate branch
|
||||||
|
- this can look like a shortcut through the pole or a less-obvious orientation
|
||||||
|
|
||||||
|
## Example 3: Wrapped axis1
|
||||||
|
|
||||||
|
- raw target axis1 value is not ideal
|
||||||
|
- planner shifts by `+360` or `-360`
|
||||||
|
- resulting branch is closer or simply the only valid one inside limits
|
||||||
|
|
||||||
|
## Example 4: Horizon-avoidance flip
|
||||||
|
|
||||||
|
- side change is needed
|
||||||
|
- direct route would be too low near the horizon
|
||||||
|
- goto first detours to an avoid waypoint
|
||||||
|
- then goes home
|
||||||
|
- then continues to the final destination
|
||||||
|
|
||||||
|
## Good Mental Summary
|
||||||
|
|
||||||
|
## The cleanest way to think about goto in OnStepX is
|
||||||
|
|
||||||
|
- transforms produce candidate target representations
|
||||||
|
- limits decide which ones are reachable
|
||||||
|
- pier-side/orientation policy chooses among them
|
||||||
|
- wrap normalization may unwind coordinates into better branches
|
||||||
|
- waypoints and heuristics make the chosen path practical
|
||||||
|
- runtime limits keep watching after motion begins
|
||||||
|
|
||||||
|
## So the goto system is best understood as
|
||||||
|
|
||||||
|
- a target-planning and motion-decision engine
|
||||||
|
|
||||||
|
not just a coordinate conversion followed by a slew.
|
||||||
Executable
+461
@@ -0,0 +1,461 @@
|
|||||||
|
# Homing Notes
|
||||||
|
|
||||||
|
## Purpose
|
||||||
|
|
||||||
|
These notes describe how mount homing currently works in OnStepX.
|
||||||
|
|
||||||
|
This is a workflow note, not a deep explanation of low-level input filtering.
|
||||||
|
For the shared sensing subsystem itself, see:
|
||||||
|
|
||||||
|
- [SENSING_NOTES.md](SENSING_NOTES.md)
|
||||||
|
|
||||||
|
## For how homing relates to startup trust/authority, also see
|
||||||
|
|
||||||
|
- [STARTUP_AUTHORITY_NOTES.md](STARTUP_AUTHORITY_NOTES.md)
|
||||||
|
|
||||||
|
## Quick Summary
|
||||||
|
|
||||||
|
## There are three related but different ideas
|
||||||
|
|
||||||
|
1. Return to home
|
||||||
|
Move the mount to the configured home coordinates
|
||||||
|
2. Sensed home
|
||||||
|
Use home switches/sensors to find home
|
||||||
|
3. Reset at home
|
||||||
|
Rebuild the coordinate basis from the known home position
|
||||||
|
|
||||||
|
Those are often used together, but they are not the same operation.
|
||||||
|
|
||||||
|
## The Main Entry Points
|
||||||
|
|
||||||
|
## The core mount home commands are
|
||||||
|
|
||||||
|
- `:hC#`
|
||||||
|
move to home
|
||||||
|
- `:hF#`
|
||||||
|
reset the mount at home / cold-start position
|
||||||
|
- `:hA0#` / `:hA1#`
|
||||||
|
disable/enable automatic home at boot
|
||||||
|
- `:hC1,R#` / `:hC2,R#`
|
||||||
|
toggle home-sense reversal for axis1/axis2
|
||||||
|
- `:hC1,n#` / `:hC2,n#`
|
||||||
|
set home sense offset in arc-seconds
|
||||||
|
|
||||||
|
## Status command
|
||||||
|
|
||||||
|
- `:h?#`
|
||||||
|
returns `hasSense,axis1Offset,axis2Offset`
|
||||||
|
|
||||||
|
## What "Home" Means
|
||||||
|
|
||||||
|
## The configured home position is derived from
|
||||||
|
|
||||||
|
- mount type
|
||||||
|
- configured home defaults
|
||||||
|
- site latitude where relevant
|
||||||
|
- optional sense offsets
|
||||||
|
- special geometry such as meridian-flip handling
|
||||||
|
|
||||||
|
That home position is refreshed by `Home::init()` and then returned through
|
||||||
|
`home.getPosition(...)`.
|
||||||
|
|
||||||
|
So "home" is not just a fixed pair of axis numbers. It is computed in context.
|
||||||
|
|
||||||
|
## It is also important to separate
|
||||||
|
|
||||||
|
- mount orientation
|
||||||
|
- coordinates assigned to that orientation
|
||||||
|
|
||||||
|
Without home switches, "home" is primarily a coordinate definition that the
|
||||||
|
system returns to or resets against. In that case, home is not independently
|
||||||
|
observed from hardware. It is whatever mount orientation the current coordinate
|
||||||
|
basis says corresponds to the home coordinates.
|
||||||
|
|
||||||
|
That means the practical truth about what mount orientation counts as "home"
|
||||||
|
can shift when the coordinate basis shifts.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
- an authoritative reset at home reassigns the coordinate basis
|
||||||
|
- sync/model/origin changes can improve accuracy by shifting how the system
|
||||||
|
maps mount orientation into coordinates
|
||||||
|
- after those changes, the home coordinates may correspond somewhat differently
|
||||||
|
to mount orientation than before
|
||||||
|
|
||||||
|
With home switches, the home procedure has a stronger mount-orientation anchor
|
||||||
|
because the system is observing a real sense event during homing.
|
||||||
|
|
||||||
|
## So it is best to think of home as
|
||||||
|
|
||||||
|
- a reference in coordinate space
|
||||||
|
|
||||||
|
that may or may not be strongly anchored to mount orientation depending on
|
||||||
|
whether home sensing is available.
|
||||||
|
|
||||||
|
## The Three Main Workflows
|
||||||
|
|
||||||
|
## Workflow 1: Return To Home Without Sensors
|
||||||
|
|
||||||
|
This is the simple "move to home coordinates" path.
|
||||||
|
|
||||||
|
## It happens when
|
||||||
|
|
||||||
|
- `home.request()` is called
|
||||||
|
- no home switches/sense inputs are configured
|
||||||
|
|
||||||
|
## Behavior
|
||||||
|
|
||||||
|
- goto must be available
|
||||||
|
- startup authority must already be trusted
|
||||||
|
- date and time must be ready
|
||||||
|
- the mount slews to the computed home coordinates
|
||||||
|
|
||||||
|
This is just motion to a known coordinate target. It does not establish truth
|
||||||
|
from hardware sensing.
|
||||||
|
|
||||||
|
## Workflow 2: Sensed Home
|
||||||
|
|
||||||
|
This is the switch/sensor-based path.
|
||||||
|
|
||||||
|
## It happens when
|
||||||
|
|
||||||
|
- `home.request()` is called
|
||||||
|
- home sense is available
|
||||||
|
|
||||||
|
## Behavior
|
||||||
|
|
||||||
|
- goto must be available
|
||||||
|
- if startup authority is not trusted, sensed home is still allowed because it
|
||||||
|
can establish trust
|
||||||
|
- the guide subsystem starts a special home-guiding mode
|
||||||
|
- each axis uses `autoSlewHome()` to find the home switch state
|
||||||
|
- the axis may first move off the switch or toward it depending on the current
|
||||||
|
sensed state
|
||||||
|
- the axis refines through fast/slow/fine homing stages
|
||||||
|
|
||||||
|
## If sensing succeeds
|
||||||
|
|
||||||
|
- `home.guideDone(true)` runs
|
||||||
|
- an authoritative reset is performed
|
||||||
|
- startup authority becomes trusted
|
||||||
|
|
||||||
|
## If sensing fails
|
||||||
|
|
||||||
|
- `home.guideDone(false)` runs
|
||||||
|
- a non-authoritative reset/recovery path is attempted
|
||||||
|
- the home operation is marked failed
|
||||||
|
|
||||||
|
## What The Axis Class Actually Does During Sensed Home
|
||||||
|
|
||||||
|
The mount-level home request is only part of the story. The detailed switch
|
||||||
|
search sequence lives down in the axis class.
|
||||||
|
|
||||||
|
Each relevant axis uses `Axis::autoSlewHome()`.
|
||||||
|
|
||||||
|
## The important sequence is
|
||||||
|
|
||||||
|
1. Check the current home-sense state
|
||||||
|
2. Choose an initial direction
|
||||||
|
3. Slew until the sense state changes in the expected way
|
||||||
|
4. Decelerate to a stop
|
||||||
|
5. Refine through additional slower passes
|
||||||
|
|
||||||
|
## More concretely
|
||||||
|
|
||||||
|
- if home sense is already ON, the axis first moves forward off the switch
|
||||||
|
- if home sense is OFF, the axis first moves reverse toward the switch
|
||||||
|
- when the sense state changes appropriately, the axis stops
|
||||||
|
- the homing stage advances from `HOME_FAST` to `HOME_SLOW`
|
||||||
|
- then usually to `HOME_FINE`
|
||||||
|
|
||||||
|
## During the refinement sequence
|
||||||
|
|
||||||
|
- the slew rate is reduced
|
||||||
|
- the axis repeats the search with tighter motion
|
||||||
|
- if the switch state is still not in the expected condition after the slow
|
||||||
|
pass, an approach correction path is used before the final fine pass
|
||||||
|
|
||||||
|
This is why sensed home is more than "drive until switch closes once." It is a
|
||||||
|
small staged search procedure implemented at the axis level.
|
||||||
|
|
||||||
|
## Timeout also matters
|
||||||
|
|
||||||
|
- if no explicit timeout is supplied, the axis derives one from the configured
|
||||||
|
home distance limit and slew rate
|
||||||
|
- if the search times out, the homing slew aborts
|
||||||
|
|
||||||
|
## Motion safety still applies
|
||||||
|
|
||||||
|
- motion errors abort homing
|
||||||
|
- motor faults abort homing
|
||||||
|
- common min/max sense conflicts can also abort the slew
|
||||||
|
|
||||||
|
## So the full sensed-home sequence is
|
||||||
|
|
||||||
|
- mount/home layer decides that sensed home should happen
|
||||||
|
- guide layer starts coordinated home-guiding
|
||||||
|
- axis layer performs the actual staged switch search
|
||||||
|
- home layer interprets success/failure and performs reset/recovery
|
||||||
|
|
||||||
|
## Workflow 3: Reset At Home
|
||||||
|
|
||||||
|
This is the coordinate-basis rebuild step.
|
||||||
|
|
||||||
|
## It happens through
|
||||||
|
|
||||||
|
- `home.reset(...)`
|
||||||
|
- `:hF#`
|
||||||
|
- startup reset logic
|
||||||
|
- successful sensed-home completion
|
||||||
|
|
||||||
|
## Behavior
|
||||||
|
|
||||||
|
- tracking is stopped
|
||||||
|
- tracking-rate offsets are cleared
|
||||||
|
- goto first-use state is reset
|
||||||
|
- motor positions are reset to zero where appropriate
|
||||||
|
- home instrument coordinates are written back
|
||||||
|
- nominal index positions are captured
|
||||||
|
- backlash and slow slew defaults are restored
|
||||||
|
|
||||||
|
## If the reset is authoritative
|
||||||
|
|
||||||
|
- startup trust is granted
|
||||||
|
|
||||||
|
## If it is not authoritative
|
||||||
|
|
||||||
|
- it does not grant trust by itself
|
||||||
|
|
||||||
|
## Authoritative vs Non-Authoritative Reset
|
||||||
|
|
||||||
|
This is one of the key distinctions.
|
||||||
|
|
||||||
|
## Authoritative reset means
|
||||||
|
|
||||||
|
- the software has a good reason to believe the home position being applied is
|
||||||
|
truly correct
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
- successful sensed home
|
||||||
|
- startup reset using valid paired absolute authority
|
||||||
|
- explicit authoritative origin/home workflows
|
||||||
|
|
||||||
|
## Non-authoritative reset means
|
||||||
|
|
||||||
|
- coordinates are being reassigned to home, but the software is not treating
|
||||||
|
that as proof of truth
|
||||||
|
|
||||||
|
## This distinction matters because
|
||||||
|
|
||||||
|
- authoritative reset can establish startup trust
|
||||||
|
- non-authoritative reset cannot
|
||||||
|
|
||||||
|
## How Trust Interacts With Homing
|
||||||
|
|
||||||
|
Homing is one of the main bridges between untrusted and trusted state.
|
||||||
|
|
||||||
|
## Important rules
|
||||||
|
|
||||||
|
- plain return-to-home without sensors requires trust first
|
||||||
|
- sensed home can be used to regain trust
|
||||||
|
- authoritative reset grants trust
|
||||||
|
- non-authoritative reset does not
|
||||||
|
|
||||||
|
## There is also one permissive carveout
|
||||||
|
|
||||||
|
- in `SA_AUTO` on simple mounts with no absolute encoders and no coordinate
|
||||||
|
memory, home/reset is allowed to bypass the sync-limit style coordinate jump
|
||||||
|
restriction
|
||||||
|
|
||||||
|
That keeps older/simple mounts practical without weakening the stricter cases
|
||||||
|
globally.
|
||||||
|
|
||||||
|
## Auto Home At Boot
|
||||||
|
|
||||||
|
## If `automaticAtBoot` is enabled
|
||||||
|
|
||||||
|
- autostart requests home after boot
|
||||||
|
|
||||||
|
This shares the same sensed-home or return-home machinery as a normal home
|
||||||
|
request. It is not a separate home implementation.
|
||||||
|
|
||||||
|
## That means
|
||||||
|
|
||||||
|
- success behaves like normal homing success
|
||||||
|
- failure behaves like normal homing failure
|
||||||
|
- auto-home does not silently pretend success if the sensed-home flow fails
|
||||||
|
|
||||||
|
## No-Goto Behavior
|
||||||
|
|
||||||
|
## If `GOTO_FEATURE == OFF`
|
||||||
|
|
||||||
|
- home request is rejected
|
||||||
|
- reset/home-with-motion request is rejected
|
||||||
|
- sensed home through guide-home is also rejected
|
||||||
|
|
||||||
|
This is intentional.
|
||||||
|
|
||||||
|
## In no-goto builds
|
||||||
|
|
||||||
|
- there is no fast automatic slew/home capability
|
||||||
|
- home/return is not supposed to pretend to exist as a supported motion mode
|
||||||
|
|
||||||
|
## How Home Sense Offsets Work
|
||||||
|
|
||||||
|
Each mount axis can have a stored sense offset.
|
||||||
|
|
||||||
|
## These offsets mean
|
||||||
|
|
||||||
|
- the physical home sense event is not necessarily the final logical home
|
||||||
|
coordinate
|
||||||
|
|
||||||
|
## Typical use
|
||||||
|
|
||||||
|
- a switch is placed somewhere repeatable but not exactly at the desired final
|
||||||
|
home location
|
||||||
|
- the offset defines the difference between switch-detected home and desired
|
||||||
|
coordinate home
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
- `:hC1,n#`
|
||||||
|
- `:hC2,n#`
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
- `:hC1,120#`
|
||||||
|
set axis1 home offset to +120 arcsec
|
||||||
|
- `:hC2,-300#`
|
||||||
|
set axis2 home offset to -300 arcsec
|
||||||
|
|
||||||
|
## Two Offset Modes
|
||||||
|
|
||||||
|
The config option `MOUNT_HOME_AT_OFFSETS` changes how offsets are used.
|
||||||
|
|
||||||
|
## When `MOUNT_HOME_AT_OFFSETS == OFF`
|
||||||
|
|
||||||
|
- sensed home resets at the switch-derived home first
|
||||||
|
- then, if offsets are in use, the mount may perform a finishing move toward
|
||||||
|
the true home coordinates after the authoritative reset
|
||||||
|
|
||||||
|
## When `MOUNT_HOME_AT_OFFSETS == ON`
|
||||||
|
|
||||||
|
- offsets are folded directly into the computed home position
|
||||||
|
|
||||||
|
## So the difference is basically
|
||||||
|
|
||||||
|
- separate finishing move
|
||||||
|
vs
|
||||||
|
- home already means the offset-adjusted position
|
||||||
|
|
||||||
|
## Home Sense Reversal
|
||||||
|
|
||||||
|
Each axis can also reverse the meaning of its home sense input.
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
- `:hC1,R#`
|
||||||
|
- `:hC2,R#`
|
||||||
|
|
||||||
|
This is layered on top of the usual home-sense logic and is applied through
|
||||||
|
`setReversal()`.
|
||||||
|
|
||||||
|
Axis1 also has a latitude-related reversal for equatorial mounts in the
|
||||||
|
southern hemisphere, so axis1 home sense behavior is slightly more subtle than
|
||||||
|
just a plain stored boolean.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
## Example 1: Simple mount, no home switches
|
||||||
|
|
||||||
|
- user powers on
|
||||||
|
- mount already has trusted startup authority or permissive `SA_AUTO`
|
||||||
|
- `:hC#` moves to home coordinates
|
||||||
|
- `:hF#` can reset at the home position
|
||||||
|
|
||||||
|
## Example 2: Mount with home switches
|
||||||
|
|
||||||
|
- user or autostart requests home
|
||||||
|
- guide-home uses switch sensing to find home
|
||||||
|
- successful sensed home performs authoritative reset
|
||||||
|
- trust is granted
|
||||||
|
|
||||||
|
## Example 3: Switch is repeatable but not exactly at desired home
|
||||||
|
|
||||||
|
- home sense is configured
|
||||||
|
- nonzero offsets are stored
|
||||||
|
- sensed home finds the switch
|
||||||
|
- reset establishes truth
|
||||||
|
- final coordinate home may be offset from the literal switch crossing
|
||||||
|
|
||||||
|
## Special Geometry Cases
|
||||||
|
|
||||||
|
Sector gear axis1 and tangent-arm axis2 are special.
|
||||||
|
|
||||||
|
In those cases, homing and reset do not always follow the plain "reset both
|
||||||
|
axes to zero and write home coordinates" pattern.
|
||||||
|
|
||||||
|
For these geometries, home is not only about returning to a meaningful
|
||||||
|
coordinate reference. It is also about resetting the mechanism so later gotos
|
||||||
|
and tracking have useful travel remaining inside the limited range.
|
||||||
|
|
||||||
|
## So on a sector gear or tangent-arm mount, homing is often better understood as
|
||||||
|
|
||||||
|
- mechanical re-baselining of the constrained axis
|
||||||
|
- restoring useful travel for later motion
|
||||||
|
- re-establishing the coordinate-to-mechanism relationship for that limited
|
||||||
|
range
|
||||||
|
|
||||||
|
Because of that, some of the ordinary coordinate-based prechecks are also less
|
||||||
|
meaningful here. On these mounts the code relaxes or skips parts of the normal
|
||||||
|
"how far are we from home in coordinates?" logic before sensed homing, because
|
||||||
|
operation is fundamentally constrained and often more manual.
|
||||||
|
|
||||||
|
## Instead
|
||||||
|
|
||||||
|
- origin/position handling is adjusted to fit the special axis geometry
|
||||||
|
- successful sensed home may set origin more directly for the special axis
|
||||||
|
|
||||||
|
So if behavior looks a little different on sector gear or tangent-arm mounts,
|
||||||
|
that is expected.
|
||||||
|
|
||||||
|
## Failure Modes
|
||||||
|
|
||||||
|
## Homing can fail because of
|
||||||
|
|
||||||
|
- goto disabled
|
||||||
|
- motion already active
|
||||||
|
- missing date/time for plain return-home
|
||||||
|
- distance-to-home outside the configured sensed-home search limit
|
||||||
|
- switch search timeout
|
||||||
|
- motion error or motor fault during homing
|
||||||
|
- reset failure after the home-search phase
|
||||||
|
|
||||||
|
The code tries to fail conservatively rather than pretending home succeeded.
|
||||||
|
|
||||||
|
## Relationship To Sensing
|
||||||
|
|
||||||
|
Homing depends heavily on the shared sensing subsystem, but that low-level
|
||||||
|
behavior is documented separately.
|
||||||
|
|
||||||
|
## If you need to understand
|
||||||
|
|
||||||
|
- how `HIGH | HYST(20)` is interpreted
|
||||||
|
- how analog threshold/hysteresis sensing works
|
||||||
|
- how runtime reversal works
|
||||||
|
|
||||||
|
## see
|
||||||
|
|
||||||
|
- [SENSING_NOTES.md](SENSING_NOTES.md)
|
||||||
|
|
||||||
|
## Good Mental Summary
|
||||||
|
|
||||||
|
## The cleanest summary is
|
||||||
|
|
||||||
|
- return-to-home is motion to a known coordinate target
|
||||||
|
- sensed home is a hardware-based search procedure
|
||||||
|
- reset-at-home rebuilds the coordinate basis
|
||||||
|
- authoritative homing/reset can establish startup trust
|
||||||
|
|
||||||
|
Those are related operations, but they are not interchangeable.
|
||||||
Executable
+420
@@ -0,0 +1,420 @@
|
|||||||
|
# PEC Notes
|
||||||
|
|
||||||
|
## Purpose
|
||||||
|
|
||||||
|
These notes describe how PEC currently works in OnStepX.
|
||||||
|
|
||||||
|
## PEC is one of the harder features to reason about because it combines
|
||||||
|
|
||||||
|
- persistent state
|
||||||
|
- a sampled correction table
|
||||||
|
- worm indexing
|
||||||
|
- tracking state
|
||||||
|
- guide interaction
|
||||||
|
- park/unpark interaction
|
||||||
|
|
||||||
|
## The implementation is concentrated mainly in
|
||||||
|
|
||||||
|
- `src/telescope/mount/pec/Pec.h`
|
||||||
|
- `src/telescope/mount/pec/Pec.cpp`
|
||||||
|
- `src/telescope/mount/pec/Pec.command.cpp`
|
||||||
|
|
||||||
|
## Quick Summary
|
||||||
|
|
||||||
|
## The clean mental model is
|
||||||
|
|
||||||
|
1. PEC stores one correction value per sidereal second of worm rotation
|
||||||
|
2. a worm index event establishes where the buffer starts
|
||||||
|
3. playback adds/subtracts a small tracking-rate correction each second
|
||||||
|
4. recording learns those per-second corrections from accumulated guide action
|
||||||
|
|
||||||
|
## So PEC in OnStepX is basically
|
||||||
|
|
||||||
|
- a one-second-slot correction table wrapped around the worm rotation
|
||||||
|
|
||||||
|
## What PEC Applies To
|
||||||
|
|
||||||
|
## Current mount PEC support is for
|
||||||
|
|
||||||
|
- axis1 only
|
||||||
|
|
||||||
|
Although the implementation and terminology are written around a worm cycle,
|
||||||
|
the correction model does not technically require a worm. It can also model
|
||||||
|
other repeatable geared error sources as long as:
|
||||||
|
|
||||||
|
- the cycle can be indexed
|
||||||
|
- the cycle length is stable
|
||||||
|
- the cycle period fits within the supported PEC limits/buffer size
|
||||||
|
|
||||||
|
## If `PEC_BUFFER_SIZE_LIMIT == 0` or `PEC_STEPS_PER_WORM_ROTATION == 0`
|
||||||
|
|
||||||
|
- PEC is effectively disabled
|
||||||
|
|
||||||
|
## The Main Stored Data
|
||||||
|
|
||||||
|
## PEC stores
|
||||||
|
|
||||||
|
- whether valid PEC data have been recorded
|
||||||
|
- current PEC state
|
||||||
|
- worm rotation length in steps
|
||||||
|
- the PEC correction buffer itself
|
||||||
|
|
||||||
|
The small settings live in normal NV settings storage.
|
||||||
|
|
||||||
|
## The correction table itself lives in a dedicated NV partition named
|
||||||
|
|
||||||
|
- `PEC`
|
||||||
|
|
||||||
|
## Important persistence detail
|
||||||
|
|
||||||
|
- changing or recording PEC data in RAM does not automatically write the PEC
|
||||||
|
table to NV
|
||||||
|
- writing the PEC table to NV only happens on explicit user command
|
||||||
|
|
||||||
|
## This is separate from PEC control state
|
||||||
|
|
||||||
|
- arming playback/record or disabling PEC updates the small PEC settings in NV
|
||||||
|
- but the actual correction table is only written by explicit save command
|
||||||
|
|
||||||
|
## That means
|
||||||
|
|
||||||
|
- after a recording session, the in-memory PEC table may differ from the
|
||||||
|
persisted PEC table
|
||||||
|
- if the user does not explicitly save the new data, a reboot comes back with
|
||||||
|
whatever PEC table was previously stored
|
||||||
|
|
||||||
|
## This is useful because
|
||||||
|
|
||||||
|
- a bad recording session can simply be abandoned by not saving it
|
||||||
|
|
||||||
|
## The PEC Buffer
|
||||||
|
|
||||||
|
The PEC buffer is not stored as one entry per motor step.
|
||||||
|
|
||||||
|
## Instead
|
||||||
|
|
||||||
|
- one entry represents one sidereal second of worm rotation
|
||||||
|
|
||||||
|
## That means
|
||||||
|
|
||||||
|
- buffer size in bytes is approximately worm rotation time in seconds
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
- if one worm rotation takes 720 sidereal seconds
|
||||||
|
- the PEC buffer has 720 entries
|
||||||
|
|
||||||
|
Each entry is an `int8_t` correction value.
|
||||||
|
|
||||||
|
So each second of worm rotation gets a small signed rate correction.
|
||||||
|
|
||||||
|
## How Worm Rotation Length Is Used
|
||||||
|
|
||||||
|
## The configured worm rotation length is stored as
|
||||||
|
|
||||||
|
- `PEC_STEPS_PER_WORM_ROTATION`
|
||||||
|
|
||||||
|
## PEC uses that to derive
|
||||||
|
|
||||||
|
- seconds per worm rotation
|
||||||
|
- buffer size
|
||||||
|
- current worm-rotation position from current axis1 motor steps
|
||||||
|
|
||||||
|
## So PEC fundamentally depends on
|
||||||
|
|
||||||
|
- knowing how many axis1 motor steps correspond to one worm rotation
|
||||||
|
|
||||||
|
## Two Ways PEC Gets Its Index
|
||||||
|
|
||||||
|
## PEC can work with
|
||||||
|
|
||||||
|
1. real sense input (`PEC_SENSE != OFF`)
|
||||||
|
2. virtual wraparound indexing (`PEC_SENSE == OFF`)
|
||||||
|
|
||||||
|
## With real sense input
|
||||||
|
|
||||||
|
- a sense event on `PEC_SENSE_PIN` defines the worm index
|
||||||
|
- PEC waits for enough worm travel before accepting another index
|
||||||
|
- this avoids repeated false retriggers too close together
|
||||||
|
|
||||||
|
## Without real sense input
|
||||||
|
|
||||||
|
- PEC treats worm rotation wraparound as a virtual index
|
||||||
|
|
||||||
|
## So
|
||||||
|
|
||||||
|
- hardware sense gives a stronger physical anchor
|
||||||
|
- no-sense PEC is still possible, but indexing is inferred
|
||||||
|
|
||||||
|
## How The Index Event Works
|
||||||
|
|
||||||
|
## When PEC sense is enabled
|
||||||
|
|
||||||
|
- the sense input is read through the shared `Sense` subsystem
|
||||||
|
- a valid ON transition after enough worm travel is treated as an index event
|
||||||
|
- the current axis1 motor step position becomes `wormSenseSteps`
|
||||||
|
- PEC marks that it has a valid worm reference
|
||||||
|
- playback buffer position can be realigned to that reference
|
||||||
|
|
||||||
|
## This is why the sensing note matters here too
|
||||||
|
|
||||||
|
- low-level sense filtering decides whether the PEC index input is ON
|
||||||
|
- PEC then adds its own motion/spacing logic before trusting that event as a
|
||||||
|
real index
|
||||||
|
|
||||||
|
## When PEC Is Active
|
||||||
|
|
||||||
|
PEC is only allowed to do real work when the mount is in an appropriate state.
|
||||||
|
|
||||||
|
## Main requirements
|
||||||
|
|
||||||
|
- the mount must be tracking
|
||||||
|
- guide state must not exceed pulse-guide style use
|
||||||
|
- the mount must not be parking or parked
|
||||||
|
|
||||||
|
## If those conditions are not true
|
||||||
|
|
||||||
|
- PEC disables recording
|
||||||
|
- PEC pauses playback
|
||||||
|
|
||||||
|
## Important distinction
|
||||||
|
|
||||||
|
- playback pause is not the same as losing PEC data
|
||||||
|
|
||||||
|
## If PEC was playing and the mount becomes ineligible
|
||||||
|
|
||||||
|
- state drops back to `PEC_READY_PLAY`
|
||||||
|
- playback can resume after re-indexing/alignment timing is right again
|
||||||
|
|
||||||
|
## The PEC State Machine
|
||||||
|
|
||||||
|
## Main states
|
||||||
|
|
||||||
|
- `PEC_NONE`
|
||||||
|
- `PEC_READY_PLAY`
|
||||||
|
- `PEC_PLAY`
|
||||||
|
- `PEC_READY_RECORD`
|
||||||
|
- `PEC_RECORD`
|
||||||
|
|
||||||
|
## Meaning
|
||||||
|
|
||||||
|
- `PEC_NONE`
|
||||||
|
PEC inactive
|
||||||
|
- `PEC_READY_PLAY`
|
||||||
|
user requested playback; PEC is waiting for the right timing/index position
|
||||||
|
- `PEC_PLAY`
|
||||||
|
PEC actively applying corrections
|
||||||
|
- `PEC_READY_RECORD`
|
||||||
|
user armed recording; PEC is waiting for the right timing/index position
|
||||||
|
- `PEC_RECORD`
|
||||||
|
PEC actively recording guide-derived corrections
|
||||||
|
|
||||||
|
## Why "Ready" States Exist
|
||||||
|
|
||||||
|
PEC does not jump into play or record at an arbitrary instant.
|
||||||
|
|
||||||
|
## Instead, it waits until
|
||||||
|
|
||||||
|
- the worm position is aligned to a one-second slot boundary
|
||||||
|
|
||||||
|
This makes the table alignment cleaner and keeps the one-second buffer indexing
|
||||||
|
consistent.
|
||||||
|
|
||||||
|
## So "ready" means
|
||||||
|
|
||||||
|
- the user has requested the action
|
||||||
|
- PEC is waiting for the correct phase/alignment to begin
|
||||||
|
|
||||||
|
## Playback
|
||||||
|
|
||||||
|
## During playback
|
||||||
|
|
||||||
|
- PEC advances the buffer index once per sidereal second
|
||||||
|
- it looks up the correction for the current worm segment
|
||||||
|
- it applies that as a fractional tracking-rate offset
|
||||||
|
|
||||||
|
## One subtle detail
|
||||||
|
|
||||||
|
- playback uses the correction from one second earlier than the current segment
|
||||||
|
|
||||||
|
The code comments describe this as a rough latency estimate between image
|
||||||
|
acquisition and response.
|
||||||
|
|
||||||
|
So PEC playback is intentionally shifted slightly ahead in effect.
|
||||||
|
|
||||||
|
## Recording
|
||||||
|
|
||||||
|
## During recording
|
||||||
|
|
||||||
|
- guide contribution on axis1 is accumulated
|
||||||
|
- once per sidereal second, that accumulated correction is quantized into a
|
||||||
|
small signed step value
|
||||||
|
- that value becomes the PEC table entry for the current buffer slot
|
||||||
|
|
||||||
|
## If this is not the first recording
|
||||||
|
|
||||||
|
- new data are blended with existing data using a weighted average
|
||||||
|
|
||||||
|
## So PEC recording is not just "write raw guide values directly." It is
|
||||||
|
|
||||||
|
- accumulate
|
||||||
|
- quantize per second
|
||||||
|
- optionally blend with existing data
|
||||||
|
|
||||||
|
## What "First Recording" Changes
|
||||||
|
|
||||||
|
## If this is the first time PEC is being recorded
|
||||||
|
|
||||||
|
- the new table is taken directly from current recording data
|
||||||
|
|
||||||
|
## If PEC data already exist
|
||||||
|
|
||||||
|
- new data are blended with the old table
|
||||||
|
|
||||||
|
That lets users refine an existing PEC table rather than always replacing it
|
||||||
|
from scratch.
|
||||||
|
|
||||||
|
## Cleanup After Recording
|
||||||
|
|
||||||
|
## When recording finishes
|
||||||
|
|
||||||
|
- PEC automatically switches to play
|
||||||
|
- the table is run through a cleanup pass
|
||||||
|
|
||||||
|
## Cleanup includes
|
||||||
|
|
||||||
|
- a low-pass smoothing pass
|
||||||
|
- a linear-regression style correction so the total sequence sums close to zero
|
||||||
|
|
||||||
|
That last part matters because PEC corrections should not create a long-term
|
||||||
|
net tracking bias over a whole worm cycle.
|
||||||
|
|
||||||
|
## If the cleanup result looks unreasonable
|
||||||
|
|
||||||
|
- PEC invalidates the recorded data
|
||||||
|
- PEC drops back to `PEC_NONE`
|
||||||
|
|
||||||
|
## Why The Sum Matters
|
||||||
|
|
||||||
|
A PEC table is supposed to redistribute tracking slightly over the worm cycle,
|
||||||
|
not permanently add or subtract motion over a full cycle.
|
||||||
|
|
||||||
|
## So after cleanup
|
||||||
|
|
||||||
|
- the total correction sequence should roughly cancel out
|
||||||
|
|
||||||
|
That is why PEC does a "reality check" on the residual sum.
|
||||||
|
|
||||||
|
## Park / Unpark Interaction
|
||||||
|
|
||||||
|
PEC interacts with park in an important way.
|
||||||
|
|
||||||
|
## When parking
|
||||||
|
|
||||||
|
- PEC is turned off
|
||||||
|
- the current worm sense position is saved into park settings
|
||||||
|
|
||||||
|
## When unparking/restoring
|
||||||
|
|
||||||
|
- that saved worm sense position is restored
|
||||||
|
|
||||||
|
## If a real `PEC_SENSE` input exists
|
||||||
|
|
||||||
|
- worm index truth is also recovered automatically once the worm rotates far
|
||||||
|
enough to detect the next valid PEC index event
|
||||||
|
|
||||||
|
So the restored saved position helps continuity immediately after unpark, while
|
||||||
|
the physical PEC sense can later re-anchor the index automatically on the next
|
||||||
|
cycle.
|
||||||
|
|
||||||
|
So park/unpark is part of how PEC continuity is maintained across a parked
|
||||||
|
interval.
|
||||||
|
|
||||||
|
This is another reason PEC is harder to reason about than a simple runtime
|
||||||
|
feature. It is not independent of park state.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
## Example 1: Playback with real worm index
|
||||||
|
|
||||||
|
- PEC data were previously recorded
|
||||||
|
- user enables PEC playback
|
||||||
|
- state becomes `PEC_READY_PLAY`
|
||||||
|
- mount tracks
|
||||||
|
- PEC waits for the right segment timing
|
||||||
|
- playback starts
|
||||||
|
- a later real PEC index event can realign buffer start
|
||||||
|
|
||||||
|
## Example 2: Recording new PEC data
|
||||||
|
|
||||||
|
- mount is tracking
|
||||||
|
- user arms PEC recording
|
||||||
|
- state becomes `PEC_READY_RECORD`
|
||||||
|
- at the right timing boundary PEC enters `PEC_RECORD`
|
||||||
|
- guide activity is accumulated into one-second corrections
|
||||||
|
- after one worm cycle, recording finishes
|
||||||
|
- cleanup runs
|
||||||
|
- PEC switches into playback
|
||||||
|
|
||||||
|
## Example 3: Mount stops tracking during playback
|
||||||
|
|
||||||
|
- PEC was in `PEC_PLAY`
|
||||||
|
- tracking stops or mount becomes ineligible
|
||||||
|
- PEC falls back to `PEC_READY_PLAY`
|
||||||
|
- rate goes to zero
|
||||||
|
- playback can later resume when conditions are valid again
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
## There are several PEC commands, but the most important control ones are
|
||||||
|
|
||||||
|
- `:$QZ+#`
|
||||||
|
arm/enable playback
|
||||||
|
- `:$QZ-#`
|
||||||
|
disable PEC
|
||||||
|
- `:$QZ/#`
|
||||||
|
arm recording
|
||||||
|
- `:$QZZ#`
|
||||||
|
clear the PEC buffer
|
||||||
|
- `:$QZ!#`
|
||||||
|
save PEC data to NV
|
||||||
|
- `:$QZ?#`
|
||||||
|
get PEC status
|
||||||
|
|
||||||
|
## There are also read/write commands for
|
||||||
|
|
||||||
|
- table contents
|
||||||
|
- worm rotation steps
|
||||||
|
- buffer size
|
||||||
|
- current index location
|
||||||
|
|
||||||
|
## For the exact command list, see
|
||||||
|
|
||||||
|
- [COMMAND_REFERENCE.md](COMMAND_REFERENCE.md)
|
||||||
|
|
||||||
|
## Things That Make PEC Hard To Reason About
|
||||||
|
|
||||||
|
## PEC combines several different concerns at once
|
||||||
|
|
||||||
|
- mount motion state
|
||||||
|
- tracking state
|
||||||
|
- guide accumulation
|
||||||
|
- worm index sensing
|
||||||
|
- one-second slot timing
|
||||||
|
- persistent storage
|
||||||
|
- park/unpark continuity
|
||||||
|
|
||||||
|
That is why local code reading can still leave the feature feeling opaque.
|
||||||
|
|
||||||
|
## Good Mental Summary
|
||||||
|
|
||||||
|
## The most useful summary is
|
||||||
|
|
||||||
|
- PEC is a per-second correction table over one worm rotation
|
||||||
|
- indexing tells PEC where the table starts
|
||||||
|
- playback applies one correction slot each sidereal second
|
||||||
|
- recording learns those slots from guide activity
|
||||||
|
- cleanup makes the finished table smooth and net-neutral over the full cycle
|
||||||
|
|
||||||
|
If you keep that model in mind, the rest of the state machine becomes much
|
||||||
|
easier to follow.
|
||||||
Executable
+401
@@ -0,0 +1,401 @@
|
|||||||
|
# Sensing Notes
|
||||||
|
|
||||||
|
## Purpose
|
||||||
|
|
||||||
|
## These notes describe the shared sensing subsystem used across OnStepX for
|
||||||
|
|
||||||
|
- home sense
|
||||||
|
- limit sense
|
||||||
|
- park sense
|
||||||
|
- PEC sense
|
||||||
|
- some local focuser/button-style inputs
|
||||||
|
|
||||||
|
The main reason this deserves its own note is that a "sense input" in OnStepX
|
||||||
|
is not just a simple digital switch. The same general machinery supports:
|
||||||
|
|
||||||
|
- ordinary digital active-high or active-low inputs
|
||||||
|
- digital inputs with software time filtering
|
||||||
|
- analog threshold sensing
|
||||||
|
- analog hysteresis behavior
|
||||||
|
- runtime inversion of the logical sense state
|
||||||
|
|
||||||
|
There is also a related but separate `Button` helper for more button-specific
|
||||||
|
input behavior, including analog range comparison. That is covered near the end
|
||||||
|
of this note.
|
||||||
|
|
||||||
|
## Quick Summary
|
||||||
|
|
||||||
|
## The simplest mental model is
|
||||||
|
|
||||||
|
1. raw GPIO or analog input comes in
|
||||||
|
2. `Sense` turns it into a normalized ON/OFF state
|
||||||
|
3. higher-level code decides what ON/OFF means operationally
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
- home code asks whether home sense is active/ON according to its configured
|
||||||
|
`HIGH`/`LOW` meaning
|
||||||
|
- limit code asks whether the min/max sense is ON
|
||||||
|
- PEC asks whether the worm index sense is ON
|
||||||
|
|
||||||
|
The same low-level sensing code is reused in all of those cases.
|
||||||
|
|
||||||
|
## Where The Shared Sense Code Lives
|
||||||
|
|
||||||
|
## The main subsystem is
|
||||||
|
|
||||||
|
- `src/lib/sense/Sense.h`
|
||||||
|
- `src/lib/sense/Sense.cpp`
|
||||||
|
|
||||||
|
## Main API
|
||||||
|
|
||||||
|
- `sense.add(...)`
|
||||||
|
- `sense.isOn(...)`
|
||||||
|
- `sense.changed(...)`
|
||||||
|
- `sense.stableMillis(...)`
|
||||||
|
- `sense.reverse(...)`
|
||||||
|
- `sense.poll()`
|
||||||
|
|
||||||
|
In most feature code, the higher-level subsystem does not read the GPIO pin
|
||||||
|
directly. It registers a sense input once and then works with the normalized
|
||||||
|
result through a sense handle.
|
||||||
|
|
||||||
|
## How Sense Configuration Works
|
||||||
|
|
||||||
|
## Each sense input is defined by
|
||||||
|
|
||||||
|
- a pin
|
||||||
|
- an init mode such as `INPUT`, `INPUT_PULLUP`, or `INPUT_PULLDOWN`
|
||||||
|
- a packed trigger value
|
||||||
|
|
||||||
|
The packed trigger value normally combines pieces with `|`.
|
||||||
|
|
||||||
|
That is the usual configuration pattern.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
- `HIGH`
|
||||||
|
- `LOW`
|
||||||
|
- `HIGH | HYST(20)`
|
||||||
|
- `LOW | HYST(50)`
|
||||||
|
- `HIGH | THLD(512)`
|
||||||
|
- `LOW | THLD(300) | HYST(25)`
|
||||||
|
|
||||||
|
Combining flags numerically with `|` is typically the intended style.
|
||||||
|
|
||||||
|
## What The Trigger Encodes
|
||||||
|
|
||||||
|
## The trigger value carries
|
||||||
|
|
||||||
|
- the active state bit: `HIGH` or `LOW`
|
||||||
|
- an optional analog threshold via `THLD(v)`
|
||||||
|
- an optional hysteresis via `HYST(v)`
|
||||||
|
|
||||||
|
## Important rule
|
||||||
|
|
||||||
|
- if the threshold part is zero, the input is treated as digital
|
||||||
|
- if the threshold part is nonzero, the input is treated as analog
|
||||||
|
|
||||||
|
## So
|
||||||
|
|
||||||
|
- `HIGH | HYST(20)` is still digital
|
||||||
|
- `LOW | THLD(400) | HYST(15)` is analog
|
||||||
|
|
||||||
|
## Digital Sense
|
||||||
|
|
||||||
|
Digital mode is used when there is no threshold component.
|
||||||
|
|
||||||
|
## Behavior
|
||||||
|
|
||||||
|
- raw input is read with `digitalReadEx(pin)`
|
||||||
|
- `HYST(n)` is the required stable time in milliseconds before a digital state
|
||||||
|
change is accepted
|
||||||
|
- the new digital sample must remain unchanged for that long before the
|
||||||
|
logical state changes
|
||||||
|
|
||||||
|
## So in digital mode, `HYST()` does not mean an analog band. It means
|
||||||
|
|
||||||
|
- how long the signal must stay stable before the change is accepted
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
- `HIGH`
|
||||||
|
active-high digital input, no extra filtering
|
||||||
|
- `LOW`
|
||||||
|
active-low digital input, no extra filtering
|
||||||
|
- `HIGH | HYST(10)`
|
||||||
|
active-high digital input, require about 10ms of stable state before the
|
||||||
|
logical result changes
|
||||||
|
- `LOW | HYST(50)`
|
||||||
|
active-low digital input with heavier software debounce/noise filtering
|
||||||
|
|
||||||
|
## This is useful for
|
||||||
|
|
||||||
|
- switch debounce
|
||||||
|
- modest EMI/RFI filtering
|
||||||
|
- noisy digital inputs that should not chatter
|
||||||
|
|
||||||
|
## Analog Sense
|
||||||
|
|
||||||
|
Analog mode is used when a threshold component is present.
|
||||||
|
|
||||||
|
## Behavior
|
||||||
|
|
||||||
|
- raw input is read with `analogRead(...)`
|
||||||
|
- on ESP32, `analogReadMilliVolts(...)` is converted back into the common
|
||||||
|
`ANALOG_READ_RANGE` scale for higher accuracy on this platform
|
||||||
|
- the threshold and hysteresis act like a software Schmitt trigger
|
||||||
|
|
||||||
|
## This means
|
||||||
|
|
||||||
|
- if the sample rises above `threshold + hysteresis`, the logical value becomes
|
||||||
|
`HIGH`
|
||||||
|
- if the sample falls below `threshold - hysteresis`, the logical value becomes
|
||||||
|
`LOW`
|
||||||
|
- inside the band between those two thresholds, the last logical state is
|
||||||
|
retained
|
||||||
|
|
||||||
|
## That band is effectively a deadband zone
|
||||||
|
|
||||||
|
- the signal can move around inside it without causing repeated state changes
|
||||||
|
- a state change only happens after the signal leaves the deadband on one side
|
||||||
|
or the other
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
- `HIGH | THLD(512)`
|
||||||
|
active-high analog threshold at mid-scale, no hysteresis band
|
||||||
|
- `LOW | THLD(300) | HYST(25)`
|
||||||
|
active-low analog threshold input with a hysteresis band around the threshold
|
||||||
|
- `HIGH | THLD(800) | HYST(50)`
|
||||||
|
active-high analog input that must move well above and below the threshold
|
||||||
|
before changing state
|
||||||
|
|
||||||
|
## This is useful when
|
||||||
|
|
||||||
|
- a clean digital threshold is not available from hardware
|
||||||
|
- analog noise would otherwise cause state chatter
|
||||||
|
|
||||||
|
## Why Hysteresis Means Two Different Things
|
||||||
|
|
||||||
|
This is one of the easiest things to forget.
|
||||||
|
|
||||||
|
## In digital mode
|
||||||
|
|
||||||
|
- `HYST(n)` means time in milliseconds
|
||||||
|
|
||||||
|
## In analog mode
|
||||||
|
|
||||||
|
- `HYST(n)` means an analog hysteresis band around the threshold, creating a
|
||||||
|
deadband zone where the current state is held
|
||||||
|
|
||||||
|
That dual meaning is intentional, but it is easy to misread in config.
|
||||||
|
|
||||||
|
## What "ON" Means
|
||||||
|
|
||||||
|
## The subsystem separates
|
||||||
|
|
||||||
|
- the filtered internal logical value (`HIGH` or `LOW`)
|
||||||
|
- whether that logical value counts as ON for the caller
|
||||||
|
|
||||||
|
`sense.isOn(...)` returns true when the filtered value matches the configured
|
||||||
|
active state.
|
||||||
|
|
||||||
|
## So
|
||||||
|
|
||||||
|
- active-high means HIGH is considered ON
|
||||||
|
- active-low means LOW is considered ON
|
||||||
|
|
||||||
|
## This lets higher-level code work with
|
||||||
|
|
||||||
|
- "is the home sense active?"
|
||||||
|
- "is the limit sense active?"
|
||||||
|
|
||||||
|
without caring whether the hardware is electrically active-high or active-low.
|
||||||
|
|
||||||
|
## Runtime Reversal
|
||||||
|
|
||||||
|
`sense.reverse(handle, state)` flips the interpretation at runtime.
|
||||||
|
|
||||||
|
This is different from the original config.
|
||||||
|
|
||||||
|
## Config answers
|
||||||
|
|
||||||
|
- what electrical state counts as active
|
||||||
|
|
||||||
|
## Runtime reversal answers
|
||||||
|
|
||||||
|
- should this sense be interpreted the opposite way right now
|
||||||
|
|
||||||
|
## In practice this is used by code such as
|
||||||
|
|
||||||
|
- `Axis::setHomeReverse()`
|
||||||
|
|
||||||
|
This is useful when the electrical truth stays the same but the motion logic
|
||||||
|
needs the opposite interpretation.
|
||||||
|
|
||||||
|
## Where `Sense` Is Used
|
||||||
|
|
||||||
|
## Shared `Sense` users currently include
|
||||||
|
|
||||||
|
- axis home sense
|
||||||
|
- axis min/max limit sense
|
||||||
|
- park sense
|
||||||
|
- park signal monitoring
|
||||||
|
- PEC worm index sense
|
||||||
|
- local focuser sense inputs
|
||||||
|
|
||||||
|
That is why it is better to think of `Sense` as a general-purpose input
|
||||||
|
normalization subsystem, not just "home switch code."
|
||||||
|
|
||||||
|
## Example: Home Sense
|
||||||
|
|
||||||
|
Axis home sense is registered in `Axis::init()`.
|
||||||
|
|
||||||
|
## Important behavior
|
||||||
|
|
||||||
|
- homing first checks whether home sense is already ON
|
||||||
|
- if it is ON, motion first goes forward off the switch
|
||||||
|
- if it is OFF, motion first goes reverse toward the switch
|
||||||
|
|
||||||
|
So home sense is not just an endpoint detector. It also affects the search
|
||||||
|
direction and homing flow.
|
||||||
|
|
||||||
|
## Typical home examples
|
||||||
|
|
||||||
|
- `AXIS1_SENSE_HOME HIGH`
|
||||||
|
simple active-high home switch
|
||||||
|
- `AXIS1_SENSE_HOME LOW | HYST(20)`
|
||||||
|
active-low home switch with digital debounce
|
||||||
|
- `AXIS1_SENSE_HOME HIGH | THLD(450) | HYST(20)`
|
||||||
|
analog thresholded home sense with hysteresis
|
||||||
|
|
||||||
|
## Example: Limit Sense
|
||||||
|
|
||||||
|
Limit sense uses the same subsystem for min/max axis limits.
|
||||||
|
|
||||||
|
## Runtime behavior
|
||||||
|
|
||||||
|
- `Axis::poll()` updates the sensed limit flags
|
||||||
|
- `Limits::poll()` reacts and stops the relevant motion direction
|
||||||
|
|
||||||
|
## One important special case
|
||||||
|
|
||||||
|
- min and max can share the same physical pin
|
||||||
|
|
||||||
|
## By default
|
||||||
|
|
||||||
|
- the axis notes this as `commonMinMaxSense`
|
||||||
|
- the higher-level limit logic avoids treating one shared input as two separate
|
||||||
|
independent events
|
||||||
|
|
||||||
|
## Config option
|
||||||
|
|
||||||
|
- `LIMIT_SENSE_STRICT == ON` disables that relaxation and treats shared min/max
|
||||||
|
more strictly
|
||||||
|
|
||||||
|
## Typical limit examples
|
||||||
|
|
||||||
|
- `LIMIT_SENSE LOW`
|
||||||
|
common active-low limit input
|
||||||
|
- `LIMIT_SENSE LOW | HYST(10)`
|
||||||
|
common active-low limit input with digital filtering
|
||||||
|
|
||||||
|
## Example: Park Sense
|
||||||
|
|
||||||
|
## Parking uses the same sensing framework for
|
||||||
|
|
||||||
|
- `PARK_SENSE`
|
||||||
|
- `PARK_SIGNAL`
|
||||||
|
|
||||||
|
Those are not special sensing implementations. They are just more clients of
|
||||||
|
the shared normalized ON/OFF sensing subsystem.
|
||||||
|
|
||||||
|
## Example: PEC Sense
|
||||||
|
|
||||||
|
PEC can also use the same shared `Sense` subsystem.
|
||||||
|
|
||||||
|
## That means the PEC index input can also be
|
||||||
|
|
||||||
|
- digital
|
||||||
|
- analog thresholded
|
||||||
|
- analog with hysteresis
|
||||||
|
|
||||||
|
Then PEC adds its own higher-level logic on top, such as only accepting a new
|
||||||
|
index event after enough motion has occurred.
|
||||||
|
|
||||||
|
## So
|
||||||
|
|
||||||
|
- `Sense` decides whether the input is ON
|
||||||
|
- PEC decides whether that ON transition counts as a valid worm index event
|
||||||
|
|
||||||
|
## What `Sense` Does Not Do
|
||||||
|
|
||||||
|
The shared `Sense` subsystem does not implement every kind of analog input
|
||||||
|
pattern.
|
||||||
|
|
||||||
|
## In particular, it does not implement
|
||||||
|
|
||||||
|
- "pressed when analog value lies within a range"
|
||||||
|
|
||||||
|
## It is focused on
|
||||||
|
|
||||||
|
- digital filtered ON/OFF sensing
|
||||||
|
- analog threshold-plus-hysteresis ON/OFF sensing
|
||||||
|
|
||||||
|
## Related But Separate: `Button`
|
||||||
|
|
||||||
|
## There is a related helper in
|
||||||
|
|
||||||
|
- `src/lib/pushButton/PushButton.h`
|
||||||
|
- `src/lib/pushButton/PushButton.cpp`
|
||||||
|
|
||||||
|
## That helper is more button-focused and adds behavior such as
|
||||||
|
|
||||||
|
- press/release semantics
|
||||||
|
- click and double-click detection
|
||||||
|
- tone/frequency detection
|
||||||
|
- analog threshold mode
|
||||||
|
- analog range/value mode
|
||||||
|
|
||||||
|
That analog value/range mode is the "pseudo-digital using analog sampling and
|
||||||
|
range comparison" behavior.
|
||||||
|
|
||||||
|
## So if someone is looking for
|
||||||
|
|
||||||
|
- analog value-in-range detection
|
||||||
|
- button semantics
|
||||||
|
- tone-style input behavior
|
||||||
|
|
||||||
|
they should usually look at `Button`, not `Sense`.
|
||||||
|
|
||||||
|
## Practical Rules Of Thumb
|
||||||
|
|
||||||
|
## If the input is a normal switch
|
||||||
|
|
||||||
|
- start with plain `HIGH` or `LOW`
|
||||||
|
|
||||||
|
## If the switch chatters or is noisy
|
||||||
|
|
||||||
|
- add `HYST(n)` and remember that in digital mode it means milliseconds
|
||||||
|
|
||||||
|
## If the input is fundamentally analog
|
||||||
|
|
||||||
|
- use `THLD(...)`
|
||||||
|
- add `HYST(...)` if you want Schmitt-trigger-like stability
|
||||||
|
|
||||||
|
## If the meaning of the signal must flip at runtime
|
||||||
|
|
||||||
|
- use runtime reversal rather than redefining the electrical config
|
||||||
|
|
||||||
|
## Good Mental Summary
|
||||||
|
|
||||||
|
## The cleanest way to think about sensing in OnStepX is
|
||||||
|
|
||||||
|
- config defines how raw input should be interpreted
|
||||||
|
- `Sense` turns that raw input into a stable ON/OFF result
|
||||||
|
- higher-level features decide what ON/OFF means operationally
|
||||||
|
|
||||||
|
That separation is why the same low-level sensing subsystem can be reused for
|
||||||
|
home, limits, park, PEC, and other features without each subsystem reinventing
|
||||||
|
analog/digital input conditioning.
|
||||||
Executable
+314
@@ -0,0 +1,314 @@
|
|||||||
|
# Serial Notes
|
||||||
|
|
||||||
|
## Purpose
|
||||||
|
|
||||||
|
These notes explain how serial interfaces are used in OnStepX and why serial
|
||||||
|
configuration can be confusing across platforms.
|
||||||
|
|
||||||
|
## The short version is
|
||||||
|
|
||||||
|
- a platform may support several kinds of serial interfaces
|
||||||
|
- a pinmap chooses which ones are exposed for a given board
|
||||||
|
- a feature may or may not be well suited to the chosen serial transport
|
||||||
|
|
||||||
|
## So "serial is supported" does not always mean
|
||||||
|
|
||||||
|
- easy to configure
|
||||||
|
- portable to another board
|
||||||
|
- good for real-time runtime use
|
||||||
|
|
||||||
|
## Quick Summary
|
||||||
|
|
||||||
|
## Think about serial in three layers
|
||||||
|
|
||||||
|
1. Platform:
|
||||||
|
What the MCU/core can do
|
||||||
|
2. Pinmap:
|
||||||
|
Which serial roles are exposed on this board
|
||||||
|
3. Feature:
|
||||||
|
Whether the transport is actually a good fit for the workload
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
- GPS over `SoftSerial` can be fine
|
||||||
|
- TMC2209 over `SoftSerial` may compile but still be a poor runtime fit
|
||||||
|
- Teensy can expose extra USB virtual serial ports
|
||||||
|
- ESP32 can often move hardware UARTs to different pins
|
||||||
|
|
||||||
|
## The Main Serial Roles
|
||||||
|
|
||||||
|
OnStepX uses generic serial role names instead of hard-coding one board's port
|
||||||
|
names everywhere.
|
||||||
|
|
||||||
|
## Common roles include
|
||||||
|
|
||||||
|
- `SERIAL_A`
|
||||||
|
- `SERIAL_B`
|
||||||
|
- `SERIAL_C`
|
||||||
|
- `SERIAL_D`
|
||||||
|
- `SERIAL_E`
|
||||||
|
- `SERIAL_GPS`
|
||||||
|
- `SERIAL_TMC`
|
||||||
|
- `SERIAL_DEBUG`
|
||||||
|
|
||||||
|
These are best thought of as roles, not fixed physical ports.
|
||||||
|
|
||||||
|
## One board might make
|
||||||
|
|
||||||
|
- `SERIAL_B = Serial2`
|
||||||
|
|
||||||
|
## Another board might make
|
||||||
|
|
||||||
|
- `SERIAL_B = HardSerial` with configured RX/TX pins
|
||||||
|
|
||||||
|
Another board might not expose `SERIAL_B` at all.
|
||||||
|
|
||||||
|
## The Main Serial Types
|
||||||
|
|
||||||
|
## In practice, OnStepX may use
|
||||||
|
|
||||||
|
- built-in hardware serial ports such as `Serial1`, `Serial2`, etc.
|
||||||
|
- created hardware serial objects using chosen RX/TX pins
|
||||||
|
- `SoftwareSerial`
|
||||||
|
- USB virtual serial ports
|
||||||
|
- internal pseudo-serial helpers such as `SERIAL_LOCAL`
|
||||||
|
|
||||||
|
All of these may look stream-like in code, but they are not equally suitable
|
||||||
|
for all jobs.
|
||||||
|
|
||||||
|
## Platform Differences
|
||||||
|
|
||||||
|
This is where a lot of confusion starts.
|
||||||
|
|
||||||
|
## Teensy
|
||||||
|
|
||||||
|
- often has multiple hardware UARTs
|
||||||
|
- can also expose extra USB virtual serial ports depending on USB mode
|
||||||
|
- some pinmaps use that to expose `SERIAL_D = SerialUSB1` and
|
||||||
|
`SERIAL_E = SerialUSB2`
|
||||||
|
|
||||||
|
## ESP32
|
||||||
|
|
||||||
|
- usually has flexible hardware UART routing
|
||||||
|
- can often place UART RX/TX on non-default pins
|
||||||
|
- that makes created hardware serial or remapped UART use more practical than
|
||||||
|
on some other Arduino-class targets
|
||||||
|
- also has optional Bluetooth serial support in the HAL
|
||||||
|
|
||||||
|
## STM32
|
||||||
|
|
||||||
|
- often supports created/remapped hardware serial well
|
||||||
|
- also pulls in `SoftwareSerial` support early in the HAL because library/core
|
||||||
|
behavior can otherwise get awkward
|
||||||
|
|
||||||
|
## Why ESP32 Is Worth Calling Out
|
||||||
|
|
||||||
|
ESP32 is a good example of why "hardware serial" does not always mean
|
||||||
|
"hard-wired fixed pins."
|
||||||
|
|
||||||
|
## In OnStepX, some ESP32 pinmaps define roles like
|
||||||
|
|
||||||
|
- `SERIAL_B = Serial2`
|
||||||
|
- `SERIAL_TMC = Serial1`
|
||||||
|
|
||||||
|
## and then separately define
|
||||||
|
|
||||||
|
- `SERIAL_B_RX`
|
||||||
|
- `SERIAL_B_TX`
|
||||||
|
- `SERIAL_TMC_RX`
|
||||||
|
- `SERIAL_TMC_TX`
|
||||||
|
|
||||||
|
That means the feature gets a real hardware UART, but the board still has some
|
||||||
|
freedom to place it where it makes sense.
|
||||||
|
|
||||||
|
## This is one reason ESP32 can be a nice middle ground
|
||||||
|
|
||||||
|
- better than `SoftSerial` for runtime work
|
||||||
|
- more flexible than boards with only fixed UART pin assignments
|
||||||
|
|
||||||
|
## Pinmaps Decide What Exists
|
||||||
|
|
||||||
|
The pinmap layer is where generic serial roles become concrete.
|
||||||
|
|
||||||
|
## This means
|
||||||
|
|
||||||
|
- a feature may request `SERIAL_GPS`
|
||||||
|
- but whether that becomes `SoftSerial`, `HardSerial`, `Serial1`, or something
|
||||||
|
else depends on the pinmap and platform
|
||||||
|
|
||||||
|
## Compile-time validation catches some problems, for example
|
||||||
|
|
||||||
|
- a baud rate is enabled for a serial role that the pinmap did not define
|
||||||
|
- a TMC UART driver is enabled but `SERIAL_TMC` is missing
|
||||||
|
|
||||||
|
## What validation does not prove
|
||||||
|
|
||||||
|
- that the chosen serial transport is a good runtime fit
|
||||||
|
- that it is non-blocking enough
|
||||||
|
- that the underlying library behaves well on that platform
|
||||||
|
|
||||||
|
## Best Uses For Each Type
|
||||||
|
|
||||||
|
## Built-in or created hardware serial
|
||||||
|
|
||||||
|
## Usually best for
|
||||||
|
|
||||||
|
- continuous runtime traffic
|
||||||
|
- higher baud rates
|
||||||
|
- frequent bidirectional communication
|
||||||
|
- motion-control related serial work
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
- shared TMC2209 UART on boards designed for it
|
||||||
|
- a secondary MCU link
|
||||||
|
- frequent device polling
|
||||||
|
|
||||||
|
## `SoftwareSerial`
|
||||||
|
|
||||||
|
## Usually best for
|
||||||
|
|
||||||
|
- one-time configuration at boot
|
||||||
|
- low-rate telemetry
|
||||||
|
- devices that become less important once startup finishes
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
- GPS
|
||||||
|
- boot-time driver setup in some constrained builds
|
||||||
|
|
||||||
|
## USB virtual serial
|
||||||
|
|
||||||
|
## Usually best for
|
||||||
|
|
||||||
|
- extra host-side channels
|
||||||
|
- debug, tooling, or auxiliary control on supported platforms
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
- Teensy `SerialUSB1`
|
||||||
|
- Teensy `SerialUSB2`
|
||||||
|
|
||||||
|
## Why `SoftwareSerial` Is Tricky
|
||||||
|
|
||||||
|
`SoftwareSerial` is often the most confusing case because it is sometimes very
|
||||||
|
useful and sometimes a terrible fit.
|
||||||
|
|
||||||
|
## General concerns
|
||||||
|
|
||||||
|
- it is often blocking or close enough to blocking to matter
|
||||||
|
- support quality varies by platform
|
||||||
|
- timing behavior varies by core and library
|
||||||
|
- library code sitting on top of it may own the actual read/write behavior
|
||||||
|
|
||||||
|
So if a feature "supports `SoftSerial`", that should not automatically be read
|
||||||
|
as:
|
||||||
|
|
||||||
|
- well tested
|
||||||
|
- non-blocking
|
||||||
|
- appropriate for real-time runtime use
|
||||||
|
|
||||||
|
## Example: GPS
|
||||||
|
|
||||||
|
GPS is one of the better cases for less-than-perfect serial.
|
||||||
|
|
||||||
|
## Why
|
||||||
|
|
||||||
|
- relatively low-rate
|
||||||
|
- mostly an input stream
|
||||||
|
- used to establish time/location
|
||||||
|
- OnStepX may close the GPS serial port once current time has been acquired
|
||||||
|
|
||||||
|
So GPS over `SoftSerial` can be a reasonable trade on many builds.
|
||||||
|
|
||||||
|
That does not make `SoftSerial` universally good. It just means GPS is a
|
||||||
|
feature that can often tolerate it.
|
||||||
|
|
||||||
|
## Example: TMC2209 UART
|
||||||
|
|
||||||
|
TMC2209 is the opposite kind of example.
|
||||||
|
|
||||||
|
## Why it is harder
|
||||||
|
|
||||||
|
- runtime UART interaction can matter
|
||||||
|
- mode changes may happen during operation
|
||||||
|
- status/config traffic may be needed while the rest of the mount is busy
|
||||||
|
- blocking behavior is much more painful in a real-time motion system
|
||||||
|
|
||||||
|
## So for TMC2209
|
||||||
|
|
||||||
|
- `SoftSerial` may be acceptable for one-time setup at boot
|
||||||
|
- `SoftSerial` is much less attractive for active runtime interaction
|
||||||
|
|
||||||
|
That does not mean `SoftSerial` is useless here. It means the use case matters.
|
||||||
|
|
||||||
|
## Example: More Than Four TMC2209s
|
||||||
|
|
||||||
|
## There is one place where `SoftSerial` can still be attractive for TMC2209
|
||||||
|
|
||||||
|
- per-device links can make scaling easier when a shared hardware UART bus gets
|
||||||
|
awkward
|
||||||
|
|
||||||
|
## So there is a real trade
|
||||||
|
|
||||||
|
- shared hardware UART is usually better for runtime quality
|
||||||
|
- per-device `SoftSerial` may make some larger or stranger topologies possible
|
||||||
|
|
||||||
|
## This is why the answer is not simply
|
||||||
|
|
||||||
|
- "never use `SoftSerial`"
|
||||||
|
|
||||||
|
## It is more like
|
||||||
|
|
||||||
|
- use it carefully
|
||||||
|
- prefer it for boot/setup or unusual topologies
|
||||||
|
- do not assume it is ideal for active runtime control
|
||||||
|
|
||||||
|
## Library Ownership Matters
|
||||||
|
|
||||||
|
## Another subtle point
|
||||||
|
|
||||||
|
OnStepX may define the transport, but the feature library often performs the
|
||||||
|
real reads and writes.
|
||||||
|
|
||||||
|
## That means serial behavior depends on
|
||||||
|
|
||||||
|
- the platform core
|
||||||
|
- the chosen transport
|
||||||
|
- the feature library
|
||||||
|
|
||||||
|
## This is especially relevant for
|
||||||
|
|
||||||
|
- TMC driver libraries
|
||||||
|
- any feature with frequent serial traffic
|
||||||
|
|
||||||
|
So a configuration can be theoretically valid while still being lightly tested
|
||||||
|
or operationally uncertain.
|
||||||
|
|
||||||
|
## Practical Rules Of Thumb
|
||||||
|
|
||||||
|
## If the serial link is mostly needed at boot
|
||||||
|
|
||||||
|
- `SoftSerial` may be acceptable
|
||||||
|
|
||||||
|
## If the serial link is needed continuously during runtime
|
||||||
|
|
||||||
|
- prefer hardware UART where possible
|
||||||
|
|
||||||
|
## If the board/platform offers extra USB serial channels
|
||||||
|
|
||||||
|
- treat that as a platform-specific bonus, not a general Arduino assumption
|
||||||
|
|
||||||
|
## If a user is choosing between "works in theory" and "works robustly"
|
||||||
|
|
||||||
|
- favor the more boring hardware-UART option
|
||||||
|
|
||||||
|
## Good Mental Summary
|
||||||
|
|
||||||
|
## The simplest reliable way to think about serial in OnStepX is
|
||||||
|
|
||||||
|
- HAL defines what the platform can plausibly do
|
||||||
|
- the pinmap assigns generic serial roles to actual transports
|
||||||
|
- the feature decides whether that transport is really suitable
|
||||||
|
|
||||||
|
That last step is where most serial surprises come from.
|
||||||
Executable
+496
@@ -0,0 +1,496 @@
|
|||||||
|
# Servo Setup Guide
|
||||||
|
|
||||||
|
## Purpose
|
||||||
|
|
||||||
|
This guide is for setting up a mount axis that uses servo feedback in OnStepX.
|
||||||
|
|
||||||
|
It is written for users who want a practical bring-up sequence:
|
||||||
|
- what to configure first
|
||||||
|
- what to test before moving faster
|
||||||
|
- what to adjust when things go the wrong way
|
||||||
|
|
||||||
|
This guide is intentionally light on control theory. The goal is to help you
|
||||||
|
get to a safe, working setup without having to understand every low-level
|
||||||
|
detail first.
|
||||||
|
|
||||||
|
## Before you begin
|
||||||
|
|
||||||
|
Have these basics sorted out first:
|
||||||
|
- the controller pinmap matches your hardware
|
||||||
|
- power wiring is correct
|
||||||
|
- motor wiring is correct enough that the driver powers up safely
|
||||||
|
- encoder wiring is correct enough that counts can be read reliably
|
||||||
|
- hard limits or other motion safeguards are planned before unattended use
|
||||||
|
|
||||||
|
Important safety note:
|
||||||
|
- do not leave a new servo setup tracking unattended until you have verified
|
||||||
|
limits, stop behavior, and the direction of both the motor and encoder
|
||||||
|
- a servo that is "mostly working" can still drive hard into a stop if the
|
||||||
|
setup is wrong
|
||||||
|
|
||||||
|
## What "servo" means here
|
||||||
|
|
||||||
|
In OnStepX, a servo axis is a motor axis that closes the loop using encoder
|
||||||
|
feedback.
|
||||||
|
|
||||||
|
In practical terms that means:
|
||||||
|
- the motor moves the axis
|
||||||
|
- the encoder tells OnStepX where the axis actually is
|
||||||
|
- OnStepX keeps correcting the motor so the axis reaches and holds the target
|
||||||
|
|
||||||
|
For the mount axes, the main items are usually:
|
||||||
|
- a servo-capable driver model such as `SERVO_PE`, `SERVO_EE`, `SERVO_TMC2209`,
|
||||||
|
`SERVO_TMC5160`, or `SERVO_KTECH`
|
||||||
|
- an encoder type such as `AB`, `KTECH_IME`, or another supported encoder
|
||||||
|
- sensible axis scale and direction settings
|
||||||
|
- usable PID values
|
||||||
|
|
||||||
|
This guide is mainly about the built-in servo axis types. ODrive-based systems
|
||||||
|
have their own workflow and deserve separate documentation.
|
||||||
|
|
||||||
|
## How the current `#define`s tie together
|
||||||
|
|
||||||
|
If you are comparing old example configs, this is the compile-time chain that
|
||||||
|
matters in the current code.
|
||||||
|
|
||||||
|
### 1. `AXIS*_DRIVER_MODEL` decides whether the axis is treated as a servo
|
||||||
|
|
||||||
|
If `AXIS1_DRIVER_MODEL` or `AXIS2_DRIVER_MODEL` is in the servo-driver range,
|
||||||
|
`Config.defaults.h` defines `AXIS*_SERVO_PRESENT`.
|
||||||
|
|
||||||
|
That is the switch that makes the mount axis build as a servo axis instead of a
|
||||||
|
step/dir axis.
|
||||||
|
|
||||||
|
### 2. `AXIS*_ENCODER` selects the encoder class
|
||||||
|
|
||||||
|
When `AXIS*_SERVO_PRESENT` is true, `Mount.axis.cpp` selects the encoder from
|
||||||
|
`AXIS*_ENCODER`.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
- `AB` selects a quadrature encoder
|
||||||
|
- `KTECH_IME` selects the KTech encoder class
|
||||||
|
- `SERIAL_BRIDGE` selects the serial bridge encoder path
|
||||||
|
|
||||||
|
### 3. `AXIS*_SERVO_FEEDBACK` selects the feedback controller
|
||||||
|
|
||||||
|
`Mount.axis.cpp` currently uses:
|
||||||
|
- `PID` for a single PID set
|
||||||
|
- `DUAL_PID` for separate tracking and goto PID sets
|
||||||
|
|
||||||
|
That means these defines feed directly into the live controller:
|
||||||
|
- `AXIS*_PID_P`
|
||||||
|
- `AXIS*_PID_I`
|
||||||
|
- `AXIS*_PID_D`
|
||||||
|
- `AXIS*_PID_P_GOTO`
|
||||||
|
- `AXIS*_PID_I_GOTO`
|
||||||
|
- `AXIS*_PID_D_GOTO`
|
||||||
|
- `AXIS*_PID_SENSITIVITY`
|
||||||
|
|
||||||
|
### 4. `AXIS*_SERVO_FLTR` selects the encoder filter
|
||||||
|
|
||||||
|
Current mount-axis choices are wired in through `Mount.axis.cpp`:
|
||||||
|
- `OFF`
|
||||||
|
- `KALMAN`
|
||||||
|
- `LEARNING` for Axis1
|
||||||
|
- `ROLLING`
|
||||||
|
|
||||||
|
If you are starting fresh, `OFF` is the simplest baseline.
|
||||||
|
|
||||||
|
### 5. Some servo driver models also use motor-side scaling
|
||||||
|
|
||||||
|
For stepper-based servo drivers such as `SERVO_TMC2209`, `SERVO_TMC5160`, and
|
||||||
|
`SERVO_KTECH`, the code uses this ratio:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
AXIS*_MOTOR_STEPS_PER_DEGREE / AXIS*_STEPS_PER_DEGREE
|
||||||
|
```
|
||||||
|
|
||||||
|
That ratio is passed into the servo driver in `Mount.axis.cpp`.
|
||||||
|
|
||||||
|
In practical terms:
|
||||||
|
- `AXIS*_STEPS_PER_DEGREE` is still the mount axis scale
|
||||||
|
- `AXIS*_MOTOR_STEPS_PER_DEGREE` matters when the motor-side step scale is not
|
||||||
|
the same as the encoder-side axis scale
|
||||||
|
|
||||||
|
These two are rarely the same. Sometimes the encoders are on the mount axes and there is not reduction and other times there is. Then the encoder has a resolution as well. On the other hand the motor almost always has an associated reduction and full-steps per rotation and 256 micro-steps per full-step.
|
||||||
|
|
||||||
|
### 6. Direction and origin are separate inputs to `ServoMotor`
|
||||||
|
|
||||||
|
The final `ServoMotor` object is built with:
|
||||||
|
- `AXIS*_REVERSE`
|
||||||
|
- `AXIS*_ENCODER_REVERSE`
|
||||||
|
- `AXIS*_ENCODER_ORIGIN`
|
||||||
|
|
||||||
|
These do different jobs:
|
||||||
|
- `AXIS*_REVERSE` changes commanded motor direction
|
||||||
|
- `AXIS*_ENCODER_REVERSE` changes encoder sign
|
||||||
|
- `AXIS*_ENCODER_ORIGIN` is the stored zero/origin for absolute encoder cases
|
||||||
|
|
||||||
|
There is also a runtime reverse path.
|
||||||
|
|
||||||
|
In practical terms:
|
||||||
|
- `AXIS*_ENCODER_REVERSE` is the baseline wiring/sign correction for the encoder
|
||||||
|
- `AXIS*_REVERSE` is the baseline motion-direction choice for the axis
|
||||||
|
- if the axis reverse state is changed at runtime, OnStepX also flips the
|
||||||
|
control direction so the feedback loop still makes sense
|
||||||
|
|
||||||
|
That is why direction can appear to be handled at more than one level. It is.
|
||||||
|
Those levels are there for different reasons.
|
||||||
|
|
||||||
|
### 7. `AXIS*_TARGET_TOLERANCE` is not servo-only, but it matters a lot for servo behavior
|
||||||
|
|
||||||
|
`AXIS*_TARGET_TOLERANCE` is passed into the `Axis` object and affects when the
|
||||||
|
system considers the axis near its target.
|
||||||
|
|
||||||
|
That is why many servo example configs override it even though it is not
|
||||||
|
strictly a servo-only define.
|
||||||
|
|
||||||
|
### 8. Absolute encoder authority is inferred from encoder type
|
||||||
|
|
||||||
|
In `Validate.h`, some encoder types automatically imply absolute encoder
|
||||||
|
authority on servo axes. That affects startup trust behavior.
|
||||||
|
|
||||||
|
So for servo users, `AXIS*_ENCODER` is doing more than just picking a driver.
|
||||||
|
It can also affect how startup authority is determined.
|
||||||
|
|
||||||
|
## Practical takeaway about old example configs
|
||||||
|
|
||||||
|
Some example servo configs are older than the current code and may not reflect
|
||||||
|
today's best defaults.
|
||||||
|
|
||||||
|
Treat them as:
|
||||||
|
- examples of working combinations
|
||||||
|
- hints for starting values
|
||||||
|
- not as an exact description of the current wiring between settings
|
||||||
|
|
||||||
|
If there is a conflict, trust the current code path in:
|
||||||
|
- [Config.defaults.h](/c:/Users/hjd19/Documents/Programs/GitHub/OnStepX/src/Config.defaults.h)
|
||||||
|
- [Mount.axis.cpp](/c:/Users/hjd19/Documents/Programs/GitHub/OnStepX/src/telescope/mount/Mount.axis.cpp)
|
||||||
|
- [Validate.h](/c:/Users/hjd19/Documents/Programs/GitHub/OnStepX/src/Validate.h)
|
||||||
|
|
||||||
|
## Minimum settings to get right first
|
||||||
|
|
||||||
|
For each servo mount axis, focus on these first:
|
||||||
|
|
||||||
|
1. Driver model
|
||||||
|
- set the axis driver model to the correct servo type
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#define AXIS1_DRIVER_MODEL SERVO_PE
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Axis scale
|
||||||
|
- set `AXIS*_STEPS_PER_DEGREE` correctly
|
||||||
|
- for stepper-based servo drivers, also check `AXIS*_MOTOR_STEPS_PER_DEGREE`
|
||||||
|
if your hardware needs it
|
||||||
|
|
||||||
|
If the scale is wrong, almost everything else becomes confusing.
|
||||||
|
|
||||||
|
3. Encoder type
|
||||||
|
- set `AXIS*_ENCODER` to the actual encoder you are using
|
||||||
|
|
||||||
|
4. Directions
|
||||||
|
- `AXIS*_REVERSE` controls motor direction
|
||||||
|
- `AXIS*_ENCODER_REVERSE` controls encoder direction
|
||||||
|
|
||||||
|
These are separate on purpose. Do not assume that fixing one also fixes the
|
||||||
|
other.
|
||||||
|
|
||||||
|
The practical rule is:
|
||||||
|
- use `AXIS*_ENCODER_REVERSE` to make encoder counts agree with real motion
|
||||||
|
- use `AXIS*_REVERSE` to make commanded axis motion go the right way
|
||||||
|
|
||||||
|
Do not use motor reverse as a substitute for fixing an encoder that counts the
|
||||||
|
wrong direction.
|
||||||
|
|
||||||
|
If the motor and encoder direction are NOT in agreement the axis will run-away.
|
||||||
|
There is code that attempts to detect run-away, or oscillation, which will hopefully
|
||||||
|
shut the axis down in short order if this happens.
|
||||||
|
|
||||||
|
5. Conservative limits
|
||||||
|
- set reasonable axis limits before doing long moves
|
||||||
|
- keep first tests short and slow
|
||||||
|
|
||||||
|
## Recommended bring-up order
|
||||||
|
|
||||||
|
This is the safest order for a fresh servo setup.
|
||||||
|
|
||||||
|
### 1. Bring up one axis at a time
|
||||||
|
|
||||||
|
If possible, get Axis1 behaving first, then copy the pattern to Axis2.
|
||||||
|
|
||||||
|
Trying to solve both axes at once can hide simple mistakes.
|
||||||
|
|
||||||
|
### 2. Verify encoder direction before worrying about motor direction
|
||||||
|
|
||||||
|
The encoder direction must make physical sense.
|
||||||
|
|
||||||
|
When the axis moves in a positive direction, the encoder should report that
|
||||||
|
same direction. If it does not:
|
||||||
|
- fix `AXIS*_ENCODER_REVERSE` first
|
||||||
|
|
||||||
|
Do this before serious PID tuning.
|
||||||
|
|
||||||
|
### 3. Verify motor direction
|
||||||
|
|
||||||
|
Once the encoder reads correctly:
|
||||||
|
- use a small manual move
|
||||||
|
- confirm the axis moves the expected way
|
||||||
|
- if not, fix `AXIS*_REVERSE`
|
||||||
|
|
||||||
|
This order matters.
|
||||||
|
|
||||||
|
If the encoder sign is wrong, the control loop can "fight" the motion and a
|
||||||
|
later motor-direction change may only hide the real problem.
|
||||||
|
|
||||||
|
### 4. Start with small motions only
|
||||||
|
|
||||||
|
For early tests:
|
||||||
|
- use guide moves or very short slews
|
||||||
|
- keep your hand near power-off
|
||||||
|
- do not start with full-length gotos
|
||||||
|
|
||||||
|
### 5. Confirm the axis can stop cleanly
|
||||||
|
|
||||||
|
Before tuning for performance, verify that:
|
||||||
|
- the axis starts moving promptly
|
||||||
|
- the axis stops when motion stops
|
||||||
|
- there is no runaway, buzzing, or repeated overshoot
|
||||||
|
|
||||||
|
If anything looks wrong, stop and correct direction, scale, or wiring before
|
||||||
|
going further.
|
||||||
|
|
||||||
|
## A simple way to think about PID
|
||||||
|
|
||||||
|
You do not need to be a controls engineer to get started.
|
||||||
|
|
||||||
|
Use this mental model:
|
||||||
|
- `P` reacts to present error
|
||||||
|
- `I` corrects lingering offset
|
||||||
|
- `D` helps calm motion and reduce overshoot
|
||||||
|
|
||||||
|
OnStepX commonly uses:
|
||||||
|
- one PID set for tracking
|
||||||
|
- another PID set for slewing/goto
|
||||||
|
|
||||||
|
Those are the `_GOTO` values:
|
||||||
|
- `AXIS*_PID_P_GOTO`
|
||||||
|
- `AXIS*_PID_I_GOTO`
|
||||||
|
- `AXIS*_PID_D_GOTO`
|
||||||
|
|
||||||
|
Often since this uses feed-forward the goto parameters are less important. Also
|
||||||
|
these can be changed instantly at runtime from the SWS or Website Plugin which makes tuning far far faster.
|
||||||
|
|
||||||
|
## How motion feed-forward works now
|
||||||
|
|
||||||
|
This is one area where older servo examples can be misleading.
|
||||||
|
|
||||||
|
In current OnStepX, the servo path does not rely on PID correction alone.
|
||||||
|
The motion command already includes a feed-forward component, and the exact
|
||||||
|
motor-side behavior depends on the servo driver type.
|
||||||
|
|
||||||
|
### TMC stepper servos
|
||||||
|
|
||||||
|
For TMC stepper servos such as `SERVO_TMC2209` and `SERVO_TMC5160`:
|
||||||
|
- motion feed-forward is automatic
|
||||||
|
- OnStepX combines the requested motion with the feedback correction and sends
|
||||||
|
a velocity command to the driver
|
||||||
|
|
||||||
|
In user terms:
|
||||||
|
- you do not usually "turn feed-forward on"
|
||||||
|
- it is part of how these servo drivers normally work
|
||||||
|
|
||||||
|
The main coupling setting is the counts-to-steps ratio:
|
||||||
|
- it starts from the config default based on
|
||||||
|
`AXIS*_MOTOR_STEPS_PER_DEGREE / AXIS*_STEPS_PER_DEGREE`
|
||||||
|
- that ratio is also a runtime-adjustable axis parameter
|
||||||
|
|
||||||
|
So for TMC stepper servos, the important question is usually not whether
|
||||||
|
feed-forward exists, but whether the counts-to-steps coupling is correct.
|
||||||
|
|
||||||
|
### DC servos
|
||||||
|
|
||||||
|
For DC servo drivers such as `SERVO_PE`, `SERVO_EE`, `SERVO_TMC2130_DC`, and
|
||||||
|
`SERVO_TMC5160_DC`:
|
||||||
|
- the same upstream motion command still includes feed-forward
|
||||||
|
- but the driver side now has more explicit runtime coupling controls
|
||||||
|
|
||||||
|
The practical runtime knobs are:
|
||||||
|
- minimum motor power
|
||||||
|
- maximum motor power
|
||||||
|
- reversal protection delay
|
||||||
|
|
||||||
|
That means DC servo behavior is more dependent on the runtime motor-output
|
||||||
|
settings than the TMC stepper-servo path is.
|
||||||
|
|
||||||
|
### DC servo velocity control loop
|
||||||
|
|
||||||
|
DC servos can also use the newer motor-side velocity loop.
|
||||||
|
|
||||||
|
When enabled:
|
||||||
|
- the driver uses encoder-derived velocity as a measured feedback signal
|
||||||
|
- the motor-side control becomes feed-forward plus a velocity PI correction
|
||||||
|
|
||||||
|
When not enabled:
|
||||||
|
- the motor-side control is basically feed-forward duty mapping
|
||||||
|
|
||||||
|
In practical terms:
|
||||||
|
- without the velocity loop, DC servos depend more heavily on a good power map
|
||||||
|
- with the velocity loop, DC servos can regulate motor behavior more directly
|
||||||
|
from measured encoder speed
|
||||||
|
|
||||||
|
### Encoder velocity support
|
||||||
|
|
||||||
|
The newer DC velocity-loop behavior depends on encoder velocity estimation.
|
||||||
|
|
||||||
|
That comes from the encoder subsystem itself, not from the PID section.
|
||||||
|
|
||||||
|
So if you are working on a DC servo and velocity control is enabled:
|
||||||
|
- encoder quality matters even more than usual
|
||||||
|
- noisy or weak encoder velocity estimates can make tuning harder
|
||||||
|
|
||||||
|
## Deadband and reversal protection
|
||||||
|
|
||||||
|
Two settings in the servo path can sound similar, but they do different jobs.
|
||||||
|
|
||||||
|
### Zero deadband
|
||||||
|
|
||||||
|
The servo driver also has a low-speed command deadband.
|
||||||
|
|
||||||
|
In practical terms:
|
||||||
|
- very small requested motor velocities are treated as zero
|
||||||
|
- this helps prevent constant tiny nudges near standstill
|
||||||
|
- it is not the same thing as backlash compensation or target tolerance
|
||||||
|
|
||||||
|
If this is set too high:
|
||||||
|
- the axis can feel reluctant to make very small corrections
|
||||||
|
|
||||||
|
If it is set too low:
|
||||||
|
- the motor may keep twitching or chattering around zero
|
||||||
|
|
||||||
|
### Reversal protection delay
|
||||||
|
|
||||||
|
DC servos also have a direction-change delay.
|
||||||
|
|
||||||
|
This is better thought of as reversal protection:
|
||||||
|
- when the commanded direction flips, the output is briefly held at zero
|
||||||
|
- that gives the drivetrain and driver a moment before power is applied in the
|
||||||
|
opposite direction
|
||||||
|
|
||||||
|
This can be helpful when:
|
||||||
|
- the motor drive does not like abrupt reversals
|
||||||
|
- the axis has noticeable mechanical shock on direction changes
|
||||||
|
- you want gentler reversal behavior during tuning
|
||||||
|
|
||||||
|
So the practical distinction is:
|
||||||
|
- zero deadband suppresses tiny commands near zero
|
||||||
|
- reversal protection delay softens direction changes
|
||||||
|
|
||||||
|
## Practical PID advice
|
||||||
|
|
||||||
|
Start simple:
|
||||||
|
- begin with modest `P`
|
||||||
|
- keep `I` small
|
||||||
|
- use little or no `D` at first
|
||||||
|
|
||||||
|
What to watch for:
|
||||||
|
- if the axis feels weak or lags badly, `P` may be too low
|
||||||
|
- if it hunts or oscillates, `P` may be too high
|
||||||
|
- if it reaches the target but stays offset, add a little `I`
|
||||||
|
- if it overshoots and rings, reduce `P` or add a small amount of `D`
|
||||||
|
|
||||||
|
Make small changes, then test again.
|
||||||
|
|
||||||
|
Avoid changing many things at once.
|
||||||
|
|
||||||
|
## About `PID_SENSITIVITY`
|
||||||
|
|
||||||
|
`AXIS*_PID_SENSITIVITY` controls how OnStepX transitions between the tracking
|
||||||
|
PID set and the slewing PID set.
|
||||||
|
|
||||||
|
A practical rule of thumb:
|
||||||
|
- for many DC servos, a nonzero value can help
|
||||||
|
- for many stepper-based servos, `0` is a reasonable starting point
|
||||||
|
|
||||||
|
If you are unsure:
|
||||||
|
- start with the value used by a similar example config
|
||||||
|
|
||||||
|
## About target tolerance
|
||||||
|
|
||||||
|
`AXIS*_TARGET_TOLERANCE` gives the axis a little room around the target.
|
||||||
|
|
||||||
|
In user terms:
|
||||||
|
- too small can make the axis fussy and restless
|
||||||
|
- too large can make the final position sloppier than you want
|
||||||
|
|
||||||
|
If the axis seems to chatter around the target, this setting may be too tight.
|
||||||
|
|
||||||
|
## First successful motion checklist
|
||||||
|
|
||||||
|
Once you have basic motion, verify these before calling it "working":
|
||||||
|
- guide moves are in the correct direction
|
||||||
|
- encoder direction remains correct through the full move
|
||||||
|
- the axis does not run away when motion starts
|
||||||
|
- the axis does not oscillate badly when motion stops
|
||||||
|
- tracking starts and holds without obvious hunting
|
||||||
|
- limits and stop behavior work as expected
|
||||||
|
|
||||||
|
Only after that should you move on to longer slews and unattended use.
|
||||||
|
|
||||||
|
## Absolute encoders and origin
|
||||||
|
|
||||||
|
If your servo setup uses absolute encoders:
|
||||||
|
- the encoder origin must be established correctly
|
||||||
|
- startup trust behavior depends on that origin being believable
|
||||||
|
|
||||||
|
If you are not using absolute encoders:
|
||||||
|
- skip this part for initial bring-up
|
||||||
|
- get basic motion stable first
|
||||||
|
|
||||||
|
## Useful optional UI aids
|
||||||
|
|
||||||
|
Some test configs enable extra web controls such as:
|
||||||
|
- `DISPLAY_SERVO_MONITOR`
|
||||||
|
- `DISPLAY_SERVO_ORIGIN_CONTROLS`
|
||||||
|
- `DISPLAY_SERVO_CALIBRATION`
|
||||||
|
|
||||||
|
These can make bring-up easier, especially while checking direction, settling,
|
||||||
|
and origin behavior.
|
||||||
|
|
||||||
|
## Common mistakes
|
||||||
|
|
||||||
|
These are the usual trouble spots:
|
||||||
|
- wrong encoder direction
|
||||||
|
- wrong motor direction
|
||||||
|
- wrong steps-per-degree
|
||||||
|
- tuning before verifying scale and direction
|
||||||
|
- trying full-speed slews too early
|
||||||
|
- leaving tracking enabled before limits and stop behavior are proven
|
||||||
|
|
||||||
|
If the setup behaves strangely, go back to:
|
||||||
|
1. scale
|
||||||
|
2. encoder direction
|
||||||
|
3. motor direction
|
||||||
|
4. only then PID tuning
|
||||||
|
|
||||||
|
## A good first goal
|
||||||
|
|
||||||
|
Do not aim for perfect tracking on the first pass.
|
||||||
|
|
||||||
|
A good first milestone is:
|
||||||
|
- the axis moves the right way
|
||||||
|
- encoder feedback agrees with motion
|
||||||
|
- it stops cleanly
|
||||||
|
- it holds position without obvious instability
|
||||||
|
|
||||||
|
After that, refine tracking, slewing response, and final pointing performance.
|
||||||
|
|
||||||
|
## Future improvements for this guide
|
||||||
|
|
||||||
|
Useful follow-up documentation would be:
|
||||||
|
- a separate ODrive setup guide
|
||||||
|
- a short PID tuning cookbook with symptom-based advice
|
||||||
|
- a checklist for absolute encoder origin setup
|
||||||
|
- a servo troubleshooting page with "if it does this, check that"
|
||||||
Executable
+366
@@ -0,0 +1,366 @@
|
|||||||
|
# Startup Authority And Coordinate Trust Notes
|
||||||
|
|
||||||
|
## Purpose
|
||||||
|
|
||||||
|
These notes describe how startup authority and coordinate trust currently work
|
||||||
|
for the mount, and how that affects automatic motion such as goto, sync,
|
||||||
|
park/unpark, and home/return.
|
||||||
|
|
||||||
|
## Core idea
|
||||||
|
|
||||||
|
The mount tracks a runtime trust state whose only question is:
|
||||||
|
"Do we trust the current coordinate basis enough for coordinate-based
|
||||||
|
automatic motion?"
|
||||||
|
|
||||||
|
If trust is true:
|
||||||
|
- coordinate-based automatic operations are allowed
|
||||||
|
|
||||||
|
If trust is false:
|
||||||
|
- coordinate-based automatic operations are blocked
|
||||||
|
- manual guide recovery is still allowed
|
||||||
|
- plain sidereal tracking is not gated by startup authority itself, but it may
|
||||||
|
still be blocked by other safety policy
|
||||||
|
|
||||||
|
## Two useful distinctions
|
||||||
|
|
||||||
|
1. Immediate startup authority
|
||||||
|
- trust is available immediately at boot from an already-available authority
|
||||||
|
source
|
||||||
|
|
||||||
|
2. Deferred startup authority
|
||||||
|
- boot starts untrusted
|
||||||
|
- an authoritative startup-time action later establishes trust
|
||||||
|
|
||||||
|
Date/time readiness is separate from both of the above.
|
||||||
|
|
||||||
|
Limit enforcement is related but separate too:
|
||||||
|
- startup authority answers whether the coordinate basis is trusted
|
||||||
|
- date/time readiness answers whether sky-referenced operation is ready
|
||||||
|
- limit enforcement can become active as soon as both are available
|
||||||
|
|
||||||
|
## What currently establishes trust
|
||||||
|
|
||||||
|
Trust can currently come from either immediate startup authority sources or
|
||||||
|
later authoritative actions.
|
||||||
|
|
||||||
|
Immediate startup authority sources:
|
||||||
|
- paired mount-axis absolute position sources at boot, with origin(s)
|
||||||
|
established
|
||||||
|
- trusted mount coordinate memory restore
|
||||||
|
|
||||||
|
Boot policy is selected by MOUNT_STARTUP_MODE.
|
||||||
|
Default:
|
||||||
|
- SA_AUTO
|
||||||
|
|
||||||
|
Modes:
|
||||||
|
- SA_STRICT:
|
||||||
|
boot stays untrusted unless an immediate startup authority source succeeds
|
||||||
|
- SA_AUTO:
|
||||||
|
if neither mount axis has an absolute position source and mount coordinate
|
||||||
|
memory is OFF, boot grants legacy session trust automatically
|
||||||
|
- SA_PERMISSIVE:
|
||||||
|
boot grants session trust automatically even when stricter authority sources
|
||||||
|
exist
|
||||||
|
|
||||||
|
Later authoritative actions:
|
||||||
|
- authoritative set-origin at a known home position
|
||||||
|
- authoritative reset at a known home position
|
||||||
|
- successful switch-based home
|
||||||
|
- SWS v2.10d or later hosting absolute encoders (for pointing correction)
|
||||||
|
|
||||||
|
Ordinary sync is not used to restore trust.
|
||||||
|
|
||||||
|
## What currently revokes trust
|
||||||
|
|
||||||
|
Trust is revoked conservatively when the system can no longer honestly assume
|
||||||
|
the coordinate basis is valid.
|
||||||
|
|
||||||
|
Currently implemented:
|
||||||
|
- motor/encoder fault
|
||||||
|
- NV fault (default behavior, because NV_INIT_ERROR_REVOKES_AUTHORITY defaults to ON)
|
||||||
|
|
||||||
|
Important non-revocation note:
|
||||||
|
- a motion stop caused by limits or StallGuard is not, by itself, a trust
|
||||||
|
revocation event
|
||||||
|
|
||||||
|
## What is blocked while untrusted
|
||||||
|
|
||||||
|
Blocked:
|
||||||
|
- goto
|
||||||
|
- set park
|
||||||
|
- park
|
||||||
|
- unpark
|
||||||
|
- normal sync
|
||||||
|
- home/return unless switch-based home is available
|
||||||
|
|
||||||
|
Allowed:
|
||||||
|
- manual guide
|
||||||
|
- plain sidereal tracking, subject to the normal tracking safety policy
|
||||||
|
|
||||||
|
Important tracking note:
|
||||||
|
- startup authority does not itself gate plain sidereal tracking
|
||||||
|
- however, tracking is still subject to other conditions such as parked state,
|
||||||
|
date/time-dependent enable rules, and limit policy
|
||||||
|
- by default, tracking is disallowed when limits are not enforced
|
||||||
|
|
||||||
|
## Parking workflow
|
||||||
|
|
||||||
|
Parking is part of the same trust model because park/set-park/unpark all depend
|
||||||
|
on the mount coordinate basis being believable.
|
||||||
|
|
||||||
|
While untrusted:
|
||||||
|
- set park is blocked
|
||||||
|
- park is blocked
|
||||||
|
- unpark/restore is blocked
|
||||||
|
|
||||||
|
Why:
|
||||||
|
- set park stores a coordinate-based reference that should not be accepted if
|
||||||
|
the current coordinate basis is already in doubt
|
||||||
|
- park and unpark are automatic coordinate-based motions, so they should follow
|
||||||
|
the same trust rules as goto
|
||||||
|
|
||||||
|
Operationally this means:
|
||||||
|
- a parked state is only useful if it was established from a trusted coordinate
|
||||||
|
basis
|
||||||
|
- unpark/restore is allowed when resuming from previously trusted parked state
|
||||||
|
- unpark/restore should not be thought of as a way to recover trust from unknown
|
||||||
|
state
|
||||||
|
- the legacy "unpark from home" exception is only allowed on simpler mounts; it
|
||||||
|
is disabled for SA_STRICT, for mounts using coordinate memory, and for mounts
|
||||||
|
with absolute position sources
|
||||||
|
|
||||||
|
## Workflow 1: Boot With Immediate Startup Authority
|
||||||
|
|
||||||
|
This is the cleanest startup path.
|
||||||
|
|
||||||
|
On these mounts, trust can be granted automatically at boot because the mount
|
||||||
|
already has an authoritative coordinate basis before any manual recovery is
|
||||||
|
needed.
|
||||||
|
|
||||||
|
Current immediate startup authority sources are:
|
||||||
|
- paired mount-axis absolute position sources
|
||||||
|
- trusted mount coordinate memory
|
||||||
|
|
||||||
|
## Workflow 1a: Boot With Paired Mount-Axis Absolute Coordinate Authority
|
||||||
|
|
||||||
|
This applies when:
|
||||||
|
- both mount axes report absolute position at startup
|
||||||
|
- the required encoder origin(s) are already established
|
||||||
|
- startup reset is therefore allowed to treat the mount-axis absolute readings
|
||||||
|
as authoritative for the initial coordinate basis
|
||||||
|
|
||||||
|
This is intentionally stricter than "one axis happens to be absolute."
|
||||||
|
For the mount axes, absolute coordinate authority is only valid as a paired
|
||||||
|
startup basis.
|
||||||
|
|
||||||
|
In practice this covers the supported mount-axis absolute-authority cases,
|
||||||
|
including:
|
||||||
|
- paired servo absolute encoders
|
||||||
|
- paired ODrive absolute-authority configuration
|
||||||
|
|
||||||
|
For runtime/NV origin storage:
|
||||||
|
- UINT32_MAX is used as the "origin not established" sentinel
|
||||||
|
|
||||||
|
Compile-time configured nonzero AXIS*_ENCODER_ORIGIN values are treated as
|
||||||
|
already established by configuration.
|
||||||
|
|
||||||
|
## Workflow 1b: Boot With Trusted Mount Coordinate Memory
|
||||||
|
|
||||||
|
Mount coordinate memory acts much like an "effective absolute startup source"
|
||||||
|
in the trust model:
|
||||||
|
- it can re-establish a coordinate basis at boot
|
||||||
|
- but only if the saved record is marked trusted
|
||||||
|
|
||||||
|
Important assumption:
|
||||||
|
- this depends on the mount being moved only by the drive system
|
||||||
|
- if clutches are present, they must not slip and must not be disengaged while
|
||||||
|
coordinate memory is being relied on as a startup authority source
|
||||||
|
|
||||||
|
Mount coordinate memory already uses:
|
||||||
|
- alternating A/B records
|
||||||
|
- CRC validation
|
||||||
|
|
||||||
|
It now also uses a trust bit:
|
||||||
|
- trusted records may restore authority
|
||||||
|
- untrusted records do not restore authority
|
||||||
|
|
||||||
|
This separates:
|
||||||
|
- storage validity
|
||||||
|
- semantic trust
|
||||||
|
|
||||||
|
So coordinate memory is not just "last known position storage." It is also a
|
||||||
|
startup authority source when, and only when, the saved record is trusted.
|
||||||
|
|
||||||
|
## Workflow 2: Boot Without Immediate Startup Authority
|
||||||
|
|
||||||
|
What happens here depends on MOUNT_STARTUP_MODE.
|
||||||
|
|
||||||
|
In SA_STRICT:
|
||||||
|
- if the mount has neither:
|
||||||
|
- paired mount-axis absolute position sources
|
||||||
|
- trusted mount coordinate memory
|
||||||
|
- trust is not granted automatically at startup
|
||||||
|
|
||||||
|
In SA_AUTO:
|
||||||
|
- if the mount has neither:
|
||||||
|
- paired mount-axis absolute position sources
|
||||||
|
- mount coordinate memory enabled
|
||||||
|
- boot grants legacy session trust automatically
|
||||||
|
- this preserves the long-standing "power up and goto" workflow on simpler
|
||||||
|
mounts
|
||||||
|
|
||||||
|
If mount coordinate memory is configured but the saved record is missing or
|
||||||
|
untrusted, SA_AUTO does not silently fall back to permissive trust. In that
|
||||||
|
case the system stays untrusted until an authoritative action succeeds.
|
||||||
|
|
||||||
|
In SA_PERMISSIVE:
|
||||||
|
- boot grants session trust automatically regardless of startup authority
|
||||||
|
sources
|
||||||
|
|
||||||
|
Current recovery model:
|
||||||
|
1. user manually guides to a known place if needed
|
||||||
|
2. user performs an authoritative action:
|
||||||
|
- set origin
|
||||||
|
- authoritative reset at a known home position
|
||||||
|
- successful switch-based home
|
||||||
|
- reboot with a valid startup authority source
|
||||||
|
3. trust becomes true again
|
||||||
|
|
||||||
|
Important practical consequence:
|
||||||
|
- the default SA_AUTO mode preserves permissive startup for simple mounts with
|
||||||
|
neither paired absolute position sources nor coordinate memory enabled
|
||||||
|
- SA_STRICT remains available for observatory and interlock-sensitive installs
|
||||||
|
|
||||||
|
## Workflow 3: Boot Untrusted, Then Establish Trust With Auto-Home
|
||||||
|
|
||||||
|
Auto-home with switches is best thought of as deferred startup authority.
|
||||||
|
|
||||||
|
It is not an immediate startup authority source.
|
||||||
|
Instead:
|
||||||
|
- boot begins untrusted
|
||||||
|
- switch-based home runs
|
||||||
|
- if successful, trust is established afterward
|
||||||
|
|
||||||
|
Switch-based home and auto-home-at-boot share the same sensed-home path.
|
||||||
|
|
||||||
|
Success:
|
||||||
|
- successful sensed home leads to authoritative reset
|
||||||
|
- trust is restored
|
||||||
|
|
||||||
|
Failure:
|
||||||
|
- coordinates are still reset for consistency
|
||||||
|
- failure is latched
|
||||||
|
- trust is not restored
|
||||||
|
- auto-home at boot does not continue as if homing succeeded
|
||||||
|
|
||||||
|
This behavior is intentionally consistent with normal switch-based return/home,
|
||||||
|
not just boot homing.
|
||||||
|
|
||||||
|
## Coordinate memory during homing
|
||||||
|
|
||||||
|
Important edge case:
|
||||||
|
when switch-based homing is in progress, mount coordinates are effectively
|
||||||
|
arbitrary relative to physical truth.
|
||||||
|
|
||||||
|
To prevent a power loss during homing from producing a misleading trusted
|
||||||
|
restore candidate:
|
||||||
|
- coordinate memory is marked untrusted as soon as switch-based homing starts
|
||||||
|
- periodic saves during HS_HOMING remain untrusted
|
||||||
|
- after successful authoritative homing, trust is restored normally
|
||||||
|
|
||||||
|
So if power is lost mid-home:
|
||||||
|
- the mount will come up with coordinate memory present but untrusted
|
||||||
|
- automatic coordinate-based motion will remain blocked
|
||||||
|
- the user can home/reset again, regain trust, and continue
|
||||||
|
|
||||||
|
## Workflow 4: Date/Time Not Ready
|
||||||
|
|
||||||
|
Date/time readiness and startup trust are related but not the same thing.
|
||||||
|
|
||||||
|
Trust answers:
|
||||||
|
- "Do we believe the coordinate basis is valid?"
|
||||||
|
|
||||||
|
Date/time answers:
|
||||||
|
- "Can we safely/usefully perform sky-referenced operations right now?"
|
||||||
|
|
||||||
|
So a mount may have trust while date/time is still not ready.
|
||||||
|
|
||||||
|
In that state:
|
||||||
|
- the coordinate basis may still be considered authoritative
|
||||||
|
- but some operations may remain postponed or blocked until date/time is ready
|
||||||
|
|
||||||
|
For mounts using trusted coordinate memory restore or trusted paired absolute
|
||||||
|
startup position:
|
||||||
|
- once date/time becomes ready, limit enforcement can be enabled immediately
|
||||||
|
- this does not require a later goto, reset/home, or unpark just to make
|
||||||
|
limits active
|
||||||
|
- that in turn allows tracking requests to succeed normally under the usual
|
||||||
|
limit-safety policy
|
||||||
|
|
||||||
|
Example:
|
||||||
|
- unpark recovery may wait for the normal site/time flow even when trust is
|
||||||
|
already valid
|
||||||
|
|
||||||
|
## Workflow 5: Losing Trust During Runtime
|
||||||
|
|
||||||
|
If trust is lost after startup:
|
||||||
|
- coordinate-based automatic motion stops being allowed
|
||||||
|
- manual guide recovery remains available
|
||||||
|
- sidereal tracking is still not gated by startup authority itself, but it
|
||||||
|
remains subject to the normal tracking safety policy
|
||||||
|
|
||||||
|
The guiding rule is:
|
||||||
|
- if the system knows where it is, coordinate-based automatic motion is allowed
|
||||||
|
- if it does not know where it is, coordinate-based automatic motion is blocked
|
||||||
|
- guide-based manual recovery remains available
|
||||||
|
|
||||||
|
## Important startup workflows to remember
|
||||||
|
|
||||||
|
1. Basic mount with clutches, no absolute encoders, no coordinate memory:
|
||||||
|
- common user workflow is manually place at home, power on, then goto/sync
|
||||||
|
- SA_AUTO preserves this by granting session trust at boot
|
||||||
|
- SA_STRICT intentionally blocks this until an authoritative action succeeds
|
||||||
|
|
||||||
|
2. Mount without coordinate memory and without clutches:
|
||||||
|
- mount may power up far from home
|
||||||
|
- user must guide back to home
|
||||||
|
- then perform an authoritative home/reset action
|
||||||
|
- then begin normal operation
|
||||||
|
- current model fits this workflow well
|
||||||
|
|
||||||
|
3. User wants only sidereal tracking at startup:
|
||||||
|
- trust does not gate sidereal tracking by itself
|
||||||
|
- but default safety behavior still disallows tracking when limits are not
|
||||||
|
enforced
|
||||||
|
- this is intentional and should remain so
|
||||||
|
|
||||||
|
## NV policy
|
||||||
|
|
||||||
|
The compile-time switch:
|
||||||
|
- NV_INIT_ERROR_REVOKES_AUTHORITY
|
||||||
|
|
||||||
|
Default:
|
||||||
|
- ON
|
||||||
|
|
||||||
|
Meaning:
|
||||||
|
- if NV reports an init/read fault that may undermine coordinate or motion
|
||||||
|
confidence, trust is not granted or is revoked
|
||||||
|
|
||||||
|
This is intentionally strict, but it has an escape hatch for expert use.
|
||||||
|
|
||||||
|
## Status exposure
|
||||||
|
|
||||||
|
The trust state is exposed in :Gu# so clients can detect it without extra
|
||||||
|
status calls.
|
||||||
|
|
||||||
|
Longer term, a small circular event log is probably a better place to record
|
||||||
|
why trust changed than trying to pack too much into live status.
|
||||||
|
|
||||||
|
## Open future work
|
||||||
|
|
||||||
|
- circular timestamped event log for trust loss/recovery reasons
|
||||||
|
- possibly record a simple trust-loss reason code
|
||||||
|
- maybe future fault-tolerant KV/partition design
|
||||||
|
- refine the basic clutch/manual-home startup case so normal users are not
|
||||||
|
surprised while still preserving the stricter safety model for systems with
|
||||||
|
stronger authority sources
|
||||||
Executable
BIN
Binary file not shown.
Executable
+76
@@ -0,0 +1,76 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// Common includes
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define SERIAL_LOCAL_MODE ON
|
||||||
|
#define STANDARD_IPSERIAL_CHANNEL ON
|
||||||
|
#define PERSISTENT_IPSERIAL_CHANNEL ON
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "Constants.h"
|
||||||
|
#include "lib/Constants.h"
|
||||||
|
#include "../Config.h"
|
||||||
|
#include "Config.defaults.h"
|
||||||
|
|
||||||
|
#ifdef USES_HW_SPI
|
||||||
|
#include <SPI.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "HAL/HAL.h"
|
||||||
|
#include "lib/Macros.h"
|
||||||
|
#include "pinmaps/Models.h"
|
||||||
|
#include "lib/debug/Debug.h"
|
||||||
|
|
||||||
|
#if ST4_HAND_CONTROL == ON
|
||||||
|
#define SERIAL_ST4_MASTER ON
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if AXIS1_DRIVER_MODEL != OFF && AXIS2_DRIVER_MODEL != OFF
|
||||||
|
#define MOUNT_PRESENT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if AXIS3_DRIVER_MODEL != OFF
|
||||||
|
#define ROTATOR_PRESENT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if AXIS4_DRIVER_MODEL != OFF || AXIS5_DRIVER_MODEL != OFF || AXIS6_DRIVER_MODEL != OFF || AXIS7_DRIVER_MODEL != OFF || AXIS8_DRIVER_MODEL != OFF || AXIS9_DRIVER_MODEL != OFF
|
||||||
|
#define FOCUSER_PRESENT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FEATURE1_PURPOSE != OFF || FEATURE2_PURPOSE != OFF || FEATURE3_PURPOSE != OFF || FEATURE4_PURPOSE != OFF || FEATURE5_PURPOSE != OFF || FEATURE6_PURPOSE != OFF || FEATURE7_PURPOSE != OFF || FEATURE8_PURPOSE != OFF
|
||||||
|
#define FEATURES_PRESENT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FEATURE1_PURPOSE == DEW_HEATER || FEATURE2_PURPOSE == DEW_HEATER || FEATURE3_PURPOSE == DEW_HEATER || FEATURE4_PURPOSE == DEW_HEATER || FEATURE5_PURPOSE == DEW_HEATER || FEATURE6_PURPOSE == DEW_HEATER || FEATURE7_PURPOSE == DEW_HEATER || FEATURE8_PURPOSE == DEW_HEATER
|
||||||
|
#define DEW_HEATER_PRESENT
|
||||||
|
|
||||||
|
#if (FEATURE1_TEMP & DS_MASK) == DS1820 || (FEATURE2_TEMP & DS_MASK) == DS1820 || (FEATURE3_TEMP & DS_MASK) == DS1820 || (FEATURE4_TEMP & DS_MASK) == DS1820 || \
|
||||||
|
(FEATURE5_TEMP & DS_MASK) == DS1820 || (FEATURE6_TEMP & DS_MASK) == DS1820 || (FEATURE7_TEMP & DS_MASK) == DS1820 || (FEATURE8_TEMP & DS_MASK) == DS1820 || \
|
||||||
|
(FEATURE1_TEMP & DS_MASK) == DS18S20 || (FEATURE2_TEMP & DS_MASK) == DS18S20 || (FEATURE3_TEMP & DS_MASK) == DS18S20 || (FEATURE4_TEMP & DS_MASK) == DS18S20 || \
|
||||||
|
(FEATURE5_TEMP & DS_MASK) == DS18S20 || (FEATURE6_TEMP & DS_MASK) == DS18S20 || (FEATURE7_TEMP & DS_MASK) == DS18S20 || (FEATURE8_TEMP & DS_MASK) == DS18S20
|
||||||
|
#define DS1820_DEVICES_PRESENT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FEATURE1_TEMP == THERMISTOR1 || FEATURE2_TEMP == THERMISTOR1 || FEATURE3_TEMP == THERMISTOR1 || FEATURE4_TEMP == THERMISTOR1 || \
|
||||||
|
FEATURE5_TEMP == THERMISTOR1 || FEATURE6_TEMP == THERMISTOR1 || FEATURE7_TEMP == THERMISTOR1 || FEATURE8_TEMP == THERMISTOR1 || \
|
||||||
|
FEATURE1_TEMP == THERMISTOR2 || FEATURE2_TEMP == THERMISTOR2 || FEATURE3_TEMP == THERMISTOR2 || FEATURE4_TEMP == THERMISTOR2 || \
|
||||||
|
FEATURE5_TEMP == THERMISTOR2 || FEATURE6_TEMP == THERMISTOR2 || FEATURE7_TEMP == THERMISTOR2 || FEATURE8_TEMP == THERMISTOR2
|
||||||
|
#define THERMISTOR_DEVICES_PRESENT
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FEATURE1_PURPOSE == COVER_SWITCH || FEATURE2_PURPOSE == COVER_SWITCH || FEATURE3_PURPOSE == COVER_SWITCH || FEATURE4_PURPOSE == COVER_SWITCH || FEATURE5_PURPOSE == COVER_SWITCH || FEATURE6_PURPOSE == COVER_SWITCH || FEATURE7_PURPOSE == COVER_SWITCH || FEATURE8_PURPOSE == COVER_SWITCH
|
||||||
|
#define COVER_SWITCH_SERVO_PRESENT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (FOCUSER_TEMPERATURE & DS_MASK) == DS1820 || (FOCUSER_TEMPERATURE & DS_MASK) == DS18S20
|
||||||
|
#ifndef DS1820_DEVICES_PRESENT
|
||||||
|
#define DS1820_DEVICES_PRESENT
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FOCUSER_TEMPERATURE == THERMISTOR1 || FOCUSER_TEMPERATURE == THERMISTOR2
|
||||||
|
#ifndef THERMISTOR_DEVICES_PRESENT
|
||||||
|
#define THERMISTOR_DEVICES_PRESENT
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
Executable
+2460
File diff suppressed because it is too large
Load Diff
Executable
+163
@@ -0,0 +1,163 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// Constants
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Configuration options ----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// PINMAPS
|
||||||
|
#define PINMAP_FIRST 1
|
||||||
|
|
||||||
|
#define FYSETC_E4 1 // FYSETC E4 Version 1.0, *** EXPERIMENTAL, MAY BE REMOVED AT ANY TIME ***
|
||||||
|
|
||||||
|
#define FYSETC_S6 2 // FYSETC S6 Version 1.2, 3D printer board, a 6-axis design
|
||||||
|
#define FYSETC_S6_1 3 // FYSETC S6 Version 1.2
|
||||||
|
#define FYSETC_S6_2 4 // FYSETC S6 Version 2.0, 3D printer board, a 6-axis design
|
||||||
|
|
||||||
|
#define BTT_SKR_PRO 5 // BigTreeTech SKR PRO Version 1.2
|
||||||
|
#define BTT_OCTOPUS_PRO 6 // BigTreeTech Octopus Pro Version 1.1
|
||||||
|
|
||||||
|
#define MiniPCB 7 // small 2-axis design for embedded or mounting behind a panel, Teensy3.2
|
||||||
|
#define MiniPCB13 8 // improved version 1.3 adds better support for ESP-01 flashing and optional I2C
|
||||||
|
|
||||||
|
#define MiniPCB2 9 // 2-axis design for small alum. case, Teensy3.2
|
||||||
|
|
||||||
|
#define MaxPCB 10 // first generation custom 4-axis board, Teensy3.5/Teensy3.6
|
||||||
|
#define MaxPCB2 11 // second generation adds alum. case, Teensy3.5/Teensy3.6
|
||||||
|
#define MaxPCB3 12 // third generation adds SPI four axis support, Teensy4.1
|
||||||
|
#define MaxPCB4 13 // forth generation with SPI/TMC2209 support, Teensy4.1
|
||||||
|
#define RESERVED 14 // RESERVED
|
||||||
|
|
||||||
|
#define MaxSTM3 15 // update to the MaxPCB3 using an Blackpill F411CE instead of the Teensy3.5/3.6
|
||||||
|
#define MaxSTM3I 16 // as above but using an onboard STM32F411CE with M24C64 EEPROM as default
|
||||||
|
|
||||||
|
#define MaxESP3 17 // adds 4th axis and option to flash the WeMos D1 Mini WiFi through OnStep
|
||||||
|
#define MaxESP4 18 // for ESP32S w/TMC2209 support
|
||||||
|
#define CNC3 19 // Arduino CNC Sheild on WeMos D1 R32 (ESP32)
|
||||||
|
#define MicroScope 20 // MicroScope PCB (ESP32, experimental and may be removed at any point!, USE AY YOUR OWN RISK!!!)
|
||||||
|
|
||||||
|
#define STM32Blue 21 // Khalid and Dave's PCB for STM32 Blue pill (STM32F103CB and STM32F303CC)
|
||||||
|
|
||||||
|
#define JTWSTM 22 // JTW Astronomy JTWSTM telescope mount controller Rev 2.1
|
||||||
|
#define MANTICORE 23 // JTW Astronomy MANTICORE telescope mount controller Rev 1.0
|
||||||
|
|
||||||
|
#define SAL_XB1 24 // SAL-XB1 telescope mount controller
|
||||||
|
|
||||||
|
#define PINMAP_LAST 24
|
||||||
|
|
||||||
|
// WEATHER sensors (temperature, pressure, and humidity)
|
||||||
|
#define WEATHER_FIRST 1
|
||||||
|
#define BME280 1 // BME280 on I2C (at default address 0x77)
|
||||||
|
#define BME280_0x77 1 // BME280 on I2C (at address 0x77)
|
||||||
|
#define BME280_0x76 2 // BME280 on I2C (at address 0x76)
|
||||||
|
#define BME280_SPI 3 // BME280 on SPI (default CS)
|
||||||
|
#define BMP280 4 // BMP280 on I2C (at default address 0x77)
|
||||||
|
#define BMP280_0x77 4 // BMP280 on I2C (at address 0x77)
|
||||||
|
#define BMP280_0x76 5 // BMP280 on I2C (at address 0x76)
|
||||||
|
#define BMP280_SPI 6 // BMP280 on SPI (default CS)
|
||||||
|
#define WEATHER_LAST 6
|
||||||
|
|
||||||
|
// STEP WAVE FORM
|
||||||
|
#define STEP_WAVE_FORM_FIRST 1
|
||||||
|
#define SQUARE 1
|
||||||
|
#define PULSE 2
|
||||||
|
#define STEP_WAVE_FORM_LAST 2
|
||||||
|
|
||||||
|
// MOUNT TYPE
|
||||||
|
#define MOUNT_TYPE_FIRST 1
|
||||||
|
#define MOUNT_SUBTYPE_FIRST 1
|
||||||
|
#define GEM 1 // German Equatorial Mount, meridian flips enabled
|
||||||
|
#define FORK 2 // Fork Mount, meridian flips disabled
|
||||||
|
#define ALTAZM 3 // Altitude Azimuth Mounts, Dobsonians, etc.
|
||||||
|
#define ALTALT 4 // Altitude Altitude Mounts
|
||||||
|
#define MOUNT_SUBTYPE_LAST 4
|
||||||
|
#define GEM_TA 5 // GEM, w/tangent arm Declination
|
||||||
|
#define GEM_TAC 6 // GEM, w/tangent arm Declination and geometry correction
|
||||||
|
#define FORK_TA 7 // FORK, w/tangent arm Declination
|
||||||
|
#define FORK_TAC 8 // FORK, w/tangent arm Declination and geometry correction
|
||||||
|
#define ALTAZM_UNL 9 // ALTAZM, w/unlimited Azmiuth motion
|
||||||
|
#define MOUNT_TYPE_LAST 9
|
||||||
|
|
||||||
|
// MOUNT COORDS
|
||||||
|
#define MOUNT_COORDS_FIRST 1
|
||||||
|
#define OBSERVED_PLACE 1
|
||||||
|
#define TOPOCENTRIC 2
|
||||||
|
#define TOPO_STRICT 3
|
||||||
|
#define ASTROMETRIC_J2000 4
|
||||||
|
#define MOUNT_COORDS_LAST 4
|
||||||
|
|
||||||
|
// STARTUP AUTHORITY MODE
|
||||||
|
#define SA_STRICT 1
|
||||||
|
#define SA_AUTO 2
|
||||||
|
#define SA_PERMISSIVE 3
|
||||||
|
|
||||||
|
// TIME LOCATION SOURCE devices supported
|
||||||
|
#define TLS_FIRST 1
|
||||||
|
#define DS3231 1 // DS3231 RTC on I2C
|
||||||
|
#define DS3234 2 // DS3234 RTC on SPI (DS3234_CS_PIN) Makuna library
|
||||||
|
#define SD3031 3 // SD3031 RTC on I2C
|
||||||
|
#define TEENSY 4 // TEENSY3.2 RTC (Built-in)
|
||||||
|
#define GPS 5 // GPS device
|
||||||
|
#define NTP 6 // NTP
|
||||||
|
#define TLS_LAST 6
|
||||||
|
|
||||||
|
// PIER SIDE
|
||||||
|
#define PIER_SIDE_FIRST 1
|
||||||
|
#define EAST 1 // same as PSS_EAST
|
||||||
|
#define WEST 2 // same as PSS_WEST
|
||||||
|
#define BEST 3 // same as PSS_BEST
|
||||||
|
#define AUTOMATIC 4 // same as PSS_AUTO
|
||||||
|
#define PIER_SIDE_LAST 4
|
||||||
|
|
||||||
|
// COMPENSATED TRACKING
|
||||||
|
#define COMPENSATED_TRACKING_FIRST 1
|
||||||
|
#define REFRACTION 1 // refraction compensated tracking RA only
|
||||||
|
#define REFRACTION_DUAL 2 // refraction compensated tracking both axes
|
||||||
|
#define MODEL 3 // pointing model compensated tracking RA only
|
||||||
|
#define MODEL_DUAL 4 // pointing model compensated tracking both axes
|
||||||
|
#define COMPENSATED_TRACKING_LAST 4
|
||||||
|
|
||||||
|
// TEMPERATURE sensing devices
|
||||||
|
#define TEMPERATURE_FIRST 1
|
||||||
|
#define DS1820 0x2800000000000000 // DS18B20 1-wire temperature sensors for focusing and dew heaters
|
||||||
|
#define DS18B20 0x2800000000000000 // as above
|
||||||
|
#define DS18S20 0x1000000000000000 // as above, except for DS18S20
|
||||||
|
#define DS_MASK 0x3F00000000000000 // not for use in Config.h
|
||||||
|
#define THERMISTOR 1 // General purpose thermistor sensor, type 1 (see Config.defaults.h)
|
||||||
|
#define THERMISTOR1 1 // as above
|
||||||
|
#define THERMISTOR2 2 // General purpose thermistor sensor, type 2 (see Config.defaults.h)
|
||||||
|
#define TEMPERATURE_LAST 2
|
||||||
|
|
||||||
|
// AUXILIARY FEATURE purpose
|
||||||
|
#define AUX_FEATURE_PURPOSE_FIRST 1
|
||||||
|
#define SWITCH 1 // control an simple on/off switch
|
||||||
|
#define ANALOG_OUTPUT 2 // control an analog (pwm) output, depends on MCU support
|
||||||
|
#define ANALOG_OUT 2 // as above
|
||||||
|
#define DEW_HEATER 3 // control an dew heater
|
||||||
|
#define INTERVALOMETER 4 // control an camera shutter
|
||||||
|
#define MOMENTARY_SWITCH 5 // control an simple momentary on/off switch
|
||||||
|
#define HIDDEN_SWITCH 6 // control an hidden on/off switch (for controlling a pin state at boot)
|
||||||
|
#define COVER_SWITCH 7 // control an servo driven OTA cover where "on" is closed and "off" is open
|
||||||
|
#define AUX_FEATURE_PURPOSE_LAST 7
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// task manager
|
||||||
|
#define TASKS_MAX 60 // up to 60 tasks
|
||||||
|
#define TASKS_SKIP_MISSED // just skip missed tasks if too late
|
||||||
|
#ifdef ESP32
|
||||||
|
#define TASKS_HWTIMERS 4 // up to 4 hardware timers
|
||||||
|
#else
|
||||||
|
#define TASKS_HWTIMERS 3
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// default start of axis class hardware timers
|
||||||
|
#define AXIS_HARDWARE_TIMER_BASE 2 // in the OnStepX timer#1 is the sidereal clock
|
||||||
|
|
||||||
|
// enable library features
|
||||||
|
#define SERIAL_LOCAL_PRESENT
|
||||||
|
#define SERIAL_ST4_SERVER_PRESENT
|
||||||
|
|
||||||
|
// NV -------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// unique volume signature for this volume/partition layout
|
||||||
|
#define NV_VOLUME_SIGNATURE 0x0001u
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// HAL global variables
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
// Must match the externs in HAL_FAST_TICKS.h exactly
|
||||||
|
uint32_t _halTicksPerSecond = 1000000UL;
|
||||||
|
uint32_t _halTicksPerMicro = 1;
|
||||||
Executable
+190
@@ -0,0 +1,190 @@
|
|||||||
|
/*
|
||||||
|
* Hardware Abstraction Layer (HAL) for OnStep
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 Khalid Baheyeldin
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// null decoration for non-ESP processors
|
||||||
|
#ifndef IRAM_ATTR
|
||||||
|
#define IRAM_ATTR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ICACHE_RAM_ATTR
|
||||||
|
#define ICACHE_RAM_ATTR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FPSTR
|
||||||
|
#define FPSTR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "HAL_FAST_TICKS.h"
|
||||||
|
|
||||||
|
#if defined(__AVR_ATmega328P__)
|
||||||
|
#define MCU_STR "AtMega328"
|
||||||
|
#include "atmel/Mega328.h"
|
||||||
|
|
||||||
|
#elif defined(__AVR_ATmega1280__)
|
||||||
|
#define MCU_STR "Mega1280"
|
||||||
|
#include "atmel/Mega2560.h"
|
||||||
|
|
||||||
|
#elif defined(__AVR_ATmega2560__)
|
||||||
|
#define MCU_STR "Mega2560"
|
||||||
|
#include "atmel/Mega2560.h"
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_UNOWIFIR4)
|
||||||
|
// Arduino UNO R4 WIFI
|
||||||
|
#define MCU_STR "RENESAS RA4M1 (Arduino UNO R4 WIFI)"
|
||||||
|
#include "esp32/ESP32UnoR4WiFi.h"
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_SAMD)
|
||||||
|
// ARDUINO M0
|
||||||
|
#define MCU_STR "ARDUINO M0"
|
||||||
|
#include "arduinoM0/ArduinoM0.h"
|
||||||
|
|
||||||
|
#elif defined(ESP32) && ESP_ARDUINO_VERSION >= 0x30000
|
||||||
|
// ESP32 w/libraries 3.x
|
||||||
|
#define MCU_STR "ESP32"
|
||||||
|
#include "esp/ESP32Libraries3.h"
|
||||||
|
|
||||||
|
#elif defined(ESP32) && ESP_ARDUINO_VERSION >= 0x20000
|
||||||
|
// ESP32 w/libraries 2.x
|
||||||
|
#define MCU_STR "ESP32"
|
||||||
|
#include "esp/ESP32Libraries2.h"
|
||||||
|
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
// ESP8266
|
||||||
|
#define MCU_STR "ESP8266"
|
||||||
|
#include "esp/ESP8266.h"
|
||||||
|
|
||||||
|
#elif defined(STM32F103xB)
|
||||||
|
// STM32F103C8/CB: 72MHz, 128K flash, 64K RAM, ARM Cortex M3
|
||||||
|
#define MCU_STR "STM32F103"
|
||||||
|
#include "stm32/STM32F103.h"
|
||||||
|
|
||||||
|
#elif defined(STM32F303xC)
|
||||||
|
// RobotDyn BlackPill STM32F303, 256K flash, ARM Cortex M4 (STM32duino board manager)
|
||||||
|
#define MCU_STR "STM32F303"
|
||||||
|
#include "stm32/STM32F303.h"
|
||||||
|
|
||||||
|
#elif defined(STM32F401xC)
|
||||||
|
// Blackpill board with STM32F401CC
|
||||||
|
#define MCU_STR "STM32F401"
|
||||||
|
#include "stm32/STM32F4x1.h"
|
||||||
|
|
||||||
|
#elif defined(STM32F411xE)
|
||||||
|
// Blackpill board with STM32F411CE
|
||||||
|
#define MCU_STR "STM32F411"
|
||||||
|
#include "stm32/STM32F4x1.h"
|
||||||
|
|
||||||
|
#elif defined(STM32F407xx)
|
||||||
|
// BTT SKR PRO board with STM32F407
|
||||||
|
#define MCU_STR "STM32F407"
|
||||||
|
#include "stm32/STM32F407.h"
|
||||||
|
|
||||||
|
#elif defined(STM32F446xx)
|
||||||
|
// FYSETC S6 board with STM32F446
|
||||||
|
#define MCU_STR "STM32F446"
|
||||||
|
#include "stm32/STM32F446.h"
|
||||||
|
|
||||||
|
#elif defined(STM32H723xx)
|
||||||
|
#define MCU_STR "STM32H723"
|
||||||
|
#include "stm32/STM32H7xx.h"
|
||||||
|
|
||||||
|
#elif defined(STM32H743xx)
|
||||||
|
// WeAct Studio board with STM32H743
|
||||||
|
#define MCU_STR "STM32H743"
|
||||||
|
#include "stm32/STM32H7xx.h"
|
||||||
|
|
||||||
|
#elif defined(STM32H750xx)
|
||||||
|
// WeAct Studio board with STM32H750
|
||||||
|
#define MCU_STR "STM32H750"
|
||||||
|
#include "stm32/STM32H7xx.h"
|
||||||
|
|
||||||
|
#elif defined(_mk20dx128_h_) || defined(__MK20DX128__)
|
||||||
|
// Teensy 3.0
|
||||||
|
#define MCU_STR "Teensy3.0"
|
||||||
|
#include "teensy/Teensy3.2.h"
|
||||||
|
|
||||||
|
#elif defined(__MK20DX256__)
|
||||||
|
// Teensy 3.2
|
||||||
|
#define MCU_STR "Teensy3.2"
|
||||||
|
#include "teensy/Teensy3.2.h"
|
||||||
|
|
||||||
|
#elif defined(__MK64FX512__)
|
||||||
|
// Teensy 3.5
|
||||||
|
#define MCU_STR "Teensy3.5"
|
||||||
|
#include "teensy/Teensy3.5.h"
|
||||||
|
|
||||||
|
#elif defined(__MK66FX1M0__)
|
||||||
|
// Teensy 3.6
|
||||||
|
#define MCU_STR "Teensy3.6"
|
||||||
|
#include "teensy/Teensy3.6.h"
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_TEENSY40)
|
||||||
|
// Teensy 4.0
|
||||||
|
#define MCU_STR "Teensy4.0"
|
||||||
|
#include "teensy/Teensy4.0.h"
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_TEENSY41)
|
||||||
|
// Teensy 4.1
|
||||||
|
#define MCU_STR "Teensy4.1"
|
||||||
|
#include "teensy/Teensy4.1.h"
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_TEENSY_MICROMOD)
|
||||||
|
// Teensy MicroMod
|
||||||
|
#define MCU_STR "TeensyMicroMod"
|
||||||
|
#include "teensy/Teensy4.1.h"
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
|
// Raspberry pi pico
|
||||||
|
#define MCU_STR "Raspberry Pi Pico"
|
||||||
|
#include "mbed/Rpi2040.h"
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2350)
|
||||||
|
// Raspberry pi pico2
|
||||||
|
#define MCU_STR "Raspberry Pi Pico2"
|
||||||
|
#include "mbed/Rpi2350.h"
|
||||||
|
|
||||||
|
#else
|
||||||
|
// Generic
|
||||||
|
#warning "Unknown Platform! If this is a new platform, it would probably do best with a new HAL designed for it."
|
||||||
|
#define MCU_STR "Generic (Unknown)"
|
||||||
|
#include "default/Default.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "HAL_ANALOG.h"
|
||||||
|
|
||||||
|
#ifndef HAL_INIT
|
||||||
|
#define HAL_INIT() do { HAL_FAST_TICKS_INIT(); } while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// baseline critical task timing
|
||||||
|
#ifdef HAL_FRACTIONAL_SEC
|
||||||
|
#define FRACTIONAL_SEC HAL_FRACTIONAL_SEC
|
||||||
|
#else
|
||||||
|
#define FRACTIONAL_SEC 100.0F
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// progmem standin for platforms that don't have it
|
||||||
|
#ifndef CAT_ATTR
|
||||||
|
#define CAT_ATTR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// default I2C interface
|
||||||
|
#if defined(HAL_WIRE_CLOCK)
|
||||||
|
#define HAL_WIRE_SET_CLOCK() HAL_WIRE.setClock(HAL_WIRE_CLOCK)
|
||||||
|
#else
|
||||||
|
#define HAL_WIRE_SET_CLOCK()
|
||||||
|
#endif
|
||||||
Executable
+73
@@ -0,0 +1,73 @@
|
|||||||
|
|
||||||
|
// Analog HAL capabilities (defaults) ----------------------------------------------------------------
|
||||||
|
// Defaults: no per-pin control, no global reconfig (safe)
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef HAL_HAS_PER_PIN_PWM_RESOLUTION
|
||||||
|
#define HAL_HAS_PER_PIN_PWM_RESOLUTION 0
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_HAS_PER_PIN_PWM_FREQUENCY
|
||||||
|
#define HAL_HAS_PER_PIN_PWM_FREQUENCY 0
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_HAS_GLOBAL_PWM_RESOLUTION
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_RESOLUTION 0
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_HAS_GLOBAL_PWM_FREQUENCY
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_FREQUENCY 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAL_HAS_PER_PIN_ADC_RESOLUTION
|
||||||
|
#define HAL_HAS_PER_PIN_ADC_RESOLUTION 0
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_HAS_GLOBAL_ADC_RESOLUTION
|
||||||
|
#define HAL_HAS_GLOBAL_ADC_RESOLUTION 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAL_ALLOW_GLOBAL_PWM_RECONFIG
|
||||||
|
#define HAL_ALLOW_GLOBAL_PWM_RECONFIG 0
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_ALLOW_GLOBAL_ADC_RECONFIG
|
||||||
|
#define HAL_ALLOW_GLOBAL_ADC_RECONFIG 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// reasonable bounds (overridden per platform below)
|
||||||
|
#ifndef HAL_PWM_BITS_MIN
|
||||||
|
#define HAL_PWM_BITS_MIN 1
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_PWM_BITS_MAX
|
||||||
|
#define HAL_PWM_BITS_MAX 16
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_ADC_BITS_MIN
|
||||||
|
#define HAL_ADC_BITS_MIN 1
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_ADC_BITS_MAX
|
||||||
|
#define HAL_ADC_BITS_MAX 12
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_PWM_HZ_MIN
|
||||||
|
#define HAL_PWM_HZ_MIN 1U
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_PWM_HZ_MAX
|
||||||
|
#define HAL_PWM_HZ_MAX 40000U
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// some validation
|
||||||
|
#if HAL_PWM_BITS_MIN < 1 || HAL_PWM_BITS_MIN > 32
|
||||||
|
#error "Error: HAL_PWM_BITS_MIN outside of 1 to 32 range."
|
||||||
|
#endif
|
||||||
|
#if HAL_PWM_BITS_MAX < 1 || HAL_PWM_BITS_MAX > 32
|
||||||
|
#error "Error: HAL_PWM_BITS_MAX outside of 1 to 32 range."
|
||||||
|
#endif
|
||||||
|
#if HAL_ADC_BITS_MIN < 1 || HAL_ADC_BITS_MIN > 32
|
||||||
|
#error "Error: HAL_ADC_BITS_MIN outside of 1 to 32 range."
|
||||||
|
#endif
|
||||||
|
#if HAL_ADC_BITS_MAX < 1 || HAL_ADC_BITS_MAX > 32
|
||||||
|
#error "Error: HAL_ADC_BITS_MAX outside of 1 to 32 range."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// global default ranges
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023U // 2^n - 1
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255U // 2^n - 1
|
||||||
|
#endif
|
||||||
Executable
+248
@@ -0,0 +1,248 @@
|
|||||||
|
// -------------------------------------------------------------------------------------------------
|
||||||
|
// HAL_FAST_TICKS.h
|
||||||
|
//
|
||||||
|
// Fast ticks: 32-bit wrapping timestamp intended for ISRs / high-rate timing.
|
||||||
|
//
|
||||||
|
// Interface:
|
||||||
|
// HAL_FAST_TICKS_INIT() call once at startup (safe no-op where not needed)
|
||||||
|
// HAL_FAST_TICKS() returns uint32_t ticks (wrapping OK)
|
||||||
|
// HAL_TICKS_PER_SECOND() returns uint32_t tick frequency in Hz (cached)
|
||||||
|
// delayNanoseconds(ns) short busy-wait delay (NOT intended for ISR use)
|
||||||
|
// nanoseconds32() convenience conversion (NOT intended for ISR use)
|
||||||
|
//
|
||||||
|
// Policy (as requested):
|
||||||
|
// - Teensy 3.x/4.x: use DWT->CYCCNT (enable once).
|
||||||
|
// - ESP32 Xtensa (ESP32/S2/S3): use CCOUNT.
|
||||||
|
// - ESP8266: use ESP.getCycleCount().
|
||||||
|
// - STM32: most use micros(), STM32H723/H743/H750 use DWT->CYCCNT.
|
||||||
|
// - ESP32 RISC-V (C3/C6/H2): use micros().
|
||||||
|
// - Everything else: use micros().
|
||||||
|
//
|
||||||
|
// Notes:
|
||||||
|
// - Tick frequency is cached in _halTicksPerSecond/_halTicksPerMicro (defined in HAL.cpp).
|
||||||
|
// -------------------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
// Make header self-contained (HAL.h may not have been included yet)
|
||||||
|
#ifndef IRAM_ATTR
|
||||||
|
#define IRAM_ATTR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Must be defined once in HAL.cpp:
|
||||||
|
// uint32_t _halTicksPerSecond = 1000000UL;
|
||||||
|
// uint32_t _halTicksPerMicro = 1;
|
||||||
|
extern uint32_t _halTicksPerSecond;
|
||||||
|
extern uint32_t _halTicksPerMicro;
|
||||||
|
|
||||||
|
// ----------------------------------------
|
||||||
|
// Platform identification helpers
|
||||||
|
// ----------------------------------------
|
||||||
|
|
||||||
|
// Teensy (3.x/4.x) detection
|
||||||
|
#if defined(TEENSYDUINO) || defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41) || \
|
||||||
|
defined(ARDUINO_TEENSY_MICROMOD) || \
|
||||||
|
defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) || \
|
||||||
|
defined(__IMXRT1062__)
|
||||||
|
#define HAL_IS_TEENSY 1
|
||||||
|
#else
|
||||||
|
#define HAL_IS_TEENSY 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// STM32 H7 detection (STM32duino)
|
||||||
|
#if defined(ARDUINO_ARCH_STM32) && (defined(STM32H723xx) || defined(STM32H743xx) || defined(STM32H750xx))
|
||||||
|
#define HAL_IS_STM32_H7 1
|
||||||
|
#else
|
||||||
|
#define HAL_IS_STM32_H7 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ESP32 RISC-V detection (C3/C6/H2)
|
||||||
|
#if (defined(ARDUINO_ARCH_ESP32) || defined(ESP_PLATFORM)) && (defined(__riscv) || defined(__riscv__))
|
||||||
|
#define HAL_IS_ESP32_RISCV 1
|
||||||
|
#else
|
||||||
|
#define HAL_IS_ESP32_RISCV 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ESP32 Xtensa detection (ESP32/S2/S3)
|
||||||
|
#if (defined(ARDUINO_ARCH_ESP32) || defined(ESP_PLATFORM)) && (defined(__XTENSA__) || defined(__xtensa__))
|
||||||
|
#define HAL_IS_ESP32_XTENSA 1
|
||||||
|
#else
|
||||||
|
#define HAL_IS_ESP32_XTENSA 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ----------------------------------------
|
||||||
|
// Platform-specific fast tick source
|
||||||
|
// ----------------------------------------
|
||||||
|
|
||||||
|
// ---------- ESP32 Xtensa: CCOUNT ----------
|
||||||
|
#if HAL_IS_ESP32_XTENSA
|
||||||
|
|
||||||
|
static inline uint32_t IRAM_ATTR HAL_FAST_TICKS() {
|
||||||
|
uint32_t ccount;
|
||||||
|
__asm__ __volatile__("rsr %0, ccount" : "=a"(ccount));
|
||||||
|
return ccount;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t HAL_TICKS_PER_SECOND() { return _halTicksPerSecond; }
|
||||||
|
|
||||||
|
static inline void HAL_FAST_TICKS_INIT() {
|
||||||
|
#if defined(F_CPU)
|
||||||
|
_halTicksPerSecond = (uint32_t)F_CPU;
|
||||||
|
#else
|
||||||
|
_halTicksPerSecond = (uint32_t)ESP.getCpuFreqMHz() * 1000000UL;
|
||||||
|
#endif
|
||||||
|
_halTicksPerMicro = _halTicksPerSecond / 1000000UL;
|
||||||
|
if (_halTicksPerMicro == 0) _halTicksPerMicro = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- ESP8266: cycle count ----------
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
|
||||||
|
static inline uint32_t IRAM_ATTR HAL_FAST_TICKS() {
|
||||||
|
return (uint32_t)ESP.getCycleCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t HAL_TICKS_PER_SECOND() { return _halTicksPerSecond; }
|
||||||
|
|
||||||
|
static inline void HAL_FAST_TICKS_INIT() {
|
||||||
|
#if defined(F_CPU)
|
||||||
|
_halTicksPerSecond = (uint32_t)F_CPU; // typically 80 or 160 MHz
|
||||||
|
#else
|
||||||
|
_halTicksPerSecond = 80000000UL;
|
||||||
|
#endif
|
||||||
|
_halTicksPerMicro = _halTicksPerSecond / 1000000UL;
|
||||||
|
if (_halTicksPerMicro == 0) _halTicksPerMicro = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- Teensy 3.x/4.x: DWT->CYCCNT ----------
|
||||||
|
#elif HAL_IS_TEENSY
|
||||||
|
|
||||||
|
static inline void HAL_FAST_TICKS_INIT() {
|
||||||
|
#if defined(DWT) && defined(CoreDebug) && defined(DWT_CTRL_CYCCNTENA_Msk)
|
||||||
|
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||||
|
if ((DWT->CTRL & DWT_CTRL_CYCCNTENA_Msk) == 0) {
|
||||||
|
DWT->CYCCNT = 0; // optional but recommended
|
||||||
|
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
||||||
|
__DSB(); __ISB();
|
||||||
|
}
|
||||||
|
#if defined(F_CPU)
|
||||||
|
_halTicksPerSecond = (uint32_t)F_CPU;
|
||||||
|
#else
|
||||||
|
_halTicksPerSecond = 1000000UL;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
// fallback tick source is micros()
|
||||||
|
_halTicksPerSecond = 1000000UL;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
_halTicksPerMicro = _halTicksPerSecond / 1000000UL;
|
||||||
|
if (_halTicksPerMicro == 0) _halTicksPerMicro = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t HAL_TICKS_PER_SECOND() { return _halTicksPerSecond; }
|
||||||
|
|
||||||
|
static inline uint32_t IRAM_ATTR HAL_FAST_TICKS() {
|
||||||
|
#if defined(DWT) && defined(DWT_CTRL_CYCCNTENA_Msk)
|
||||||
|
return (uint32_t)DWT->CYCCNT;
|
||||||
|
#else
|
||||||
|
return (uint32_t)micros();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// - STM32H7: use DWT->CYCCNT (enable once).
|
||||||
|
// - Other STM32: use micros().
|
||||||
|
#elif HAL_IS_STM32_H7
|
||||||
|
|
||||||
|
// Some STM32 cores expose these via CMSIS headers already included by Arduino.h.
|
||||||
|
// If not, you may need: #include "core_cm7.h"
|
||||||
|
|
||||||
|
static inline void HAL_FAST_TICKS_INIT() {
|
||||||
|
// Ensure SystemCoreClock is up to date (harmless if already correct).
|
||||||
|
#if defined(SystemCoreClockUpdate)
|
||||||
|
SystemCoreClockUpdate();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Enable DWT CYCCNT
|
||||||
|
#if defined(DWT) && defined(CoreDebug) && defined(DWT_CTRL_CYCCNTENA_Msk) && defined(CoreDebug_DEMCR_TRCENA_Msk)
|
||||||
|
// Enable tracing (required to access DWT on Cortex-M)
|
||||||
|
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||||
|
|
||||||
|
#if defined(DWT_LAR)
|
||||||
|
// DWT->LAR = 0xC5ACCE55; // unlock (if implemented)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Enable the cycle counter
|
||||||
|
if ((DWT->CTRL & DWT_CTRL_CYCCNTENA_Msk) == 0) {
|
||||||
|
DWT->CYCCNT = 0;
|
||||||
|
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
||||||
|
__DSB(); __ISB();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tick frequency is core clock
|
||||||
|
#if defined(F_CPU)
|
||||||
|
_halTicksPerSecond = (uint32_t)F_CPU;
|
||||||
|
#elif defined(SystemCoreClock)
|
||||||
|
_halTicksPerSecond = (uint32_t)SystemCoreClock;
|
||||||
|
#else
|
||||||
|
_halTicksPerSecond = 1000000UL; // last-resort fallback
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
// If DWT isn't available for some reason, fall back to micros().
|
||||||
|
_halTicksPerSecond = 1000000UL;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
_halTicksPerMicro = _halTicksPerSecond / 1000000UL;
|
||||||
|
if (_halTicksPerMicro == 0) _halTicksPerMicro = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t HAL_TICKS_PER_SECOND() { return _halTicksPerSecond; }
|
||||||
|
|
||||||
|
static inline uint32_t IRAM_ATTR HAL_FAST_TICKS() {
|
||||||
|
#if defined(DWT) && defined(CoreDebug) && defined(DWT_CTRL_CYCCNTENA_Msk) && defined(CoreDebug_DEMCR_TRCENA_Msk)
|
||||||
|
return (uint32_t)DWT->CYCCNT; // 32-bit wraps naturally
|
||||||
|
#else
|
||||||
|
return (uint32_t)micros(); // fallback
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
static inline void HAL_FAST_TICKS_INIT() {
|
||||||
|
_halTicksPerSecond = 1000000UL;
|
||||||
|
_halTicksPerMicro = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t HAL_TICKS_PER_SECOND() { return _halTicksPerSecond; }
|
||||||
|
|
||||||
|
static inline uint32_t IRAM_ATTR HAL_FAST_TICKS() { return (uint32_t)micros(); }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ----------------------------------------
|
||||||
|
// Helpers (non-ISR intent)
|
||||||
|
// ----------------------------------------
|
||||||
|
|
||||||
|
static inline uint32_t nanoseconds32() {
|
||||||
|
// rolls over ~4.29s when returning uint32_t
|
||||||
|
return (uint32_t)((uint64_t)HAL_FAST_TICKS() * 1000000000ULL / (uint64_t)HAL_TICKS_PER_SECOND());
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t halNsToTicks(uint32_t ns) {
|
||||||
|
// ticks = ns * (ticks/us) / 1000
|
||||||
|
return (uint32_t)(((uint64_t)ns * (uint64_t)_halTicksPerMicro + 999ULL) / 1000ULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !HAL_IS_TEENSY
|
||||||
|
static inline void delayNanoseconds(uint32_t ns) {
|
||||||
|
if (ns >= 20000UL) {
|
||||||
|
delayMicroseconds((ns + 999UL) / 1000UL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const uint32_t wait = halNsToTicks(ns);
|
||||||
|
if (wait == 0) return;
|
||||||
|
const uint32_t start = HAL_FAST_TICKS();
|
||||||
|
while ((uint32_t)(HAL_FAST_TICKS() - start) < wait) { }
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Executable
+57
@@ -0,0 +1,57 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// We define a more generic symbol, in case more Teensy boards based on different lines are supported
|
||||||
|
#define __M0__
|
||||||
|
|
||||||
|
#include <avr/dtostrf.h>
|
||||||
|
|
||||||
|
// Base rate for critical task timing
|
||||||
|
#define HAL_FRACTIONAL_SEC 100.0F
|
||||||
|
|
||||||
|
// Analog read and write
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023 // always use 2^n - 1, within the platform's limits
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_READ_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255 // always use 2^n - 1, within the platform's limits
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_WRITE_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in us for this platform (in SQW mode) and width of step pulse
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 40
|
||||||
|
#define HAL_PULSE_WIDTH 900 // in ns, estimated
|
||||||
|
|
||||||
|
// New symbol for the default I2C port ---------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ------------------------------------------------------------------------------
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
// Library FlashStorage defaults to 1024 bytes https://github.com/cmaglie/FlashStorage
|
||||||
|
#define E2END 1023
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_M0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define HAL_TEMP() ( NAN )
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes and defines to support this processor's operation
|
||||||
|
|
||||||
Executable
+68
@@ -0,0 +1,68 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// We define a more generic symbol, in case more Teensy boards based on different lines are supported
|
||||||
|
// __AVR__
|
||||||
|
|
||||||
|
// 1/100 second resolution
|
||||||
|
#define HAL_FRACTIONAL_SEC 100.0F
|
||||||
|
|
||||||
|
// This platform has 8 bit PWM
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 5.0F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_READ_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_WRITE_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// This platform doesn't support true double precision math
|
||||||
|
#define HAL_NO_DOUBLE_PRECISION
|
||||||
|
|
||||||
|
// This is for ~16MHz AVR processors or similar.
|
||||||
|
#define HAL_SLOW_PROCESSOR
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in us for this platform (in SQW mode) and width of step pulse
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 76.8
|
||||||
|
#define HAL_PULSE_WIDTH 10000 // in ns, estimated
|
||||||
|
|
||||||
|
// New symbol for the default I2C port -------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ----------------------------------------------------------------------------
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_EEPROM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
|
||||||
|
#define HAL_INIT() { \
|
||||||
|
analogReference(DEFAULT); \
|
||||||
|
HAL_FAST_TICKS_INIT(); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define HAL_RESET() mega2560restart();
|
||||||
|
#define HAL_RESET_FUNC void (*mega2560restart) (void) = 0;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define HAL_TEMP() ( NAN )
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
|
|
||||||
|
#define strtof strtod // there is no strtof defined for the AVR platform
|
||||||
Executable
+63
@@ -0,0 +1,63 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// We define a more generic symbol, in case more Teensy boards based on different lines are supported
|
||||||
|
// __AVR__
|
||||||
|
|
||||||
|
// 1/100 second resolution
|
||||||
|
#define HAL_FRACTIONAL_SEC 100.0F
|
||||||
|
|
||||||
|
// This platform has 8 bit PWM
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 5.0F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023 // always use 2^n - 1, within the platform's limits
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_READ_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255 // always use 2^n - 1, within the platform's limits
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_WRITE_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// This platform doesn't support true double precision math
|
||||||
|
#define HAL_NO_DOUBLE_PRECISION
|
||||||
|
|
||||||
|
// This is for ~16MHz AVR processors or similar.
|
||||||
|
#define HAL_SLOW_PROCESSOR
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in us for this platform (in SQW mode) and width of step pulse
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 76.8
|
||||||
|
#define HAL_PULSE_WIDTH 10000 // in ns, estimated
|
||||||
|
|
||||||
|
// New symbol for the default I2C port -------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ----------------------------------------------------------------------------
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_EEPROM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define HAL_TEMP() ( NAN )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
|
||||||
|
#define HAL_INIT() { \
|
||||||
|
analogReference(DEFAULT); \
|
||||||
|
HAL_FAST_TICKS_INIT(); \
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
Executable
+55
@@ -0,0 +1,55 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// We define a more generic symbol, in case more Platform_Name boards based on different lines are supported
|
||||||
|
|
||||||
|
// Base rate for critical task timing
|
||||||
|
#define HAL_FRACTIONAL_SEC 100.0F
|
||||||
|
|
||||||
|
// Analog read and write
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_READ_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_WRITE_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in uS for this platform (in SQW mode) and width of step pulse
|
||||||
|
#ifndef HAL_MAXRATE_LOWER_LIMIT
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 60
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_PULSE_WIDTH
|
||||||
|
#define HAL_PULSE_WIDTH 10000 // in ns, estimated
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// New symbol for the default I2C port -------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ----------------------------------------------------------------------------
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_EEPROM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define HAL_TEMP() ( NAN )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
Executable
+96
@@ -0,0 +1,96 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// This is for fast processors with hardware FP
|
||||||
|
#define HAL_FAST_PROCESSOR
|
||||||
|
|
||||||
|
// Base rate for critical task timing (0.0095s = 0.14", 0.2 sec/day)
|
||||||
|
#define HAL_FRACTIONAL_SEC 105.2631579F
|
||||||
|
|
||||||
|
// Analog read and write
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023 // always use 2^n - 1, within the platform's limits
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255 // always use 2^n - 1, within the platform's limits
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// analog read/write capabilities
|
||||||
|
#define HAL_HAS_PER_PIN_PWM_RESOLUTION 0
|
||||||
|
#define HAL_HAS_PER_PIN_PWM_FREQUENCY 0
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_RESOLUTION 1
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_FREQUENCY 1
|
||||||
|
#define HAL_PWM_HZ_MAX 200000U
|
||||||
|
|
||||||
|
#define HAL_HAS_GLOBAL_ADC_RESOLUTION 1
|
||||||
|
|
||||||
|
#define HAL_PWM_BITS_MAX 16
|
||||||
|
#define HAL_ADC_BITS_MAX 12
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in us for this platform (in SQW mode) and width of step pulse
|
||||||
|
#if CAN_PLUS != OFF
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 60
|
||||||
|
#else
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 40
|
||||||
|
#endif
|
||||||
|
#define HAL_PULSE_WIDTH 300 // in ns, measured 12/5/25 (ESP32 v2.0.17)
|
||||||
|
|
||||||
|
// New symbol for the default I2C port -------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ----------------------------------------------------------------------------
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_ESP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
// Correction for ESP32's internal temperture sensor
|
||||||
|
#ifndef INTERNAL_TEMP_CORRECTION
|
||||||
|
#define INTERNAL_TEMP_CORRECTION 0
|
||||||
|
#endif
|
||||||
|
#define HAL_TEMP() ( temperatureRead() + INTERNAL_TEMP_CORRECTION )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL, optionally also early init of SERIAL_SIP/PIP or SERIAL_BT
|
||||||
|
#ifndef SERIAL_BT_MODE
|
||||||
|
#define SERIAL_BT_MODE OFF
|
||||||
|
#endif
|
||||||
|
#if SERIAL_BT_MODE != OFF
|
||||||
|
#include <BluetoothSerial.h>
|
||||||
|
extern BluetoothSerial bluetoothSerial;
|
||||||
|
#define SERIAL_BT bluetoothSerial
|
||||||
|
#endif
|
||||||
|
#if SERIAL_BT_MODE == SLAVE
|
||||||
|
#ifdef SERIAL_BT_PASSKEY
|
||||||
|
#define SERIAL_BT_BEGIN() if (strlen(SERIAL_BT_PASSKEY) != 0) SERIAL_BT.setPin(SERIAL_BT_PASSKEY); SERIAL_BT.begin(SERIAL_BT_NAME)
|
||||||
|
#else
|
||||||
|
#define SERIAL_BT_BEGIN() SERIAL_BT.begin(SERIAL_BT_NAME)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define SERIAL_BT_BEGIN()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
|
||||||
|
#define HAL_INIT() { \
|
||||||
|
SERIAL_BT_BEGIN(); \
|
||||||
|
HAL_FAST_TICKS_INIT(); \
|
||||||
|
}
|
||||||
|
|
||||||
|
// MCU reset
|
||||||
|
#define HAL_RESET() ESP.restart()
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
Executable
+98
@@ -0,0 +1,98 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// This is for fast processors with hardware FP
|
||||||
|
#define HAL_FAST_PROCESSOR
|
||||||
|
|
||||||
|
// Base rate for critical task timing (0.0095s = 0.14", 0.2 sec/day)
|
||||||
|
#define HAL_FRACTIONAL_SEC 105.2631579F
|
||||||
|
|
||||||
|
// Analog read and write
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_WRITE_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// analog read/write capabilities
|
||||||
|
#define HAL_HAS_PER_PIN_PWM_RESOLUTION 0
|
||||||
|
#define HAL_HAS_PER_PIN_PWM_FREQUENCY 0
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_RESOLUTION 1
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_FREQUENCY 1
|
||||||
|
#define HAL_PWM_HZ_MAX 200000U
|
||||||
|
|
||||||
|
#define HAL_HAS_GLOBAL_ADC_RESOLUTION 1
|
||||||
|
|
||||||
|
#define HAL_PWM_BITS_MAX 16
|
||||||
|
#define HAL_ADC_BITS_MAX 12
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in us for this platform (in SQW mode) and width of step pulse
|
||||||
|
#if CAN_PLUS != OFF
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 60
|
||||||
|
#else
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 40
|
||||||
|
#endif
|
||||||
|
#define HAL_PULSE_WIDTH 200 // in ns, measured 1/18/22 (ESP32 v2.0.0)
|
||||||
|
|
||||||
|
// New symbol for the default I2C port -------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ----------------------------------------------------------------------------
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_ESP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
// Correction for ESP32's internal temperture sensor
|
||||||
|
#ifndef INTERNAL_TEMP_CORRECTION
|
||||||
|
#define INTERNAL_TEMP_CORRECTION 0
|
||||||
|
#endif
|
||||||
|
#define HAL_TEMP() ( temperatureRead() + INTERNAL_TEMP_CORRECTION )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL, optionally also early init of SERIAL_SIP/PIP or SERIAL_BT
|
||||||
|
#ifndef SERIAL_BT_MODE
|
||||||
|
#define SERIAL_BT_MODE OFF
|
||||||
|
#endif
|
||||||
|
#if SERIAL_BT_MODE != OFF
|
||||||
|
#include <BluetoothSerial.h>
|
||||||
|
extern BluetoothSerial bluetoothSerial;
|
||||||
|
#define SERIAL_BT bluetoothSerial
|
||||||
|
#endif
|
||||||
|
#if SERIAL_BT_MODE == SLAVE
|
||||||
|
#ifdef SERIAL_BT_PASSKEY
|
||||||
|
#define SERIAL_BT_BEGIN() if (strlen(SERIAL_BT_PASSKEY) != 0) SERIAL_BT.setPin(SERIAL_BT_PASSKEY, strlen(SERIAL_BT_PASSKEY)); SERIAL_BT.begin(SERIAL_BT_NAME)
|
||||||
|
#else
|
||||||
|
#define SERIAL_BT_BEGIN() SERIAL_BT.begin(SERIAL_BT_NAME)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define SERIAL_BT_BEGIN()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
|
||||||
|
#define HAL_INIT() { \
|
||||||
|
SERIAL_BT_BEGIN(); \
|
||||||
|
HAL_FAST_TICKS_INIT(); \
|
||||||
|
}
|
||||||
|
|
||||||
|
// MCU reset
|
||||||
|
#define HAL_RESET() ESP.restart()
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
Executable
+56
@@ -0,0 +1,56 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// This is for fast processors with hardware FP
|
||||||
|
#define HAL_FAST_PROCESSOR
|
||||||
|
|
||||||
|
// Base rate for critical task timing (0.0095s = 0.14", 0.2 sec/day)
|
||||||
|
#define HAL_FRACTIONAL_SEC 105.2631579F
|
||||||
|
|
||||||
|
// Analog read and write
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in us for this platform (in SQW mode) and width of step pulse
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 60
|
||||||
|
#define HAL_PULSE_WIDTH 10000 // in ns, estimated
|
||||||
|
|
||||||
|
// New symbol for the default I2C port -------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ----------------------------------------------------------------------------
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#define E2END 2047
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_EEPROM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define HAL_TEMP() ( NAN )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
|
||||||
|
#define HAL_INIT() { \
|
||||||
|
HAL_FAST_TICKS_INIT(); \
|
||||||
|
}
|
||||||
|
|
||||||
|
// MCU reset
|
||||||
|
#define HAL_RESET() ESP.restart()
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
Executable
+51
@@ -0,0 +1,51 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// We define a more generic symbol, in case more Platform_Name boards based on different lines are supported
|
||||||
|
|
||||||
|
// Base rate for critical task timing
|
||||||
|
#define HAL_FRACTIONAL_SEC 100.0F
|
||||||
|
|
||||||
|
// Analog read and write
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in us for this platform (in SQW mode) and width of step pulse
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 60
|
||||||
|
#define HAL_PULSE_WIDTH 10000 // in ns, estimated
|
||||||
|
|
||||||
|
// New symbol for the default I2C port ---------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ------------------------------------------------------------------------------
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#define E2END 1023
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_ESP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define HAL_TEMP() ( NAN )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes and defines to support this processor's operation
|
||||||
|
|
||||||
|
// MCU reset
|
||||||
|
#define HAL_RESET() ESP.restart()
|
||||||
Executable
+52
@@ -0,0 +1,52 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// 1/100 second resolution
|
||||||
|
#define HAL_FRACTIONAL_SEC 100.0F
|
||||||
|
|
||||||
|
// This platform has 8 bit PWM
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023 // always use 2^n - 1, within the platform's limits
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_READ_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255 // always use 2^n - 1, within the platform's limits
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_WRITE_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in us for this platform (in SQW mode) and width of step pulse
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 76.8
|
||||||
|
#define HAL_PULSE_WIDTH 10000 // in ns, estimated
|
||||||
|
|
||||||
|
// New symbol for the default I2C port -------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ----------------------------------------------------------------------------
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_AT24C32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define HAL_TEMP() ( NAN )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
|
||||||
|
// MCU reset
|
||||||
|
#define HAL_RESET() (*((volatile uint32_t*)(PPB_BASE + 0x0ED0C))) = 0x5FA0004;
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
Executable
+52
@@ -0,0 +1,52 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// 1/100 second resolution
|
||||||
|
#define HAL_FRACTIONAL_SEC 100.0F
|
||||||
|
|
||||||
|
// This platform has 8 bit PWM
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023 // always use 2^n - 1, within the platform's limits
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_READ_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255 // always use 2^n - 1, within the platform's limits
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_WRITE_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in us for this platform (in SQW mode) and width of step pulse
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 76.8
|
||||||
|
#define HAL_PULSE_WIDTH 10000 // in ns, estimated
|
||||||
|
|
||||||
|
// New symbol for the default I2C port -------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ----------------------------------------------------------------------------
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_AT24C32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define HAL_TEMP() ( NAN )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
|
||||||
|
// MCU reset
|
||||||
|
#define HAL_RESET() (*((volatile uint32_t*)(PPB_BASE + 0x0ED0C))) = 0x5FA0004;
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
Executable
+65
@@ -0,0 +1,65 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// We define a more generic symbol, in case more STM32 boards based on different lines are supported
|
||||||
|
#define __ARM_STM32__
|
||||||
|
|
||||||
|
// Base rate for critical task timing (0.0095s = 0.14", 0.2 sec/day)
|
||||||
|
#define HAL_FRACTIONAL_SEC 105.2631579F
|
||||||
|
|
||||||
|
// Analog read and write
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_READ_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in uS for this platform (in SQW mode) and width of step pulse
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 34 // assumes optimization set to Fastest (-O3)
|
||||||
|
#define HAL_PULSE_WIDTH 900 // in ns, estimated
|
||||||
|
|
||||||
|
#include <HardwareTimer.h>
|
||||||
|
|
||||||
|
// Interrupts
|
||||||
|
#define cli() noInterrupts()
|
||||||
|
#define sei() interrupts()
|
||||||
|
|
||||||
|
// New symbol for the default I2C port ---------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ------------------------------------------------------------------------------
|
||||||
|
#undef E2END
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_AT24C32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define HAL_TEMP() ( NAN )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
#define HAL_INIT() { \
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
|
|
||||||
|
// always bring in the software serial library early as strange things happen otherwise
|
||||||
|
#include <SoftwareSerial.h>
|
||||||
|
|
||||||
|
// MCU reset
|
||||||
|
#define HAL_RESET() NVIC_SystemReset()
|
||||||
Executable
+67
@@ -0,0 +1,67 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// We define a more generic symbol, in case more STM32 boards based on different lines are supported
|
||||||
|
#define __ARM_STM32__
|
||||||
|
|
||||||
|
#define HAL_FAST_PROCESSOR
|
||||||
|
|
||||||
|
// Base rate for critical task timing (0.0057s = 0.09", 0.2 sec/day)
|
||||||
|
#define HAL_FRACTIONAL_SEC 175.4385965F
|
||||||
|
|
||||||
|
// Analog read and write
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_READ_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in uS for this platform (in SQW mode) and width of step pulse
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 20 // assumes optimization set to Fastest (-O3)
|
||||||
|
#define HAL_PULSE_WIDTH 450 // in ns, estimated
|
||||||
|
|
||||||
|
#include <HardwareTimer.h>
|
||||||
|
|
||||||
|
// Interrupts
|
||||||
|
#define cli() noInterrupts()
|
||||||
|
#define sei() interrupts()
|
||||||
|
|
||||||
|
// New symbol for the default I2C port ---------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ------------------------------------------------------------------------------
|
||||||
|
#undef E2END
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_AT24C32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define HAL_TEMP() ( NAN )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
#define HAL_INIT() { \
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
|
|
||||||
|
// always bring in the software serial library early as strange things happen otherwise
|
||||||
|
#include <SoftwareSerial.h>
|
||||||
|
|
||||||
|
// MCU reset
|
||||||
|
#define HAL_RESET() NVIC_SystemReset()
|
||||||
Executable
+75
@@ -0,0 +1,75 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// We define a more generic symbol, in case more STM32 boards based on different lines are supported
|
||||||
|
#define __ARM_STM32__
|
||||||
|
|
||||||
|
// Base rate for critical task timing (0.0038s = 0.06", 0.2 sec/day)
|
||||||
|
#define HAL_FRACTIONAL_SEC 263.1578947F
|
||||||
|
|
||||||
|
// Analog read and write
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_READ_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// STM32 Arduino cores (F4 + H7):
|
||||||
|
// assume global resolution functions exist; per-pin freq/res is not generic.
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_RESOLUTION 1
|
||||||
|
#define HAL_HAS_GLOBAL_ADC_RESOLUTION 1
|
||||||
|
|
||||||
|
#define HAL_PWM_BITS_MAX 16
|
||||||
|
|
||||||
|
// F4 ADC is 12-bit; H7 can be higher, but core support varies.
|
||||||
|
// Default to 12 and let advanced HAL override to 16 for known-good H7 setup.
|
||||||
|
#define HAL_ADC_BITS_MAX 12
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in uS for this platform (in SQW mode) and width of step pulse
|
||||||
|
#define HAL_FAST_PROCESSOR
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 14 // assumes optimization set to Fastest (-O3)
|
||||||
|
#define HAL_PULSE_WIDTH 250 // in ns, estimated
|
||||||
|
|
||||||
|
#include <HardwareTimer.h>
|
||||||
|
|
||||||
|
// Interrupts
|
||||||
|
#define cli() noInterrupts()
|
||||||
|
#define sei() interrupts()
|
||||||
|
|
||||||
|
// New symbol for the default I2C port ---------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
// no HAL_WIRE_CLOCK, it breaks the STM32 library
|
||||||
|
|
||||||
|
// Non-volatile storage ------------------------------------------------------------------------------
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_AT24C32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define HAL_TEMP() ( NAN )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
#define HAL_INIT() { \
|
||||||
|
HAL_WIRE.setSDA(PB7); \
|
||||||
|
HAL_WIRE.setSCL(PB6); \
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
|
|
||||||
|
// always bring in the software serial library early as strange things happen otherwise
|
||||||
|
#include <SoftwareSerial.h>
|
||||||
|
|
||||||
|
// MCU reset
|
||||||
|
#define HAL_RESET() NVIC_SystemReset()
|
||||||
Executable
+86
@@ -0,0 +1,86 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// We define a more generic symbol, in case more STM32 boards based on different lines are supported
|
||||||
|
#define __ARM_STM32__
|
||||||
|
|
||||||
|
// Base rate for critical task timing (0.0038s = 0.06", 0.2 sec/day)
|
||||||
|
#define HAL_FRACTIONAL_SEC 263.1578947F
|
||||||
|
|
||||||
|
// Analog read and write
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_READ_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// STM32 Arduino cores (F4 + H7):
|
||||||
|
// assume global resolution functions exist; per-pin freq/res is not generic.
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_RESOLUTION 1
|
||||||
|
#define HAL_HAS_GLOBAL_ADC_RESOLUTION 1
|
||||||
|
|
||||||
|
#define HAL_PWM_BITS_MAX 16
|
||||||
|
|
||||||
|
// F4 ADC is 12-bit; H7 can be higher, but core support varies.
|
||||||
|
// Default to 12 and let advanced HAL override to 16 for known-good H7 setup.
|
||||||
|
#define HAL_ADC_BITS_MAX 12
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in uS for this platform (in SQW mode) and width of step pulse
|
||||||
|
#define HAL_FAST_PROCESSOR
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 14 // assumes optimization set to Fastest (-O3)
|
||||||
|
#define HAL_PULSE_WIDTH 250 // in ns, estimated
|
||||||
|
|
||||||
|
#include <HardwareTimer.h>
|
||||||
|
|
||||||
|
// Interrupts
|
||||||
|
#define cli() noInterrupts()
|
||||||
|
#define sei() interrupts()
|
||||||
|
|
||||||
|
// New symbol for the default I2C port ---------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ------------------------------------------------------------------------------
|
||||||
|
#undef E2END
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#if PINMAP == FYSETC_S6_2
|
||||||
|
// The FYSETC S6 v2 has a 4096 byte EEPROM built-in
|
||||||
|
#define NV_DRIVER NV_2432
|
||||||
|
#elif PINMAP == FYSETC_S6
|
||||||
|
// The FYSETC S6 has a 2048 byte EEPROM built-in
|
||||||
|
#define NV_DRIVER NV_2416
|
||||||
|
#else
|
||||||
|
// Fallback to the EEPROM present on an ZS-042 module
|
||||||
|
#define NV_DRIVER NV_AT24C32
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define HAL_TEMP() ( NAN )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
#define HAL_INIT() { \
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
|
|
||||||
|
// always bring in the software serial library early as strange things happen otherwise
|
||||||
|
#include <SoftwareSerial.h>
|
||||||
|
|
||||||
|
// MCU reset
|
||||||
|
#define HAL_RESET() NVIC_SystemReset()
|
||||||
Executable
+81
@@ -0,0 +1,81 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// We define a more generic symbol, in case more STM32 boards based on different lines are supported
|
||||||
|
#define __ARM_STM32__
|
||||||
|
|
||||||
|
#define HAL_FAST_PROCESSOR
|
||||||
|
|
||||||
|
// Base rate for critical task timing (0.0057s = 0.09", 0.2 sec/day)
|
||||||
|
#define HAL_FRACTIONAL_SEC 175.4385965F
|
||||||
|
|
||||||
|
// Analog read and write
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_READ_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in uS for this platform (in SQW mode) and width of step pulse
|
||||||
|
#ifdef STM32F401xC
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 20 // assumes optimization set to Fastest (-O3)
|
||||||
|
#define HAL_PULSE_WIDTH 300 // in ns, estimated
|
||||||
|
#elif STM32F411xE
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 20 // Lower limit (fastest) step rate in us (in SQW mode) assumes optimization set to Fastest (-O3)
|
||||||
|
#define HAL_PULSE_WIDTH 300 // in ns, estimated
|
||||||
|
#else
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 60
|
||||||
|
#define HAL_PULSE_WIDTH 900 // in ns, estimated
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <HardwareTimer.h>
|
||||||
|
|
||||||
|
// Interrupts
|
||||||
|
#define cli() noInterrupts()
|
||||||
|
#define sei() interrupts()
|
||||||
|
|
||||||
|
// New symbol for the default I2C port ---------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ------------------------------------------------------------------------------
|
||||||
|
#undef E2END
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#if PINMAP == MaxSTM3I
|
||||||
|
// The MaxPCB3I has an 8192 byte EEPROM built-in (rated for 5M write cycles)
|
||||||
|
#define NV_DRIVER NV_2464
|
||||||
|
#else
|
||||||
|
// fall back to the DS3231/AT24C32
|
||||||
|
#define NV_DRIVER NV_AT24C32
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define HAL_TEMP() ( NAN )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
#define HAL_INIT() { \
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
|
|
||||||
|
// always bring in the software serial library early as strange things happen otherwise
|
||||||
|
#include <SoftwareSerial.h>
|
||||||
|
|
||||||
|
// MCU reset
|
||||||
|
#define HAL_RESET() NVIC_SystemReset()
|
||||||
Executable
+80
@@ -0,0 +1,80 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// We define a more generic symbol, in case more STM32 boards based on different lines are supported
|
||||||
|
#define __ARM_STM32__
|
||||||
|
|
||||||
|
// Base rate for critical task timing (0.0019s = 0.03", 0.2 sec/day)
|
||||||
|
#define HAL_FRACTIONAL_SEC 526.3157895F
|
||||||
|
|
||||||
|
// Analog read and write
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023
|
||||||
|
#else
|
||||||
|
#error "Configuration (Config.h): ANALOG_READ_RANGE can't be changed on this platform"
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// STM32 Arduino cores (F4 + H7):
|
||||||
|
// assume global resolution functions exist; per-pin freq/res is not generic.
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_RESOLUTION 1
|
||||||
|
#define HAL_HAS_GLOBAL_ADC_RESOLUTION 1
|
||||||
|
|
||||||
|
#define HAL_PWM_BITS_MAX 16
|
||||||
|
|
||||||
|
// F4 ADC is 12-bit; H7 can be higher, but core support varies.
|
||||||
|
// Default to 12 and let advanced HAL override to 16 for known-good H7 setup.
|
||||||
|
#ifndef HAL_ADC_BITS_MAX
|
||||||
|
#define HAL_ADC_BITS_MAX 12
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in uS for this platform (in SQW mode) and width of step pulse
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 1.5
|
||||||
|
#define HAL_PULSE_WIDTH 0 // effectively disable pulse mode
|
||||||
|
#define HAL_FAST_PROCESSOR
|
||||||
|
#define HAL_VFAST_PROCESSOR
|
||||||
|
|
||||||
|
#include <HardwareTimer.h>
|
||||||
|
|
||||||
|
// Interrupts
|
||||||
|
#define cli() noInterrupts()
|
||||||
|
#define sei() interrupts()
|
||||||
|
|
||||||
|
// New symbol for the default I2C port ---------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ------------------------------------------------------------------------------
|
||||||
|
#undef E2END
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_24256
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define HAL_TEMP() ( NAN )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
#define HAL_INIT() { \
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
|
|
||||||
|
// always bring in the software serial library early as strange things happen otherwise
|
||||||
|
#include <SoftwareSerial.h>
|
||||||
|
|
||||||
|
// MCU reset
|
||||||
|
#define HAL_RESET() NVIC_SystemReset()
|
||||||
Executable
+82
@@ -0,0 +1,82 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
// Teensy3.0, 3.1, 3.2
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// We define a more generic symbol, in case more Teensy boards based on different lines are supported
|
||||||
|
#define __TEENSYDUINO__
|
||||||
|
|
||||||
|
// This platform has digitalReadFast, digitalWriteFast, etc.
|
||||||
|
#define HAL_HAS_DIGITAL_FAST
|
||||||
|
|
||||||
|
// Base rate for critical task timing (0.0076s = 0.11", 0.2 sec/day)
|
||||||
|
#define HAL_FRACTIONAL_SEC 131.5789474F
|
||||||
|
|
||||||
|
// Analog read and write
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// analog read/write capabilities
|
||||||
|
#define HAL_HAS_PER_PIN_PWM_RESOLUTION 0
|
||||||
|
#define HAL_HAS_PER_PIN_PWM_FREQUENCY 1
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_RESOLUTION 1
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_FREQUENCY 0
|
||||||
|
#define HAL_PWM_BITS_MAX 16
|
||||||
|
#define HAL_PWM_HZ_MAX 200000U
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in uS for this platform (in SQW mode) and width of step pulse
|
||||||
|
#if F_CPU >= 120000000
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 10
|
||||||
|
#define HAL_PULSE_WIDTH 400 // in ns, estimated
|
||||||
|
#elif F_CPU >= 96000000
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 12
|
||||||
|
#define HAL_PULSE_WIDTH 450 // in ns, estimated
|
||||||
|
#elif F_CPU >= 72000000
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 14
|
||||||
|
#define HAL_PULSE_WIDTH 500 // in ns, estimated
|
||||||
|
#else
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 28
|
||||||
|
#define HAL_PULSE_WIDTH 750 // in ns, estimated
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// New symbol for the default I2C port -------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ------------------------------------------------------------------------------
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_EEPROM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define _Tpin 38
|
||||||
|
#define HAL_TEMP() ( (-((analog.readV(_Tpin) - 0.719F)/0.001715F) + 25.0F ) )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
|
||||||
|
#define HAL_INIT() { \
|
||||||
|
HAL_FAST_TICKS_INIT(); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define HAL_RESET() { \
|
||||||
|
SCB_AIRCR = 0x05FA0004; \
|
||||||
|
asm volatile ("dsb"); \
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
|
|
||||||
Executable
+74
@@ -0,0 +1,74 @@
|
|||||||
|
// Platform setup ----------------------------------------------------------------------------------
|
||||||
|
// Teensy3.5
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// We define a more generic symbol, in case more Teensy boards based on different lines are supported
|
||||||
|
#define __TEENSYDUINO__
|
||||||
|
|
||||||
|
// This platform has digitalReadFast, digitalWriteFast, etc.
|
||||||
|
#define HAL_HAS_DIGITAL_FAST
|
||||||
|
|
||||||
|
// Turn on support for using DACs to output digital signals using Arduino standard commands
|
||||||
|
#define HAL_DAC_AS_DIGITAL
|
||||||
|
|
||||||
|
// Base rate for critical task timing (0.0057s = 0.09", 0.2 sec/day)
|
||||||
|
#define HAL_FRACTIONAL_SEC 175.4385965F
|
||||||
|
|
||||||
|
// Analog read and write
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// analog read/write capabilities
|
||||||
|
#define HAL_HAS_PER_PIN_PWM_RESOLUTION 0
|
||||||
|
#define HAL_HAS_PER_PIN_PWM_FREQUENCY 1
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_RESOLUTION 1
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_FREQUENCY 0
|
||||||
|
#define HAL_PWM_BITS_MAX 16
|
||||||
|
#define HAL_PWM_HZ_MAX 200000U
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in uS for this platform (in SQW mode) and width of step pulse
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 12
|
||||||
|
#define HAL_PULSE_WIDTH 400 // in ns, measured 1/18/22
|
||||||
|
#define HAL_FAST_PROCESSOR
|
||||||
|
|
||||||
|
// New symbol for the default I2C port -------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire1
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ----------------------------------------------------------------------------
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_EEPROM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define _Tpin 70
|
||||||
|
#define HAL_TEMP() ( (-(analog.readV(_Tpin)-0.719F)/0.001715F)+25.0F )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
|
||||||
|
#define HAL_INIT() { \
|
||||||
|
HAL_FAST_TICKS_INIT(); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define HAL_RESET() { \
|
||||||
|
SCB_AIRCR = 0x05FA0004; \
|
||||||
|
asm volatile ("dsb"); \
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
Executable
+82
@@ -0,0 +1,82 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
// Teensy3.6
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// We define a more generic symbol, in case more Teensy boards based on different lines are supported
|
||||||
|
#define __TEENSYDUINO__
|
||||||
|
|
||||||
|
// This platform has digitalReadFast, digitalWriteFast, etc.
|
||||||
|
#define HAL_HAS_DIGITAL_FAST
|
||||||
|
|
||||||
|
// Turn on support for using DACs to output digital signals using Arduino standard commands
|
||||||
|
#define HAL_DAC_AS_DIGITAL
|
||||||
|
|
||||||
|
// Base rate for critical task timing (0.0038s = 0.06", 0.2 sec/day)
|
||||||
|
#define HAL_FRACTIONAL_SEC 263.1578947F
|
||||||
|
|
||||||
|
// Analog read and write
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// analog read/write capabilities
|
||||||
|
#define HAL_HAS_PER_PIN_PWM_RESOLUTION 0
|
||||||
|
#define HAL_HAS_PER_PIN_PWM_FREQUENCY 1
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_RESOLUTION 1
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_FREQUENCY 0
|
||||||
|
#define HAL_PWM_BITS_MAX 16
|
||||||
|
#define HAL_PWM_HZ_MAX 200000U
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in uS for this platform (in SQW mode) and width of step pulse
|
||||||
|
#if F_CPU >= 240000000
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 2
|
||||||
|
#define HAL_PULSE_WIDTH 200 // in ns, estimated
|
||||||
|
#elif F_CPU >= 180000000
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 2.6
|
||||||
|
#define HAL_PULSE_WIDTH 300 // in ns, estimated
|
||||||
|
#else
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 4.8
|
||||||
|
#define HAL_PULSE_WIDTH 400 // in ns, estimated
|
||||||
|
#endif
|
||||||
|
#define HAL_FAST_PROCESSOR
|
||||||
|
|
||||||
|
// New symbol for the default I2C port -------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire1
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ------------------------------------------------------------------------------
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_EEPROM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define _Tpin 70
|
||||||
|
#define HAL_TEMP() ( (-(analog.readV(_Tpin)-0.719F)/0.001715F)+25.0F )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
|
||||||
|
#define HAL_INIT() { \
|
||||||
|
HAL_FAST_TICKS_INIT(); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define HAL_RESET() { \
|
||||||
|
SCB_AIRCR = 0x05FA0004; \
|
||||||
|
asm volatile ("dsb"); \
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
Executable
+77
@@ -0,0 +1,77 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// We define a more generic symbol, in case more Teensy boards based on different lines are supported
|
||||||
|
#define __TEENSYDUINO__
|
||||||
|
|
||||||
|
// This platform has digitalReadFast, digitalWriteFast, etc.
|
||||||
|
#define HAL_HAS_DIGITAL_FAST
|
||||||
|
|
||||||
|
// Base rate for critical task timing (0.0019s = 0.03", 0.2 sec/day)
|
||||||
|
#define HAL_FRACTIONAL_SEC 526.3157895F
|
||||||
|
|
||||||
|
// Analog read and write
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// analog read/write capabilities
|
||||||
|
#define HAL_HAS_PER_PIN_PWM_RESOLUTION 0
|
||||||
|
#define HAL_HAS_PER_PIN_PWM_FREQUENCY 1
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_RESOLUTION 1
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_FREQUENCY 0
|
||||||
|
#define HAL_PWM_BITS_MAX 16
|
||||||
|
#define HAL_PWM_HZ_MAX 200000U
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in uS for this platform (in SQW mode) and width of step pulse
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 1.5
|
||||||
|
#define HAL_PULSE_WIDTH 0 // effectively disable pulse mode
|
||||||
|
#define HAL_FAST_PROCESSOR
|
||||||
|
#define HAL_VFAST_PROCESSOR
|
||||||
|
|
||||||
|
// New symbol for the default I2C port -------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ------------------------------------------------------------------------------
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_EEPROM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define HAL_TEMP() ( tempmonGetTemp() )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
|
||||||
|
#define HAL_INIT() { \
|
||||||
|
HAL_FAST_TICKS_INIT(); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define HAL_RESET() { \
|
||||||
|
SCB_AIRCR = 0x05FA0004; \
|
||||||
|
asm volatile ("dsb"); \
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
|
|
||||||
|
#ifdef EmptyStr
|
||||||
|
#undef EmptyStr
|
||||||
|
#endif
|
||||||
|
#define EmptyStr "\1"
|
||||||
|
|
||||||
|
#define CAT_ATTR PROGMEM
|
||||||
Executable
+77
@@ -0,0 +1,77 @@
|
|||||||
|
// Platform setup ------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// We define a more generic symbol, in case more Teensy boards based on different lines are supported
|
||||||
|
#define __TEENSYDUINO__
|
||||||
|
|
||||||
|
// This platform has digitalReadFast, digitalWriteFast, etc.
|
||||||
|
#define HAL_HAS_DIGITAL_FAST
|
||||||
|
|
||||||
|
// Base rate for critical task timing (0.0019s = 0.03", 0.2 sec/day)
|
||||||
|
#define HAL_FRACTIONAL_SEC 526.3157895F
|
||||||
|
|
||||||
|
// Analog read and write
|
||||||
|
#ifndef HAL_VCC
|
||||||
|
#define HAL_VCC 3.3F
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_READ_RANGE
|
||||||
|
#define ANALOG_READ_RANGE 1023
|
||||||
|
#endif
|
||||||
|
#ifndef ANALOG_WRITE_RANGE
|
||||||
|
#define ANALOG_WRITE_RANGE 255
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// analog read/write capabilities
|
||||||
|
#define HAL_HAS_PER_PIN_PWM_RESOLUTION 0
|
||||||
|
#define HAL_HAS_PER_PIN_PWM_FREQUENCY 1
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_RESOLUTION 1
|
||||||
|
#define HAL_HAS_GLOBAL_PWM_FREQUENCY 0
|
||||||
|
#define HAL_PWM_BITS_MAX 16
|
||||||
|
#define HAL_PWM_HZ_MAX 200000U
|
||||||
|
|
||||||
|
// Lower limit (fastest) step rate in uS for this platform (in SQW mode) and width of step pulse
|
||||||
|
#define HAL_MAXRATE_LOWER_LIMIT 1.5
|
||||||
|
#define HAL_PULSE_WIDTH 0 // effectively disable pulse mode
|
||||||
|
#define HAL_FAST_PROCESSOR
|
||||||
|
#define HAL_VFAST_PROCESSOR
|
||||||
|
|
||||||
|
// New symbol for the default I2C port -------------------------------------------------------------
|
||||||
|
#include <Wire.h>
|
||||||
|
#ifndef HAL_WIRE
|
||||||
|
#define HAL_WIRE Wire
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_WIRE_CLOCK
|
||||||
|
#define HAL_WIRE_CLOCK 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Non-volatile storage ------------------------------------------------------------------------------
|
||||||
|
#if NV_DRIVER == NV_DEFAULT
|
||||||
|
#undef NV_DRIVER
|
||||||
|
#define NV_DRIVER NV_EEPROM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// Internal MCU temperature (in degrees C)
|
||||||
|
#define HAL_TEMP() ( tempmonGetTemp() )
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// General purpose initialize for HAL
|
||||||
|
|
||||||
|
#define HAL_INIT() { \
|
||||||
|
HAL_FAST_TICKS_INIT(); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define HAL_RESET() { \
|
||||||
|
SCB_AIRCR = 0x05FA0004; \
|
||||||
|
asm volatile ("dsb"); \
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
// Misc. includes to support this processor's operation
|
||||||
|
|
||||||
|
#ifdef EmptyStr
|
||||||
|
#undef EmptyStr
|
||||||
|
#endif
|
||||||
|
#define EmptyStr "\1"
|
||||||
|
|
||||||
|
#define CAT_ATTR PROGMEM
|
||||||
Executable
+1466
File diff suppressed because it is too large
Load Diff
Executable
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// Dallas/Maxim 1-Wire library
|
||||||
|
|
||||||
|
#include "1Wire.h"
|
||||||
|
|
||||||
|
#if defined(DS1820_DEVICES_PRESENT) || (defined(GPIO_DEVICE) && GPIO_DEVICE == DS2413)
|
||||||
|
|
||||||
|
OneWire oneWire(ONE_WIRE_PIN);
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+13
@@ -0,0 +1,13 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// Dallas/Maxim 1-Wire library
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../../Common.h"
|
||||||
|
|
||||||
|
#if defined(DS1820_DEVICES_PRESENT) || (defined(GPIO_DEVICE) && GPIO_DEVICE == DS2413)
|
||||||
|
|
||||||
|
#include <OneWire.h> // my OneWire library https://github.com/hjd1964/OneWire
|
||||||
|
|
||||||
|
extern OneWire oneWire;
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+202
@@ -0,0 +1,202 @@
|
|||||||
|
// Library general purpose constants
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// misc.
|
||||||
|
#define AUTO -1
|
||||||
|
#define OFF -1
|
||||||
|
#define ON -2
|
||||||
|
#define AUX -4
|
||||||
|
#define MASTER -5
|
||||||
|
#define SLAVE -6
|
||||||
|
#define BOTH -7
|
||||||
|
#define SoftSerial -8
|
||||||
|
#define HardSerial -9
|
||||||
|
#define CONSOLE -10
|
||||||
|
#define PROFILER -11
|
||||||
|
#define VERBOSE -12
|
||||||
|
#define REMOTE -13
|
||||||
|
#define WIFI_ACCESS_POINT -14 // shorthand for easy WIFI mode settings
|
||||||
|
#define WIFI_STATION -15 // shorthand for easy WIFI mode settings
|
||||||
|
#define BLUETOOTH -16 // shorthand for easy bluetooth mode settings
|
||||||
|
#define SHARED -17
|
||||||
|
#define STANDARD -18
|
||||||
|
#define PERSISTENT -19
|
||||||
|
#define ERRORS_ONLY -20
|
||||||
|
#define MINIMUM -21
|
||||||
|
#define MIDDLE -22
|
||||||
|
#define MAXIMUM -23
|
||||||
|
#define INVALID -127
|
||||||
|
|
||||||
|
// CAN interface options
|
||||||
|
#define CAN_SAN 0
|
||||||
|
#define CAN_ESP32 1
|
||||||
|
#define CAN_MCP2515 2
|
||||||
|
#define CAN0_TEENSY4 3
|
||||||
|
#define CAN1_TEENSY4 4
|
||||||
|
#define CAN2_TEENSY4 5
|
||||||
|
#define CAN3_TEENSY4 6
|
||||||
|
|
||||||
|
// network interface options
|
||||||
|
#define ETHERNET_FIRST 1
|
||||||
|
#define ETHERNET_W5100 1
|
||||||
|
#define ETHERNET_W5500 2
|
||||||
|
#define ETHERNET_TEENSY41 3
|
||||||
|
#define ETHERNET_LAST 3
|
||||||
|
#define WIFI_FIRST 4
|
||||||
|
#define WIFI 4
|
||||||
|
#define WIFI_LAST 4
|
||||||
|
|
||||||
|
// driver (step/dir interface, usually for stepper motors)
|
||||||
|
// changes here must be reflected in the StepDirDriver.cpp file, etc.
|
||||||
|
#define STEP_DIR_DRIVER_FIRST 0
|
||||||
|
#define A4988 0 // allows M0,M1,M2 bit patterens for 1x,2x,4x,8x,16x
|
||||||
|
#define DRV8825 1 // allows M0,M1,M2 bit patterens for 1x,2x,4x,8x,16x,32x
|
||||||
|
#define GENERIC 2 // generic s/d driver allows for 1x,2x,4x,8x,16x,32x,64x,128x,256x (using just the M2 pin)
|
||||||
|
#define LV8729 3 // allows M0,M1,M2 bit patterens for 1x,2x,4x,8x,16x,32x,64x,128x
|
||||||
|
#define RAPS128 4 // allows M0,M1,M2 bit patterens for 1x,2x,4x,8x,16x,32x,64x,128x
|
||||||
|
#define S109 5 // allows M0,M1,M2 bit patterens for 1x,2x,4x,8x,16x,32x
|
||||||
|
#define ST820 6 // allows M0,M1,M2 bit patterens for 1x,2x,4x,8x,16x,32x,128x,256x
|
||||||
|
#define TMC2100 7 // allows M0,M1 bit patterens for 1x,2x,4x,16x (spreadCycle only, no 256x intpol)
|
||||||
|
#define TMC2130S 8 // allows M0,M1 bit patterens for 1x,2x,4x,16x (spreadCycle only, no 256x intpol)
|
||||||
|
#define TMC2208S 9 // allows M0,M1 bit patterens for 2x,4x,8x,16x (stealthChop default, uses 256x intpol)
|
||||||
|
#define TMC2225S 10 // allows M0,M1 bit patterens for 4x,8x,16x,32x (M2 sets spreadCycle/stealthChop, uses 256x intpol)
|
||||||
|
#define TMC2209S 11 // allows M0,M1 bit patterens for 8x,16x,32x,64x (M2 sets spreadCycle/stealthChop, uses 256x intpol)
|
||||||
|
#define TMC2226S 12 // allows M0,M1 bit patterens for 8x,16x,32x,64x (M2 sets spreadCycle/stealthChop, uses 256x intpol)
|
||||||
|
#define TMC_DRIVER_FIRST 13
|
||||||
|
#define TMC2130 13 // uses TMC software SPI comms for 1x,2x...,256x (SPI sets spreadCycle/stealthChop etc.)
|
||||||
|
#define TMC2160 14 // uses TMC software SPI comms for 1x,2x...,256x (SPI sets spreadCycle/stealthChop etc.)
|
||||||
|
#define TMC2660 15 // uses TMC software SPI comms for 1x,2x...,256x (SPI sets spreadCycle/stealthChop etc.)
|
||||||
|
#define TMC5160 16 // uses TMC software SPI comms for 1x,2x...,256x (SPI sets spreadCycle/stealthChop etc.)
|
||||||
|
#define TMC5161 17 // uses TMC software SPI comms for 1x,2x...,256x (SPI sets spreadCycle/stealthChop etc.)
|
||||||
|
#define TMC_UART_DRIVER_FIRST 18
|
||||||
|
#define TMC2208 18 // uses TMC software UART comms for 1x,2x...,256x (UART sets spreadCycle/stealthChop etc, dedicated RX/TX UART to each driver using index 0)
|
||||||
|
#define TMC2225 19 // uses TMC software UART comms for 1x,2x...,256x (UART sets spreadCycle/stealthChop etc, dedicated RX/TX UART to each driver using index 0)
|
||||||
|
#define TMC2209 20 // uses TMC software UART comms for 1x,2x...,256x (UART sets spreadCycle/stealthChop etc, dedicated RX/TX UART to each driver using index 0)
|
||||||
|
#define TMC2226 21 // uses TMC software UART comms for 1x,2x...,256x (UART sets spreadCycle/stealthChop etc, dedicated RX/TX UART to each driver using index 0)
|
||||||
|
#define STEP_DIR_DRIVER_LAST 21
|
||||||
|
|
||||||
|
// servo driver (usually for DC motors equipped with encoders)
|
||||||
|
// changes here must be reflected in the ServoDriver.cpp file, etc.
|
||||||
|
#define SERVO_DRIVER_FIRST 100
|
||||||
|
#define SERVO_PE 100 // SERVO, direction (phase) and pwm (enable) connections
|
||||||
|
#define SERVO_EE 101 // SERVO, dual pwm input (enable/enable) connections
|
||||||
|
#define SERVO_TMC2130_DC 102 // TMC2130 DC motor control
|
||||||
|
#define SERVO_TMC5160_DC 103 // TMC5160 DC motor control
|
||||||
|
#define SERVO_TMC2209 104 // TMC2209 stepper driver using VACTUAL velocity control
|
||||||
|
#define SERVO_TMC5160 105 // TMC5160 stepper driver using VMAX velocity control
|
||||||
|
#define SERVO_KTECH 106 // KTech servo motor using velocity control
|
||||||
|
#define SERVO_DRIVER_LAST 106
|
||||||
|
|
||||||
|
// integrated motor drivers
|
||||||
|
#define MOTOR_DRIVER_FIRST 200
|
||||||
|
#define ODRIVE 200 // First generation ODrive (axis 1 and 2 only), EXPERIMENTAL!
|
||||||
|
#define KTECH 201 // KTech CAN driver
|
||||||
|
#define MKS42D 202 // MKS SERVO 42D, EXPERIMENTAL!
|
||||||
|
#define MKS57D 202 // MKS SERVO 57D, EXPERIMENTAL!
|
||||||
|
#define MOTOR_DRIVER_LAST 202
|
||||||
|
|
||||||
|
// driver (step/dir) decay mode
|
||||||
|
#define DRIVER_DECAY_MODE_FIRST 1
|
||||||
|
#define MIXED 1
|
||||||
|
#define FAST 2
|
||||||
|
#define SLOW 3
|
||||||
|
#define SPREADCYCLE 4
|
||||||
|
#define STEALTHCHOP 5
|
||||||
|
#define DRIVER_DECAY_MODE_LAST 6
|
||||||
|
|
||||||
|
// servo encoder (must match Encoder library)
|
||||||
|
#define ENC_FIRST 1
|
||||||
|
#define AB 1 // AB quadrature encoder
|
||||||
|
#define AB_ESP32 2 // AB quadrature encoder (using fast ESP32 hardware decode)
|
||||||
|
#define CW_CCW 3 // clockwise/counter-clockwise encoder
|
||||||
|
#define PULSE_DIR 4 // pulse/direction encoder
|
||||||
|
#define PULSE_ONLY 5 // pulse only encoder (uses hint for direction)
|
||||||
|
#define VIRTUAL 6 // virtual encoder (uses hints for velocity and direction)
|
||||||
|
#define AS37_H39B_B 7 // Broadcom AS37-H39B-B BISS-C interface encoder
|
||||||
|
#define JTW_24BIT 8 // JTW Trident BISS-C interface 24bit encoder
|
||||||
|
#define JTW_26BIT 9 // JTW Trident BISS-C interface 26bit encoder
|
||||||
|
#define LIKA_ASC85 10 // Lika ASC85 BISS-C interface 25bit encoder (experimental)
|
||||||
|
#define KTECH_IME 11 // KTech in motor encoder
|
||||||
|
#define SERIAL_BRIDGE 12 // serial bridge to encoders
|
||||||
|
#define ENC_LAST 12
|
||||||
|
|
||||||
|
// encoder filter types
|
||||||
|
#define ENC_FILT_FIRST 1
|
||||||
|
#define KALMAN 1 // more advanced, predictive
|
||||||
|
#define ROLLING 2 // basic, rolling average
|
||||||
|
#define WINDOWING ROLLING // deprecated compatibility alias for rolling average
|
||||||
|
#define LEARNING 4 // learning, for RA axis only (experimental may be removed)
|
||||||
|
#define ENC_FILT_LAST 4
|
||||||
|
|
||||||
|
// servo feedback (must match Encoder library)
|
||||||
|
#define SERVO_FEEDBACK_FIRST 1
|
||||||
|
#define PID 1 // PID feedback
|
||||||
|
#define DUAL_PID 2 // Dual PID feedback
|
||||||
|
#define SERVO_FEEDBACK_LAST 2
|
||||||
|
|
||||||
|
// driver (step/dir) and servo, misc.
|
||||||
|
#define ODRIVER -10 // general purpose flag for a ODRIVE driver motor
|
||||||
|
#define SERVO -11 // general purpose flag for a SERVO driver motor
|
||||||
|
#define STEP_DIR -12 // general purpose flag for a STEP_DIR driver motor
|
||||||
|
|
||||||
|
// NV/EEPROM
|
||||||
|
#define NV_KEY_VALUE 111111111UL
|
||||||
|
|
||||||
|
#define NV_DEF 0
|
||||||
|
#define NV_DEFAULT 0 // PLATFORM SPECIFIC (HAL)
|
||||||
|
#define NV_EEPROM 1 // EEPROM.h
|
||||||
|
#define NV_ESP 2 // ESP8266/ESP32 EEPROM emulation with commits
|
||||||
|
#define NV_M0 3 // Arduino M0 EEPROM emulation with commits
|
||||||
|
#define NV_2416 4 // 2KB I2C EEPROM AT DEFAULT ADDRESS 0x50
|
||||||
|
#define NV_2432 5 // 4KB I2C EEPROM AT DEFAULT ADDRESS 0x50
|
||||||
|
#define NV_2464 6 // 8KB I2C EEPROM AT DEFAULT ADDRESS 0x50
|
||||||
|
#define NV_24128 7 // 16KB I2C EEPROM AT DEFAULT ADDRESS 0x50
|
||||||
|
#define NV_24256 8 // 32KB I2C EEPROM AT DEFAULT ADDRESS 0x50
|
||||||
|
#define NV_AT24C32 9 // 4KB I2C EEPROM AT DEFAULT ADDRESS 0x57 (ZS042 module for instance)
|
||||||
|
#define NV_MB85RC32 10 // 4KB I2C FRAM AT DEFAULT ADDRESS 0x50
|
||||||
|
#define NV_MB85RC64 11 // 8KB I2C FRAM AT DEFAULT ADDRESS 0x50
|
||||||
|
#define NV_MB85RC256 12 // 32KB I2C FRAM AT DEFAULT ADDRESS 0x50
|
||||||
|
|
||||||
|
#define NVE_LOW 0 // low (< 100K writes)
|
||||||
|
#define NVE_MID 1 // mid (~ 100K writes)
|
||||||
|
#define NVE_HIGH 2 // high (~ 1M writes)
|
||||||
|
#define NVE_VHIGH 3 // very high (> 300M writes, FRAM)
|
||||||
|
|
||||||
|
// GPIO devices (pin# 512 up to 543)
|
||||||
|
// these can work for most digital I/O EXCEPT: STEP/DIR, 1-WIRE/I2C/SPI (CS is ok), the ST4 port, and the PPS pin
|
||||||
|
#define GPIO_FIRST 1
|
||||||
|
#define DS2413 1 // DS2413 2-channel GPIO
|
||||||
|
#define MCP23008 2 // MCP23008 8-channel GPIO
|
||||||
|
#define MCP23017 3 // MCP23017 16-channel GPIO
|
||||||
|
#define X9555 4 // TCA/PCA9555 16-channel GPIO
|
||||||
|
#define X8574 5 // PCF8574 8-channel GPIO (up to 4)
|
||||||
|
#define X8575 6 // PCF8575 16-channel GPIO
|
||||||
|
#define SWS 7 // Smart Web Server 8-channel GPIO (usually on the four Encoder pins, if otherwise unused)
|
||||||
|
#define SSR74HC595 8 // 74HC595 8,16,24,32-channel GPIO (serial shift register, output only)
|
||||||
|
#define GPIO_LAST 8
|
||||||
|
|
||||||
|
// angular
|
||||||
|
#define RAD_DEG_RATIO 57.29577951308232L
|
||||||
|
#define RAD_DEG_RATIO_F 57.295780F
|
||||||
|
#define RAD_HOUR_RATIO 3.819718634205488L
|
||||||
|
#define RAD_HOUR_RATIO_F 3.8197186F
|
||||||
|
#define SIDEREAL_RATIO 1.002737909350795L
|
||||||
|
#define SIDEREAL_RATIO_F 1.0027379F
|
||||||
|
#define SIDEREAL_PERIOD 15956313.06126534L
|
||||||
|
#define SIDEREAL_RATE_HZ 60.16427456104770L
|
||||||
|
#define SOLAR_RATE_HZ 60.0L
|
||||||
|
#define LUNAR_RATE_HZ 57.9L
|
||||||
|
#define KING_RATE_HZ 60.136L
|
||||||
|
#define Deg10 0.174532925199432L
|
||||||
|
#define Deg20 0.349065850398865L
|
||||||
|
#define Deg45 0.785398163397448L
|
||||||
|
#define Deg60 1.047197551196597L
|
||||||
|
#define Deg85 1.483529864195180L
|
||||||
|
#define Deg90 1.570796326794896L
|
||||||
|
#define Deg180 3.141592653589793L
|
||||||
|
#define Deg360 6.283185307179586L
|
||||||
|
|
||||||
|
// for handling degenerate spherical coordinates near the poles
|
||||||
|
#define TenthArcSec 0.000000484813681L
|
||||||
|
#define OneArcSec 0.000004848136811L
|
||||||
|
#define SmallestFloat 0.0000005F
|
||||||
Executable
+291
@@ -0,0 +1,291 @@
|
|||||||
|
// Library general purpose macros
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// conversion math
|
||||||
|
#define degToArcsecF(x) ((x)/3600.0F)
|
||||||
|
#define degToRad(x) ((x)/(double)RAD_DEG_RATIO)
|
||||||
|
#define degToRadF(x) ((x)/(double)RAD_DEG_RATIO_F)
|
||||||
|
#define radToDeg(x) ((x)*(double)RAD_DEG_RATIO)
|
||||||
|
#define radToDegF(x) ((x)*(double)RAD_DEG_RATIO_F)
|
||||||
|
#define hrsToRad(x) ((x)/(double)RAD_HOUR_RATIO)
|
||||||
|
#define radToHrs(x) ((x)*(double)RAD_HOUR_RATIO)
|
||||||
|
#define arcsecToRad(x) ((x)/(double)206264.8062470963L)
|
||||||
|
#define radToArcsec(x) ((x)*(double)206264.8062470963L)
|
||||||
|
#define siderealToRad(x) ((x)/(double)13750.98708313975L)
|
||||||
|
#define siderealToRadF(x) ((x)/13750.987F)
|
||||||
|
#define radToSidereal(x) ((x)*(double)13750.98708313975L)
|
||||||
|
#define hzToSubMicros(x) ((x)*(double)266666.666666667L)
|
||||||
|
#define hzToSidereal(x) ((x)/(double)SIDEREAL_RATE_HZ)
|
||||||
|
#define siderealToHz(x) ((x)*(double)SIDEREAL_RATE_HZ)
|
||||||
|
#define fequal(x,y) (fabs((x)-(y))<SmallestFloat)
|
||||||
|
#define fgt(x,y) ((x)-(y)>SmallestFloat)
|
||||||
|
#define flt(x,y) ((y)-(x)>SmallestFloat)
|
||||||
|
#define NormalizeAzimuth(x) (x<0.0L?x+360.0L:x)
|
||||||
|
|
||||||
|
// strings
|
||||||
|
|
||||||
|
// tests if strings are equal
|
||||||
|
#define strequ(str1, str2) (strlen(str1) != strlen(str2) ? 0 : strstr(str1, str2))
|
||||||
|
|
||||||
|
// safe string copy from (char*)source to (char *)dest for a destination array of size bytes
|
||||||
|
#define sstrcpy(dest, source) do { \
|
||||||
|
int16_t _cap = sizeof(dest); \
|
||||||
|
if (_cap) { \
|
||||||
|
int16_t _i = 0; \
|
||||||
|
for (; _i + 1 < _cap && (source)[_i]; ++_i) { \
|
||||||
|
(dest)[_i] = (source)[_i]; \
|
||||||
|
} \
|
||||||
|
(dest)[_i] = '\0'; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define sstrcpyex(dest, source, cap) do { \
|
||||||
|
if (cap) { \
|
||||||
|
int16_t _i = 0; \
|
||||||
|
for (; _i + 1 < cap && (source)[_i]; ++_i) { \
|
||||||
|
(dest)[_i] = (source)[_i]; \
|
||||||
|
} \
|
||||||
|
(dest)[_i] = '\0'; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
// safe string append from (char*)source to (char*)dest for a destination array of size bytes
|
||||||
|
#define sstrcat(dest, source) do { \
|
||||||
|
int16_t _cap = sizeof(dest); \
|
||||||
|
if (_cap) { \
|
||||||
|
int16_t _i = 0; \
|
||||||
|
while (_i < _cap && (dest)[_i]) ++_i; \
|
||||||
|
if (_i >= _cap) { \
|
||||||
|
(dest)[_cap - 1] = '\0'; \
|
||||||
|
} else { \
|
||||||
|
int16_t _j = 0; \
|
||||||
|
for (; _i + 1 < _cap && (source)[_j]; ++_i, ++_j) { \
|
||||||
|
(dest)[_i] = (source)[_j]; \
|
||||||
|
} \
|
||||||
|
(dest)[_i] = '\0'; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define sstrcatex(dest, source, cap) do { \
|
||||||
|
int16_t _cap = (cap); \
|
||||||
|
if (_cap) { \
|
||||||
|
int16_t _i = 0; \
|
||||||
|
while (_i < _cap && (dest)[_i]) ++_i; \
|
||||||
|
if (_i >= _cap) { \
|
||||||
|
(dest)[_cap - 1] = '\0'; \
|
||||||
|
} else { \
|
||||||
|
int16_t _j = 0; \
|
||||||
|
for (; _i + 1 < _cap && (source)[_j]; ++_i, ++_j) { \
|
||||||
|
(dest)[_i] = (source)[_j]; \
|
||||||
|
} \
|
||||||
|
(dest)[_i] = '\0'; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
// safe single-character append for a destination array of size bytes
|
||||||
|
#define sstrcatc(dest, value) do { \
|
||||||
|
int16_t _cap = sizeof(dest); \
|
||||||
|
if (_cap) { \
|
||||||
|
int16_t _i = 0; \
|
||||||
|
while (_i < _cap && (dest)[_i]) ++_i; \
|
||||||
|
if (_i >= _cap) { \
|
||||||
|
(dest)[_cap - 1] = '\0'; \
|
||||||
|
} else if (_i + 1 < _cap) { \
|
||||||
|
(dest)[_i] = (value); \
|
||||||
|
(dest)[_i + 1] = '\0'; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define sstrcatcex(dest, value, cap) do { \
|
||||||
|
int16_t _cap = (cap); \
|
||||||
|
if (_cap) { \
|
||||||
|
int16_t _i = 0; \
|
||||||
|
while (_i < _cap && (dest)[_i]) ++_i; \
|
||||||
|
if (_i >= _cap) { \
|
||||||
|
(dest)[_cap - 1] = '\0'; \
|
||||||
|
} else if (_i + 1 < _cap) { \
|
||||||
|
(dest)[_i] = (value); \
|
||||||
|
(dest)[_i + 1] = '\0'; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
// truncate a string so there is room for reserve bytes plus the null terminator
|
||||||
|
#define sstrreserve(dest, reserve) do { \
|
||||||
|
int16_t _cap = sizeof(dest); \
|
||||||
|
int16_t _reserve = (reserve); \
|
||||||
|
if (_cap) { \
|
||||||
|
if (_reserve >= _cap) { \
|
||||||
|
(dest)[0] = '\0'; \
|
||||||
|
} else { \
|
||||||
|
int16_t _max = _cap - _reserve - 1; \
|
||||||
|
int16_t _i = 0; \
|
||||||
|
while (_i < _cap && (dest)[_i]) ++_i; \
|
||||||
|
if (_i >= _cap) { \
|
||||||
|
(dest)[_cap - 1] = '\0'; \
|
||||||
|
_i = _cap - 1; \
|
||||||
|
} \
|
||||||
|
if (_i > _max) (dest)[_max] = '\0'; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define sstrreserveex(dest, reserve, cap) do { \
|
||||||
|
int16_t _cap = (cap); \
|
||||||
|
int16_t _reserve = (reserve); \
|
||||||
|
if (_cap) { \
|
||||||
|
if (_reserve >= _cap) { \
|
||||||
|
(dest)[0] = '\0'; \
|
||||||
|
} else { \
|
||||||
|
int16_t _max = _cap - _reserve - 1; \
|
||||||
|
int16_t _i = 0; \
|
||||||
|
while (_i < _cap && (dest)[_i]) ++_i; \
|
||||||
|
if (_i >= _cap) { \
|
||||||
|
(dest)[_cap - 1] = '\0'; \
|
||||||
|
_i = _cap - 1; \
|
||||||
|
} \
|
||||||
|
if (_i > _max) (dest)[_max] = '\0'; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
// convert string to lower case
|
||||||
|
#define strtolower(source) for (int i = 0; source[i]; i++) source[i] = tolower(source[i])
|
||||||
|
|
||||||
|
#define _allowed_fqdn "0123456789abcdefghijklmnopqrstuvwxyz"
|
||||||
|
// convert to lower case and strip away characters that aren't allowed in an hostname
|
||||||
|
#define strtohostname(source) for (int i = 0; source[i]; i++) { source[i] = tolower(source[i]); if (!strchr(_allowed_fqdn "-", source[i])) { if (i < (int)(strlen(source) - 1)) { memmove(&source[i], &source[i + 1], strlen(&source[i])); i--; } else source[i] = 0;; } }
|
||||||
|
|
||||||
|
// convert to lower case and strip away characters that aren't allowed in an hostname (and '-')
|
||||||
|
#define strtohostname2(source) for (int i = 0; source[i]; i++) { source[i] = tolower(source[i]); if (!strchr(_allowed_fqdn, source[i])) { if (i < (int)(strlen(source) - 1)) { memmove(&source[i], &source[i + 1], strlen(&source[i])); i--; } else source[i] = 0;; } }
|
||||||
|
|
||||||
|
// embeds a string in a macro
|
||||||
|
#define STR_HELPER(x) #x
|
||||||
|
#define STR(x) STR_HELPER(x)
|
||||||
|
|
||||||
|
// ip address helper copies from one ip[4] address to another
|
||||||
|
#define ip4toip4(ip4, ip) for (int i = 0; i < 4; i++) ip4[i] = ip[i]
|
||||||
|
|
||||||
|
// check for an invalid ip[4] address of 0:0:0:0
|
||||||
|
#define validip4(ip4) (ip4[0]!=0?true:ip4[1]!=0?true:ip4[2]!=0?true:ip4[3]!=0?true:false)
|
||||||
|
|
||||||
|
// an empty string
|
||||||
|
#ifndef EmptyStr
|
||||||
|
#define EmptyStr ""
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// pins
|
||||||
|
#define DAC_PIN(v) ((v)+0x100)
|
||||||
|
#define GPIO_PIN(v) ((v)+0x200)
|
||||||
|
|
||||||
|
// sense
|
||||||
|
#define THLD(v) ((v)<<1) // 10 bit analog threshold, bits 1 through 10
|
||||||
|
#define HYST(v) ((v)<<11) // 10 bit hysteresis, bits 11 through 20
|
||||||
|
#define ANLG(v) ((v)<<21) // 10 bit analog value, bits 21 through 30
|
||||||
|
#ifndef INPUT_PULLDOWN
|
||||||
|
#define INPUT_PULLDOWN INPUT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define RANGE_FROM_BITS(bits) ((1 << (bits)) - 1)
|
||||||
|
|
||||||
|
#define BITS_FROM_RANGE(R) ( \
|
||||||
|
(R)<=1?1 : (R)<=3?2 : (R)<=7?3 : (R)<=15?4 : (R)<=31?5 : (R)<=63?6 : \
|
||||||
|
(R)<=127?7 : (R)<=255?8 : (R)<=511?9 : (R)<=1023?10 : (R)<=2047?11 : \
|
||||||
|
(R)<=4095?12 : (R)<=8191?13 : (R)<=16383?14 : (R)<=32767?15 : 16 )
|
||||||
|
|
||||||
|
#define IS_POW2_MINUS1(R) ((R) > 0 && (R) < 0xFFFFFFFFU && (((R) + 1) & (R)) == 0)
|
||||||
|
|
||||||
|
// Atomic helpers for single ISR-shared scalars.
|
||||||
|
// Use for single reads/writes/RMW only. For multi-variable invariants, keep cli/sei blocks.
|
||||||
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
|
|
||||||
|
#define ATOMIC_LOAD(var) (__atomic_load_n(&(var), __ATOMIC_ACQUIRE))
|
||||||
|
#define ATOMIC_STORE(var, val) (__atomic_store_n(&(var), (val), __ATOMIC_RELEASE))
|
||||||
|
#define ATOMIC_XCHG(var, val) (__atomic_exchange_n(&(var), (val), __ATOMIC_ACQ_REL))
|
||||||
|
|
||||||
|
// Read/Modify/Write bit ops (return previous value)
|
||||||
|
#define ATOMIC_OR(var, mask) (__atomic_fetch_or(&(var), (mask), __ATOMIC_ACQ_REL))
|
||||||
|
#define ATOMIC_AND(var, mask) (__atomic_fetch_and(&(var), (mask), __ATOMIC_ACQ_REL))
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define ATOMIC_LOAD(var) \
|
||||||
|
({ __typeof__(var) _v; noInterrupts(); _v = (var); interrupts(); _v; })
|
||||||
|
|
||||||
|
#define ATOMIC_STORE(var, val) \
|
||||||
|
do { noInterrupts(); (var) = (val); interrupts(); } while (0)
|
||||||
|
|
||||||
|
#define ATOMIC_XCHG(var, val) \
|
||||||
|
({ __typeof__(var) _old; noInterrupts(); _old = (var); (var) = (val); interrupts(); _old; })
|
||||||
|
|
||||||
|
// Read/Modify/Write bit ops (return previous value)
|
||||||
|
#define ATOMIC_OR(var, mask) \
|
||||||
|
({ __typeof__(var) _old; noInterrupts(); _old = (var); (var) = (__typeof__(var))(_old | (__typeof__(var))(mask)); interrupts(); _old; })
|
||||||
|
|
||||||
|
#define ATOMIC_AND(var, mask) \
|
||||||
|
({ __typeof__(var) _old; noInterrupts(); _old = (var); (var) = (__typeof__(var))(_old & (__typeof__(var))(mask)); interrupts(); _old; })
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Fast GPIO read/write for Arduino-ESP32 cores 2.x / 3.x
|
||||||
|
// Works across ESP32 / ESP32-S2 / ESP32-S3
|
||||||
|
#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||||
|
#include "soc/gpio_struct.h"
|
||||||
|
|
||||||
|
// SOC_GPIO_PIN_COUNT exists in ESP-IDF-based cores; core 1.x may be missing it.
|
||||||
|
#if defined(__has_include)
|
||||||
|
#if __has_include("soc/soc_caps.h")
|
||||||
|
#include "soc/soc_caps.h"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static inline IRAM_ATTR void gpioWriteFast(uint32_t pin, uint32_t level) {
|
||||||
|
if (pin >= (uint32_t)SOC_GPIO_PIN_COUNT) return;
|
||||||
|
uint32_t mask = 1UL << (pin & 31U);
|
||||||
|
if (pin < 32U) { if (level) GPIO.out_w1ts = mask; else GPIO.out_w1tc = mask; }
|
||||||
|
#if SOC_GPIO_PIN_COUNT > 32
|
||||||
|
else { if (level) GPIO.out1_w1ts.val = mask; else GPIO.out1_w1tc.val = mask; }
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#ifndef digitalWriteF
|
||||||
|
#define digitalWriteF(pin,value) gpioWriteFast((uint32_t)(pin), (uint32_t)(value))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static inline IRAM_ATTR uint32_t gpioReadFast(uint32_t pin) {
|
||||||
|
if (pin >= (uint32_t)SOC_GPIO_PIN_COUNT) return 0;
|
||||||
|
uint32_t mask = 1UL << (pin & 31U);
|
||||||
|
if (pin < 32U) { return (GPIO.in & mask) ? 1U : 0U; }
|
||||||
|
#if SOC_GPIO_PIN_COUNT > 32
|
||||||
|
else { return (GPIO.in1.data & mask) ? 1U : 0U; }
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#ifndef digitalReadF
|
||||||
|
#define digitalReadF(pin) gpioReadFast((uint32_t)(pin))
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// automatically use fast I/O if available
|
||||||
|
#ifndef digitalReadF
|
||||||
|
#ifdef HAL_HAS_DIGITAL_FAST
|
||||||
|
#define digitalReadF(pin) ( digitalReadFast(pin) )
|
||||||
|
#else
|
||||||
|
#define digitalReadF(pin) ( digitalRead(pin) )
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#ifndef digitalWriteF
|
||||||
|
#ifdef HAL_HAS_DIGITAL_FAST
|
||||||
|
#define digitalWriteF(pin,value) { digitalWriteFast(pin,value); }
|
||||||
|
#else
|
||||||
|
#define digitalWriteF(pin,value) { digitalWrite(pin,value); }
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// supress compiler warnings for unused parameters
|
||||||
|
#ifndef UNUSED
|
||||||
|
#define UNUSED(x) (void)(x)
|
||||||
|
#endif
|
||||||
Executable
+660
@@ -0,0 +1,660 @@
|
|||||||
|
// Analog.cpp
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "Analog.h"
|
||||||
|
|
||||||
|
// this was only for pin 38 of a Teensy4.1, now any pin
|
||||||
|
#if defined(ARDUINO_TEENSY41) && defined(PWM_CUSTOM_PIN) && \
|
||||||
|
defined(PWM_CUSTOM_ANALOG_WRITE_FREQUENCY) && defined(PWM_CUSTOM_ANALOG_WRITE_RANGE)
|
||||||
|
#define HAS_CUSTOM_PIN
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAS_CUSTOM_PIN
|
||||||
|
static IntervalTimer itimer4;
|
||||||
|
static volatile uint16_t _pwm_custom_period = 0;
|
||||||
|
static volatile uint8_t _pwm_custom_toggle = 0;
|
||||||
|
static float _base_freq_divider = PWM_CUSTOM_ANALOG_WRITE_FREQUENCY/(1.0F/(PWM_CUSTOM_ANALOG_WRITE_RANGE/1000000.0F));
|
||||||
|
|
||||||
|
void PWM_CUSTOM_HWTIMER() {
|
||||||
|
if (_pwm_custom_period == 0 || _pwm_custom_period == PWM_CUSTOM_ANALOG_WRITE_RANGE) {
|
||||||
|
itimer4.update(PWM_CUSTOM_ANALOG_WRITE_RANGE/_base_freq_divider);
|
||||||
|
digitalWriteF(PWM_CUSTOM_PIN, _pwm_custom_period == PWM_CUSTOM_ANALOG_WRITE_RANGE);
|
||||||
|
_pwm_custom_toggle = 0;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
if (!_pwm_custom_toggle) {
|
||||||
|
itimer4.update((PWM_CUSTOM_ANALOG_WRITE_RANGE - _pwm_custom_period)/_base_freq_divider);
|
||||||
|
digitalWriteF(PWM_CUSTOM_PIN, LOW);
|
||||||
|
} else {
|
||||||
|
itimer4.update(_pwm_custom_period/_base_freq_divider);
|
||||||
|
digitalWriteF(PWM_CUSTOM_PIN, HIGH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_pwm_custom_toggle = !_pwm_custom_toggle;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define analogWriteCustomPin(x) do { \
|
||||||
|
uint32_t _v = (uint32_t)(x); \
|
||||||
|
if (_v > (uint32_t)PWM_CUSTOM_ANALOG_WRITE_RANGE) _v = (uint32_t)PWM_CUSTOM_ANALOG_WRITE_RANGE; \
|
||||||
|
_pwm_custom_period = (uint16_t)_v; \
|
||||||
|
} while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// track actual global resolution when platform only supports global reconfig.
|
||||||
|
// keeps behavior honest (no "virtual range trick").
|
||||||
|
static uint16_t gPwmBits = (uint16_t)BITS_FROM_RANGE(ANALOG_WRITE_RANGE);
|
||||||
|
static uint16_t gAdcBits = (uint16_t)BITS_FROM_RANGE(ANALOG_READ_RANGE);
|
||||||
|
static volatile bool ready = false;
|
||||||
|
|
||||||
|
static inline bool toCorePin(int16_t pin, uint8_t &out) {
|
||||||
|
if (!ready) return false; // not initialized
|
||||||
|
if (pin == OFF) return false;
|
||||||
|
if (pin < 0) return false; // reject any other negative
|
||||||
|
if (pin > 0xFF) return false; // prevents wrap on platforms with >255 pins
|
||||||
|
out = (uint8_t)pin;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t clampU32(uint32_t v, uint32_t lo, uint32_t hi) {
|
||||||
|
if (v < lo) return lo;
|
||||||
|
if (v > hi) return hi;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline float clamp01(float x) {
|
||||||
|
if (isnan(x) || isinf(x)) return 0.0F;
|
||||||
|
if (x < 0.0F) return 0.0F;
|
||||||
|
if (x > 1.0F) return 1.0F;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t rangeFromBits(uint16_t bits) {
|
||||||
|
if (bits == 0) return 0;
|
||||||
|
if (bits >= 32) return 0xFFFFFFFFu;
|
||||||
|
return (1u << bits) - 1u;
|
||||||
|
}
|
||||||
|
|
||||||
|
int AnalogClass::pwmIndex(int16_t pin) const {
|
||||||
|
for (int i = 0; i < MAX_TRACKED; i++) if (pwm_[i].pin == pin) return i;
|
||||||
|
for (int i = 0; i < MAX_TRACKED; i++) if (pwm_[i].pin == OFF) return i;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int AnalogClass::adcIndex(int16_t pin) const {
|
||||||
|
for (int i = 0; i < MAX_TRACKED; i++) if (adc_[i].pin == pin) return i;
|
||||||
|
for (int i = 0; i < MAX_TRACKED; i++) if (adc_[i].pin == OFF) return i;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// prepare global adc read resolution and global pwm write resolution/frequency
|
||||||
|
void AnalogClass::begin() {
|
||||||
|
if (ready) return;
|
||||||
|
|
||||||
|
VLF("MSG: Analog, begin");
|
||||||
|
|
||||||
|
// ADC global default
|
||||||
|
(void)gAdcBits;
|
||||||
|
#if HAL_HAS_GLOBAL_ADC_RESOLUTION
|
||||||
|
const uint16_t adcBits = (uint16_t)BITS_FROM_RANGE(ANALOG_READ_RANGE);
|
||||||
|
analogReadResolution(adcBits);
|
||||||
|
gAdcBits = adcBits;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// PWM global default (ONLY if your platform truly uses a global resolution)
|
||||||
|
(void)gPwmBits;
|
||||||
|
#if HAL_HAS_GLOBAL_PWM_RESOLUTION && !HAL_HAS_PER_PIN_PWM_RESOLUTION
|
||||||
|
const uint16_t pwmBits = (uint16_t)BITS_FROM_RANGE(ANALOG_WRITE_RANGE);
|
||||||
|
analogWriteResolution(pwmBits);
|
||||||
|
gPwmBits = pwmBits;
|
||||||
|
VF("MSG: Analog, pwmInit global PWM resolution changed to bits="); VL(pwmBits);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// PWM global freq (again: only if global is real on that platform)
|
||||||
|
#if defined(ANALOG_WRITE_FREQUENCY) && HAL_HAS_GLOBAL_PWM_FREQUENCY
|
||||||
|
analogWriteFrequency(ANALOG_WRITE_FREQUENCY);
|
||||||
|
VF("MSG: Analog, pwmInit global PWM freq changed to hz="); VL(ANALOG_WRITE_FREQUENCY);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ready = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------- PWM ----------------
|
||||||
|
|
||||||
|
bool AnalogClass::pwmInit(int16_t pin, const AnalogPwmConfig& cfg) {
|
||||||
|
uint8_t p;
|
||||||
|
if (!toCorePin(pin, p)) {
|
||||||
|
DF("ERR: Analog, pwmInit invalid pin="); DL(pin);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int idx = pwmIndex(pin);
|
||||||
|
if (idx < 0) { DF("ERR: Analog, pwmInit table full pin="); DL(pin); return false; }
|
||||||
|
const uint32_t defRange = (uint32_t)ANALOG_WRITE_RANGE;
|
||||||
|
uint16_t reqBits = cfg.bits;
|
||||||
|
uint32_t reqRange = cfg.range;
|
||||||
|
uint32_t reqHz = cfg.hz;
|
||||||
|
|
||||||
|
// if this is a T4.1 allow one extra custom PWM pin
|
||||||
|
#ifdef HAS_CUSTOM_PIN
|
||||||
|
if (pin == PWM_CUSTOM_PIN) {
|
||||||
|
pinMode(PWM_CUSTOM_PIN, OUTPUT);
|
||||||
|
pwm_[idx].custom = true;
|
||||||
|
itimer4.priority(0);
|
||||||
|
itimer4.begin(PWM_CUSTOM_HWTIMER, 100);
|
||||||
|
VF("MSG: Analog, pwmInit emulating PWM using Teensy4.1 iTimer4 on pin"); VL(pin);
|
||||||
|
reqBits = BITS_FROM_RANGE(PWM_CUSTOM_ANALOG_WRITE_RANGE);
|
||||||
|
reqRange = PWM_CUSTOM_ANALOG_WRITE_RANGE;
|
||||||
|
reqHz = PWM_CUSTOM_ANALOG_WRITE_FREQUENCY;
|
||||||
|
} else pwm_[idx].custom = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!pwm_[idx].custom) {
|
||||||
|
|
||||||
|
// derive bits from range if only range provided (range must be 2^n-1)
|
||||||
|
if (reqBits == 0 && reqRange != 0) {
|
||||||
|
if (reqRange == 0xFFFFFFFFu) {
|
||||||
|
DF("ERR: Analog, pwmInit range wrap pin="); D(pin); DF(" range="); DL(reqRange);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
uint32_t r = reqRange + 1;
|
||||||
|
if ((r & (r - 1)) != 0) {
|
||||||
|
DF("ERR: Analog, pwmInit range not 2^n-1 pin="); D(pin); DF(" range="); DL(reqRange);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
uint16_t b = 0;
|
||||||
|
while (r >>= 1) b++;
|
||||||
|
reqBits = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
// derive range from bits or default
|
||||||
|
if (reqBits == 0 && reqRange == 0) {
|
||||||
|
reqRange = defRange;
|
||||||
|
} else if (reqRange == 0 && reqBits != 0) {
|
||||||
|
reqRange = rangeFromBits(reqBits);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef ANALOG_WRITE_FREQUENCY
|
||||||
|
if (reqHz == 0) {
|
||||||
|
reqHz = ANALOG_WRITE_FREQUENCY;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// bounds
|
||||||
|
if (reqBits) {
|
||||||
|
if (reqBits < HAL_PWM_BITS_MIN || reqBits > HAL_PWM_BITS_MAX) {
|
||||||
|
DF("ERR: Analog, pwmInit bits out of bounds pin="); D(pin);
|
||||||
|
DF(" bits="); D(reqBits); DF(" ("); D(HAL_PWM_BITS_MIN); DF(".."); D(HAL_PWM_BITS_MAX); DLF(")");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (reqHz) {
|
||||||
|
if (reqHz < HAL_PWM_HZ_MIN || reqHz > HAL_PWM_HZ_MAX) {
|
||||||
|
DF("ERR: Analog, pwmInit hz out of bounds pin="); D(pin);
|
||||||
|
DF(" hz="); D(reqHz); DF(" ("); D(HAL_PWM_HZ_MIN); DF(".."); D(HAL_PWM_HZ_MAX); DLF(")");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- APPLY (best-effort) ---
|
||||||
|
|
||||||
|
// warn generally the "per-pin resolutions/frequencies" can still affect other pins if the core
|
||||||
|
// maps channels to shared timers. This may interfere with tone() or other PWM users.
|
||||||
|
static bool warned = false;
|
||||||
|
(void)warned;
|
||||||
|
|
||||||
|
// frequency
|
||||||
|
if (reqHz) {
|
||||||
|
#if HAL_HAS_PER_PIN_PWM_FREQUENCY
|
||||||
|
analogWriteFrequency(p, reqHz);
|
||||||
|
if (!warned) {
|
||||||
|
warned = true;
|
||||||
|
VLF("WRN: Analog, adding new resolutions/frequencies may affect other PWM pins (tone, servo, due to shared timers.)");
|
||||||
|
}
|
||||||
|
#elif HAL_HAS_GLOBAL_PWM_FREQUENCY
|
||||||
|
if (!HAL_ALLOW_GLOBAL_PWM_RECONFIG) {
|
||||||
|
DF("ERR: Analog, pwmInit global PWM freq reconfig disallowed pin="); DL(pin);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
analogWriteFrequency(reqHz);
|
||||||
|
VF("WRN: Analog, pwmInit global PWM freq changed hz="); VL(reqHz);
|
||||||
|
#else
|
||||||
|
DF("ERR: Analog, pwmInit no PWM frequency control pin="); DL(pin);
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// resolution
|
||||||
|
if (reqBits) {
|
||||||
|
#if HAL_HAS_PER_PIN_PWM_RESOLUTION
|
||||||
|
analogWriteResolution(p, reqBits);
|
||||||
|
if (!warned) {
|
||||||
|
warned = true;
|
||||||
|
VLF("WRN: Analog, adding new resolutions/frequencies may affect other PWM pins (tone, servo, due to shared timers.)");
|
||||||
|
}
|
||||||
|
#elif HAL_HAS_GLOBAL_PWM_RESOLUTION
|
||||||
|
if (reqBits != gPwmBits) {
|
||||||
|
if (!HAL_ALLOW_GLOBAL_PWM_RECONFIG) {
|
||||||
|
DF("ERR: Analog, pwmInit global PWM resolution reconfig disallowed pin="); D(pin);
|
||||||
|
DF(" reqBits="); D(reqBits);
|
||||||
|
DF(" currentBits="); DL(gPwmBits);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
analogWriteResolution(reqBits);
|
||||||
|
gPwmBits = reqBits;
|
||||||
|
VF("WRN: Analog, pwmInit global PWM bits set bits="); VL(reqBits);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
DF("ERR: Analog, pwmInit no PWM resolution control pin="); DL(pin);
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
} else reqBits = gPwmBits;
|
||||||
|
}
|
||||||
|
|
||||||
|
pwm_[idx].pin = pin;
|
||||||
|
pwm_[idx].bits = reqBits;
|
||||||
|
pwm_[idx].hz = reqHz;
|
||||||
|
pwm_[idx].range = reqRange ? reqRange : defRange;
|
||||||
|
|
||||||
|
VF("MSG: Analog, pwmInit ok pin="); V(pin);
|
||||||
|
VF(" bits="); V(reqBits);
|
||||||
|
VF(" hz="); V(reqHz);
|
||||||
|
VF(" range="); VL(pwm_[idx].range);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
AnalogPwmHandle AnalogClass::pwmInitHandle(int16_t pin, const AnalogPwmConfig& cfg) {
|
||||||
|
AnalogPwmHandle h;
|
||||||
|
h.pin = 0;
|
||||||
|
h.idx = ANALOG_INVALID_IDX;
|
||||||
|
|
||||||
|
uint8_t p;
|
||||||
|
if (!toCorePin(pin, p)) {
|
||||||
|
DF("ERR: Analog pwmInitHandle invalid pin="); DL(pin);
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
if (!pwmInit(pin, cfg)) {
|
||||||
|
// pwmInit already emits the detailed error path
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
// find the committed slot for this pin (no allocation now, should hit first loop)
|
||||||
|
int idx = -1;
|
||||||
|
for (int i = 0; i < MAX_TRACKED; i++) if (pwm_[i].pin == pin) { idx = i; break; }
|
||||||
|
if (idx < 0 || idx > 0xFE) {
|
||||||
|
DF("ERR: Analog pwmInitHandle slot not found pin="); DL(pin);
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
h.pin = p;
|
||||||
|
h.idx = (uint8_t)idx;
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t AnalogClass::pwmRange(int16_t pin) const {
|
||||||
|
const uint32_t fallback = (uint32_t)ANALOG_WRITE_RANGE;
|
||||||
|
|
||||||
|
#ifdef HAS_CUSTOM_PIN
|
||||||
|
if (pin == (int16_t)PWM_CUSTOM_PIN) {
|
||||||
|
for (int i = 0; i < MAX_TRACKED; i++)
|
||||||
|
if (pwm_[i].pin == pin) return pwm_[i].range ? pwm_[i].range : fallback;
|
||||||
|
return (uint32_t)PWM_CUSTOM_ANALOG_WRITE_RANGE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// if only global PWM resolution exists, report the true global range
|
||||||
|
#if HAL_HAS_GLOBAL_PWM_RESOLUTION && !HAL_HAS_PER_PIN_PWM_RESOLUTION
|
||||||
|
return rangeFromBits(gPwmBits);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (int i = 0; i < MAX_TRACKED; i++) {
|
||||||
|
if (pwm_[i].pin == pin) return pwm_[i].range ? pwm_[i].range : fallback;
|
||||||
|
}
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnalogClass::write(int16_t pin, uint32_t v) {
|
||||||
|
uint8_t p;
|
||||||
|
if (!toCorePin(pin, p)) {
|
||||||
|
VF("WRN: Analog write(u32) invalid pin="); VL(pin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint32_t r = pwmRange(pin);
|
||||||
|
v = clampU32(v, 0, r);
|
||||||
|
|
||||||
|
#ifdef HAS_CUSTOM_PIN
|
||||||
|
if (p == (uint8_t)PWM_CUSTOM_PIN) { analogWriteCustomPin(v); } else
|
||||||
|
#endif
|
||||||
|
analogWrite(p, (int)v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnalogClass::write(int16_t pin, float x01) {
|
||||||
|
uint8_t p;
|
||||||
|
if (!toCorePin(pin, p)) {
|
||||||
|
VF("WRN: Analog write(f) invalid pin="); VL(pin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
x01 = clamp01(x01);
|
||||||
|
const uint32_t r = pwmRange(pin);
|
||||||
|
const uint32_t v = (uint32_t)lroundf(x01 * (float)r);
|
||||||
|
|
||||||
|
#ifdef HAS_CUSTOM_PIN
|
||||||
|
if (p == (uint8_t)PWM_CUSTOM_PIN) { analogWriteCustomPin(v); } else
|
||||||
|
#endif
|
||||||
|
analogWrite(p, (int)v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnalogClass::writeQ16(int16_t pin, uint16_t q16) {
|
||||||
|
uint8_t p;
|
||||||
|
if (!toCorePin(pin, p)) {
|
||||||
|
VF("WRN: Analog writeQ16 invalid pin="); VL(pin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint32_t r = pwmRange(pin);
|
||||||
|
const uint32_t v = (uint32_t)((((uint64_t)q16) * (uint64_t)r + 32767ULL) / 65535ULL);
|
||||||
|
|
||||||
|
#ifdef HAS_CUSTOM_PIN
|
||||||
|
if (p == (uint8_t)PWM_CUSTOM_PIN) { analogWriteCustomPin(v); } else
|
||||||
|
#endif
|
||||||
|
analogWrite(p, (int)v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnalogClass::write(const AnalogPwmHandle& h, uint32_t v) {
|
||||||
|
if (h.idx == ANALOG_INVALID_IDX) return;
|
||||||
|
|
||||||
|
uint32_t r;
|
||||||
|
#ifdef HAS_CUSTOM_PIN
|
||||||
|
if (h.pin == (uint8_t)PWM_CUSTOM_PIN) {
|
||||||
|
r = pwm_[h.idx].range ? pwm_[h.idx].range : (uint32_t)PWM_CUSTOM_ANALOG_WRITE_RANGE;
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
#if HAL_HAS_GLOBAL_PWM_RESOLUTION && !HAL_HAS_PER_PIN_PWM_RESOLUTION
|
||||||
|
r = rangeFromBits(gPwmBits);
|
||||||
|
#else
|
||||||
|
r = pwm_[h.idx].range ? pwm_[h.idx].range : (uint32_t)ANALOG_WRITE_RANGE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
v = clampU32(v, 0, r);
|
||||||
|
|
||||||
|
#ifdef HAS_CUSTOM_PIN
|
||||||
|
if (h.pin == (uint8_t)PWM_CUSTOM_PIN) { analogWriteCustomPin(v); } else
|
||||||
|
#endif
|
||||||
|
analogWrite(h.pin, (int)v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnalogClass::write(const AnalogPwmHandle& h, float x01) {
|
||||||
|
if (h.idx == ANALOG_INVALID_IDX) return;
|
||||||
|
|
||||||
|
x01 = clamp01(x01);
|
||||||
|
|
||||||
|
uint32_t r;
|
||||||
|
#ifdef HAS_CUSTOM_PIN
|
||||||
|
if (h.pin == (uint8_t)PWM_CUSTOM_PIN) {
|
||||||
|
r = pwm_[h.idx].range ? pwm_[h.idx].range : (uint32_t)PWM_CUSTOM_ANALOG_WRITE_RANGE;
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
#if HAL_HAS_GLOBAL_PWM_RESOLUTION && !HAL_HAS_PER_PIN_PWM_RESOLUTION
|
||||||
|
r = rangeFromBits(gPwmBits);
|
||||||
|
#else
|
||||||
|
r = pwm_[h.idx].range ? pwm_[h.idx].range : (uint32_t)ANALOG_WRITE_RANGE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const uint32_t v = (uint32_t)lroundf(x01 * (float)r);
|
||||||
|
|
||||||
|
#ifdef HAS_CUSTOM_PIN
|
||||||
|
if (h.pin == (uint8_t)PWM_CUSTOM_PIN) { analogWriteCustomPin(v); } else
|
||||||
|
#endif
|
||||||
|
analogWrite(h.pin, (int)v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnalogClass::writeQ16(const AnalogPwmHandle& h, uint16_t q16) {
|
||||||
|
if (h.idx == ANALOG_INVALID_IDX) return;
|
||||||
|
|
||||||
|
uint32_t r;
|
||||||
|
#ifdef HAS_CUSTOM_PIN
|
||||||
|
if (h.pin == (uint8_t)PWM_CUSTOM_PIN) {
|
||||||
|
r = pwm_[h.idx].range ? pwm_[h.idx].range : (uint32_t)PWM_CUSTOM_ANALOG_WRITE_RANGE;
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
#if HAL_HAS_GLOBAL_PWM_RESOLUTION && !HAL_HAS_PER_PIN_PWM_RESOLUTION
|
||||||
|
r = rangeFromBits(gPwmBits);
|
||||||
|
#else
|
||||||
|
r = pwm_[h.idx].range ? pwm_[h.idx].range : (uint32_t)ANALOG_WRITE_RANGE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const uint32_t v = (uint32_t)((((uint64_t)q16) * (uint64_t)r + 32767ULL) / 65535ULL);
|
||||||
|
|
||||||
|
#ifdef HAS_CUSTOM_PIN
|
||||||
|
if (h.pin == (uint8_t)PWM_CUSTOM_PIN) { analogWriteCustomPin(v); } else
|
||||||
|
#endif
|
||||||
|
analogWrite(h.pin, (int)v);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------- ADC ----------------
|
||||||
|
|
||||||
|
bool AnalogClass::adcInit(int16_t pin, const AnalogAdcConfig& cfg) {
|
||||||
|
uint8_t p;
|
||||||
|
if (!toCorePin(pin, p)) {
|
||||||
|
DF("ERR: Analog adcInit invalid pin="); DL(pin);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int idx = adcIndex(pin);
|
||||||
|
if (idx < 0) { DF("ERR: Analog adcInit table full pin="); DL(pin); return false; }
|
||||||
|
const uint32_t defRange = (uint32_t)ANALOG_READ_RANGE;
|
||||||
|
|
||||||
|
uint16_t reqBits = cfg.bits;
|
||||||
|
uint32_t reqRange = cfg.range;
|
||||||
|
|
||||||
|
// derive bits from range if needed (range must be 2^n-1)
|
||||||
|
if (reqBits == 0 && reqRange != 0) {
|
||||||
|
if (!IS_POW2_MINUS1(reqRange)) {
|
||||||
|
DF("ERR: Analog adcInit range not 2^n-1 pin="); D(pin); DF(" range="); DL(reqRange);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
reqBits = (uint16_t)BITS_FROM_RANGE(reqRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
// derive range from bits or default
|
||||||
|
if (reqBits == 0 && reqRange == 0) {
|
||||||
|
reqRange = defRange;
|
||||||
|
} else if (reqRange == 0 && reqBits != 0) {
|
||||||
|
reqRange = rangeFromBits(reqBits);
|
||||||
|
}
|
||||||
|
|
||||||
|
// bounds
|
||||||
|
if (reqBits) {
|
||||||
|
if (reqBits < HAL_ADC_BITS_MIN || reqBits > HAL_ADC_BITS_MAX) {
|
||||||
|
DF("ERR: Analog, adcInit bits out of bounds pin="); D(pin);
|
||||||
|
DF(" bits="); D(reqBits); DF(" ("); D(HAL_ADC_BITS_MIN); DF(".."); D(HAL_ADC_BITS_MAX); DLF(")");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// apply resolution only if allowed
|
||||||
|
if (reqBits) {
|
||||||
|
#if HAL_HAS_PER_PIN_ADC_RESOLUTION
|
||||||
|
analogReadResolution(p, reqBits);
|
||||||
|
#elif HAL_HAS_GLOBAL_ADC_RESOLUTION
|
||||||
|
if (!HAL_ALLOW_GLOBAL_ADC_RECONFIG) {
|
||||||
|
DF("ERR: Analog, adcInit global ADC reconfig disallowed pin="); DL(pin);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
analogReadResolution(reqBits);
|
||||||
|
gAdcBits = reqBits; // reflect actual global state
|
||||||
|
VF("WRN: Analog, adcInit global ADC bits set bits="); VL(reqBits);
|
||||||
|
#else
|
||||||
|
DF("ERR: Analog, adcInit no ADC resolution control pin="); DL(pin);
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
adc_[idx].pin = pin;
|
||||||
|
adc_[idx].bits = reqBits;
|
||||||
|
adc_[idx].range = reqRange ? reqRange : defRange;
|
||||||
|
adc_[idx].oversample = cfg.oversample ? cfg.oversample : 1;
|
||||||
|
|
||||||
|
VF("MSG: Analog, adcInit ok pin="); V(pin);
|
||||||
|
VF(" bits="); V(reqBits);
|
||||||
|
VF(" range="); V(adc_[idx].range);
|
||||||
|
VF(" os="); VL(adc_[idx].oversample);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
AnalogAdcHandle AnalogClass::adcInitHandle(int16_t pin, const AnalogAdcConfig& cfg) {
|
||||||
|
AnalogAdcHandle h;
|
||||||
|
h.pin = 0;
|
||||||
|
h.oversample = 1;
|
||||||
|
h.idx = ANALOG_INVALID_IDX;
|
||||||
|
|
||||||
|
uint8_t p;
|
||||||
|
if (!toCorePin(pin, p)) {
|
||||||
|
DF("ERR: Analog, adcInitHandle invalid pin="); DL(pin);
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
if (!adcInit(pin, cfg)) {
|
||||||
|
// adcInit already emits the detailed error path
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
int idx = -1;
|
||||||
|
for (int i = 0; i < MAX_TRACKED; i++) if (adc_[i].pin == pin) { idx = i; break; }
|
||||||
|
if (idx < 0 || idx > 0xFE) {
|
||||||
|
DF("ERR: Analog, adcInitHandle slot not found pin="); DL(pin);
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
h.pin = p;
|
||||||
|
h.idx = (uint8_t)idx;
|
||||||
|
h.oversample = adc_[idx].oversample ? adc_[idx].oversample : 1;
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t AnalogClass::adcRange(int16_t pin) const {
|
||||||
|
const uint32_t fallback = (uint32_t)ANALOG_READ_RANGE;
|
||||||
|
|
||||||
|
// If only global ADC resolution exists, report the true global range
|
||||||
|
#if HAL_HAS_GLOBAL_ADC_RESOLUTION && !HAL_HAS_PER_PIN_ADC_RESOLUTION
|
||||||
|
(void)pin;
|
||||||
|
return rangeFromBits(gAdcBits);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (int i = 0; i < MAX_TRACKED; i++) {
|
||||||
|
if (adc_[i].pin == pin) return adc_[i].range ? adc_[i].range : fallback;
|
||||||
|
}
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t AnalogClass::read(int16_t pin) {
|
||||||
|
uint8_t p;
|
||||||
|
if (!toCorePin(pin, p)) {
|
||||||
|
VF("WRN: Analog, read invalid pin="); VL(pin);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t os = 1;
|
||||||
|
for (int i = 0; i < MAX_TRACKED; i++) {
|
||||||
|
if (adc_[i].pin == pin) { os = adc_[i].oversample; break; }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (os <= 1) return (uint32_t)analogRead(p);
|
||||||
|
|
||||||
|
uint32_t acc = 0;
|
||||||
|
for (uint8_t i = 0; i < os; i++) acc += (uint32_t)analogRead(p);
|
||||||
|
return (acc + (os / 2)) / os;
|
||||||
|
}
|
||||||
|
|
||||||
|
float AnalogClass::readf(int16_t pin) {
|
||||||
|
uint8_t p;
|
||||||
|
if (!toCorePin(pin, p)) {
|
||||||
|
VF("WRN: Analog, readf invalid pin="); VL(pin);
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
(void)p;
|
||||||
|
|
||||||
|
const uint32_t r = adcRange(pin);
|
||||||
|
const uint32_t v = read(pin);
|
||||||
|
if (r == 0) return 0.0f;
|
||||||
|
return clamp01((float)v / (float)r);
|
||||||
|
}
|
||||||
|
|
||||||
|
float AnalogClass::readV(int16_t pin) {
|
||||||
|
uint8_t p;
|
||||||
|
if (!toCorePin(pin, p)) {
|
||||||
|
VF("WRN: Analog, readV invalid pin="); VL(pin);
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(ESP32)
|
||||||
|
return (float)analogReadMilliVolts(p) * 0.001F;
|
||||||
|
#else
|
||||||
|
const uint32_t r = adcRange(pin);
|
||||||
|
if (r == 0) return 0.0F;
|
||||||
|
const uint32_t raw = read(pin);
|
||||||
|
return (float)raw * (HAL_VCC / (float)r);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t AnalogClass::readQ16(int16_t pin) {
|
||||||
|
uint8_t p;
|
||||||
|
if (!toCorePin(pin, p)) {
|
||||||
|
VF("WRN: Analog, readQ16 invalid pin="); VL(pin);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
(void)p;
|
||||||
|
|
||||||
|
const uint32_t r = adcRange(pin);
|
||||||
|
const uint32_t v = read(pin);
|
||||||
|
if (r == 0) return 0;
|
||||||
|
|
||||||
|
const uint32_t q = (uint32_t)((((uint64_t)v) * 65535ULL + (r / 2)) / (uint64_t)r);
|
||||||
|
return (uint16_t)clampU32(q, 0, 65535U);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t AnalogClass::read(const AnalogAdcHandle& h) {
|
||||||
|
if (h.idx == ANALOG_INVALID_IDX) return 0;
|
||||||
|
|
||||||
|
const uint8_t os = (h.oversample <= 1) ? 1 : h.oversample;
|
||||||
|
if (os == 1) return (uint32_t)analogRead(h.pin);
|
||||||
|
|
||||||
|
uint32_t acc = 0;
|
||||||
|
for (uint8_t i = 0; i < os; i++) acc += (uint32_t)analogRead(h.pin);
|
||||||
|
return (acc + (os / 2)) / os;
|
||||||
|
}
|
||||||
|
|
||||||
|
float AnalogClass::readf(const AnalogAdcHandle& h) {
|
||||||
|
if (h.idx == ANALOG_INVALID_IDX) return 0.0f;
|
||||||
|
|
||||||
|
uint32_t r;
|
||||||
|
#if HAL_HAS_GLOBAL_ADC_RESOLUTION && !HAL_HAS_PER_PIN_ADC_RESOLUTION
|
||||||
|
r = rangeFromBits(gAdcBits);
|
||||||
|
#else
|
||||||
|
r = adc_[h.idx].range ? adc_[h.idx].range : (uint32_t)ANALOG_READ_RANGE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (r == 0) return 0.0f;
|
||||||
|
const uint32_t v = read(h);
|
||||||
|
return clamp01((float)v / (float)r);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t AnalogClass::readQ16(const AnalogAdcHandle& h) {
|
||||||
|
if (h.idx == ANALOG_INVALID_IDX) return 0;
|
||||||
|
|
||||||
|
uint32_t r;
|
||||||
|
#if HAL_HAS_GLOBAL_ADC_RESOLUTION && !HAL_HAS_PER_PIN_ADC_RESOLUTION
|
||||||
|
r = rangeFromBits(gAdcBits);
|
||||||
|
#else
|
||||||
|
r = adc_[h.idx].range ? adc_[h.idx].range : (uint32_t)ANALOG_READ_RANGE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (r == 0) return 0;
|
||||||
|
const uint32_t v = read(h);
|
||||||
|
const uint32_t q = (uint32_t)((((uint64_t)v) * 65535ULL + (r / 2)) / (uint64_t)r);
|
||||||
|
return (uint16_t)clampU32(q, 0, 65535U);
|
||||||
|
}
|
||||||
|
|
||||||
|
AnalogClass analog;
|
||||||
Executable
+112
@@ -0,0 +1,112 @@
|
|||||||
|
// Analog.h
|
||||||
|
#pragma once
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "../../Common.h"
|
||||||
|
|
||||||
|
// --- Pin sentinel ---
|
||||||
|
#ifndef OFF
|
||||||
|
#define OFF (-1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// --- Some error checking ---
|
||||||
|
#if !IS_POW2_MINUS1(ANALOG_WRITE_RANGE)
|
||||||
|
#error "ANALOG_WRITE_RANGE must be (2^n - 1)."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !IS_POW2_MINUS1(ANALOG_WRITE_RANGE)
|
||||||
|
#error "ANALOG_WRITE_RANGE must be (2^n - 1)."
|
||||||
|
#endif
|
||||||
|
#if ANALOG_WRITE_RANGE < RANGE_FROM_BITS(HAL_PWM_BITS_MIN)
|
||||||
|
#error "ANALOG_WRITE_RANGE below platform PWM resolution limits."
|
||||||
|
#endif
|
||||||
|
#if ANALOG_WRITE_RANGE > RANGE_FROM_BITS(HAL_PWM_BITS_MAX)
|
||||||
|
#error "ANALOG_WRITE_RANGE exceeds platform PWM resolution limits."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !IS_POW2_MINUS1(ANALOG_READ_RANGE)
|
||||||
|
#error "ANALOG_READ_RANGE must be (2^n - 1)."
|
||||||
|
#endif
|
||||||
|
#if ANALOG_READ_RANGE < RANGE_FROM_BITS(HAL_ADC_BITS_MIN)
|
||||||
|
#error "ANALOG_READ_RANGE below platform ADC resolution limits."
|
||||||
|
#endif
|
||||||
|
#if ANALOG_READ_RANGE > RANGE_FROM_BITS(HAL_ADC_BITS_MAX)
|
||||||
|
#error "ANALOG_READ_RANGE exceeds platform ADC resolution limits."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Optional: Servo PWM range only allowed to differ when per-pin PWM resolution exists
|
||||||
|
#ifdef SERVO_ANALOG_WRITE_RANGE
|
||||||
|
#if !IS_POW2_MINUS1(SERVO_ANALOG_WRITE_RANGE)
|
||||||
|
#error "SERVO_ANALOG_WRITE_RANGE must be (2^n - 1)."
|
||||||
|
#endif
|
||||||
|
#if !HAL_HAS_PER_PIN_PWM_RESOLUTION && SERVO_ANALOG_WRITE_RANGE != ANALOG_WRITE_RANGE
|
||||||
|
#error "Global-only PWM: SERVO_ANALOG_WRITE_RANGE must equal ANALOG_WRITE_RANGE."
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static constexpr uint8_t ANALOG_INVALID_IDX = 0xFF;
|
||||||
|
|
||||||
|
struct AnalogPwmConfig {
|
||||||
|
uint32_t hz = 0; // 0 = leave default
|
||||||
|
uint16_t bits = 0; // 0 = leave default
|
||||||
|
uint32_t range = 0; // 0 = auto (2^bits-1) or leave
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AnalogPwmHandle {
|
||||||
|
uint8_t pin = 0; // core pin for analogWrite()
|
||||||
|
uint8_t idx = ANALOG_INVALID_IDX; // index into pwm_[] cache
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AnalogAdcConfig {
|
||||||
|
uint16_t bits = 0; // 0 = leave default
|
||||||
|
uint32_t range = 0; // 0 = auto (2^bits-1) or leave
|
||||||
|
uint8_t oversample = 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AnalogAdcHandle {
|
||||||
|
uint8_t pin = 0; // core pin for analogRead()
|
||||||
|
uint8_t oversample = 1; // cached oversample (avoid adc_[] lookup each read)
|
||||||
|
uint8_t idx = ANALOG_INVALID_IDX; // index into adc_[] cache
|
||||||
|
};
|
||||||
|
|
||||||
|
class AnalogClass {
|
||||||
|
public:
|
||||||
|
// prepare global adc read resolution and global pwm write resolution/frequency
|
||||||
|
void begin();
|
||||||
|
|
||||||
|
// pwm write, with per pin frequency/resolution where possible
|
||||||
|
bool pwmInit(int16_t pin, const AnalogPwmConfig& cfg = {});
|
||||||
|
AnalogPwmHandle pwmInitHandle(int16_t pin, const AnalogPwmConfig& cfg);
|
||||||
|
void write(int16_t pin, uint32_t value); // native 0..range
|
||||||
|
void write(int16_t pin, float x01); // normalized 0..1
|
||||||
|
void writeQ16(int16_t pin, uint16_t q16); // normalized 0..65535
|
||||||
|
void write(const AnalogPwmHandle& h, uint32_t v);
|
||||||
|
void write(const AnalogPwmHandle& h, float x01);
|
||||||
|
void writeQ16(const AnalogPwmHandle& h, uint16_t q16);
|
||||||
|
uint32_t pwmRange(int16_t pin) const;
|
||||||
|
|
||||||
|
// adc read, with per pin resolution where possible
|
||||||
|
bool adcInit(int16_t pin, const AnalogAdcConfig& cfg = {});
|
||||||
|
AnalogAdcHandle adcInitHandle(int16_t pin, const AnalogAdcConfig& cfg);
|
||||||
|
uint32_t read(int16_t pin); // native 0..range
|
||||||
|
float readf(int16_t pin); // normalized 0..1
|
||||||
|
float readV(int16_t pin); // volts (best-effort)
|
||||||
|
uint16_t readQ16(int16_t pin); // normalized 0..65535
|
||||||
|
uint32_t read(const AnalogAdcHandle& h);
|
||||||
|
float readf(const AnalogAdcHandle& h);
|
||||||
|
uint16_t readQ16(const AnalogAdcHandle& h);
|
||||||
|
uint32_t adcRange(int16_t pin) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct PwmState { int16_t pin = OFF; uint16_t bits = 0; uint32_t hz = 0; uint32_t range = 0; bool custom = false; };
|
||||||
|
struct AdcState { int16_t pin = OFF; uint16_t bits = 0; uint8_t oversample = 1; uint32_t range = 0; };
|
||||||
|
|
||||||
|
static constexpr uint8_t MAX_TRACKED = 32; // must be <= 254
|
||||||
|
mutable PwmState pwm_[MAX_TRACKED]{};
|
||||||
|
mutable AdcState adc_[MAX_TRACKED]{};
|
||||||
|
|
||||||
|
int pwmIndex(int16_t pin) const;
|
||||||
|
int adcIndex(int16_t pin) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern AnalogClass analog;
|
||||||
Executable
+195
@@ -0,0 +1,195 @@
|
|||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// telescope mount control, commands
|
||||||
|
|
||||||
|
#include "Axis.h"
|
||||||
|
|
||||||
|
#ifdef MOTOR_PRESENT
|
||||||
|
|
||||||
|
#include "../../lib/nv/Nv.h"
|
||||||
|
|
||||||
|
#include "../convert/Convert.h"
|
||||||
|
|
||||||
|
extern AxesRevert revert;
|
||||||
|
|
||||||
|
bool Axis::command(char *reply, char *command, char *parameter, bool *suppressFrame, bool *numericReply, CommandError *commandError) {
|
||||||
|
*suppressFrame = false;
|
||||||
|
|
||||||
|
if (command[0] == 'G' && command[1] == 'X') {
|
||||||
|
|
||||||
|
// :GXA[n],[p]# Get axis/motor/driver parameter
|
||||||
|
// Returns: Value
|
||||||
|
if (parameter[0] == 'A' && parameter[1] >= '1' && parameter[1] <= '9' && parameter[2] == ',') {
|
||||||
|
if (parameter[1] - '0' != axisNumber) return false;
|
||||||
|
|
||||||
|
// return motor/driver name
|
||||||
|
if (parameter[3] == 'M' && parameter[4] == 0) {
|
||||||
|
strncpy(reply, motor->name(), 40);
|
||||||
|
*numericReply = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int parameterNumber = atoi(¶meter[3]);
|
||||||
|
if (parameterNumber < 0 || parameterNumber > getParameterCount()) { *commandError = CE_PARAM_RANGE; return true; }
|
||||||
|
|
||||||
|
// check if all axes are set to revert
|
||||||
|
if (revert.all) { *commandError = CE_0; return true; }
|
||||||
|
|
||||||
|
// check if this axis is set to revert
|
||||||
|
if (getAxisRevert()) { *commandError = CE_0; return true; }
|
||||||
|
|
||||||
|
// requesting parameter 0 returns the parameter count
|
||||||
|
if (parameterNumber == 0) {
|
||||||
|
sprintf(reply, "%d", (int)getParameterCount());
|
||||||
|
*numericReply = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get parameter values
|
||||||
|
double value = ((parameterNumber == 1) ? stepsPerMeasureValueNv : getParameter(parameterNumber)->valueNv);
|
||||||
|
float min = getParameter(parameterNumber)->min;
|
||||||
|
float max = getParameter(parameterNumber)->max;
|
||||||
|
AxisParameterType type = getParameter(parameterNumber)->type;
|
||||||
|
|
||||||
|
// convert to degrees if necessary
|
||||||
|
if (getParameter(parameterNumber)->type == AXP_FLOAT_RAD) {
|
||||||
|
value = radToDeg(value);
|
||||||
|
min = radToDeg(min);
|
||||||
|
max = radToDeg(max);
|
||||||
|
type = AXP_FLOAT;
|
||||||
|
}
|
||||||
|
if (getParameter(parameterNumber)->type == AXP_FLOAT_RAD_INV) {
|
||||||
|
value = degToRad(value);
|
||||||
|
min = degToRad(min);
|
||||||
|
max = degToRad(max);
|
||||||
|
type = AXP_FLOAT;
|
||||||
|
}
|
||||||
|
|
||||||
|
char valueStr[24];
|
||||||
|
sprintF(valueStr, "%1.3f", value);
|
||||||
|
convert.stripNumericStr(valueStr);
|
||||||
|
|
||||||
|
sprintf(reply, "%s,%ld,%ld,%d,%s", valueStr, lround(min), lround(max), (int)type, getParameter(parameterNumber)->name);
|
||||||
|
|
||||||
|
*numericReply = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef SERVO_MOTOR_PRESENT
|
||||||
|
// :GXS[n]# Get axis servo delta (in counts) and velocity
|
||||||
|
// Returns: Values
|
||||||
|
if (parameter[0] == 'S' && parameter[2] == 0) {
|
||||||
|
int index = parameter[1] - '1';
|
||||||
|
if (index > 8) { *commandError = CE_PARAM_RANGE; return true; }
|
||||||
|
if (index + 1 != axisNumber) return false; // command wasn't processed
|
||||||
|
if (motor->driverType != SERVO) { *commandError = CE_CMD_UNKNOWN; return true; } // not a servo
|
||||||
|
|
||||||
|
char temp[20];
|
||||||
|
sprintF(temp, "%0.3f", ((ServoMotor*)motor)->velocityPercent);
|
||||||
|
sprintf(reply, "%ld,%s", ((ServoMotor*)motor)->delta, temp);
|
||||||
|
*numericReply = false;
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// :GXU[n]# Get stepper driver statUs for axis [n]
|
||||||
|
// Returns: Value
|
||||||
|
if (parameter[0] == 'U' && parameter[2] == 0) {
|
||||||
|
int index = parameter[1] - '1';
|
||||||
|
if (index < 0 || index > 8) { *commandError = CE_PARAM_RANGE; return true; }
|
||||||
|
if (index + 1 != axisNumber) return false; // command wasn't processed
|
||||||
|
DriverStatus status = getStatus();
|
||||||
|
if (status.active) {
|
||||||
|
strcat(reply, status.standstill ? "ST," : ",");
|
||||||
|
strcat(reply, status.outputA.openLoad ? "OA," : ",");
|
||||||
|
strcat(reply, status.outputB.openLoad ? "OB," : ",");
|
||||||
|
strcat(reply, status.outputA.shortToGround ? "GA," : ",");
|
||||||
|
strcat(reply, status.outputB.shortToGround ? "GB," : ",");
|
||||||
|
strcat(reply, status.overTemperature ? "OT," : ","); // > 150C
|
||||||
|
strcat(reply, status.overTemperatureWarning ? "PW," : ","); // > 120C
|
||||||
|
strcat(reply, status.fault ? "GF" : "");
|
||||||
|
} else { *commandError = CE_0; return true; }
|
||||||
|
*numericReply = false;
|
||||||
|
} else return false;
|
||||||
|
} else
|
||||||
|
|
||||||
|
if (command[0] == 'S' && command[1] == 'X') {
|
||||||
|
|
||||||
|
// :SXA[n],R# Revert axis/motor/driver parameters to default
|
||||||
|
// :SXA[n],[p],nnnn.n# Set axis/motor/driver parameter value
|
||||||
|
if (parameter[0] == 'A' && parameter[2] == ',') {
|
||||||
|
|
||||||
|
// check for axis settings enable/disable
|
||||||
|
// :SXAC,0# for run-time NV (EEPROM) axis settings
|
||||||
|
// :SXAC,1# for compile-time Config.h axis settings
|
||||||
|
// Return: 0 failure, 1 success
|
||||||
|
if (parameter[1] == 'C') {
|
||||||
|
if ((parameter[3] == '0' || parameter[3] == '1') && parameter[4] == 0) {
|
||||||
|
|
||||||
|
if (parameter[3] == '0') {
|
||||||
|
VLF("MSG: Using Axes settings from NV (EEPROM)");
|
||||||
|
revert.all = false;
|
||||||
|
} else {
|
||||||
|
VLF("MSG: Using Axes settings from Config.h");
|
||||||
|
revert.all = true;
|
||||||
|
}
|
||||||
|
nv().kv().put(nvRevertKey, revert);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else { *commandError = CE_PARAM_RANGE; return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for a valid axisNumber
|
||||||
|
int index = parameter[1] - '1';
|
||||||
|
if (index + 1 != axisNumber) return false;
|
||||||
|
|
||||||
|
// check if all axes are set to revert
|
||||||
|
if (revert.all) { *commandError = CE_0; return true; }
|
||||||
|
|
||||||
|
// check if this axis is set to revert
|
||||||
|
if (getAxisRevert()) { *commandError = CE_0; return true; }
|
||||||
|
|
||||||
|
// :SXA[n],R# reverts this axis to defaults on next boot
|
||||||
|
if (parameter[3] == 'R' && parameter[4] == 0) {
|
||||||
|
setAxisRevert(true);
|
||||||
|
nv().kv().put(nvRevertKey, revert);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// :SXA[n],[p],nnn.n# Set axis/motor/driver parameter value
|
||||||
|
// :SXA[n],[p],nnn.n# :SXA1,14,12.5#
|
||||||
|
int parameterNumber = atoi(¶meter[3]);
|
||||||
|
char* valueStr = strchr(¶meter[3], ',');
|
||||||
|
if (valueStr == NULL) { *commandError = CE_PARAM_FORM; return true; }
|
||||||
|
char* conv_end;
|
||||||
|
double value = strtod(++valueStr, &conv_end);
|
||||||
|
if (&valueStr[0] == conv_end) { *commandError = CE_PARAM_FORM; return true; }
|
||||||
|
|
||||||
|
// convert to radians if necessary
|
||||||
|
if (getParameter(parameterNumber)->type == AXP_FLOAT_RAD) value = degToRad(value);
|
||||||
|
if (getParameter(parameterNumber)->type == AXP_FLOAT_RAD_INV) value = radToDeg(value);
|
||||||
|
|
||||||
|
if (parameterIsValid(getParameter(parameterNumber), value, true)) {
|
||||||
|
// save parameter values
|
||||||
|
getParameter(parameterNumber)->valueNv = value;
|
||||||
|
if (parameterNumber == 1) stepsPerMeasureValueNv = value;
|
||||||
|
|
||||||
|
// get ready to write to NV
|
||||||
|
AxisStoredSettings nvAxisSettings;
|
||||||
|
nvAxisSettings.stepsPerMeasure = stepsPerMeasureValueNv;
|
||||||
|
for (int i = 1; i <= getParameterCount(); i++) nvAxisSettings.value[i - 1] = getParameter(i)->valueNv;
|
||||||
|
|
||||||
|
// write the settings to NV
|
||||||
|
nv().kv().put(nvKey, nvAxisSettings);
|
||||||
|
|
||||||
|
// update immediate parameters now
|
||||||
|
AxisParameterType type = getParameter(parameterNumber)->type;
|
||||||
|
if (type == AXP_BOOLEAN_IMMEDIATE || type == AXP_INTEGER_IMMEDIATE || type == AXP_FLOAT_IMMEDIATE) {
|
||||||
|
getParameter(parameterNumber)->value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else *commandError = CE_PARAM_RANGE;
|
||||||
|
} else return false;
|
||||||
|
} else return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+765
@@ -0,0 +1,765 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// Axis motion control
|
||||||
|
|
||||||
|
#include "Axis.h"
|
||||||
|
|
||||||
|
#include "../tasks/OnTask.h"
|
||||||
|
#include "../nv/Nv.h"
|
||||||
|
|
||||||
|
#ifdef MOTOR_PRESENT
|
||||||
|
|
||||||
|
AxesRevert revert = {true, false, false, false, false, false, false, false, false, false, false};
|
||||||
|
|
||||||
|
Axis *axisWrapper[9];
|
||||||
|
IRAM_ATTR void axisWrapper1() { axisWrapper[0]->poll(); }
|
||||||
|
IRAM_ATTR void axisWrapper2() { axisWrapper[1]->poll(); }
|
||||||
|
IRAM_ATTR void axisWrapper3() { axisWrapper[2]->poll(); }
|
||||||
|
IRAM_ATTR void axisWrapper4() { axisWrapper[3]->poll(); }
|
||||||
|
IRAM_ATTR void axisWrapper5() { axisWrapper[4]->poll(); }
|
||||||
|
IRAM_ATTR void axisWrapper6() { axisWrapper[5]->poll(); }
|
||||||
|
IRAM_ATTR void axisWrapper7() { axisWrapper[6]->poll(); }
|
||||||
|
IRAM_ATTR void axisWrapper8() { axisWrapper[7]->poll(); }
|
||||||
|
IRAM_ATTR void axisWrapper9() { axisWrapper[8]->poll(); }
|
||||||
|
|
||||||
|
Axis::Axis(uint8_t axisNumber, const AxisPins *pins, const AxisSettings *Settings, const AxisMeasure axisMeasure, float targetTolerance) {
|
||||||
|
axisPrefix[5] = '0' + axisNumber;
|
||||||
|
this->axisNumber = axisNumber;
|
||||||
|
|
||||||
|
this->pins = pins;
|
||||||
|
|
||||||
|
// attach the function pointers to the callbacks
|
||||||
|
axisWrapper[axisNumber - 1] = this;
|
||||||
|
switch (axisNumber) {
|
||||||
|
case 1: callback = axisWrapper1; break;
|
||||||
|
case 2: callback = axisWrapper2; break;
|
||||||
|
case 3: callback = axisWrapper3; break;
|
||||||
|
case 4: callback = axisWrapper4; break;
|
||||||
|
case 5: callback = axisWrapper5; break;
|
||||||
|
case 6: callback = axisWrapper6; break;
|
||||||
|
case 7: callback = axisWrapper7; break;
|
||||||
|
case 8: callback = axisWrapper8; break;
|
||||||
|
case 9: callback = axisWrapper9; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
unitsRadians = false;
|
||||||
|
switch (axisMeasure) {
|
||||||
|
case AXIS_MEASURE_MICRONS:
|
||||||
|
strcpy(unitsStr, "um");
|
||||||
|
stepsPerMeasure = &stepsPerMicron;
|
||||||
|
minMeasure = &minMicrons;
|
||||||
|
maxMeasure = &maxMicrons;
|
||||||
|
break;
|
||||||
|
case AXIS_MEASURE_RADIANS:
|
||||||
|
strcpy(unitsStr, " deg");
|
||||||
|
stepsPerMeasure = &stepsPerRadian;
|
||||||
|
minMeasure = &minRadians;
|
||||||
|
maxMeasure = &maxRadians;
|
||||||
|
unitsRadians = true;
|
||||||
|
break;
|
||||||
|
case AXIS_MEASURE_UNKNOWN:
|
||||||
|
case AXIS_MEASURE_DEGREES:
|
||||||
|
default:
|
||||||
|
strcpy(unitsStr, " deg");
|
||||||
|
stepsPerMeasure = &stepsPerDegree;
|
||||||
|
minMeasure = &minDegrees;
|
||||||
|
maxMeasure = &maxDegrees;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stepsPerMeasure != NULL) {
|
||||||
|
stepsPerMeasure->valueDefault = Settings->stepsPerMeasure;
|
||||||
|
stepsPerMeasureDefault = Settings->stepsPerMeasure;
|
||||||
|
minMeasure->valueDefault = Settings->limits.min;
|
||||||
|
maxMeasure->valueDefault = Settings->limits.max;
|
||||||
|
}
|
||||||
|
|
||||||
|
backlashFreq = Settings->backlashFreq;
|
||||||
|
|
||||||
|
this->targetTolerance = targetTolerance;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Axis::init(Motor *motor) {
|
||||||
|
this->motor = motor;
|
||||||
|
|
||||||
|
// get default parameter values
|
||||||
|
AxisStoredSettings nvAxisSettings;
|
||||||
|
nvAxisSettings.revert = true;
|
||||||
|
nvAxisSettings.stepsPerMeasure = stepsPerMeasureDefault;
|
||||||
|
for (int i = 1; i <= getParameterCount(); i++) {
|
||||||
|
#if DEBUG == VERBOSE
|
||||||
|
const char* axpn[26] = {AXPN_1, AXPN_2, AXPN_3, AXPN_4, AXPN_5, AXPN_6, AXPN_7, AXPN_8, AXPN_9, AXPN_10,
|
||||||
|
AXPN_11, AXPN_12, AXPN_13, AXPN_14, AXPN_15, AXPN_16, AXPN_17, AXPN_18, AXPN_19, AXPN_20, AXPN_21, AXPN_22,
|
||||||
|
AXPN_23, AXPN_24, AXPN_25, AXPN_26};
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("found parameter \"");
|
||||||
|
if (getParameter(i)->name[0] == '$') {
|
||||||
|
char number[3] = "";
|
||||||
|
number[0] = getParameter(i)->name[1];
|
||||||
|
number[1] = getParameter(i)->name[2];
|
||||||
|
number[2] = 0;
|
||||||
|
V(axpn[atoi(number) - 1]);
|
||||||
|
} else { V(getParameter(i)->name); }
|
||||||
|
VF("\" with default value "); VL(getParameter(i)->valueDefault);
|
||||||
|
#endif
|
||||||
|
getParameter(i)->value = getParameter(i)->valueDefault;
|
||||||
|
getParameter(i)->valueNv = getParameter(i)->valueDefault;
|
||||||
|
nvAxisSettings.value[i - 1] = getParameter(i)->valueDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check default parameters
|
||||||
|
for (int i = 1; i <= getParameterCount(); i++) {
|
||||||
|
if (!parameterIsValid(getParameter(i))) {
|
||||||
|
DF("ERR:"); D(axisPrefix); DF("default parameter# "); D(i); DLF(" validation failed!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// prepare the revert key
|
||||||
|
nvRevertKey = nv().kv().computeKey("AXIS_SETTINGS_REVERT");
|
||||||
|
|
||||||
|
// get the revert setting
|
||||||
|
if (!nv().kv().getOrInit(nvRevertKey, revert)) { DLF("WRN: init failed for AXIS_SETTINGS_REVERT"); };
|
||||||
|
|
||||||
|
// prepare the axis settings key for this axis
|
||||||
|
char keyStr[26];
|
||||||
|
snprintf(keyStr, sizeof(keyStr), "AXIS%u_SETTINGS", (unsigned)axisNumber);
|
||||||
|
nvKey = nv().kv().computeKey(keyStr);
|
||||||
|
|
||||||
|
// read axis settings from NV, unless we are reverting to defaults
|
||||||
|
if (!revert.all) {
|
||||||
|
if (getAxisRevert()) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("reverting settings on NV");
|
||||||
|
nv().kv().put(nvKey, nvAxisSettings);
|
||||||
|
setAxisRevert(false);
|
||||||
|
nv().kv().put(nvRevertKey, revert);
|
||||||
|
} else {
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("reading settings from NV");
|
||||||
|
if (!nv().kv().getOrInit(nvKey, nvAxisSettings)) { DF("WRN: init failed for "); DL(keyStr); }
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nv().kv().del(nvKey);
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("revert all ignoring settings on NV");
|
||||||
|
}
|
||||||
|
|
||||||
|
// move NV stepsPerMeasure into parameter (special case of using a double)
|
||||||
|
stepsPerMeasureValue = nvAxisSettings.stepsPerMeasure;
|
||||||
|
stepsPerMeasureValueNv = nvAxisSettings.stepsPerMeasure;
|
||||||
|
getParameter(1)->value = nvAxisSettings.value[0];
|
||||||
|
getParameter(1)->valueNv = nvAxisSettings.value[0];
|
||||||
|
if (!parameterIsValid(getParameter(1))) {
|
||||||
|
DF("WRN:"); D(axisPrefix); DLF("parameter validation failed, reverting to default");
|
||||||
|
stepsPerMeasureValue = stepsPerMeasureDefault;
|
||||||
|
stepsPerMeasureValueNv = stepsPerMeasureDefault;
|
||||||
|
getParameter(1)->value = getParameter(1)->valueDefault;
|
||||||
|
getParameter(1)->valueNv = getParameter(1)->valueDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
// move other NV values into parameters
|
||||||
|
for (int i = 2; i <= getParameterCount(); i++) {
|
||||||
|
getParameter(i)->value = nvAxisSettings.value[i - 1];
|
||||||
|
getParameter(i)->valueNv = nvAxisSettings.value[i - 1];
|
||||||
|
if (!parameterIsValid(getParameter(i))) {
|
||||||
|
DF("WRN:"); D(axisPrefix); DLF("reverting parameter to default");
|
||||||
|
getParameter(i)->value = getParameter(i)->valueDefault;
|
||||||
|
getParameter(i)->valueNv = getParameter(i)->valueDefault;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DEBUG == VERBOSE
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("stepsPerMeasure="); VL(stepsPerMeasureValue);
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("backlash takeup frequency set to ");
|
||||||
|
if (unitsRadians) V(radToDegF(backlashFreq)); else V(backlashFreq);
|
||||||
|
V(unitsStr); VLF("/s");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// activate home and limit sense
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("adding any home and/or limit senses");
|
||||||
|
homeSenseHandle = sense.add(pins->home, pins->axisSense.homeInit, pins->axisSense.homeTrigger);
|
||||||
|
minSenseHandle = sense.add(pins->min, pins->axisSense.minMaxInit, pins->axisSense.minTrigger);
|
||||||
|
maxSenseHandle = sense.add(pins->max, pins->axisSense.minMaxInit, pins->axisSense.maxTrigger);
|
||||||
|
#if LIMIT_SENSE_STRICT != ON
|
||||||
|
commonMinMaxSense = pins->min != OFF && pins->min == pins->max;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// setup motor
|
||||||
|
if (!motor->init()) { DF("ERR:"); D(axisPrefix); DLF("no motor driver!"); return false; }
|
||||||
|
|
||||||
|
motor->setBacklashFrequencySteps(backlashFreq*stepsPerMeasureValue);
|
||||||
|
|
||||||
|
// start monitor
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("start motion controller task (rate "); V(FRACTIONAL_SEC_US); VF("us priority 1)... ");
|
||||||
|
uint8_t taskHandle = 0;
|
||||||
|
char taskName[] = "Ax_Motn";
|
||||||
|
taskName[2] = axisNumber + '0';
|
||||||
|
taskHandle = tasks.add(0, 0, true, 1, callback, taskName);
|
||||||
|
tasks.setPeriodMicros(taskHandle, FRACTIONAL_SEC_US);
|
||||||
|
if (taskHandle) { VLF("success"); } else {
|
||||||
|
VLF("FAILED!");
|
||||||
|
DF("ERR:"); D(axisPrefix); DLF("no motion controller task!"); return false;
|
||||||
|
}
|
||||||
|
motor->monitorHandle = taskHandle;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
AxisParameter* Axis::getParameter(uint8_t number) {
|
||||||
|
if (number == 0) { return motor->getParameter(number); } else
|
||||||
|
if (number == 1) { return stepsPerMeasure; } else
|
||||||
|
if (number == 2) { return minMeasure; } else
|
||||||
|
if (number == 3) { return maxMeasure; } else
|
||||||
|
if (number >= 4) { return motor->getParameter(number - 3); } else return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::enable(bool state) {
|
||||||
|
enabled = state;
|
||||||
|
motor->enable(enabled & !poweredDown);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::setPowerDownTime(int time) {
|
||||||
|
if (time == 0) powerDownStandstill = false; else { powerDownStandstill = true; powerDownDelay = time; }
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::setPowerDownOverrideTime(int time) {
|
||||||
|
if (time == 0) powerDownOverride = false; else {
|
||||||
|
if (poweredDown) {
|
||||||
|
poweredDown = false;
|
||||||
|
motor->enable(true);
|
||||||
|
}
|
||||||
|
powerDownOverride = true;
|
||||||
|
powerDownOverrideEnds = millis() + time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::setBacklash(float value) {
|
||||||
|
if (autoRate == AR_NONE) motor->setBacklashSteps(round(value*stepsPerMeasureValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
float Axis::getBacklash() {
|
||||||
|
return motor->getBacklashSteps()/stepsPerMeasureValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandError Axis::resetPosition(double value) {
|
||||||
|
return resetPositionSteps(lround(value*stepsPerMeasureValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandError Axis::resetPositionSteps(long value) {
|
||||||
|
if (autoRate != AR_NONE) return CE_SLEW_IN_MOTION;
|
||||||
|
if (motor->getFrequencySteps() != 0) return CE_SLEW_IN_MOTION;
|
||||||
|
motor->resetPositionSteps(value);
|
||||||
|
return CE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Axis::getMotorPosition() {
|
||||||
|
return motor->getMotorPositionSteps()/stepsPerMeasureValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Axis::getIndexPosition() {
|
||||||
|
return motor->getIndexPositionSteps()/stepsPerMeasureValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
double distance(double c1, double c2) {
|
||||||
|
double d1 = fabs(c1 - c2);
|
||||||
|
double d2 = fabs(c2 - c1);
|
||||||
|
if (d1 <= d2) return d1; else return d2;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Axis::wrap(double value) {
|
||||||
|
if (wrapEnabled) {
|
||||||
|
while (value > maxMeasure->value) value -= wrapAmount;
|
||||||
|
while (value < minMeasure->value) value += wrapAmount;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Axis::unwrap(double value) {
|
||||||
|
if (wrapEnabled) {
|
||||||
|
double position = motor->getInstrumentCoordinateSteps()/stepsPerMeasureValue;
|
||||||
|
while (value > position + wrapAmount/2.0L) value -= wrapAmount;
|
||||||
|
while (value < position - wrapAmount/2.0L) value += wrapAmount;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Axis::unwrapNearest(double value) {
|
||||||
|
if (wrapEnabled) {
|
||||||
|
value = unwrap(value);
|
||||||
|
double instr = motor->getInstrumentCoordinateSteps()/stepsPerMeasureValue;
|
||||||
|
// VF("MSG:"); V(axisPrefix);
|
||||||
|
// VF("unwrapNearest instr "); V(radToDeg(instr));
|
||||||
|
// VF(", before "); V(radToDeg(value));
|
||||||
|
double dist = distance(value, instr);
|
||||||
|
if (distance(value + wrapAmount, instr) < dist) value += wrapAmount; else
|
||||||
|
if (distance(value - wrapAmount, instr) < dist) value -= wrapAmount;
|
||||||
|
// VF(", after "); VL(radToDeg(value));
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::setInstrumentCoordinate(double value) {
|
||||||
|
setInstrumentCoordinateSteps(lround(unwrap(value)*stepsPerMeasureValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
double Axis::getInstrumentCoordinate() {
|
||||||
|
return wrap(motor->getInstrumentCoordinateSteps()/stepsPerMeasureValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::setInstrumentCoordinatePark(double value) {
|
||||||
|
motor->setInstrumentCoordinateParkSteps(lround(unwrapNearest(value)*stepsPerMeasureValue), motor->getSequencerSteps());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::setTargetCoordinatePark(double value) {
|
||||||
|
motor->setFrequencySteps(0);
|
||||||
|
motor->setTargetCoordinateParkSteps(lround(unwrapNearest(value)*stepsPerMeasureValue), motor->getSequencerSteps());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::setTargetCoordinate(double value) {
|
||||||
|
setTargetCoordinateSteps(lround(unwrapNearest(value)*stepsPerMeasureValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
double Axis::getTargetCoordinate() {
|
||||||
|
return wrap(motor->getTargetCoordinateSteps()/stepsPerMeasureValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Axis::atTarget() {
|
||||||
|
return labs(motor->getTargetDistanceSteps()) <= targetTolerance*stepsPerMeasureValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Axis::nearTarget() {
|
||||||
|
return labs(motor->getTargetDistanceSteps()) < backlashFreq*stepsPerMeasureValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Axis::getTargetDistance() {
|
||||||
|
return labs(motor->getTargetDistanceSteps())/stepsPerMeasureValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Axis::getOriginOrTargetDistance() {
|
||||||
|
return motor->getOriginOrTargetDistanceSteps()/stepsPerMeasureValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::setSlewAccelerationRate(float mpsps) {
|
||||||
|
if (autoRate == AR_NONE) {
|
||||||
|
slewAccelRateFs = mpsps/FRACTIONAL_SEC;
|
||||||
|
if (slewAccelRateFs > backlashFreq) slewAccelRateFs = backlashFreq;
|
||||||
|
slewAccelTime = NAN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::setSlewAccelerationTime(float seconds) {
|
||||||
|
if (autoRate == AR_NONE) {
|
||||||
|
if (seconds < 0.1F) seconds = 0.1F;
|
||||||
|
slewAccelTime = seconds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::setSlewAccelerationRateAbort(float mpsps) {
|
||||||
|
if (autoRate == AR_NONE) {
|
||||||
|
abortAccelRateFs = mpsps/FRACTIONAL_SEC;
|
||||||
|
if (abortAccelRateFs > backlashFreq) abortAccelRateFs = backlashFreq;
|
||||||
|
abortAccelTime = NAN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::setSlewAccelerationTimeAbort(float seconds) {
|
||||||
|
if (autoRate == AR_NONE) abortAccelTime = seconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandError Axis::autoGoto(float frequency) {
|
||||||
|
if (!enabled) return CE_SLEW_ERR_IN_STANDBY;
|
||||||
|
if (autoRate != AR_NONE) return CE_SLEW_IN_SLEW;
|
||||||
|
if (motionError(DIR_BOTH)) return CE_SLEW_ERR_OUTSIDE_LIMITS;
|
||||||
|
if (motorFault()) return CE_SLEW_ERR_HARDWARE_FAULT;
|
||||||
|
|
||||||
|
if (!isnan(frequency)) setFrequencySlew(frequency);
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix);
|
||||||
|
VF("autoGoto start ");
|
||||||
|
|
||||||
|
motor->markOriginCoordinateSteps();
|
||||||
|
motor->setSynchronized(false);
|
||||||
|
motor->setSlewing(true);
|
||||||
|
autoRate = AR_RATE_BY_DISTANCE;
|
||||||
|
|
||||||
|
#if DEBUG == VERBOSE
|
||||||
|
if (unitsRadians) V(radToDeg(slewFreq)); else V(slewFreq);
|
||||||
|
V(unitsStr); VF("/s, accel ");
|
||||||
|
if (unitsRadians) SERIAL_DEBUG.print(radToDeg(slewAccelRateFs)*FRACTIONAL_SEC, 3); else SERIAL_DEBUG.print(slewAccelRateFs*FRACTIONAL_SEC, 3);
|
||||||
|
V(unitsStr); VLF("/s/s");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return CE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandError Axis::autoSlew(Direction direction, float frequency) {
|
||||||
|
if (!enabled) return CE_SLEW_ERR_IN_STANDBY;
|
||||||
|
if (autoRate == AR_RATE_BY_DISTANCE) return CE_SLEW_IN_SLEW;
|
||||||
|
if (direction != DIR_FORWARD && direction != DIR_REVERSE) return CE_SLEW_ERR_UNSPECIFIED;
|
||||||
|
if (motionError(direction)) return CE_SLEW_ERR_OUTSIDE_LIMITS;
|
||||||
|
if (motorFault()) return CE_SLEW_ERR_HARDWARE_FAULT;
|
||||||
|
|
||||||
|
if (!isnan(frequency)) setFrequencySlew(frequency);
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix);
|
||||||
|
if (autoRate == AR_NONE) {
|
||||||
|
motor->setSynchronized(true);
|
||||||
|
motor->setSlewing(true);
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("autoSlew start ");
|
||||||
|
} else { VF("autoSlew resum "); }
|
||||||
|
|
||||||
|
if (direction == DIR_FORWARD) {
|
||||||
|
autoRate = AR_RATE_BY_TIME_FORWARD;
|
||||||
|
VF("fwd@ ");
|
||||||
|
} else {
|
||||||
|
autoRate = AR_RATE_BY_TIME_REVERSE;
|
||||||
|
VF("rev@ ");
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DEBUG == VERBOSE
|
||||||
|
if (unitsRadians) {
|
||||||
|
if (radToDeg(slewFreq) >= 0.01F ) {
|
||||||
|
V(radToDeg(slewFreq)); V(unitsStr);
|
||||||
|
} else {
|
||||||
|
V(radToDeg(slewFreq)*3600.0F); V(" arc-sec");
|
||||||
|
}
|
||||||
|
} else { V(slewFreq); V(unitsStr); }
|
||||||
|
|
||||||
|
VF("/s, accel ");
|
||||||
|
if (unitsRadians) SERIAL_DEBUG.print(radToDeg(slewAccelRateFs)*FRACTIONAL_SEC, 3); else SERIAL_DEBUG.print(slewAccelRateFs*FRACTIONAL_SEC, 3);
|
||||||
|
V(unitsStr); VLF("/s/s");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return CE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandError Axis::autoSlewHome(unsigned long timeout) {
|
||||||
|
if (!enabled) return CE_SLEW_ERR_IN_STANDBY;
|
||||||
|
if (autoRate != AR_NONE) return CE_SLEW_IN_SLEW;
|
||||||
|
if (motionError(DIR_BOTH)) return CE_SLEW_ERR_OUTSIDE_LIMITS;
|
||||||
|
if (motorFault()) return CE_SLEW_ERR_HARDWARE_FAULT;
|
||||||
|
|
||||||
|
if (pins->axisSense.homeTrigger != OFF) {
|
||||||
|
motor->setSynchronized(true);
|
||||||
|
if (homingStage == HOME_NONE) homingStage = HOME_FAST;
|
||||||
|
if (autoRate == AR_NONE) {
|
||||||
|
motor->setSlewing(true);
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("autoSlewHome ");
|
||||||
|
switch (homingStage) {
|
||||||
|
case HOME_FAST: VF("fast "); break;
|
||||||
|
case HOME_SLOW: VF("slow "); break;
|
||||||
|
case HOME_FINE: VF("fine "); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sense.isOn(homeSenseHandle)) {
|
||||||
|
VF("fwd@ ");
|
||||||
|
autoRate = AR_RATE_BY_TIME_FORWARD;
|
||||||
|
} else {
|
||||||
|
VF("rev@ ");
|
||||||
|
autoRate = AR_RATE_BY_TIME_REVERSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// automatically set timeout if not specified
|
||||||
|
if (timeout == 0) timeout = (pins->axisSense.homeDistLimit/slewFreq)*1.2F*1000.0F;
|
||||||
|
|
||||||
|
#if DEBUG == VERBOSE
|
||||||
|
if (unitsRadians) V(radToDeg(slewFreq)); else V(slewFreq);
|
||||||
|
V(unitsStr); VF("/s, accel ");
|
||||||
|
if (unitsRadians) SERIAL_DEBUG.print(radToDeg(slewAccelRateFs)*FRACTIONAL_SEC, 3); else SERIAL_DEBUG.print(slewAccelRateFs*FRACTIONAL_SEC, 3);
|
||||||
|
V(unitsStr); VF("/s/s, timeout ");
|
||||||
|
#endif
|
||||||
|
VL(timeout);
|
||||||
|
homeTimeoutTime = millis() + timeout;
|
||||||
|
}
|
||||||
|
return CE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::autoSlewStop() {
|
||||||
|
if (autoRate <= AR_RATE_BY_TIME_END) return;
|
||||||
|
|
||||||
|
motor->setSynchronized(true);
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("slew stopping");
|
||||||
|
autoRate = AR_RATE_BY_TIME_END;
|
||||||
|
poll();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::autoSlewAbort() {
|
||||||
|
if (autoRate <= AR_RATE_BY_TIME_ABORT) return;
|
||||||
|
|
||||||
|
motor->setSynchronized(true);
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("slew aborting");
|
||||||
|
autoRate = AR_RATE_BY_TIME_ABORT;
|
||||||
|
homingStage = HOME_NONE;
|
||||||
|
poll();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Axis::isSlewing() {
|
||||||
|
return autoRate != AR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::poll() {
|
||||||
|
// make sure we're ready
|
||||||
|
if (axisNumber == 0) return;
|
||||||
|
|
||||||
|
// check physical limit switches
|
||||||
|
errors.minLimitSensed = sense.isOn(minSenseHandle);
|
||||||
|
errors.maxLimitSensed = sense.isOn(maxSenseHandle);
|
||||||
|
bool commonMinMaxSensed = commonMinMaxSense && (errors.minLimitSensed || errors.maxLimitSensed);
|
||||||
|
|
||||||
|
// let the user know if the associated senses change state
|
||||||
|
#if DEBUG == VERBOSE
|
||||||
|
bool senseMin = sense.isOn(minSenseHandle);
|
||||||
|
bool senseMax = sense.isOn(maxSenseHandle);
|
||||||
|
if (lastSenseMin != senseMin || lastSenseMax != senseMax) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("limit sense state: ");
|
||||||
|
V("A"); V(axisNumber); V("S-");
|
||||||
|
if (senseMin) VF("< "); else VF(" ");
|
||||||
|
V("A"); V(axisNumber); V("S+");
|
||||||
|
if (senseMax) VLF("< "); else VLF(" ");
|
||||||
|
lastSenseMin = senseMin;
|
||||||
|
lastSenseMax = senseMax;
|
||||||
|
}
|
||||||
|
bool senseHome = sense.isOn(homeSenseHandle);
|
||||||
|
if (lastSenseHome != senseHome) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("home sense state: ");
|
||||||
|
if (senseHome) VLF("ON"); else VLF("OFF");
|
||||||
|
lastSenseHome = senseHome;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// stop homing as we pass by the switch or times out
|
||||||
|
if (homingStage != HOME_NONE && (autoRate == AR_RATE_BY_TIME_FORWARD || autoRate == AR_RATE_BY_TIME_REVERSE)) {
|
||||||
|
if (autoRate == AR_RATE_BY_TIME_FORWARD && !sense.isOn(homeSenseHandle)) autoSlewStop();
|
||||||
|
if (autoRate == AR_RATE_BY_TIME_REVERSE && sense.isOn(homeSenseHandle)) autoSlewStop();
|
||||||
|
if ((long)(millis() - homeTimeoutTime) > 0) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("autoSlewHome timed out");
|
||||||
|
autoSlewAbort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Y;
|
||||||
|
|
||||||
|
// slewing
|
||||||
|
if (autoRate != AR_NONE && !motor->inBacklash) {
|
||||||
|
|
||||||
|
if (autoRate != AR_RATE_BY_TIME_ABORT) {
|
||||||
|
if (motionError(motor->getDirection())) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("motion error");
|
||||||
|
autoSlewAbort();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (motorFault()) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("motor fault");
|
||||||
|
autoSlewAbort();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (autoRate == AR_RATE_BY_DISTANCE) {
|
||||||
|
if (commonMinMaxSensed) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("commonMinMaxSensed");
|
||||||
|
autoSlewAbort();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (atTarget()) {
|
||||||
|
motor->setSlewing(false);
|
||||||
|
autoRate = AR_NONE;
|
||||||
|
freq = 0.0F;
|
||||||
|
motor->setSynchronized(true);
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("slew stopped");
|
||||||
|
} else {
|
||||||
|
freq = sqrtf(2.0F*(slewAccelRateFs*FRACTIONAL_SEC)*getOriginOrTargetDistance());
|
||||||
|
if (freq < backlashFreq) freq = backlashFreq;
|
||||||
|
if (freq > slewFreq) freq = slewFreq;
|
||||||
|
if (motor->getTargetDistanceSteps() < 0) freq = -freq;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
if (autoRate == AR_RATE_BY_TIME_FORWARD) {
|
||||||
|
freq += slewAccelRateFs;
|
||||||
|
if (freq > slewFreq) freq = slewFreq;
|
||||||
|
} else
|
||||||
|
if (autoRate == AR_RATE_BY_TIME_REVERSE) {
|
||||||
|
freq -= slewAccelRateFs;
|
||||||
|
if (freq < -slewFreq) freq = -slewFreq;
|
||||||
|
} else
|
||||||
|
if (autoRate == AR_RATE_BY_TIME_END) {
|
||||||
|
if (commonMinMaxSensed) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("commonMinMaxSensed");
|
||||||
|
autoSlewAbort();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (freq > slewAccelRateFs) freq -= slewAccelRateFs; else if (freq < -slewAccelRateFs) freq += slewAccelRateFs; else freq = 0.0F;
|
||||||
|
if (fabs(freq) <= slewAccelRateFs) {
|
||||||
|
motor->setSlewing(false);
|
||||||
|
autoRate = AR_NONE;
|
||||||
|
freq = 0.0F;
|
||||||
|
if (homingStage == HOME_FAST) homingStage = HOME_SLOW; else
|
||||||
|
if (homingStage == HOME_SLOW) {
|
||||||
|
if (!sense.isOn(homeSenseHandle)) homingStage = HOME_FINE; else {
|
||||||
|
slewFreq *= 6.0F;
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("autoSlewHome approach correction");
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
if (homingStage == HOME_FINE) homingStage = HOME_NONE;
|
||||||
|
if (homingStage != HOME_NONE) {
|
||||||
|
float f = fabs(slewFreq)/6.0F;
|
||||||
|
if (f < 0.0003F) f = 0.0003F;
|
||||||
|
setFrequencySlew(f);
|
||||||
|
autoSlewHome(SLEW_HOME_REFINE_TIME_LIMIT * 1000);
|
||||||
|
} else {
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("slew stopped");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
if (autoRate == AR_RATE_BY_TIME_ABORT) {
|
||||||
|
if (freq > abortAccelRateFs) freq -= abortAccelRateFs; else if (freq < -abortAccelRateFs) freq += abortAccelRateFs; else freq = 0.0F;
|
||||||
|
if (fabs(freq) <= abortAccelRateFs) {
|
||||||
|
motor->setSlewing(false);
|
||||||
|
autoRate = AR_NONE;
|
||||||
|
freq = 0.0F;
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("slew aborted");
|
||||||
|
}
|
||||||
|
} else freq = 0.0F;
|
||||||
|
} else {
|
||||||
|
freq = 0.0F;
|
||||||
|
if (commonMinMaxSensed || motionError(DIR_BOTH) || motorFault()) baseFreq = 0.0F;
|
||||||
|
}
|
||||||
|
Y;
|
||||||
|
|
||||||
|
setFrequency(freq);
|
||||||
|
|
||||||
|
// keep associated motor updated
|
||||||
|
motor->poll();
|
||||||
|
|
||||||
|
// respond to the motor disabling itself
|
||||||
|
if (autoRate != AR_NONE && !motor->enabled) {
|
||||||
|
autoRate = AR_NONE;
|
||||||
|
freq = 0.0F;
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("motion stopped, motor disabled!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::setFrequencyMin(float frequency) {
|
||||||
|
minFreq = frequency;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::setFrequencyMax(float frequency) {
|
||||||
|
maxFreq = frequency;
|
||||||
|
motor->setFrequencyMax(frequency*stepsPerMeasure->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::setFrequencySlew(float frequency) {
|
||||||
|
if (minFreq != 0.0F && frequency < minFreq) frequency = minFreq;
|
||||||
|
if (maxFreq != 0.0F && frequency > maxFreq) frequency = maxFreq;
|
||||||
|
slewFreq = frequency;
|
||||||
|
|
||||||
|
// adjust acceleration rates if they depend on slewFreq
|
||||||
|
if (!isnan(slewAccelTime)) slewAccelRateFs = (slewFreq/slewAccelTime)/FRACTIONAL_SEC;
|
||||||
|
if (!isnan(abortAccelTime)) abortAccelRateFs = (slewFreq/abortAccelTime)/FRACTIONAL_SEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::setFrequency(float frequency) {
|
||||||
|
const unsigned long now = millis();
|
||||||
|
|
||||||
|
frequency *= scaleFreq;
|
||||||
|
if (powerDownStandstill && frequency == 0.0F && baseFreq == 0.0F) {
|
||||||
|
if (!poweredDown) {
|
||||||
|
if (!powerDownOverride || (long)(now - powerDownOverrideEnds) > 0) {
|
||||||
|
powerDownOverride = false;
|
||||||
|
if ((long)(now - powerDownTime) > 0) {
|
||||||
|
poweredDown = true;
|
||||||
|
motor->enable(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (poweredDown) {
|
||||||
|
poweredDown = false;
|
||||||
|
motor->enable(true);
|
||||||
|
}
|
||||||
|
powerDownTime = now + powerDownDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frequency != 0.0F) {
|
||||||
|
if (frequency < 0.0F) {
|
||||||
|
if (maxFreq != 0.0F && frequency < -maxFreq) frequency = -maxFreq;
|
||||||
|
if (minFreq != 0.0F && frequency > -minFreq) frequency = -minFreq;
|
||||||
|
} else {
|
||||||
|
if (minFreq != 0.0F && frequency < minFreq) frequency = minFreq;
|
||||||
|
if (maxFreq != 0.0F && frequency > maxFreq) frequency = maxFreq;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// apply base frequency as required
|
||||||
|
if (enabled) {
|
||||||
|
if (autoRate == AR_NONE) {
|
||||||
|
motor->setFrequencySteps((frequency + baseFreq)*stepsPerMeasureValue);
|
||||||
|
} else {
|
||||||
|
motor->setFrequencySteps(frequency*stepsPerMeasureValue);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
motor->setFrequencySteps(0.0F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float Axis::getFrequency() {
|
||||||
|
return motor->getFrequencySteps()/stepsPerMeasureValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Axis::getBacklashFrequency() {
|
||||||
|
return backlashFreq;
|
||||||
|
}
|
||||||
|
|
||||||
|
DriverStatus Axis::getStatus() {
|
||||||
|
return motor->getDriverStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::setMotionLimitsCheck(bool state) {
|
||||||
|
limitsCheck = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Axis::motionError(Direction direction) {
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
if (motor->isStalled()) return true;
|
||||||
|
|
||||||
|
if (direction == DIR_FORWARD || direction == DIR_BOTH) {
|
||||||
|
result = getInstrumentCoordinateSteps() > lroundf(0.9F*INT32_MAX) ||
|
||||||
|
(limitsCheck && homingStage == HOME_NONE && getInstrumentCoordinate() > maxMeasure->value + 1.0F/stepsPerMeasureValue) ||
|
||||||
|
(!commonMinMaxSense && errors.maxLimitSensed);
|
||||||
|
if (result == true && result != lastErrorResult) { VF("MSG:"); V(axisPrefix); VLF("motion error forward limit"); }
|
||||||
|
} else
|
||||||
|
|
||||||
|
if (direction == DIR_REVERSE || direction == DIR_BOTH) {
|
||||||
|
result = getInstrumentCoordinateSteps() < lroundf(0.9F*INT32_MIN) ||
|
||||||
|
(limitsCheck && homingStage == HOME_NONE && getInstrumentCoordinate() < minMeasure->value - 1.0F/stepsPerMeasureValue) ||
|
||||||
|
(!commonMinMaxSense && errors.minLimitSensed);
|
||||||
|
if (result == true && result != lastErrorResult) { VF("MSG:"); V(axisPrefix); VLF("motion error reverse limit"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
lastErrorResult = result;
|
||||||
|
|
||||||
|
return lastErrorResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Axis::motionErrorSensed(Direction direction) {
|
||||||
|
if ((direction == DIR_REVERSE || direction == DIR_BOTH) && errors.minLimitSensed) return true; else
|
||||||
|
if ((direction == DIR_FORWARD || direction == DIR_BOTH) && errors.maxLimitSensed) return true; else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Axis::setAxisRevert(bool state) {
|
||||||
|
switch (axisNumber) {
|
||||||
|
case 1: revert.axis1 = state; break; case 2: revert.axis2 = state; break; case 3: revert.axis3 = state; break;
|
||||||
|
case 4: revert.axis4 = state; break; case 5: revert.axis5 = state; break; case 6: revert.axis6 = state; break;
|
||||||
|
case 7: revert.axis7 = state; break; case 8: revert.axis8 = state; break; case 9: revert.axis9 = state; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Axis::getAxisRevert() {
|
||||||
|
switch (axisNumber) {
|
||||||
|
case 1: return revert.axis1; case 2: return revert.axis2; case 3: return revert.axis3;
|
||||||
|
case 4: return revert.axis4; case 5: return revert.axis5; case 6: return revert.axis6;
|
||||||
|
case 7: return revert.axis7; case 8: return revert.axis8; case 9: return revert.axis9;
|
||||||
|
default: return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+552
@@ -0,0 +1,552 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// Axis motion control
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../../Common.h"
|
||||||
|
#include "../sense/Sense.h"
|
||||||
|
|
||||||
|
#ifdef MOTOR_PRESENT
|
||||||
|
|
||||||
|
// default start of axis class hardware timers
|
||||||
|
#ifndef AXIS_HARDWARE_TIMER_BASE
|
||||||
|
#define AXIS_HARDWARE_TIMER_BASE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// polling frequency for monitoring axis motion (default 100X/second)
|
||||||
|
#ifndef FRACTIONAL_SEC
|
||||||
|
#define FRACTIONAL_SEC 100.0F
|
||||||
|
#endif
|
||||||
|
#define FRACTIONAL_SEC_US (lround(1000000.0F / FRACTIONAL_SEC))
|
||||||
|
|
||||||
|
// time limit in seconds for slew home phases
|
||||||
|
#ifndef SLEW_HOME_REFINE_TIME_LIMIT
|
||||||
|
#define SLEW_HOME_REFINE_TIME_LIMIT 120
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ON blocks all motion when min/max are on the same pin, applies to all axes (mount/rotator/focusers)
|
||||||
|
#ifndef LIMIT_SENSE_STRICT
|
||||||
|
#define LIMIT_SENSE_STRICT OFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "../../libApp/commands/ProcessCmds.h"
|
||||||
|
#include "motor/Motor.h"
|
||||||
|
#include "motor/stepDir/StepDir.h"
|
||||||
|
#include "motor/servo/Servo.h"
|
||||||
|
#include "motor/oDrive/ODriveNew.h"
|
||||||
|
#include "motor/oDrive/ODrive.h"
|
||||||
|
#include "motor/kTech/KTech.h"
|
||||||
|
|
||||||
|
#pragma pack(1)
|
||||||
|
|
||||||
|
typedef struct AxesRevert
|
||||||
|
{
|
||||||
|
uint16_t all : 1;
|
||||||
|
uint16_t axis1 : 1;
|
||||||
|
uint16_t axis2 : 1;
|
||||||
|
uint16_t axis3 : 1;
|
||||||
|
uint16_t axis4 : 1;
|
||||||
|
uint16_t axis5 : 1;
|
||||||
|
uint16_t axis6 : 1;
|
||||||
|
uint16_t axis7 : 1;
|
||||||
|
uint16_t axis8 : 1;
|
||||||
|
uint16_t axis9 : 1;
|
||||||
|
uint16_t reserved : 5;
|
||||||
|
} AxesRevert;
|
||||||
|
|
||||||
|
typedef struct AxisLimits
|
||||||
|
{
|
||||||
|
float min; // unit (radians, microns, etc.) depends on axis settings
|
||||||
|
float max; // unit (radians, microns, etc.) depends on axis settings
|
||||||
|
} AxisLimits;
|
||||||
|
|
||||||
|
typedef struct AxisSettings
|
||||||
|
{
|
||||||
|
double stepsPerMeasure; // unit (radians, microns, etc.) depends on axis settings
|
||||||
|
AxisLimits limits;
|
||||||
|
float backlashFreq; // in measures/s
|
||||||
|
} AxisSettings;
|
||||||
|
|
||||||
|
// axis parameters
|
||||||
|
#define MOTOR_PARAMETER_MAX_COUNT 20
|
||||||
|
|
||||||
|
#define AxisStoredSettingsSize 89
|
||||||
|
typedef struct AxisStoredSettings
|
||||||
|
{
|
||||||
|
bool revert;
|
||||||
|
double stepsPerMeasure; // unit (radians, microns, etc.) depends on axis settings
|
||||||
|
float value[MOTOR_PARAMETER_MAX_COUNT];
|
||||||
|
} AxisStoredSettings;
|
||||||
|
#pragma pack()
|
||||||
|
|
||||||
|
typedef struct AxisSense
|
||||||
|
{
|
||||||
|
int32_t homeTrigger;
|
||||||
|
int8_t homeInit;
|
||||||
|
float homeDistLimit;
|
||||||
|
int32_t minTrigger;
|
||||||
|
int32_t maxTrigger;
|
||||||
|
int8_t minMaxInit;
|
||||||
|
} AxisSense;
|
||||||
|
|
||||||
|
typedef struct AxisPins
|
||||||
|
{
|
||||||
|
int16_t min;
|
||||||
|
int16_t home;
|
||||||
|
int16_t max;
|
||||||
|
AxisSense axisSense;
|
||||||
|
} AxisPins;
|
||||||
|
|
||||||
|
typedef struct AxisErrors
|
||||||
|
{
|
||||||
|
uint8_t minLimitSensed : 1;
|
||||||
|
uint8_t maxLimitSensed : 1;
|
||||||
|
} AxisErrors;
|
||||||
|
|
||||||
|
enum AutoRate : uint8_t
|
||||||
|
{
|
||||||
|
AR_NONE,
|
||||||
|
AR_RATE_BY_TIME_ABORT,
|
||||||
|
AR_RATE_BY_TIME_END,
|
||||||
|
AR_RATE_BY_DISTANCE,
|
||||||
|
AR_RATE_BY_TIME_FORWARD,
|
||||||
|
AR_RATE_BY_TIME_REVERSE
|
||||||
|
};
|
||||||
|
enum HomingStage : uint8_t
|
||||||
|
{
|
||||||
|
HOME_NONE,
|
||||||
|
HOME_FINE,
|
||||||
|
HOME_SLOW,
|
||||||
|
HOME_FAST
|
||||||
|
};
|
||||||
|
enum AxisMeasure : uint8_t
|
||||||
|
{
|
||||||
|
AXIS_MEASURE_UNKNOWN,
|
||||||
|
AXIS_MEASURE_MICRONS,
|
||||||
|
AXIS_MEASURE_DEGREES,
|
||||||
|
AXIS_MEASURE_RADIANS
|
||||||
|
};
|
||||||
|
|
||||||
|
class Axis
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructor for this motion controller
|
||||||
|
// \param axisNumber: from 1 to 9
|
||||||
|
// \param *pins: provides pins and states for h/w limits and homing
|
||||||
|
// \param *settings: provides axis scale (steps per measure,) s/w limits, reversal, and backlash frequency
|
||||||
|
// \param axisMeasure: one of AXIS_MEASURE_MICRONS, _DEGREES, or _RADIANS for conversion to/from steps
|
||||||
|
// \param targetTolerance: in "measures" for detecting when slews arrive at their target
|
||||||
|
Axis(uint8_t axisNumber, const AxisPins *pins, const AxisSettings *settings, const AxisMeasure axisMeasure, float targetTolerance = 0.0F);
|
||||||
|
|
||||||
|
// process axis commands
|
||||||
|
bool command(char *reply, char *command, char *parameter, bool *suppressFrame, bool *numericReply, CommandError *commandError);
|
||||||
|
|
||||||
|
// init prepares this motion controller and the provided motor for operation
|
||||||
|
// \param motor: associated motor to be controlled
|
||||||
|
bool init(Motor *motor);
|
||||||
|
|
||||||
|
// returns the maximum number of parameters possible
|
||||||
|
uint8_t getParameterMaxCount() { return MOTOR_PARAMETER_MAX_COUNT; }
|
||||||
|
|
||||||
|
// returns the number of parameters for this axis
|
||||||
|
uint8_t getParameterCount() { return 3 + motor->getParameterCount(); }
|
||||||
|
|
||||||
|
// returns the specified axis parameter
|
||||||
|
AxisParameter *getParameter(uint8_t number);
|
||||||
|
|
||||||
|
// check if parameter is valid
|
||||||
|
bool parameterIsValid(AxisParameter *parameter, bool next = false) { return motor->parameterIsValid(parameter, next); }
|
||||||
|
bool parameterIsValid(AxisParameter *parameter, float value, bool next = false) {
|
||||||
|
bool result;
|
||||||
|
float temp = parameter->value;
|
||||||
|
float tempNv = parameter->valueNv;
|
||||||
|
if (next) parameter->valueNv = value; else parameter->value = value;
|
||||||
|
result = motor->parameterIsValid(parameter, next);
|
||||||
|
parameter->valueNv = tempNv;
|
||||||
|
parameter->value = temp;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets the enabled state (and for its associated motor if supported)
|
||||||
|
// \param state: true to enable or false to disable
|
||||||
|
void enable(bool state);
|
||||||
|
|
||||||
|
// gets the enabled state
|
||||||
|
inline bool isEnabled() { return enabled && !motor->calibrating; }
|
||||||
|
|
||||||
|
// sets the automatic power down time
|
||||||
|
// \param time: allowed standstill time in milliseconds before power down, or 0 to disable
|
||||||
|
void setPowerDownTime(int time);
|
||||||
|
|
||||||
|
// sets the automatic power down override time
|
||||||
|
// \param time: time in milliseconds to disable automatic power down, or 0 to disable
|
||||||
|
void setPowerDownOverrideTime(int time);
|
||||||
|
|
||||||
|
// get steps per "measure" (radian, micron, etc.)
|
||||||
|
inline double getStepsPerMeasure() { return stepsPerMeasureValue; }
|
||||||
|
|
||||||
|
// get tracking mode steps per slewing mode step
|
||||||
|
inline int getStepsPerStepSlewing() { return motor->getStepsPerStepSlewing(); }
|
||||||
|
|
||||||
|
// reset position, also zeros backlash and index
|
||||||
|
// \param value: position of motor and target in "measures" (radians, microns, etc.)
|
||||||
|
CommandError resetPosition(double value);
|
||||||
|
|
||||||
|
// reset position, also zeros backlash and index
|
||||||
|
// \param value: position of motor and target in steps
|
||||||
|
CommandError resetPositionSteps(long value);
|
||||||
|
|
||||||
|
// resets the target position to the motor position
|
||||||
|
inline void resetTargetToMotorPosition() { motor->resetTargetToMotorPosition(); }
|
||||||
|
|
||||||
|
// get motor position, in "measures" (radians, microns, etc.)
|
||||||
|
// \note motor: position based on actual motion taken since startup/reset (including backlash)
|
||||||
|
double getMotorPosition();
|
||||||
|
|
||||||
|
// get motor position, in steps
|
||||||
|
// \note motor: position based on actual motion taken since startup/reset (including backlash)
|
||||||
|
inline long getMotorPositionSteps() { return motor->getMotorPositionSteps(); }
|
||||||
|
|
||||||
|
// get index position, in "measures" (radians, microns, etc.)
|
||||||
|
// \note indexPosition: added to motorPositon (-backlash) yeilds an instrumentCoordinate
|
||||||
|
double getIndexPosition();
|
||||||
|
|
||||||
|
// get index position, in steps
|
||||||
|
// \note indexPosition: added to motorPositon (-backlash) yeilds an instrumentCoordinate
|
||||||
|
inline long getIndexPositionSteps() { return motor->getIndexPositionSteps(); }
|
||||||
|
|
||||||
|
// coordinate wrap
|
||||||
|
// \param value: one complete rotation in "measures" (radians, microns, etc.), 0.0 disables
|
||||||
|
// \note wrap occurs when the coordinate exceeds the min or max limits
|
||||||
|
inline void coordinateWrap(double value)
|
||||||
|
{
|
||||||
|
wrapAmount = value;
|
||||||
|
wrapEnabled = fabs(value) > 0.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set instrument coordinate
|
||||||
|
// \param value: position in "measures" (radians, microns, etc.)
|
||||||
|
void setInstrumentCoordinate(double value);
|
||||||
|
|
||||||
|
// set instrument coordinate
|
||||||
|
// \param value: position in steps
|
||||||
|
inline void setInstrumentCoordinateSteps(long value) { motor->setInstrumentCoordinateSteps(value); }
|
||||||
|
|
||||||
|
// get instrument coordinate in "measures" (radians, microns, etc.)
|
||||||
|
double getInstrumentCoordinate();
|
||||||
|
|
||||||
|
// get instrument coordinate, in steps
|
||||||
|
inline long getInstrumentCoordinateSteps() { return motor->getInstrumentCoordinateSteps(); }
|
||||||
|
|
||||||
|
// set instrument coordinate to park at
|
||||||
|
// \param value: position in "measures" (radians, microns, etc.)
|
||||||
|
// \note with backlash disabled this indexes to the nearest position where the motor wouldn't cog
|
||||||
|
void setInstrumentCoordinatePark(double value);
|
||||||
|
|
||||||
|
// set the target coordinate for park
|
||||||
|
// \param value: postion in "measures" (degrees, microns, etc.)
|
||||||
|
// \note with backlash disabled this moves to the nearest position where the motor doesn't cog
|
||||||
|
void setTargetCoordinatePark(double value);
|
||||||
|
|
||||||
|
// set target coordinate for autoGoto()
|
||||||
|
// \param value: postion in "measures" (degrees, microns, etc.)
|
||||||
|
void setTargetCoordinate(double value);
|
||||||
|
|
||||||
|
// set target coordinate for autoGoto()
|
||||||
|
// \param value: postion in steps
|
||||||
|
inline void setTargetCoordinateSteps(long value) { motor->setTargetCoordinateSteps(value); }
|
||||||
|
|
||||||
|
// get target coordinate, in "measures" (degrees, microns, etc.)
|
||||||
|
double getTargetCoordinate();
|
||||||
|
|
||||||
|
// get target coordinate, in steps
|
||||||
|
inline long getTargetCoordinateSteps() { return motor->getTargetCoordinateSteps(); }
|
||||||
|
|
||||||
|
// distance to target in "measures" (degrees, microns, etc.)
|
||||||
|
double getTargetDistance();
|
||||||
|
|
||||||
|
// returns true if at the target coordinate (+/- targetTolerance)
|
||||||
|
bool atTarget();
|
||||||
|
|
||||||
|
// returns true if within one second of the target coordinate at the backlash takeup rate
|
||||||
|
bool nearTarget();
|
||||||
|
|
||||||
|
// sets backlash amount
|
||||||
|
// \param value: backlash distance in "measures" (degrees, microns, etc.)
|
||||||
|
void setBacklash(float value);
|
||||||
|
|
||||||
|
// sets backlash amount
|
||||||
|
// \param value: backlash distance in steps
|
||||||
|
inline void setBacklashSteps(long value)
|
||||||
|
{
|
||||||
|
if (autoRate == AR_NONE)
|
||||||
|
motor->setBacklashSteps(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get backlash amount in "measures" (radians, microns, etc.)
|
||||||
|
float getBacklash();
|
||||||
|
|
||||||
|
// get frequency in "measures" (degrees, microns, etc.) per second
|
||||||
|
float getFrequency();
|
||||||
|
|
||||||
|
// get frequency in steps per second
|
||||||
|
float getFrequencySteps() { return motor->getFrequencySteps(); }
|
||||||
|
|
||||||
|
// get direction
|
||||||
|
Direction getDirection() { return motor->getDirection(); }
|
||||||
|
|
||||||
|
// gets backlash frequency in "measures" (degrees, microns, etc.) per second
|
||||||
|
float getBacklashFrequency();
|
||||||
|
|
||||||
|
// sets reversal of axis directions
|
||||||
|
// \param state: true reverses the direction behavior specified in settings
|
||||||
|
inline void setReverse(bool state) { motor->setReverse(state); }
|
||||||
|
|
||||||
|
// sets reversal of homing directions
|
||||||
|
// \param state: true reverses the normal sense direction behavior
|
||||||
|
inline void setHomeReverse(bool state) { sense.reverse(homeSenseHandle, state); }
|
||||||
|
|
||||||
|
// sets maximum frequency for next slew
|
||||||
|
// \param frequency: rate of motion in "measures" (radians, microns, etc.) per second
|
||||||
|
void setFrequencySlew(float frequency);
|
||||||
|
|
||||||
|
// sets overall minimum frequency
|
||||||
|
// \param frequency: rate of motion in "measures" (radians, microns, etc.) per second
|
||||||
|
void setFrequencyMin(float frequency);
|
||||||
|
|
||||||
|
// sets overall maximum frequency
|
||||||
|
// \param frequency: rate of motion in "measures" (radians, microns, etc.) per second
|
||||||
|
void setFrequencyMax(float frequency);
|
||||||
|
|
||||||
|
// sets frequency scaling factor for slews
|
||||||
|
// \param frequency: scaling factor for this axis ranging from 0.0 (0%) to 1.0 (100%) of normal
|
||||||
|
void setFrequencyScale(float frequency)
|
||||||
|
{
|
||||||
|
if (frequency >= 0.0F && frequency <= 1.0F)
|
||||||
|
scaleFreq = frequency;
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets acceleration rate for slews
|
||||||
|
// \param mpsps: acceleration rate in "measures" per second per second
|
||||||
|
void setSlewAccelerationRate(float mpsps);
|
||||||
|
|
||||||
|
// set acceleration rate for slews
|
||||||
|
// \param seconds: time during which acceleration to/from the last specified slew frequency occurs
|
||||||
|
void setSlewAccelerationTime(float seconds);
|
||||||
|
|
||||||
|
// sets acceleration rate for emergency stop of movement
|
||||||
|
// \param mpsps: deceleration rate in "measures" per second per second
|
||||||
|
void setSlewAccelerationRateAbort(float mpsps);
|
||||||
|
|
||||||
|
// set acceleration rate for emergency stop of movement
|
||||||
|
// \param seconds: time during which deceleration from the last specified slew frequency occurs
|
||||||
|
void setSlewAccelerationTimeAbort(float seconds);
|
||||||
|
|
||||||
|
// auto goto to destination target coordinate
|
||||||
|
// \param frequency: optional frequency of slew in "measures" (radians, microns, etc.) per second
|
||||||
|
CommandError autoGoto(float frequency = NAN);
|
||||||
|
|
||||||
|
// auto slew
|
||||||
|
// \param direction: direction of motion, DIR_FORWARD or DIR_REVERSE
|
||||||
|
// \param frequency: optional frequency of slew in "measures" (radians, microns, etc.) per second
|
||||||
|
CommandError autoSlew(Direction direction, float frequency = NAN);
|
||||||
|
|
||||||
|
// automatic slew to home
|
||||||
|
// \param timeout: time in seconds before aborting the operation
|
||||||
|
// \note requires a home sensor (switch)
|
||||||
|
CommandError autoSlewHome(unsigned long timeout = 0);
|
||||||
|
|
||||||
|
// returns true homing is in progress
|
||||||
|
bool isHoming() { return homingStage != HOME_NONE; }
|
||||||
|
|
||||||
|
// returns true if a home sensor is available
|
||||||
|
inline bool hasHomeSense() { return pins->axisSense.homeTrigger != OFF; }
|
||||||
|
|
||||||
|
// stops any autoGoto() or autoSlew() or autoSlewHome() with deacceleration by time
|
||||||
|
void autoSlewStop();
|
||||||
|
|
||||||
|
// stops any autoGoto() or autoSlew() or autoSlewHome() with deacceleration by time using the abort rate
|
||||||
|
void autoSlewAbort();
|
||||||
|
|
||||||
|
// returns true if a slew is active on this axis
|
||||||
|
bool isSlewing();
|
||||||
|
|
||||||
|
// returns 1 if departing origin or -1 if approaching target
|
||||||
|
inline int getRampDirection() { return motor->getRampDirection(); }
|
||||||
|
|
||||||
|
// sets synchronized automatic target movement frequency
|
||||||
|
// \param frequency: rate of motion in "measures" (radians, microns, etc.) per second
|
||||||
|
inline void setSynchronizedFrequency(float frequency) { baseFreq = frequency; }
|
||||||
|
|
||||||
|
// set synchronized automatic target movement
|
||||||
|
// \param state: true to force target synchronized movement
|
||||||
|
// \note movement at the setSynchronizedFrequency() rate
|
||||||
|
inline void setSynchronized(bool state) { motor->setSynchronized(state); }
|
||||||
|
|
||||||
|
// returns true if synchronized automatic target movement is active
|
||||||
|
// \note movement at the setSynchronizedFrequency() rate
|
||||||
|
inline bool getSynchronized() { return motor->getSynchronized(); }
|
||||||
|
|
||||||
|
// returns true if the associated motor reports a fault
|
||||||
|
inline bool motorFault() { return motor->getDriverStatus().fault; };
|
||||||
|
|
||||||
|
// returns the associated motors driver status
|
||||||
|
DriverStatus getStatus();
|
||||||
|
|
||||||
|
// enables or disables software based position range limits
|
||||||
|
// \param state: true to enable or false to disable
|
||||||
|
void setMotionLimitsCheck(bool state);
|
||||||
|
|
||||||
|
// check for all errors that would disallow motion in the given direction
|
||||||
|
// \param direction: one of DIR_FORWARD, DIR_REVERSE, or DIR_BOTH
|
||||||
|
bool motionError(Direction direction);
|
||||||
|
|
||||||
|
// gets the minimum coordinate in "measures" (radians, microns, etc.)
|
||||||
|
float getLimitMin() { return minMeasure->value; }
|
||||||
|
|
||||||
|
// sets the minimum coordinate in "measures" (radians, microns, etc.)
|
||||||
|
void setLimitMin(float value) { if (parameterIsValid(minMeasure, value)) minMeasure->value = value; }
|
||||||
|
|
||||||
|
// gets the maximum coordinate in "measures" (radians, microns, etc.)
|
||||||
|
float getLimitMax() { return maxMeasure->value; }
|
||||||
|
|
||||||
|
// sets the maximum coordinate in "measures" (radians, microns, etc.)
|
||||||
|
void setLimitMax(float value) { if (parameterIsValid(maxMeasure, value)) maxMeasure->value = value; }
|
||||||
|
|
||||||
|
// check for sense (h/w limit) errors that would disallow motion in the given direction
|
||||||
|
// \param direction: one of DIR_FORWARD, DIR_REVERSE, or DIR_BOTH
|
||||||
|
bool motionErrorSensed(Direction direction);
|
||||||
|
|
||||||
|
// calibrate the associated motor
|
||||||
|
void calibrate(float value) { motor->calibrate(value); }
|
||||||
|
|
||||||
|
// calibrate the associated motor's driver
|
||||||
|
void calibrateDriver() { motor->calibrateDriver(); }
|
||||||
|
|
||||||
|
// monitor movement
|
||||||
|
void poll();
|
||||||
|
|
||||||
|
// associated motor
|
||||||
|
Motor *motor;
|
||||||
|
|
||||||
|
// hint that min and max pins are the same (no directional limit indication)
|
||||||
|
bool commonMinMaxSense = false;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// set frequency in "measures" (degrees, microns, etc.) per second (0 stops motion)
|
||||||
|
void setFrequency(float frequency);
|
||||||
|
|
||||||
|
// sets driver power on/off
|
||||||
|
void powered(bool value);
|
||||||
|
|
||||||
|
// distance to origin or target, whichever is closer, in "measures" (degrees, microns, etc.)
|
||||||
|
double getOriginOrTargetDistance();
|
||||||
|
|
||||||
|
// returns true if traveling through backlash
|
||||||
|
bool inBacklash();
|
||||||
|
|
||||||
|
// convert from unwrapped (full range) to normal (+/- wrapAmount) coordinate
|
||||||
|
double wrap(double value);
|
||||||
|
|
||||||
|
// convert from normal (+/- wrapAmount) to an unwrapped (full range) coordinate
|
||||||
|
double unwrap(double value);
|
||||||
|
|
||||||
|
// convert from normal (+/- wrapAmount) to an unwrapped (full range) coordinate
|
||||||
|
// nearest the instrument coordinate
|
||||||
|
double unwrapNearest(double value);
|
||||||
|
|
||||||
|
// get or set the axis revert flags
|
||||||
|
void setAxisRevert(bool state);
|
||||||
|
bool getAxisRevert();
|
||||||
|
|
||||||
|
AxisErrors errors;
|
||||||
|
bool lastErrorResult = false;
|
||||||
|
|
||||||
|
uint8_t axisNumber = 0;
|
||||||
|
char axisPrefix[9] = " Axis_, ";
|
||||||
|
|
||||||
|
char unitsStr[5] = "?";
|
||||||
|
bool unitsRadians = false;
|
||||||
|
|
||||||
|
bool enabled = false; // enabled or disabled axis and motor power
|
||||||
|
bool limitsCheck = true; // enabled or disabled software range limits check
|
||||||
|
|
||||||
|
uint8_t homeSenseHandle = 0; // home sensor handle
|
||||||
|
uint8_t minSenseHandle = 0; // min sensor handle
|
||||||
|
uint8_t maxSenseHandle = 0; // max sensor handle
|
||||||
|
|
||||||
|
#if DEBUG == VERBOSE
|
||||||
|
bool lastSenseMin = false;
|
||||||
|
bool lastSenseMax = false;
|
||||||
|
bool lastSenseHome = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uint16_t backlashStepsStore;
|
||||||
|
volatile uint16_t backlashSteps = 0;
|
||||||
|
volatile uint16_t backlashAmountSteps = 0;
|
||||||
|
|
||||||
|
volatile bool takeStep = false;
|
||||||
|
|
||||||
|
// coordinate handling
|
||||||
|
double wrapAmount = 0.0L;
|
||||||
|
bool wrapEnabled = false;
|
||||||
|
|
||||||
|
// power down standstill control
|
||||||
|
bool powerDownStandstill = false;
|
||||||
|
bool powerDownOverride = false;
|
||||||
|
bool poweredDown = false;
|
||||||
|
unsigned long powerDownDelay; // in milliseconds
|
||||||
|
unsigned long powerDownOverrideEnds; // in milliseconds
|
||||||
|
unsigned long powerDownTime = 0; // in milliseconds
|
||||||
|
|
||||||
|
// timeout for home switch detection
|
||||||
|
unsigned long homeTimeoutTime = 0; // in milliseconds
|
||||||
|
|
||||||
|
// rates (in measures per second) to control motor movement
|
||||||
|
float freq = 0.0F; // momentary frequency in measures/s
|
||||||
|
float baseFreq = 0.0F; // base frequency for continuous movement in measures/s
|
||||||
|
float minFreq = 0.0F; // minimum frequency in measures/s
|
||||||
|
float slewFreq = 0.0F; // slewing frequency in measures/s
|
||||||
|
float maxFreq = 0.0F; // maximum frequency in measures/s
|
||||||
|
float backlashFreq = 0.0F; // in measures/s
|
||||||
|
|
||||||
|
float scaleFreq = 1.0F;
|
||||||
|
|
||||||
|
double stepsPerMeasureValue = NAN;
|
||||||
|
double stepsPerMeasureValueNv = NAN;
|
||||||
|
double stepsPerMeasureDefault = NAN;
|
||||||
|
|
||||||
|
float targetTolerance = 0.0F;
|
||||||
|
|
||||||
|
AutoRate autoRate = AR_NONE; // auto slew mode
|
||||||
|
float slewAccelRateFs; // auto slew rate in measures per second per frac-sec
|
||||||
|
float abortAccelRateFs; // abort slew rate in measures per second per frac-sec
|
||||||
|
float slewAccelTime = NAN; // auto slew acceleration time in seconds
|
||||||
|
float abortAccelTime = NAN; // abort slew acceleration time in seconds
|
||||||
|
|
||||||
|
HomingStage homingStage = HOME_NONE;
|
||||||
|
|
||||||
|
const AxisPins *pins;
|
||||||
|
|
||||||
|
void (*volatile callback)() = NULL;
|
||||||
|
|
||||||
|
uint16_t nvKey, nvRevertKey;
|
||||||
|
|
||||||
|
AxisParameter stepsPerDegree = {NAN, NAN, NAN, 1.0, 360000.0, AXP_FLOAT, AXPN_STEPS_PER_DEG};
|
||||||
|
AxisParameter minDegrees = {NAN, NAN, NAN, -360.0, 360.0, AXP_FLOAT, AXPN_LIMIT_DEGS_MIN};
|
||||||
|
AxisParameter maxDegrees = {NAN, NAN, NAN, -360.0, 360.0, AXP_FLOAT, AXPN_LIMIT_DEGS_MAX};
|
||||||
|
|
||||||
|
AxisParameter stepsPerRadian = {NAN, NAN, NAN, radToDegF(1.0), radToDegF(360000.0), AXP_FLOAT_RAD_INV, AXPN_STEPS_PER_DEG};
|
||||||
|
AxisParameter minRadians = {NAN, NAN, NAN, -Deg360, Deg360, AXP_FLOAT_RAD, AXPN_LIMIT_DEGS_MIN};
|
||||||
|
AxisParameter maxRadians = {NAN, NAN, NAN, -Deg360, Deg360, AXP_FLOAT_RAD, AXPN_LIMIT_DEGS_MAX};
|
||||||
|
|
||||||
|
AxisParameter stepsPerMicron = {NAN, NAN, NAN, 0.001, 1000.0, AXP_FLOAT, AXPN_STEPS_PER_UM};
|
||||||
|
AxisParameter minMicrons = {NAN, NAN, NAN, 0.0, 500000.0, AXP_FLOAT, AXPN_LIMIT_UM_MIN};
|
||||||
|
AxisParameter maxMicrons = {NAN, NAN, NAN, 0.0, 500000.0, AXP_FLOAT, AXPN_LIMIT_UM_MAX};
|
||||||
|
|
||||||
|
AxisParameter *stepsPerMeasure = NULL;
|
||||||
|
AxisParameter *minMeasure = NULL;
|
||||||
|
AxisParameter *maxMeasure = NULL;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+93
@@ -0,0 +1,93 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
typedef struct DriverOutputStatus {
|
||||||
|
bool shortToGround;
|
||||||
|
bool openLoad;
|
||||||
|
} DriverOutputStatus;
|
||||||
|
|
||||||
|
typedef struct DriverStatus {
|
||||||
|
bool active;
|
||||||
|
DriverOutputStatus outputA;
|
||||||
|
DriverOutputStatus outputB;
|
||||||
|
bool overTemperatureWarning;
|
||||||
|
bool overTemperature;
|
||||||
|
bool standstill;
|
||||||
|
bool fault;
|
||||||
|
} DriverStatus;
|
||||||
|
|
||||||
|
// codes for locale specific name generation of certain terms in SWS, etc.
|
||||||
|
// any AxisParameter can instead just pass a string of up to 18 chars directly
|
||||||
|
#define AXPN_STEPS_PER_DEG "$1"
|
||||||
|
#define AXPN_LIMIT_DEGS_MIN "$2"
|
||||||
|
#define AXPN_LIMIT_DEGS_MAX "$3"
|
||||||
|
#define AXPN_STEPS_PER_UM "$4"
|
||||||
|
#define AXPN_LIMIT_UM_MIN "$5"
|
||||||
|
#define AXPN_LIMIT_UM_MAX "$6"
|
||||||
|
#define AXPN_REVERSE "$7"
|
||||||
|
#define AXPN_MICROSTEPS "$8"
|
||||||
|
#define AXPN_MICROSTEPS_GOTO "$9"
|
||||||
|
#define AXPN_DECAY_MODE "$10"
|
||||||
|
#define AXPN_DECAY_MODE_GOTO "$11"
|
||||||
|
#define AXPN_CURRENT_HOLD "$12"
|
||||||
|
#define AXPN_CURRENT_RUN "$13"
|
||||||
|
#define AXPN_CURRENT_GOTO "$14"
|
||||||
|
#define AXPN_INTERPOLATE "$15"
|
||||||
|
#define AXPN_PID_P "$16"
|
||||||
|
#define AXPN_PID_I "$17"
|
||||||
|
#define AXPN_PID_D "$18"
|
||||||
|
#define AXPN_PID_SLEWING_P "$19"
|
||||||
|
#define AXPN_PID_SLEWING_I "$20"
|
||||||
|
#define AXPN_PID_SLEWING_D "$21"
|
||||||
|
#define AXPN_COUNTS_PER_RAD "$22"
|
||||||
|
#define AXPN_STEPS_TO_COUNTS "$23"
|
||||||
|
#define AXPN_MAX_ACCEL "$24"
|
||||||
|
#define AXPN_MIN_PWR "$25"
|
||||||
|
#define AXPN_MAX_PWR "$26"
|
||||||
|
|
||||||
|
#define AXPN_1 "Steps/degree"
|
||||||
|
#define AXPN_2 "Min limit, degs"
|
||||||
|
#define AXPN_3 "Max limit, degs"
|
||||||
|
#define AXPN_4 "Steps/um"
|
||||||
|
#define AXPN_5 "Min limit, um"
|
||||||
|
#define AXPN_6 "Max limit, um"
|
||||||
|
#define AXPN_7 "Reverse"
|
||||||
|
#define AXPN_8 "Microsteps"
|
||||||
|
#define AXPN_9 "Microsteps Goto"
|
||||||
|
#define AXPN_10 "Decay mode"
|
||||||
|
#define AXPN_11 "Decay mode Goto"
|
||||||
|
#define AXPN_12 "mA Hold"
|
||||||
|
#define AXPN_13 "mA Run"
|
||||||
|
#define AXPN_14 "mA Goto"
|
||||||
|
#define AXPN_15 "256x Interpolate"
|
||||||
|
#define AXPN_16 "P tracking"
|
||||||
|
#define AXPN_17 "I tracking"
|
||||||
|
#define AXPN_18 "D tracking"
|
||||||
|
#define AXPN_19 "P slewing"
|
||||||
|
#define AXPN_20 "I slewing"
|
||||||
|
#define AXPN_21 "D slewing"
|
||||||
|
#define AXPN_22 "Rads/count"
|
||||||
|
#define AXPN_23 "Steps/count ratio"
|
||||||
|
#define AXPN_24 "Max accel, %/s/s"
|
||||||
|
#define AXPN_25 "Min power, %"
|
||||||
|
#define AXPN_26 "Max power, %"
|
||||||
|
|
||||||
|
// AXP_FLOAT_RAD and AXP_FLOAT_RAD_INV automatically translate to/from AXP_FLOAT (in degrees) for commands
|
||||||
|
enum AxisParameterType: uint8_t {AXP_INVALID,
|
||||||
|
AXP_BOOLEAN, AXP_BOOLEAN_IMMEDIATE,
|
||||||
|
AXP_INTEGER, AXP_INTEGER_IMMEDIATE,
|
||||||
|
AXP_FLOAT, AXP_FLOAT_IMMEDIATE,
|
||||||
|
AXP_FLOAT_RAD, AXP_FLOAT_RAD_INV,
|
||||||
|
AXP_POW2,
|
||||||
|
AXP_DECAY};
|
||||||
|
|
||||||
|
typedef struct AxisParameter {
|
||||||
|
float value;
|
||||||
|
float valueNv;
|
||||||
|
float valueDefault;
|
||||||
|
float min;
|
||||||
|
float max;
|
||||||
|
AxisParameterType type;
|
||||||
|
const char name[18];
|
||||||
|
} AxisParameter;
|
||||||
Executable
+212
@@ -0,0 +1,212 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// Generic motor controller
|
||||||
|
|
||||||
|
#include "Motor.h"
|
||||||
|
|
||||||
|
#ifdef MOTOR_PRESENT
|
||||||
|
|
||||||
|
Motor::Motor(uint8_t axisNumber, int8_t reverse) {
|
||||||
|
this->axisNumber = axisNumber;
|
||||||
|
this->reverse.valueDefault = reverse == ON;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Motor::init() {
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("motor init");
|
||||||
|
normalizedReverse = (bool)lround(reverse.value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns the specified axis parameter by name
|
||||||
|
AxisParameter* Motor::getParameterByName(const char* name) {
|
||||||
|
for (int i = 1; i <= getParameterCount(); i++) {
|
||||||
|
if (strcmp(getParameter(i)->name, name) == 0) { return getParameter(i); }
|
||||||
|
}
|
||||||
|
return &invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if parameter is valid
|
||||||
|
bool Motor::parameterIsValid(AxisParameter* parameter, bool next) {
|
||||||
|
const float value = next ? parameter->valueNv : parameter->value;
|
||||||
|
|
||||||
|
if (isnan(value) || isinf(value)) return false;
|
||||||
|
|
||||||
|
// reject nonsense bounds
|
||||||
|
const float pmin = parameter->min;
|
||||||
|
const float pmax = parameter->max;
|
||||||
|
if (isnan(pmin) || isnan(pmax) || isinf(pmin) || isinf(pmax) || (pmax < pmin)) return false;
|
||||||
|
|
||||||
|
if (value < pmin) return false;
|
||||||
|
if (value > pmax) return false;
|
||||||
|
|
||||||
|
if (parameter->type == AXP_POW2) {
|
||||||
|
static constexpr float kIntEps = 1E-3F;
|
||||||
|
|
||||||
|
// Value must be effectively integral
|
||||||
|
const float vf = value;
|
||||||
|
const int32_t vi = (int32_t)lroundf(vf);
|
||||||
|
if (fabsf(vf - (float)vi) > kIntEps) return false;
|
||||||
|
|
||||||
|
if (vi < 1 || vi > 256) return false;
|
||||||
|
if ((vi & (vi - 1)) != 0) return false; // power of two check
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// resets motor and target angular position in steps, also zeros backlash and index
|
||||||
|
void Motor::resetPositionSteps(long value) {
|
||||||
|
indexSteps = 0;
|
||||||
|
noInterrupts();
|
||||||
|
motorSteps = value;
|
||||||
|
targetSteps = value;
|
||||||
|
backlashSteps = 0;
|
||||||
|
interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
// resets target position to the motor position
|
||||||
|
void Motor::resetTargetToMotorPosition() {
|
||||||
|
noInterrupts();
|
||||||
|
targetSteps = motorSteps;
|
||||||
|
interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
// get motor position in steps (including backlash)
|
||||||
|
long Motor::getMotorPositionSteps() {
|
||||||
|
noInterrupts();
|
||||||
|
long steps = motorSteps + backlashSteps;
|
||||||
|
interrupts();
|
||||||
|
return steps;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get instrument coordinate, in steps
|
||||||
|
long Motor::getInstrumentCoordinateSteps() {
|
||||||
|
long steps = ATOMIC_LOAD(motorSteps);
|
||||||
|
return steps + indexSteps;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set instrument coordinate, in steps
|
||||||
|
void Motor::setInstrumentCoordinateSteps(long value) {
|
||||||
|
indexSteps = value - ATOMIC_LOAD(motorSteps);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set instrument park coordinate, in steps
|
||||||
|
// should only be called when the axis is not moving
|
||||||
|
// nudge index so park lands on a stable cogging grid (multiple of 4*modulo steps)
|
||||||
|
void Motor::setInstrumentCoordinateParkSteps(long value, int modulo) {
|
||||||
|
long priorLocationOffset = value - ATOMIC_LOAD(motorSteps);
|
||||||
|
if (driverType == STEP_DIR) {
|
||||||
|
if (modulo == OFF) modulo = 1;
|
||||||
|
long steps = priorLocationOffset;
|
||||||
|
steps -= modulo*2L;
|
||||||
|
for (int l = 0; l < modulo*4; l++) { if (steps % (modulo*4L) == 0) break; steps++; }
|
||||||
|
indexSteps = steps;
|
||||||
|
} else setInstrumentCoordinateSteps(value);
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("setInstrumentCoordinateParkSteps at "); V(indexSteps); VF(" (was "); V(priorLocationOffset); VL(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
// get target coordinate (with index), in steps
|
||||||
|
long Motor::getTargetCoordinateSteps() {
|
||||||
|
long steps = ATOMIC_LOAD(targetSteps) + indexSteps;
|
||||||
|
return steps;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set target coordinate (with index), in steps
|
||||||
|
void Motor::setTargetCoordinateSteps(long value) {
|
||||||
|
noInterrupts();
|
||||||
|
targetSteps = value - indexSteps;
|
||||||
|
interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
// set target park coordinate, in steps (taking into account stepper motor cogging when powered off)
|
||||||
|
// should only be called when the axis is not moving
|
||||||
|
void Motor::setTargetCoordinateParkSteps(long value, int modulo) {
|
||||||
|
if (driverType == STEP_DIR) {
|
||||||
|
if (modulo == OFF) modulo = 1;
|
||||||
|
long steps = value - indexSteps;
|
||||||
|
steps -= modulo*2L;
|
||||||
|
for (int l = 0; l < modulo*4; l++) { if (steps % (modulo*4L) == 0) break; steps++; }
|
||||||
|
noInterrupts();
|
||||||
|
targetSteps = steps;
|
||||||
|
interrupts();
|
||||||
|
} else setTargetCoordinateSteps(value);
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("setTargetCoordinateParkSteps at "); V(targetSteps); VF(" (was "); V(value - indexSteps); VL(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
// get backlash amount in steps
|
||||||
|
long Motor::getBacklashSteps() {
|
||||||
|
uint16_t backlash = ATOMIC_LOAD(backlashAmountSteps);
|
||||||
|
return (long)backlash;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set backlash amount in steps
|
||||||
|
void Motor::setBacklashSteps(long value) {
|
||||||
|
if (value < 0) value = 0;
|
||||||
|
if (value > 65535) value = 65535;
|
||||||
|
ATOMIC_STORE(backlashAmountSteps, (uint16_t)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// mark origin coordinate for autoGoto as current location
|
||||||
|
void Motor::markOriginCoordinateSteps() {
|
||||||
|
noInterrupts();
|
||||||
|
originSteps = motorSteps;
|
||||||
|
interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
// distance to target in steps (+/-)
|
||||||
|
long Motor::getTargetDistanceSteps() {
|
||||||
|
noInterrupts();
|
||||||
|
long dist = targetSteps - motorSteps;
|
||||||
|
interrupts();
|
||||||
|
return dist;
|
||||||
|
}
|
||||||
|
|
||||||
|
// distance to origin or target, whichever is closer, in steps
|
||||||
|
long Motor::getOriginOrTargetDistanceSteps() {
|
||||||
|
long steps = ATOMIC_LOAD(motorSteps);
|
||||||
|
long distanceOrigin = labs(originSteps - steps);
|
||||||
|
long distanceTarget = labs(targetSteps - steps);
|
||||||
|
if (distanceOrigin < distanceTarget) return distanceOrigin; else return distanceTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns 1 if distance to origin is closer else -1 if target is closer
|
||||||
|
int Motor::getRampDirection() {
|
||||||
|
long steps = ATOMIC_LOAD(motorSteps);
|
||||||
|
long distanceOrigin = labs(originSteps - steps);
|
||||||
|
long distanceTarget = labs(targetSteps - steps);
|
||||||
|
if (distanceOrigin < distanceTarget) return 1; else return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set backlash frequency in steps per second
|
||||||
|
void Motor::setBacklashFrequencySteps(float frequency) {
|
||||||
|
backlashFrequency = frequency;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the current direction of motion
|
||||||
|
Direction Motor::getDirection() {
|
||||||
|
if (getFrequencySteps() != 0.0F) {
|
||||||
|
if (step >= 1) return DIR_FORWARD;
|
||||||
|
if (step <= -1) return DIR_REVERSE;
|
||||||
|
}
|
||||||
|
return DIR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Motor::disableBacklash() {
|
||||||
|
noInterrupts();
|
||||||
|
backlashAmountStepsStore = backlashAmountSteps;
|
||||||
|
motorSteps += backlashSteps;
|
||||||
|
backlashStepsStore = backlashSteps;
|
||||||
|
backlashSteps = 0;
|
||||||
|
interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Motor::enableBacklash() {
|
||||||
|
noInterrupts();
|
||||||
|
backlashSteps = backlashStepsStore;
|
||||||
|
motorSteps -= backlashSteps;
|
||||||
|
backlashAmountSteps = backlashAmountStepsStore;
|
||||||
|
interrupts();
|
||||||
|
backlashStepsStore = 0;
|
||||||
|
backlashAmountStepsStore = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+219
@@ -0,0 +1,219 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// Generic motor controller
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "../../../Common.h"
|
||||||
|
#include "Drivers.h"
|
||||||
|
|
||||||
|
#ifdef MOTOR_PRESENT
|
||||||
|
|
||||||
|
enum Direction: uint8_t {DIR_NONE, DIR_FORWARD, DIR_REVERSE, DIR_BOTH};
|
||||||
|
|
||||||
|
#ifndef STEP_WAVE_FORM
|
||||||
|
#define STEP_WAVE_FORM SQUARE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class Motor {
|
||||||
|
public:
|
||||||
|
Motor(uint8_t axisNumber, int8_t reverse);
|
||||||
|
|
||||||
|
// sets up the motor identification
|
||||||
|
virtual bool init();
|
||||||
|
|
||||||
|
// returns the number of parameters from the motor and motor driver
|
||||||
|
virtual uint8_t getParameterCount() { return numParameters; }
|
||||||
|
|
||||||
|
// returns the specified axis parameter
|
||||||
|
virtual AxisParameter* getParameter(uint8_t number) { if (number > numParameters) return &invalid; else return parameter[number]; }
|
||||||
|
|
||||||
|
// check if parameter is valid
|
||||||
|
virtual bool parameterIsValid(AxisParameter* parameter, bool next = false);
|
||||||
|
|
||||||
|
// returns the specified axis parameter by name
|
||||||
|
AxisParameter* getParameterByName(const char* name);
|
||||||
|
|
||||||
|
// sets reversal of axis directions
|
||||||
|
// \param state: true reverses the direction behavior specified in settings
|
||||||
|
virtual void setReverse(bool state) { reversed = state; }
|
||||||
|
|
||||||
|
// sets motor enable on/off (if possible)
|
||||||
|
virtual void enable(bool value) { UNUSED(value); }
|
||||||
|
|
||||||
|
// get the associated stepper motor driver status
|
||||||
|
virtual DriverStatus getDriverStatus() { return errorStatus; }
|
||||||
|
|
||||||
|
// resets motor and target angular position in steps, also zeros backlash and index
|
||||||
|
virtual void resetPositionSteps(long value);
|
||||||
|
|
||||||
|
// resets target position to the motor position
|
||||||
|
void resetTargetToMotorPosition();
|
||||||
|
|
||||||
|
// get motor position in steps (including backlash)
|
||||||
|
long getMotorPositionSteps();
|
||||||
|
|
||||||
|
// get index position in steps
|
||||||
|
inline long getIndexPositionSteps() { return indexSteps; }
|
||||||
|
|
||||||
|
// get instrument coordinate, in steps
|
||||||
|
virtual long getInstrumentCoordinateSteps();
|
||||||
|
|
||||||
|
// set instrument coordinate, in steps
|
||||||
|
virtual void setInstrumentCoordinateSteps(long value);
|
||||||
|
|
||||||
|
// set instrument park coordinate, in steps
|
||||||
|
// should only be called when the axis is not moving
|
||||||
|
void setInstrumentCoordinateParkSteps(long value, int modulo);
|
||||||
|
|
||||||
|
// get target coordinate (with index), in steps
|
||||||
|
long getTargetCoordinateSteps();
|
||||||
|
|
||||||
|
// set target coordinate (with index), in steps
|
||||||
|
void setTargetCoordinateSteps(long value);
|
||||||
|
|
||||||
|
// set target park coordinate, in steps (taking into account stepper motor cogging when powered off)
|
||||||
|
// should only be called when the axis is not moving
|
||||||
|
void setTargetCoordinateParkSteps(long value, int modulo);
|
||||||
|
|
||||||
|
// get backlash amount in steps
|
||||||
|
long getBacklashSteps();
|
||||||
|
|
||||||
|
// set backlash amount in steps
|
||||||
|
void setBacklashSteps(long value);
|
||||||
|
|
||||||
|
// mark origin coordinate at current location
|
||||||
|
void markOriginCoordinateSteps();
|
||||||
|
|
||||||
|
// distance to target in steps (+/-)
|
||||||
|
virtual long getTargetDistanceSteps();
|
||||||
|
|
||||||
|
// distance to origin or target, whichever is closer, in steps
|
||||||
|
long getOriginOrTargetDistanceSteps();
|
||||||
|
|
||||||
|
// returns 1 if distance to origin is closer else -1 if target is closer
|
||||||
|
int getRampDirection();
|
||||||
|
|
||||||
|
// sets overall maximum frequency
|
||||||
|
// \param frequency: rate of motion in steps per second
|
||||||
|
virtual void setFrequencyMax(float frequency) { UNUSED(frequency); }
|
||||||
|
|
||||||
|
// get movement frequency in steps per second
|
||||||
|
virtual float getFrequencySteps() { return 0; }
|
||||||
|
|
||||||
|
// set frequency (+/-) in steps per second negative frequencies move reverse in direction (0 stops motion)
|
||||||
|
virtual void setFrequencySteps(float frequency) { UNUSED(frequency); }
|
||||||
|
|
||||||
|
// set backlash frequency in steps per second
|
||||||
|
virtual void setBacklashFrequencySteps(float frequency);
|
||||||
|
|
||||||
|
// get tracking mode steps per slewing mode step
|
||||||
|
virtual int getStepsPerStepSlewing() { return 1; }
|
||||||
|
|
||||||
|
// get synchronized state (automatic movement of target at setFrequencySteps() rate)
|
||||||
|
inline bool getSynchronized() { return sync; }
|
||||||
|
|
||||||
|
// set synchronized state (automatic movement of target at setFrequencySteps() rate)
|
||||||
|
virtual inline void setSynchronized(bool state) {
|
||||||
|
if (state) {
|
||||||
|
noInterrupts();
|
||||||
|
sync = state;
|
||||||
|
targetSteps = motorSteps;
|
||||||
|
interrupts();
|
||||||
|
} else sync = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the current direction of motion
|
||||||
|
Direction getDirection();
|
||||||
|
|
||||||
|
// microstep sequencer steps
|
||||||
|
int getSequencerSteps() { return 1; };
|
||||||
|
|
||||||
|
// set slewing state (hint that we are about to slew or are done slewing)
|
||||||
|
virtual void setSlewing(bool state) { UNUSED(state); }
|
||||||
|
|
||||||
|
// signal that the motor load has exceeded its threshold
|
||||||
|
virtual bool isStalled() { return false; }
|
||||||
|
|
||||||
|
// calibrate the motor if required
|
||||||
|
virtual void calibrate(float value) { UNUSED(value); }
|
||||||
|
|
||||||
|
// calibrate the motor driver if required
|
||||||
|
virtual void calibrateDriver() {}
|
||||||
|
|
||||||
|
// set zero of absolute encoders
|
||||||
|
virtual uint32_t encoderZero() { return 0; }
|
||||||
|
|
||||||
|
// return the encoder count, if present
|
||||||
|
virtual int32_t getEncoderCount() { return 0; }
|
||||||
|
|
||||||
|
// set origin of absolute encoders
|
||||||
|
virtual void encoderSetOrigin(uint32_t origin) { UNUSED(origin); }
|
||||||
|
|
||||||
|
// true when this motor has an absolute position source after boot
|
||||||
|
virtual bool hasAbsoluteEncoder() const { return false; }
|
||||||
|
|
||||||
|
// get the motor name
|
||||||
|
virtual const char* name() { return NULL; }
|
||||||
|
|
||||||
|
// monitor and respond to motor state as required
|
||||||
|
virtual void poll() {}
|
||||||
|
|
||||||
|
int driverType = OFF;
|
||||||
|
volatile bool inBacklash = false; // must be true if within the backlash travel
|
||||||
|
|
||||||
|
volatile uint8_t monitorHandle = 0; // handle to the axis task monitor
|
||||||
|
|
||||||
|
bool enabled = false; // enable/disable logical state
|
||||||
|
|
||||||
|
bool ready = false; // set to true after successful init
|
||||||
|
|
||||||
|
bool calibrating = false; // shadow disable when calibrating
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// disable backlash compensation, to work properly there must be an enable call to match
|
||||||
|
void disableBacklash();
|
||||||
|
|
||||||
|
// enable backlash compensation, to work properly this must be proceeded by a disable call
|
||||||
|
void enableBacklash();
|
||||||
|
|
||||||
|
volatile uint8_t axisNumber = 0; // axis number for this motor (1 to 9 in OnStepX)
|
||||||
|
char axisPrefix[32]; // prefix for debug messages
|
||||||
|
char nameStr[40]; // name of this motor/driver
|
||||||
|
|
||||||
|
volatile bool sync = true; // locks movement of axis target with timer rate
|
||||||
|
bool limitsCheck = true; // enable/disable numeric range limits (doesn't apply to limit switches)
|
||||||
|
|
||||||
|
uint8_t homeSenseHandle = 0; // home sensor handle
|
||||||
|
uint8_t minSenseHandle = 0; // limit min sensor handle
|
||||||
|
uint8_t maxSenseHandle = 0; // limit max sensor handle
|
||||||
|
|
||||||
|
float backlashFrequency = 0.0F;
|
||||||
|
volatile uint16_t backlashSteps = 0; // count of motor steps taken for backlash
|
||||||
|
uint16_t backlashStepsStore; // temporary storage for the position in backlash
|
||||||
|
volatile uint16_t backlashAmountSteps = 0; // the amount of backlash travel
|
||||||
|
uint16_t backlashAmountStepsStore; // temporary storage for the amount of backlash travel
|
||||||
|
|
||||||
|
long originSteps = 0; // start position for an autoGoto()
|
||||||
|
volatile long targetSteps = 0; // where we want the motor
|
||||||
|
volatile long motorSteps = 0; // where the motor is not counting backlash
|
||||||
|
volatile long indexSteps = 0; // for absolute motor position to axis position
|
||||||
|
volatile long step = 1; // step size, and for direction control
|
||||||
|
|
||||||
|
// a fault return status
|
||||||
|
const DriverStatus errorStatus = {false, {false, false}, {false, false}, false, false, false, true};
|
||||||
|
|
||||||
|
// reverses the set direction of motion
|
||||||
|
bool reversed = false;
|
||||||
|
|
||||||
|
// set direction of motion
|
||||||
|
bool normalizedReverse = false;
|
||||||
|
|
||||||
|
// runtime adjustable settings
|
||||||
|
const int numParameters = 1;
|
||||||
|
AxisParameter invalid = {NAN, NAN, NAN, NAN, NAN, AXP_INVALID, ""};
|
||||||
|
AxisParameter reverse = {NAN, NAN, NAN, 0, 1, AXP_BOOLEAN, AXPN_REVERSE};
|
||||||
|
|
||||||
|
AxisParameter* parameter[2] = {&invalid, &reverse};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+377
@@ -0,0 +1,377 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis ktech servo motor (designed for the MS4010v3)
|
||||||
|
|
||||||
|
#include "KTech.h"
|
||||||
|
|
||||||
|
#ifdef KTECH_MOTOR_PRESENT
|
||||||
|
|
||||||
|
#include "../../../tasks/OnTask.h"
|
||||||
|
#include "../../../canPlus/CanPlus.h"
|
||||||
|
|
||||||
|
static KTechMotor *ktechMotorInstance[9];
|
||||||
|
IRAM_ATTR void moveKTechMotorAxis1() { ktechMotorInstance[0]->move(); }
|
||||||
|
IRAM_ATTR void moveKTechMotorAxis2() { ktechMotorInstance[1]->move(); }
|
||||||
|
IRAM_ATTR void moveKTechMotorAxis3() { ktechMotorInstance[2]->move(); }
|
||||||
|
IRAM_ATTR void moveKTechMotorAxis4() { ktechMotorInstance[3]->move(); }
|
||||||
|
IRAM_ATTR void moveKTechMotorAxis5() { ktechMotorInstance[4]->move(); }
|
||||||
|
IRAM_ATTR void moveKTechMotorAxis6() { ktechMotorInstance[5]->move(); }
|
||||||
|
IRAM_ATTR void moveKTechMotorAxis7() { ktechMotorInstance[6]->move(); }
|
||||||
|
IRAM_ATTR void moveKTechMotorAxis8() { ktechMotorInstance[7]->move(); }
|
||||||
|
IRAM_ATTR void moveKTechMotorAxis9() { ktechMotorInstance[8]->move(); }
|
||||||
|
|
||||||
|
void statusKTechMotorAxis1(uint8_t data[8]) { ktechMotorInstance[0]->requestStatusCallback(data); }
|
||||||
|
void statusKTechMotorAxis2(uint8_t data[8]) { ktechMotorInstance[1]->requestStatusCallback(data); }
|
||||||
|
void statusKTechMotorAxis3(uint8_t data[8]) { ktechMotorInstance[2]->requestStatusCallback(data); }
|
||||||
|
void statusKTechMotorAxis4(uint8_t data[8]) { ktechMotorInstance[3]->requestStatusCallback(data); }
|
||||||
|
void statusKTechMotorAxis5(uint8_t data[8]) { ktechMotorInstance[4]->requestStatusCallback(data); }
|
||||||
|
void statusKTechMotorAxis6(uint8_t data[8]) { ktechMotorInstance[5]->requestStatusCallback(data); }
|
||||||
|
void statusKTechMotorAxis7(uint8_t data[8]) { ktechMotorInstance[6]->requestStatusCallback(data); }
|
||||||
|
void statusKTechMotorAxis8(uint8_t data[8]) { ktechMotorInstance[7]->requestStatusCallback(data); }
|
||||||
|
void statusKTechMotorAxis9(uint8_t data[8]) { ktechMotorInstance[8]->requestStatusCallback(data); }
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
KTechMotor::KTechMotor(uint8_t axisNumber, int8_t reverse, const KTechDriverSettings *Settings, bool useFastHardwareTimers)
|
||||||
|
:Motor(axisNumber, reverse) {
|
||||||
|
if (axisNumber < 1 || axisNumber > 9) return;
|
||||||
|
|
||||||
|
driverType = ODRIVER;
|
||||||
|
|
||||||
|
strcpy(axisPrefix, " Axis_KTech, ";
|
||||||
|
axisPrefix[5] = '0' + axisNumber;
|
||||||
|
|
||||||
|
// the motor CAN ID is the axis number!
|
||||||
|
canID = 0x140 + axisNumber;
|
||||||
|
|
||||||
|
statusMode = Settings->status;
|
||||||
|
|
||||||
|
if (axisNumber > 2) useFastHardwareTimers = false;
|
||||||
|
this->useFastHardwareTimers = useFastHardwareTimers;
|
||||||
|
|
||||||
|
// attach the function pointers to the callbacks
|
||||||
|
ktechMotorInstance[this->axisNumber - 1] = this;
|
||||||
|
switch (this->axisNumber) {
|
||||||
|
case 1: callback = moveKTechMotorAxis1; break;
|
||||||
|
case 2: callback = moveKTechMotorAxis2; break;
|
||||||
|
case 3: callback = moveKTechMotorAxis3; break;
|
||||||
|
case 4: callback = moveKTechMotorAxis4; break;
|
||||||
|
case 5: callback = moveKTechMotorAxis5; break;
|
||||||
|
case 6: callback = moveKTechMotorAxis6; break;
|
||||||
|
case 7: callback = moveKTechMotorAxis7; break;
|
||||||
|
case 8: callback = moveKTechMotorAxis8; break;
|
||||||
|
case 9: callback = moveKTechMotorAxis9; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KTechMotor::init() {
|
||||||
|
if (!Motor::init()) return false;
|
||||||
|
|
||||||
|
if (!canPlus.ready) {
|
||||||
|
V("ERR:"); V(axisPrefix); VLF("No CAN interface!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ready = true;
|
||||||
|
enable(false);
|
||||||
|
|
||||||
|
// start the motion timer
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("start task to synthesize motion... ");
|
||||||
|
char timerName[] = "Ax_KTec";
|
||||||
|
timerName[2] = axisNumber + '0';
|
||||||
|
taskHandle = tasks.add(0, 0, true, 0, callback, timerName);
|
||||||
|
if (taskHandle) {
|
||||||
|
VF("success");
|
||||||
|
if (useFastHardwareTimers) {
|
||||||
|
if (!tasks.requestHardwareTimer(taskHandle, 0)) {
|
||||||
|
VF(" (no hardware timer!)");
|
||||||
|
} else {
|
||||||
|
maxFrequency = (1000000.0F/HAL_MAXRATE_LOWER_LIMIT)/2.0F;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
VLF("");
|
||||||
|
} else {
|
||||||
|
VLF("FAILED!");
|
||||||
|
ready = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
stopSyntheticMotion();
|
||||||
|
|
||||||
|
// get ready for status messages
|
||||||
|
if (statusMode == ON) {
|
||||||
|
switch (this->axisNumber) {
|
||||||
|
case 1: canPlus.callbackRegisterMessage(canID, 0x9a, statusKTechMotorAxis1); break;
|
||||||
|
case 2: canPlus.callbackRegisterMessage(canID, 0x9a, statusKTechMotorAxis2); break;
|
||||||
|
case 3: canPlus.callbackRegisterMessage(canID, 0x9a, statusKTechMotorAxis3); break;
|
||||||
|
case 4: canPlus.callbackRegisterMessage(canID, 0x9a, statusKTechMotorAxis4); break;
|
||||||
|
case 5: canPlus.callbackRegisterMessage(canID, 0x9a, statusKTechMotorAxis5); break;
|
||||||
|
case 6: canPlus.callbackRegisterMessage(canID, 0x9a, statusKTechMotorAxis6); break;
|
||||||
|
case 7: canPlus.callbackRegisterMessage(canID, 0x9a, statusKTechMotorAxis7); break;
|
||||||
|
case 8: canPlus.callbackRegisterMessage(canID, 0x9a, statusKTechMotorAxis8); break;
|
||||||
|
case 9: canPlus.callbackRegisterMessage(canID, 0x9a, statusKTechMotorAxis9); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// low level reversal of axis directions
|
||||||
|
// \param state: OFF normal or ON to reverse
|
||||||
|
void KTechMotor::setReverse(int8_t state) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
if (state == ON) {
|
||||||
|
V("WRN:"); V(axisPrefix); VLF("axis reversal must be accomplished with hardware or KTech setup!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets motor enable on/off (if possible)
|
||||||
|
void KTechMotor::enable(bool state) {
|
||||||
|
if (!ready || state == enabled) return;
|
||||||
|
|
||||||
|
if (!state) enabled = false;
|
||||||
|
|
||||||
|
stopSyntheticMotion();
|
||||||
|
resetToTrackingBaseline();
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("driver powered "); VLF(state ? "up" : "down");
|
||||||
|
|
||||||
|
// best-effort command (no ACK assumed)
|
||||||
|
if (state) {
|
||||||
|
static const uint8_t cmdOn[] = "\x88\x00\x00\x00\x00\x00\x00\x00";
|
||||||
|
canPlus.writePacket(canID, cmdOn, 8);
|
||||||
|
enabled = true; // open window only if we intend to be enabled
|
||||||
|
} else {
|
||||||
|
static const uint8_t cmdOff[] = "\x80\x00\x00\x00\x00\x00\x00\x00";
|
||||||
|
canPlus.writePacket(canID, cmdOff, 8);
|
||||||
|
// enabled already false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KTechMotor::setInstrumentCoordinateSteps(long value) {
|
||||||
|
Motor::setInstrumentCoordinateSteps(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// resets motor and target angular position in steps, also zeros backlash and index
|
||||||
|
void KTechMotor::resetPositionSteps(long value) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
static const uint8_t cmd[] = "\x95\x00\x00\x00";
|
||||||
|
canPlus.txWait();
|
||||||
|
canPlus.beginPacket(canID);
|
||||||
|
canPlus.write(cmd, 4);
|
||||||
|
canPlus.write((uint8_t*)&value, 4);
|
||||||
|
canPlus.endPacket();
|
||||||
|
|
||||||
|
noInterrupts();
|
||||||
|
motorSteps = value;
|
||||||
|
targetSteps = value;
|
||||||
|
backlashSteps = 0;
|
||||||
|
interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
// set frequency (+/-) in steps per second negative frequencies move reverse in direction (0 stops motion)
|
||||||
|
void KTechMotor::setFrequencySteps(float frequency) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
if (!enabled) { stopSyntheticMotion(); return; }
|
||||||
|
|
||||||
|
// negative frequency, convert to positive and reverse the direction
|
||||||
|
int dir = 0;
|
||||||
|
if (frequency > 0.0F) dir = 1; else if (frequency < 0.0F) { frequency = -frequency; dir = -1; }
|
||||||
|
|
||||||
|
// if in backlash override the frequency
|
||||||
|
if (inBacklash) frequency = backlashFrequency;
|
||||||
|
|
||||||
|
if (frequency != currentFrequency) {
|
||||||
|
// compensate for performace limitations by taking larger steps as needed
|
||||||
|
if (frequency < maxFrequency) stepSize = 1; else
|
||||||
|
if (frequency < maxFrequency*2) stepSize = 2; else
|
||||||
|
if (frequency < maxFrequency*4) stepSize = 4; else
|
||||||
|
if (frequency < maxFrequency*8) stepSize = 8; else
|
||||||
|
if (frequency < maxFrequency*16) stepSize = 16; else
|
||||||
|
if (frequency < maxFrequency*32) stepSize = 32; else
|
||||||
|
if (frequency < maxFrequency*64) stepSize = 64; else
|
||||||
|
if (frequency < maxFrequency*128) stepSize = 128; else stepSize = 256;
|
||||||
|
|
||||||
|
// timer period in microseconds
|
||||||
|
float period = (1000000.0F*stepSize)/frequency;
|
||||||
|
|
||||||
|
// range is 0 to 134 seconds/step
|
||||||
|
if (!isnan(period) && period <= 130000000.0F) {
|
||||||
|
period *= 16.0F;
|
||||||
|
lastPeriod = (unsigned long)lroundf(period);
|
||||||
|
} else {
|
||||||
|
lastPeriod = 0;
|
||||||
|
frequency = 0.0F;
|
||||||
|
dir = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentFrequency = frequency;
|
||||||
|
|
||||||
|
// change the motor rate/direction
|
||||||
|
noInterrupts();
|
||||||
|
step = 0;
|
||||||
|
interrupts();
|
||||||
|
tasks.setPeriodSubMicros(taskHandle, lastPeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
noInterrupts();
|
||||||
|
step = dir * stepSize;
|
||||||
|
absStep = (int)labs(step);
|
||||||
|
interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
float KTechMotor::getFrequencySteps() {
|
||||||
|
if (!ready) return 0.0F;
|
||||||
|
|
||||||
|
if (lastPeriod == 0) return 0;
|
||||||
|
return (16000000.0F / lastPeriod) * absStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set slewing state (hint that we are about to slew or are done slewing)
|
||||||
|
void KTechMotor::setSlewing(bool state) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
isSlewing = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
// updates PID and sets ktech position
|
||||||
|
void KTechMotor::poll() {
|
||||||
|
const unsigned long now = millis();
|
||||||
|
|
||||||
|
if (statusMode == ON && (now - lastStatusRequestTime) >= KTECH_STATUS_MS) {
|
||||||
|
lastStatusRequestTime = now;
|
||||||
|
static const uint8_t cmd[] = "\x9a\x00\x00\x00\x00\x00\x00\x00";
|
||||||
|
canPlus.writePacket(canID, cmd, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
// hard faults on loss of comms during motion
|
||||||
|
if (statusMode == ON) {
|
||||||
|
if (!hasHeartbeat(KTECH_STATUS_MS * 4U) || status.fault) {
|
||||||
|
enabled = false;
|
||||||
|
stopSyntheticMotion();
|
||||||
|
resetToTrackingBaseline();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!enabled) return;
|
||||||
|
|
||||||
|
if (now - lastSetPositionTime < CAN_SEND_RATE_MS) return;
|
||||||
|
lastSetPositionTime = now;
|
||||||
|
|
||||||
|
noInterrupts();
|
||||||
|
#if KTECH_SLEW_DIRECT == ON
|
||||||
|
long target = targetSteps + backlashSteps;
|
||||||
|
#else
|
||||||
|
long target = motorSteps + backlashSteps;
|
||||||
|
#endif
|
||||||
|
interrupts();
|
||||||
|
|
||||||
|
if (lastTarget != target) {
|
||||||
|
static const uint8_t cmd[] = "\xa3\x00\x00\x00";
|
||||||
|
canPlus.txWait();
|
||||||
|
canPlus.beginPacket(canID);
|
||||||
|
canPlus.write(cmd, 4);
|
||||||
|
canPlus.write((uint8_t*)&target, 4);
|
||||||
|
canPlus.endPacket();
|
||||||
|
lastTarget = target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KTechMotor::stopSyntheticMotion() {
|
||||||
|
if (lastPeriod == 0 && step == 0 && absStep == 0) return;
|
||||||
|
currentFrequency = 0.0F;
|
||||||
|
lastPeriod = 0;
|
||||||
|
noInterrupts();
|
||||||
|
step = 0;
|
||||||
|
absStep = 0;
|
||||||
|
interrupts();
|
||||||
|
if (taskHandle) tasks.setPeriodSubMicros(taskHandle, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KTechMotor::resetToTrackingBaseline() {
|
||||||
|
noInterrupts();
|
||||||
|
step = 0;
|
||||||
|
absStep = 0;
|
||||||
|
inBacklash = false;
|
||||||
|
backlashSteps = 0;
|
||||||
|
interrupts();
|
||||||
|
|
||||||
|
currentFrequency = 0.0F;
|
||||||
|
lastPeriod = 0;
|
||||||
|
stepSize = 1;
|
||||||
|
|
||||||
|
// force next poll() to send target
|
||||||
|
lastTarget = LONG_MIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets dir as required and moves coord toward target at setFrequencySteps() rate
|
||||||
|
IRAM_ATTR void KTechMotor::move() {
|
||||||
|
if (sync && !inBacklash) targetSteps += step;
|
||||||
|
|
||||||
|
if (motorSteps > targetSteps) {
|
||||||
|
if (backlashSteps > 0) {
|
||||||
|
backlashSteps -= absStep;
|
||||||
|
inBacklash = backlashSteps > 0;
|
||||||
|
} else {
|
||||||
|
motorSteps -= absStep;
|
||||||
|
inBacklash = false;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
|
||||||
|
if (motorSteps < targetSteps || inBacklash) {
|
||||||
|
if (backlashSteps < backlashAmountSteps) {
|
||||||
|
backlashSteps += absStep;
|
||||||
|
inBacklash = backlashSteps < backlashAmountSteps;
|
||||||
|
} else {
|
||||||
|
motorSteps += absStep;
|
||||||
|
inBacklash = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KTechMotor::updateStatus() {
|
||||||
|
if (statusMode == OFF) return;
|
||||||
|
if (millis() - lastStatusUpdateTime >= KTECH_STATUS_MS*4U) {
|
||||||
|
status.outputA.shortToGround = true;
|
||||||
|
status.outputA.openLoad = true;
|
||||||
|
status.outputB.shortToGround = true;
|
||||||
|
status.outputB.openLoad = true;
|
||||||
|
status.overTemperatureWarning = true;
|
||||||
|
status.overTemperature = true;
|
||||||
|
status.standstill = true;
|
||||||
|
status.fault = true;
|
||||||
|
status.active = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update the associated driver status from CAN
|
||||||
|
void KTechMotor::requestStatusCallback(uint8_t data[8]) {
|
||||||
|
if (statusMode == OFF) return;
|
||||||
|
|
||||||
|
uint8_t errorState = data[7];
|
||||||
|
status.outputA.shortToGround = false;
|
||||||
|
status.outputA.openLoad = false;
|
||||||
|
status.outputB.shortToGround = false;
|
||||||
|
status.outputB.openLoad = false;
|
||||||
|
status.overTemperatureWarning = false;
|
||||||
|
status.overTemperature = bitRead(errorState, 3);
|
||||||
|
status.standstill = false;
|
||||||
|
status.fault = bitRead(errorState, 0) || bitRead(errorState, 3);
|
||||||
|
status.active = true;
|
||||||
|
|
||||||
|
lastStatusUpdateTime = millis();
|
||||||
|
statusValid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KTechMotor::hasHeartbeat(uint32_t maxAgeMs) const {
|
||||||
|
if (!ready || statusMode == OFF) return false;
|
||||||
|
|
||||||
|
const unsigned long now = millis();
|
||||||
|
const unsigned long age = now - lastStatusUpdateTime;
|
||||||
|
|
||||||
|
return statusValid && (age < maxAgeMs);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+118
@@ -0,0 +1,118 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis ktech servo motor (designed for the MS4010v3)
|
||||||
|
#pragma once
|
||||||
|
#include "../../../../Common.h"
|
||||||
|
|
||||||
|
#ifdef KTECH_MOTOR_PRESENT
|
||||||
|
|
||||||
|
#if !defined(CAN_PLUS) || CAN_PLUS == OFF
|
||||||
|
#error "No KTECH motor CAN interface!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "../Motor.h"
|
||||||
|
#include "../../../convert/Convert.h"
|
||||||
|
|
||||||
|
// KTECH status rate default 1Hz
|
||||||
|
#ifndef KTECH_STATUS_MS
|
||||||
|
#define KTECH_STATUS_MS 1000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// KTECH direct slewing ON or OFF (KTech handles acceleration)
|
||||||
|
#ifndef KTECH_SLEW_DIRECT
|
||||||
|
#define KTECH_SLEW_DIRECT OFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct KTechDriverSettings {
|
||||||
|
int16_t model;
|
||||||
|
int8_t status;
|
||||||
|
} KTechDriverSettings;
|
||||||
|
|
||||||
|
class KTechMotor : public Motor {
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
KTechMotor(uint8_t axisNumber, int8_t reverse, const KTechDriverSettings *Settings, bool useFastHardwareTimers = true);
|
||||||
|
|
||||||
|
// sets up the ktech motor
|
||||||
|
bool init();
|
||||||
|
|
||||||
|
// low level reversal of axis directions
|
||||||
|
// \param state: OFF normal or ON to reverse
|
||||||
|
void setReverse(int8_t state);
|
||||||
|
|
||||||
|
// sets motor enable on/off (if possible)
|
||||||
|
void enable(bool value);
|
||||||
|
|
||||||
|
// set instrument coordinate, in steps
|
||||||
|
void setInstrumentCoordinateSteps(long value);
|
||||||
|
|
||||||
|
// get the associated driver status
|
||||||
|
DriverStatus getDriverStatus() { if (ready) updateStatus(); else status = errorStatus; return status; }
|
||||||
|
bool hasHeartbeat(uint32_t maxAgeMs) const;
|
||||||
|
|
||||||
|
// resets motor and target angular position in steps, also zeros backlash and index
|
||||||
|
void resetPositionSteps(long value);
|
||||||
|
|
||||||
|
// get tracking mode steps per slewing mode step
|
||||||
|
inline int getStepsPerStepSlewing() { return 256; }
|
||||||
|
|
||||||
|
// get movement frequency in steps per second
|
||||||
|
float getFrequencySteps();
|
||||||
|
|
||||||
|
// set frequency (+/-) in steps per second negative frequencies move reverse in direction (0 stops motion)
|
||||||
|
void setFrequencySteps(float frequency);
|
||||||
|
|
||||||
|
// set slewing state (hint that we are about to slew or are done slewing)
|
||||||
|
void setSlewing(bool state);
|
||||||
|
|
||||||
|
// updates PID and sets servo motor power/direction
|
||||||
|
void poll();
|
||||||
|
|
||||||
|
// sets dir as required and moves coord toward target at setFrequencySteps() rate
|
||||||
|
void move();
|
||||||
|
|
||||||
|
// update the associated driver status
|
||||||
|
void updateStatus();
|
||||||
|
|
||||||
|
// update the associated driver status from CAN
|
||||||
|
void requestStatusCallback(uint8_t data[8]);
|
||||||
|
|
||||||
|
// get the motor name
|
||||||
|
const char* name() { return "KTECH"; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void stopSyntheticMotion();
|
||||||
|
void resetToTrackingBaseline();
|
||||||
|
|
||||||
|
int canID;
|
||||||
|
|
||||||
|
unsigned long lastSetPositionTime = 0;
|
||||||
|
unsigned long lastStatusRequestTime = 0;
|
||||||
|
unsigned long lastStatusUpdateTime = 0;
|
||||||
|
bool statusValid = false;
|
||||||
|
|
||||||
|
uint8_t taskHandle = 0;
|
||||||
|
|
||||||
|
int stepSize = 1; // step size
|
||||||
|
volatile bool takeStep = false; // should we take a step
|
||||||
|
long lastTarget = 0;
|
||||||
|
|
||||||
|
float currentFrequency = 0.0F; // last frequency set
|
||||||
|
unsigned long lastPeriod = 0; // last timer period (in sub-micros)
|
||||||
|
float maxFrequency = HAL_FRACTIONAL_SEC; // fastest timer rate
|
||||||
|
|
||||||
|
volatile int absStep = 0; // absolute step size (unsigned)
|
||||||
|
|
||||||
|
void (*callback)() = NULL;
|
||||||
|
|
||||||
|
bool useFastHardwareTimers = true;
|
||||||
|
|
||||||
|
bool isSlewing = false;
|
||||||
|
|
||||||
|
int16_t statusMode = OFF;
|
||||||
|
DriverStatus status = { false, {false, false}, {false, false}, false, false, false, false };
|
||||||
|
bool statusRequestSent = false;
|
||||||
|
|
||||||
|
float stepsPerMeasure = 0.0F;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+454
@@ -0,0 +1,454 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis MKS SERVO42D/57D motor driver via CAN, using 0xFE absolute position updates
|
||||||
|
// EXPERIMENTAL!!!
|
||||||
|
|
||||||
|
#include "MksServo.h"
|
||||||
|
|
||||||
|
#ifdef MKS42D_MOTOR_PRESENT
|
||||||
|
|
||||||
|
#include "../../../tasks/OnTask.h"
|
||||||
|
#include "../../../canPlus/CanPlus.h"
|
||||||
|
|
||||||
|
static Mks42DMotor *mksMotorInstance[9] = {nullptr};
|
||||||
|
|
||||||
|
IRAM_ATTR void moveMksAxis1() { mksMotorInstance[0]->move(); }
|
||||||
|
IRAM_ATTR void moveMksAxis2() { mksMotorInstance[1]->move(); }
|
||||||
|
IRAM_ATTR void moveMksAxis3() { mksMotorInstance[2]->move(); }
|
||||||
|
IRAM_ATTR void moveMksAxis4() { mksMotorInstance[3]->move(); }
|
||||||
|
IRAM_ATTR void moveMksAxis5() { mksMotorInstance[4]->move(); }
|
||||||
|
IRAM_ATTR void moveMksAxis6() { mksMotorInstance[5]->move(); }
|
||||||
|
IRAM_ATTR void moveMksAxis7() { mksMotorInstance[6]->move(); }
|
||||||
|
IRAM_ATTR void moveMksAxis8() { mksMotorInstance[7]->move(); }
|
||||||
|
IRAM_ATTR void moveMksAxis9() { mksMotorInstance[8]->move(); }
|
||||||
|
|
||||||
|
// Status callbacks (0xF1 and 0x3E both funnel into requestStatusCallback)
|
||||||
|
static void statusMksAxis1(uint8_t data[8]) { if (mksMotorInstance[0]) mksMotorInstance[0]->requestStatusCallback(data); }
|
||||||
|
static void statusMksAxis2(uint8_t data[8]) { if (mksMotorInstance[1]) mksMotorInstance[1]->requestStatusCallback(data); }
|
||||||
|
static void statusMksAxis3(uint8_t data[8]) { if (mksMotorInstance[2]) mksMotorInstance[2]->requestStatusCallback(data); }
|
||||||
|
static void statusMksAxis4(uint8_t data[8]) { if (mksMotorInstance[3]) mksMotorInstance[3]->requestStatusCallback(data); }
|
||||||
|
static void statusMksAxis5(uint8_t data[8]) { if (mksMotorInstance[4]) mksMotorInstance[4]->requestStatusCallback(data); }
|
||||||
|
static void statusMksAxis6(uint8_t data[8]) { if (mksMotorInstance[5]) mksMotorInstance[5]->requestStatusCallback(data); }
|
||||||
|
static void statusMksAxis7(uint8_t data[8]) { if (mksMotorInstance[6]) mksMotorInstance[6]->requestStatusCallback(data); }
|
||||||
|
static void statusMksAxis8(uint8_t data[8]) { if (mksMotorInstance[7]) mksMotorInstance[7]->requestStatusCallback(data); }
|
||||||
|
static void statusMksAxis9(uint8_t data[8]) { if (mksMotorInstance[8]) mksMotorInstance[8]->requestStatusCallback(data); }
|
||||||
|
|
||||||
|
Mks42DMotor::Mks42DMotor(uint8_t axisNumber,
|
||||||
|
int8_t reverse,
|
||||||
|
const MksDriverSettings *Settings,
|
||||||
|
bool useFastHardwareTimers)
|
||||||
|
: Motor(axisNumber, reverse) {
|
||||||
|
|
||||||
|
if (axisNumber < 1 || axisNumber > 9) return;
|
||||||
|
|
||||||
|
driverType = ODRIVER;
|
||||||
|
|
||||||
|
strcpy(axisPrefix, " Axis_Mks42D, ");
|
||||||
|
axisPrefix[5] = '0' + axisNumber;
|
||||||
|
|
||||||
|
// Mapping policy: CAN ID == axis number (1..9)
|
||||||
|
canID = axisNumber;
|
||||||
|
|
||||||
|
// reserve settings for future protocol/status differences
|
||||||
|
if (Settings) {
|
||||||
|
model = Settings->model;
|
||||||
|
statusMode = Settings->status;
|
||||||
|
} else {
|
||||||
|
model = 0;
|
||||||
|
statusMode = OFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
// AxisParameter defaults (must be assigned here)
|
||||||
|
// stepsPerSecondToRpm is intentionally *not* used in the simple/robust mode below.
|
||||||
|
stepsPerSecondToRpm.valueDefault = 0.01F;
|
||||||
|
maxRpm.valueDefault = 60.0F;
|
||||||
|
|
||||||
|
if (axisNumber > 2) useFastHardwareTimers = false;
|
||||||
|
this->useFastHardwareTimers = useFastHardwareTimers;
|
||||||
|
|
||||||
|
mksMotorInstance[axisNumber - 1] = this;
|
||||||
|
switch (axisNumber) {
|
||||||
|
case 1: callback = moveMksAxis1; break;
|
||||||
|
case 2: callback = moveMksAxis2; break;
|
||||||
|
case 3: callback = moveMksAxis3; break;
|
||||||
|
case 4: callback = moveMksAxis4; break;
|
||||||
|
case 5: callback = moveMksAxis5; break;
|
||||||
|
case 6: callback = moveMksAxis6; break;
|
||||||
|
case 7: callback = moveMksAxis7; break;
|
||||||
|
case 8: callback = moveMksAxis8; break;
|
||||||
|
case 9: callback = moveMksAxis9; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Mks42DMotor::init() {
|
||||||
|
if (!Motor::init()) return false;
|
||||||
|
|
||||||
|
if (!canPlus.ready) {
|
||||||
|
V("ERR:"); V(axisPrefix); VLF("No CAN interface!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ready = true;
|
||||||
|
enable(false);
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("start task to synthesize motion... ");
|
||||||
|
char timerName[] = "Ax_Mks_";
|
||||||
|
timerName[2] = axisNumber + '0';
|
||||||
|
|
||||||
|
taskHandle = tasks.add(0, 0, true, 0, callback, timerName);
|
||||||
|
if (taskHandle) {
|
||||||
|
VF("success");
|
||||||
|
if (useFastHardwareTimers) {
|
||||||
|
if (!tasks.requestHardwareTimer(taskHandle, 0)) {
|
||||||
|
VF(" (no hardware timer!)");
|
||||||
|
} else {
|
||||||
|
maxFrequency = (1000000.0F / HAL_MAXRATE_LOWER_LIMIT) / 2.0F;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
VLF("");
|
||||||
|
} else {
|
||||||
|
VLF("FAILED!");
|
||||||
|
ready = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
stopSyntheticMotion();
|
||||||
|
resetToTrackingBaseline();
|
||||||
|
|
||||||
|
// Always-on heartbeat + protect polling (RX callbacks)
|
||||||
|
if (statusMode == ON) {
|
||||||
|
switch (axisNumber) {
|
||||||
|
case 1:
|
||||||
|
canPlus.callbackRegisterMessage(canID, 0xF1, statusMksAxis1);
|
||||||
|
canPlus.callbackRegisterMessage(canID, 0x3E, statusMksAxis1);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
canPlus.callbackRegisterMessage(canID, 0xF1, statusMksAxis2);
|
||||||
|
canPlus.callbackRegisterMessage(canID, 0x3E, statusMksAxis2);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
canPlus.callbackRegisterMessage(canID, 0xF1, statusMksAxis3);
|
||||||
|
canPlus.callbackRegisterMessage(canID, 0x3E, statusMksAxis3);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
canPlus.callbackRegisterMessage(canID, 0xF1, statusMksAxis4);
|
||||||
|
canPlus.callbackRegisterMessage(canID, 0x3E, statusMksAxis4);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
canPlus.callbackRegisterMessage(canID, 0xF1, statusMksAxis5);
|
||||||
|
canPlus.callbackRegisterMessage(canID, 0x3E, statusMksAxis5);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
canPlus.callbackRegisterMessage(canID, 0xF1, statusMksAxis6);
|
||||||
|
canPlus.callbackRegisterMessage(canID, 0x3E, statusMksAxis6);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
canPlus.callbackRegisterMessage(canID, 0xF1, statusMksAxis7);
|
||||||
|
canPlus.callbackRegisterMessage(canID, 0x3E, statusMksAxis7);
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
canPlus.callbackRegisterMessage(canID, 0xF1, statusMksAxis8);
|
||||||
|
canPlus.callbackRegisterMessage(canID, 0x3E, statusMksAxis8);
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
canPlus.callbackRegisterMessage(canID, 0xF1, statusMksAxis9);
|
||||||
|
canPlus.callbackRegisterMessage(canID, 0x3E, statusMksAxis9);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
statusValid = false;
|
||||||
|
protectActive = false;
|
||||||
|
status.fault = false;
|
||||||
|
lastStatusUpdateTime = 0;
|
||||||
|
lastStatusRequestTime = 0;
|
||||||
|
lastProtectRequestTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mks42DMotor::setReverse(int8_t state) {
|
||||||
|
if (!ready) return;
|
||||||
|
if (state == ON) {
|
||||||
|
V("WRN:"); V(axisPrefix); VLF("axis reversal must be done in MKS setup or wiring!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mks42DMotor::setReverse(bool state) {
|
||||||
|
if (state) {
|
||||||
|
V("WRN:"); V(axisPrefix); VLF("software reverse requested; prefer MKS setup or wiring!");
|
||||||
|
}
|
||||||
|
Motor::setReverse(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mks42DMotor::enable(bool state) {
|
||||||
|
if (!ready || state == enabled) return;
|
||||||
|
|
||||||
|
if (!state) enabled = false;
|
||||||
|
|
||||||
|
stopSyntheticMotion();
|
||||||
|
resetToTrackingBaseline();
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("driver powered "); VLF(state ? "up" : "down");
|
||||||
|
|
||||||
|
canPlus.txWait();
|
||||||
|
sendF3(state);
|
||||||
|
|
||||||
|
if (state) {
|
||||||
|
enabled = true;
|
||||||
|
lastEnableTime = millis();
|
||||||
|
|
||||||
|
// clear latched faults on enable attempt (simple policy for v1)
|
||||||
|
status.fault = false;
|
||||||
|
protectActive = false;
|
||||||
|
// statusValid remains as-is; always-on polling will refresh it soon
|
||||||
|
}
|
||||||
|
|
||||||
|
// force next poll() to send target
|
||||||
|
lastTarget = LONG_MIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mks42DMotor::resetPositionSteps(long value) {
|
||||||
|
if (!ready) return;
|
||||||
|
Motor::resetPositionSteps(value);
|
||||||
|
|
||||||
|
// force next poll() to send target
|
||||||
|
lastTarget = LONG_MIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Mks42DMotor::getFrequencySteps() {
|
||||||
|
if (!ready) return 0.0F;
|
||||||
|
if (lastPeriod == 0) return 0.0F;
|
||||||
|
return (16000000.0F / lastPeriod) * absStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mks42DMotor::setFrequencySteps(float frequency) {
|
||||||
|
if (!ready) return;
|
||||||
|
if (!enabled) { stopSyntheticMotion(); return; }
|
||||||
|
|
||||||
|
int dir = 0;
|
||||||
|
if (frequency > 0.0F) dir = 1;
|
||||||
|
else if (frequency < 0.0F) { frequency = -frequency; dir = -1; }
|
||||||
|
|
||||||
|
if (inBacklash) frequency = backlashFrequency;
|
||||||
|
|
||||||
|
if (frequency != currentFrequency) {
|
||||||
|
// compensate for performance limitations by taking larger steps as needed
|
||||||
|
if (frequency < maxFrequency) stepSize = 1; else
|
||||||
|
if (frequency < maxFrequency*2) stepSize = 2; else
|
||||||
|
if (frequency < maxFrequency*4) stepSize = 4; else
|
||||||
|
if (frequency < maxFrequency*8) stepSize = 8; else
|
||||||
|
if (frequency < maxFrequency*16) stepSize = 16; else
|
||||||
|
if (frequency < maxFrequency*32) stepSize = 32; else
|
||||||
|
if (frequency < maxFrequency*64) stepSize = 64; else
|
||||||
|
if (frequency < maxFrequency*128) stepSize = 128; else stepSize = 256;
|
||||||
|
|
||||||
|
// timer period in microseconds
|
||||||
|
float period = (1000000.0F * stepSize) / frequency;
|
||||||
|
|
||||||
|
// range is 0 to 134 seconds/step
|
||||||
|
if (!isnan(period) && period <= 130000000.0F) {
|
||||||
|
period *= 16.0F;
|
||||||
|
lastPeriod = (unsigned long)lroundf(period);
|
||||||
|
} else {
|
||||||
|
lastPeriod = 0;
|
||||||
|
frequency = 0.0F;
|
||||||
|
dir = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentFrequency = frequency;
|
||||||
|
|
||||||
|
// change the motor rate/direction
|
||||||
|
noInterrupts();
|
||||||
|
step = 0;
|
||||||
|
interrupts();
|
||||||
|
tasks.setPeriodSubMicros(taskHandle, lastPeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
noInterrupts();
|
||||||
|
step = dir * stepSize;
|
||||||
|
absStep = (int)labs(step);
|
||||||
|
interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mks42DMotor::setSlewing(bool state) {
|
||||||
|
if (!ready) return;
|
||||||
|
isSlewing = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- CAN helpers ----
|
||||||
|
|
||||||
|
inline void Mks42DMotor::sendWithCrc(const uint8_t *payload, size_t n) {
|
||||||
|
if (!payload || n < 1 || n > 7) return;
|
||||||
|
|
||||||
|
uint8_t buf[8] = {0};
|
||||||
|
memcpy(buf, payload, n);
|
||||||
|
buf[n] = crc8((uint16_t)canID, buf, n);
|
||||||
|
|
||||||
|
canPlus.writePacket(canID, buf, n + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Mks42DMotor::sendF3(bool en) {
|
||||||
|
const uint8_t p[2] = { 0xF3, (uint8_t)(en ? 1 : 0) };
|
||||||
|
sendWithCrc(p, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Mks42DMotor::sendFE(int32_t pos, uint16_t speed) {
|
||||||
|
const int32_t p = clamp24(pos);
|
||||||
|
const uint32_t u = (uint32_t)p & 0x00FFFFFFUL; // signed 24-bit in low 24 bits
|
||||||
|
|
||||||
|
const uint8_t payload[7] = {
|
||||||
|
0xFE,
|
||||||
|
(uint8_t)(speed >> 8),
|
||||||
|
(uint8_t)(speed & 0xFF),
|
||||||
|
(uint8_t)MKS_FE_ACCEL_CONST,
|
||||||
|
(uint8_t)((u >> 16) & 0xFF),
|
||||||
|
(uint8_t)((u >> 8) & 0xFF),
|
||||||
|
(uint8_t)((u >> 0) & 0xFF),
|
||||||
|
};
|
||||||
|
|
||||||
|
sendWithCrc(payload, 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always-on polling commands
|
||||||
|
inline void Mks42DMotor::sendF1() { const uint8_t p[1] = { 0xF1 }; sendWithCrc(p, 1); }
|
||||||
|
inline void Mks42DMotor::send3E() { const uint8_t p[1] = { 0x3E }; sendWithCrc(p, 1); }
|
||||||
|
|
||||||
|
// RX: treat 0xF1 and 0x3E as heartbeat sources; latch fault on protect active.
|
||||||
|
void Mks42DMotor::requestStatusCallback(uint8_t data[8]) {
|
||||||
|
if (statusMode == OFF) return;
|
||||||
|
|
||||||
|
const uint8_t code = data[0];
|
||||||
|
if (code != 0xF1 && code != 0x3E) return;
|
||||||
|
|
||||||
|
lastStatusUpdateTime = millis();
|
||||||
|
statusValid = true;
|
||||||
|
|
||||||
|
if (code == 0x3E) {
|
||||||
|
protectActive = (data[1] != 0);
|
||||||
|
if (protectActive) status.fault = true; // latch
|
||||||
|
}
|
||||||
|
|
||||||
|
// Optional extension hook: decode 0xF1 state from data[1] later if desired.
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Mks42DMotor::hasHeartbeat(uint32_t maxAgeMs) const {
|
||||||
|
if (!ready || statusMode == OFF) return false;
|
||||||
|
if (!statusValid) return false;
|
||||||
|
|
||||||
|
const unsigned long now = millis();
|
||||||
|
return (now - lastStatusUpdateTime) < maxAgeMs;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Absolute position streaming (simple/robust):
|
||||||
|
// - Stream 0xFE target position
|
||||||
|
// - Use a fixed speed cap (maxRpm) rather than a dynamic feed-forward mapping
|
||||||
|
void Mks42DMotor::poll() {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
const unsigned long now = millis();
|
||||||
|
|
||||||
|
// Always-on heartbeat + protect polling
|
||||||
|
if (statusMode == ON) {
|
||||||
|
if ((now - lastStatusRequestTime) >= MKS_STATUS_MS) {
|
||||||
|
lastStatusRequestTime = now;
|
||||||
|
if (canPlus.txTryLock()) sendF1(); // best-effort, non-blocking
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((now - lastProtectRequestTime) >= MKS_PROTECT_MS) {
|
||||||
|
lastProtectRequestTime = now;
|
||||||
|
if (canPlus.txTryLock()) send3E(); // best-effort, non-blocking
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hard faults only when enabled, with grace window after enabling
|
||||||
|
if (enabled) {
|
||||||
|
const bool inGrace = (now - lastEnableTime) < (unsigned long)MKS_HEARTBEAT_GRACE_MS;
|
||||||
|
|
||||||
|
const bool ok = statusValid ? hasHeartbeat(MKS_STATUS_MS * 4U) : inGrace;
|
||||||
|
|
||||||
|
if (!ok || status.fault) {
|
||||||
|
enabled = false;
|
||||||
|
stopSyntheticMotion();
|
||||||
|
resetToTrackingBaseline();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!enabled) return;
|
||||||
|
|
||||||
|
noInterrupts();
|
||||||
|
#if MKS_SLEW_DIRECT == ON
|
||||||
|
long target = targetSteps + backlashSteps;
|
||||||
|
#else
|
||||||
|
long target = motorSteps + backlashSteps;
|
||||||
|
#endif
|
||||||
|
interrupts();
|
||||||
|
|
||||||
|
// signed 24-bit domain enforced here
|
||||||
|
const int32_t pos = clamp24((int32_t)target);
|
||||||
|
|
||||||
|
// simple: speed is a cap (RPM), not a feed-forward term
|
||||||
|
uint16_t spd = (uint16_t)lroundf(pval(maxRpm));
|
||||||
|
if (spd > 3000) spd = 3000;
|
||||||
|
|
||||||
|
// send only on position change (avoid any "speed jitter" surprises)
|
||||||
|
if (lastTarget == (long)pos) return;
|
||||||
|
|
||||||
|
if (!canPlus.txTryLock()) return;
|
||||||
|
|
||||||
|
sendFE(pos, spd);
|
||||||
|
|
||||||
|
lastTarget = (long)pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mks42DMotor::stopSyntheticMotion() {
|
||||||
|
if (lastPeriod == 0 && step == 0 && absStep == 0) return;
|
||||||
|
currentFrequency = 0.0F;
|
||||||
|
lastPeriod = 0;
|
||||||
|
noInterrupts();
|
||||||
|
step = 0;
|
||||||
|
absStep = 0;
|
||||||
|
interrupts();
|
||||||
|
if (taskHandle) tasks.setPeriodSubMicros(taskHandle, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mks42DMotor::resetToTrackingBaseline() {
|
||||||
|
noInterrupts();
|
||||||
|
step = 0;
|
||||||
|
absStep = 0;
|
||||||
|
inBacklash = false;
|
||||||
|
backlashSteps = 0;
|
||||||
|
interrupts();
|
||||||
|
|
||||||
|
currentFrequency = 0.0F;
|
||||||
|
lastPeriod = 0;
|
||||||
|
stepSize = 1;
|
||||||
|
|
||||||
|
// force next poll() to send target
|
||||||
|
lastTarget = LONG_MIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets dir as required and moves coord toward target at setFrequencySteps() rate
|
||||||
|
IRAM_ATTR void Mks42DMotor::move() {
|
||||||
|
if (sync && !inBacklash) targetSteps += step;
|
||||||
|
|
||||||
|
if (motorSteps > targetSteps) {
|
||||||
|
if (backlashSteps > 0) {
|
||||||
|
backlashSteps -= absStep;
|
||||||
|
inBacklash = backlashSteps > 0;
|
||||||
|
} else {
|
||||||
|
motorSteps -= absStep;
|
||||||
|
inBacklash = false;
|
||||||
|
}
|
||||||
|
} else if (motorSteps < targetSteps || inBacklash) {
|
||||||
|
if (backlashSteps < backlashAmountSteps) {
|
||||||
|
backlashSteps += absStep;
|
||||||
|
inBacklash = backlashSteps < backlashAmountSteps;
|
||||||
|
} else {
|
||||||
|
motorSteps += absStep;
|
||||||
|
inBacklash = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+184
@@ -0,0 +1,184 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis MKS SERVO42D/57D motor driver via CAN, using 0xFE absolute position updates
|
||||||
|
// EXPERIMENTAL!!!
|
||||||
|
#pragma once
|
||||||
|
#include "../../../../Common.h"
|
||||||
|
|
||||||
|
#ifdef MKS42D_MOTOR_PRESENT
|
||||||
|
|
||||||
|
#if !defined(CAN_PLUS) || CAN_PLUS == OFF
|
||||||
|
#error "No MKS motor CAN interface!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "../Motor.h"
|
||||||
|
|
||||||
|
#ifndef MKS_SLEW_DIRECT
|
||||||
|
#define MKS_SLEW_DIRECT OFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MKS_FE_ACCEL_CONST
|
||||||
|
#define MKS_FE_ACCEL_CONST 10
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// always-on status request (0xF1) rate
|
||||||
|
#ifndef MKS_STATUS_MS
|
||||||
|
#define MKS_STATUS_MS 250
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// always-on protect-state request (0x3E) rate
|
||||||
|
#ifndef MKS_PROTECT_MS
|
||||||
|
#define MKS_PROTECT_MS 1000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// grace period after enabling before enforcing heartbeat
|
||||||
|
#ifndef MKS_HEARTBEAT_GRACE_MS
|
||||||
|
#define MKS_HEARTBEAT_GRACE_MS 1500
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct MksDriverSettings {
|
||||||
|
int16_t model;
|
||||||
|
int8_t status; // ON/OFF (enables always-on heartbeat + protect polling)
|
||||||
|
} MksDriverSettings;
|
||||||
|
|
||||||
|
class Mks42DMotor : public Motor {
|
||||||
|
public:
|
||||||
|
Mks42DMotor(uint8_t axisNumber,
|
||||||
|
int8_t reverse,
|
||||||
|
const MksDriverSettings *Settings,
|
||||||
|
bool useFastHardwareTimers = true);
|
||||||
|
|
||||||
|
bool init() override;
|
||||||
|
|
||||||
|
uint8_t getParameterCount() override { return Motor::getParameterCount() + numParameters; }
|
||||||
|
|
||||||
|
AxisParameter* getParameter(uint8_t number) override {
|
||||||
|
const uint8_t base = Motor::getParameterCount();
|
||||||
|
if (number >= 1 && number <= base) return Motor::getParameter(number);
|
||||||
|
|
||||||
|
const uint8_t i = number - base;
|
||||||
|
if (i == 1) return &stepsPerSecondToRpm;
|
||||||
|
if (i == 2) return &maxRpm;
|
||||||
|
return &invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Integrated-driver style reverse control (kept for parity with other integrated CAN motors)
|
||||||
|
void setReverse(int8_t state);
|
||||||
|
|
||||||
|
// Base-class reverse (prevents silent bypass if someone calls Motor::setReverse(bool))
|
||||||
|
void setReverse(bool state) override;
|
||||||
|
|
||||||
|
void enable(bool state) override;
|
||||||
|
|
||||||
|
void resetPositionSteps(long value) override;
|
||||||
|
|
||||||
|
int getStepsPerStepSlewing() override { return 256; }
|
||||||
|
|
||||||
|
float getFrequencySteps() override;
|
||||||
|
void setFrequencySteps(float frequency) override;
|
||||||
|
|
||||||
|
void setSlewing(bool state) override;
|
||||||
|
|
||||||
|
void poll() override;
|
||||||
|
|
||||||
|
const char* name() override { return "MKS_FE"; }
|
||||||
|
|
||||||
|
// ISR uses this; not a Motor virtual
|
||||||
|
void move();
|
||||||
|
|
||||||
|
// minimal heartbeat API (updated by 0xF1 or 0x3E callbacks)
|
||||||
|
bool hasHeartbeat(uint32_t maxAgeMs) const;
|
||||||
|
|
||||||
|
// driver status (minimal; only "fault" is currently meaningful)
|
||||||
|
DriverStatus getDriverStatus() { return ready ? status : errorStatus; }
|
||||||
|
|
||||||
|
// RX callback (wired via CanPlus callbackRegisterMessage)
|
||||||
|
void requestStatusCallback(uint8_t data[8]);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static inline uint8_t crc8(uint16_t id11, const uint8_t *data, size_t n) {
|
||||||
|
uint32_t sum = (uint32_t)(id11 & 0x7FF);
|
||||||
|
for (size_t i = 0; i < n; i++) sum += data[i];
|
||||||
|
return (uint8_t)(sum & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int32_t clamp24(int32_t v) {
|
||||||
|
if (v > 8388607L) return 8388607L;
|
||||||
|
if (v < -8388608L) return -8388608L;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float pval(const AxisParameter &p) const {
|
||||||
|
const float v = p.value;
|
||||||
|
return isnan(v) ? p.valueDefault : v;
|
||||||
|
}
|
||||||
|
|
||||||
|
// stepsPerSecondToRpm unit: RPM per (steps/second)
|
||||||
|
inline uint16_t speedFromStepRate(float stepsPerSec) const {
|
||||||
|
if (stepsPerSec < 0.0F) stepsPerSec = -stepsPerSec;
|
||||||
|
|
||||||
|
const float scale = pval(stepsPerSecondToRpm);
|
||||||
|
float sF = stepsPerSec * scale;
|
||||||
|
if (sF < 0.0F) sF = 0.0F;
|
||||||
|
|
||||||
|
// MKS protocol speed range is 0..3000 RPM; keep the clamp aligned to that.
|
||||||
|
float capF = pval(maxRpm);
|
||||||
|
if (capF < 0.0F) capF = 0.0F;
|
||||||
|
if (capF > 3000.0F) capF = 3000.0F;
|
||||||
|
|
||||||
|
if (sF > capF) sF = capF;
|
||||||
|
return (uint16_t)lroundf(sF);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void sendWithCrc(const uint8_t *payload, size_t n); // n<=7
|
||||||
|
inline void sendF3(bool en);
|
||||||
|
inline void sendFE(int32_t pos, uint16_t speed);
|
||||||
|
|
||||||
|
// Always-on polling helpers
|
||||||
|
inline void sendF1(); // queryStatus (0xF1)
|
||||||
|
inline void send3E(); // readProtectState (0x3E)
|
||||||
|
|
||||||
|
void stopSyntheticMotion();
|
||||||
|
void resetToTrackingBaseline();
|
||||||
|
|
||||||
|
int canID = 0;
|
||||||
|
|
||||||
|
// reserved / future
|
||||||
|
int16_t model = 0;
|
||||||
|
int8_t statusMode = OFF;
|
||||||
|
|
||||||
|
uint8_t taskHandle = 0;
|
||||||
|
|
||||||
|
int stepSize = 1;
|
||||||
|
float currentFrequency = 0.0F;
|
||||||
|
unsigned long lastPeriod = 0;
|
||||||
|
float maxFrequency = HAL_FRACTIONAL_SEC;
|
||||||
|
|
||||||
|
volatile int absStep = 0;
|
||||||
|
|
||||||
|
void (*callback)() = nullptr;
|
||||||
|
|
||||||
|
bool useFastHardwareTimers = true;
|
||||||
|
bool isSlewing = false;
|
||||||
|
|
||||||
|
long lastTarget = LONG_MIN;
|
||||||
|
|
||||||
|
// --- always-on heartbeat / protect state ---
|
||||||
|
unsigned long lastStatusRequestTime = 0;
|
||||||
|
unsigned long lastProtectRequestTime = 0;
|
||||||
|
unsigned long lastStatusUpdateTime = 0;
|
||||||
|
unsigned long lastEnableTime = 0;
|
||||||
|
bool statusValid = false;
|
||||||
|
|
||||||
|
bool protectActive = false; // latched via 0x3E
|
||||||
|
|
||||||
|
// Minimal status model: only "fault" is currently meaningful
|
||||||
|
DriverStatus status = { false, {false, false}, {false, false}, false, false, false, false };
|
||||||
|
|
||||||
|
// runtime adjustable settings
|
||||||
|
AxisParameter stepsPerSecondToRpm = {NAN, NAN, NAN, 0.0F, 10000.0F, AXP_FLOAT, "Steps/s to RPM"};
|
||||||
|
AxisParameter maxRpm = {NAN, NAN, NAN, 0.0F, 3000.0F, AXP_INTEGER, "Max Speed RPM"};
|
||||||
|
|
||||||
|
const int numParameters = 2;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+288
@@ -0,0 +1,288 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis odrive servo motor
|
||||||
|
|
||||||
|
#include "ODrive.h"
|
||||||
|
|
||||||
|
#ifndef ODRIVE_NEW_MOTOR_PRESENT
|
||||||
|
#ifdef ODRIVE_MOTOR_PRESENT
|
||||||
|
|
||||||
|
#include "../../../tasks/OnTask.h"
|
||||||
|
#include "../../../gpioEx/GpioEx.h"
|
||||||
|
|
||||||
|
#include "ODriveEnums.h"
|
||||||
|
|
||||||
|
ODriveMotor *odriveMotorInstance[2];
|
||||||
|
IRAM_ATTR void moveODriveMotorAxis1() { odriveMotorInstance[0]->move(); }
|
||||||
|
IRAM_ATTR void moveODriveMotorAxis2() { odriveMotorInstance[1]->move(); }
|
||||||
|
|
||||||
|
// ODrive servo motor driver object pointer
|
||||||
|
#if ODRIVE_COMM_MODE == OD_UART
|
||||||
|
ODriveArduino *_oDriveDriver;
|
||||||
|
#elif ODRIVE_COMM_MODE == OD_CAN
|
||||||
|
ODriveTeensyCAN *_oDriveDriver;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
ODriveMotor::ODriveMotor(uint8_t axisNumber, int8_t reverse, const ODriveDriverSettings *Settings, float radsPerCount, bool useFastHardwareTimers)
|
||||||
|
:Motor(axisNumber, reverse) {
|
||||||
|
if (axisNumber < 1 || axisNumber > 2) return;
|
||||||
|
|
||||||
|
driverType = ODRIVER;
|
||||||
|
|
||||||
|
#if ODRIVE_SWAP_AXES == ON
|
||||||
|
this->axisNumber = 3 - axisNumber;
|
||||||
|
#else
|
||||||
|
this->axisNumber = axisNumber;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
strcpy(axisPrefix, " Axis_ODrive, ");
|
||||||
|
axisPrefix[5] = '0' + axisNumber;
|
||||||
|
|
||||||
|
if (axisNumber > 2) useFastHardwareTimers = false;
|
||||||
|
this->useFastHardwareTimers = useFastHardwareTimers;
|
||||||
|
|
||||||
|
if (axisNumber == 1) { // only do once since motor 2 object creation could
|
||||||
|
#if ODRIVE_COMM_MODE == OD_UART
|
||||||
|
_oDriveDriver = new ODriveArduino(ODRIVE_SERIAL);
|
||||||
|
#elif ODRIVE_COMM_MODE == OD_CAN
|
||||||
|
_oDriveDriver = new ODriveTeensyCAN(250000);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// set parameter default values during object creation
|
||||||
|
radsPerCount.valueDefualt = radsPerCount;
|
||||||
|
|
||||||
|
// attach the function pointers to the callbacks
|
||||||
|
odriveMotorInstance[this->axisNumber - 1] = this;
|
||||||
|
switch (this->axisNumber) {
|
||||||
|
case 1: callback = moveODriveMotorAxis1; break;
|
||||||
|
case 2: callback = moveODriveMotorAxis2; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ODriveMotor::init() {
|
||||||
|
if (!Motor::init()) return false;
|
||||||
|
|
||||||
|
if (axisNumber == 1) {
|
||||||
|
pinModeEx(ODRIVE_RST_PIN, OUTPUT);
|
||||||
|
digitalWriteEx(ODRIVE_RST_PIN, HIGH); // bring ODrive out of Reset
|
||||||
|
delay(1000); // allow time for ODrive to boot
|
||||||
|
|
||||||
|
#if ODRIVE_COMM_MODE == OD_UART
|
||||||
|
ODRIVE_SERIAL.begin(ODRIVE_SERIAL_BAUD);
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("SERIAL channel init");
|
||||||
|
#elif ODRIVE_COMM_MODE == OD_CAN
|
||||||
|
// .begin is done by the constructor
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("CAN channel init");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
enable(false);
|
||||||
|
|
||||||
|
// start the motion timer
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("start task to synthesize motion... ");
|
||||||
|
char timerName[] = "Target_";
|
||||||
|
timerName[6] = '0' + axisNumber;
|
||||||
|
taskHandle = tasks.add(0, 0, true, 0, callback, timerName);
|
||||||
|
if (taskHandle) {
|
||||||
|
V("success");
|
||||||
|
if (useFastHardwareTimers && !tasks.requestHardwareTimer(taskHandle, 0)) { VLF(" (no hardware timer!)"); } else { VLF(""); }
|
||||||
|
} else {
|
||||||
|
VLF("FAILED!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ready = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set motor reverse state
|
||||||
|
void ODriveMotor::setReverse(int8_t state) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
if (state == ON) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("axis reversal must be accomplished with hardware or ODrive setup!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets motor enable on/off (if possible)
|
||||||
|
void ODriveMotor::enable(bool state) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("driver powered "); if (state) { VLF("up"); } else { VLF("down"); }
|
||||||
|
|
||||||
|
int requestedState = AXIS_STATE_IDLE;
|
||||||
|
if (state) requestedState = AXIS_STATE_CLOSED_LOOP_CONTROL;
|
||||||
|
|
||||||
|
#if ODRIVE_COMM_MODE == OD_UART
|
||||||
|
float timeout = 0.5;
|
||||||
|
if(!_oDriveDriver->run_state(axisNumber - 1, requestedState, false, timeout)) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF(" Power, closed loop control - command timeout!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#elif ODRIVE_COMM_MODE == OD_CAN
|
||||||
|
if(!_oDriveDriver->RunState(axisNumber - 1, requestedState)) { //currently, always returns true...need to add timeout
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF(" Power, closed loop control - command timeout!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("closed loop control - "); if (state) { VLF("Active"); } else { VLF("Idle"); }
|
||||||
|
|
||||||
|
enabled = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ODriveMotor::setInstrumentCoordinateSteps(long value) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
#if ODRIVE_ABSOLUTE == ON && ODRIVE_SYNC_LIMIT != OFF
|
||||||
|
noInterrupts();
|
||||||
|
long index = value - motorSteps;
|
||||||
|
interrupts();
|
||||||
|
float indexDeg = index/radsPerCount.value;
|
||||||
|
if (indexDeg >= -degToRadF(ODRIVE_SYNC_LIMIT/3600.0F) && indexDeg <= degToRadF(ODRIVE_SYNC_LIMIT/3600.0F))
|
||||||
|
#endif
|
||||||
|
Motor::setInstrumentCoordinateSteps(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// resets motor and target angular position in steps, also zeros backlash and index
|
||||||
|
void ODriveMotor::resetPositionSteps(long value) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
// this is where the initial odrive position in "steps" is brought into agreement with the motor position in steps
|
||||||
|
// not sure on this... but code below ignores (value,) gets the odrive position convert to steps and resets the motor
|
||||||
|
// there (as the odrive encoders are absolute.)
|
||||||
|
|
||||||
|
long oPosition;
|
||||||
|
// if (axisNumber - 1 == 0) oPosition = o_position0;
|
||||||
|
// if (axisNumber - 1 == 1) oPosition = o_position1;
|
||||||
|
|
||||||
|
// get ODrive position in fractionial Turns
|
||||||
|
#if ODRIVE_COMM_MODE == OD_UART
|
||||||
|
oPosition = _oDriveDriver->GetPosition(axisNumber - 1)*TWO_PI*radsPerCount.value; // axis1/2 are in steps per radian
|
||||||
|
#elif ODRIVE_COMM_MODE == OD_CAN
|
||||||
|
oPosition = _oDriveDriver->GetPosition(axisNumber - 1)*TWO_PI*radsPerCount.value; // axis1/2 are in steps per radian
|
||||||
|
#endif
|
||||||
|
|
||||||
|
noInterrupts();
|
||||||
|
motorSteps = oPosition;
|
||||||
|
targetSteps = motorSteps;
|
||||||
|
#if ODRIVE_ABSOLUTE == OFF
|
||||||
|
// but what if the odrive encoders are incremental? how to tell the odrive what its angular position is?
|
||||||
|
// here thinking we'll ignore it... sync OnStepX there and let the offset handle it
|
||||||
|
indexSteps = value - motorSteps;
|
||||||
|
#else
|
||||||
|
UNUSED(value);
|
||||||
|
indexSteps = 0;
|
||||||
|
#endif
|
||||||
|
backlashSteps = 0;
|
||||||
|
interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
// set frequency (+/-) in steps per second negative frequencies move reverse in direction (0 stops motion)
|
||||||
|
void ODriveMotor::setFrequencySteps(float frequency) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
// negative frequency, convert to positive and reverse the direction
|
||||||
|
int dir = 0;
|
||||||
|
if (frequency > 0.0F) dir = 1; else if (frequency < 0.0F) { frequency = -frequency; dir = -1; }
|
||||||
|
|
||||||
|
// if in backlash override the frequency
|
||||||
|
if (inBacklash)
|
||||||
|
frequency = backlashFrequency;
|
||||||
|
|
||||||
|
if (frequency != currentFrequency) {
|
||||||
|
lastFrequency = frequency;
|
||||||
|
|
||||||
|
// if slewing has a larger step size divide the frequency to account for it
|
||||||
|
if (lastFrequency <= backlashFrequency * 2.0F) stepSize = 1; else { if (!inBacklash) stepSize = 64; }
|
||||||
|
frequency /= stepSize;
|
||||||
|
|
||||||
|
// timer period in microseconds
|
||||||
|
float period = 1000000.0F / frequency;
|
||||||
|
|
||||||
|
// range is 0 to 134 seconds/step
|
||||||
|
if (!isnan(period) && period <= 130000000.0F) {
|
||||||
|
period *= 16.0F;
|
||||||
|
lastPeriod = (unsigned long)lroundf(period);
|
||||||
|
} else {
|
||||||
|
lastPeriod = 0;
|
||||||
|
frequency = 0.0F;
|
||||||
|
dir = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentFrequency = frequency;
|
||||||
|
|
||||||
|
// change the motor rate/direction
|
||||||
|
noInterrupts();
|
||||||
|
step = 0;
|
||||||
|
interrupts();
|
||||||
|
tasks.setPeriodSubMicros(taskHandle, lastPeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
noInterrupts();
|
||||||
|
step = dir * stepSize;
|
||||||
|
absStep = abs(step);
|
||||||
|
interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
float ODriveMotor::getFrequencySteps() {
|
||||||
|
if (!ready) return 0.0F;
|
||||||
|
|
||||||
|
if (lastPeriod == 0) return 0.0F;
|
||||||
|
return (16000000.0F / lastPeriod) * absStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set slewing state (hint that we are about to slew or are done slewing)
|
||||||
|
void ODriveMotor::setSlewing(bool state) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
isSlewing = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
// updates PID and sets odrive position
|
||||||
|
void ODriveMotor::poll() {
|
||||||
|
if ((long)(millis() - lastSetPositionTime) < ODRIVE_UPDATE_MS) return;
|
||||||
|
lastSetPositionTime = millis();
|
||||||
|
|
||||||
|
noInterrupts();
|
||||||
|
#if ODRIVE_SLEW_DIRECT == ON
|
||||||
|
long target = targetSteps + backlashSteps;
|
||||||
|
#else
|
||||||
|
long target = motorSteps + backlashSteps;
|
||||||
|
#endif
|
||||||
|
interrupts();
|
||||||
|
#if ODRIVE_COMM_MODE == OD_UART
|
||||||
|
setPosition(axisNumber -1, target/(TWO_PI*radsPerCount.value));
|
||||||
|
#elif ODRIVE_COMM_MODE == OD_CAN
|
||||||
|
_oDriveDriver->SetPosition(axisNumber -1, target/(TWO_PI*radsPerCount.value));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets dir as required and moves coord toward target at setFrequencySteps() rate
|
||||||
|
IRAM_ATTR void ODriveMotor::move() {
|
||||||
|
if (sync && !inBacklash) targetSteps += step;
|
||||||
|
|
||||||
|
if (motorSteps > targetSteps) {
|
||||||
|
if (backlashSteps > 0) {
|
||||||
|
backlashSteps -= absStep;
|
||||||
|
inBacklash = backlashSteps > 0;
|
||||||
|
} else {
|
||||||
|
motorSteps -= absStep;
|
||||||
|
inBacklash = false;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
|
||||||
|
if (motorSteps < targetSteps || inBacklash) {
|
||||||
|
if (backlashSteps < backlashAmountSteps) {
|
||||||
|
backlashSteps += absStep;
|
||||||
|
inBacklash = backlashSteps < backlashAmountSteps;
|
||||||
|
} else {
|
||||||
|
motorSteps += absStep;
|
||||||
|
inBacklash = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
Executable
+181
@@ -0,0 +1,181 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis oDrive servo motor
|
||||||
|
#pragma once
|
||||||
|
#include "../../../../Common.h"
|
||||||
|
|
||||||
|
#ifndef ODRIVE_NEW_MOTOR_PRESENT
|
||||||
|
#ifdef ODRIVE_MOTOR_PRESENT
|
||||||
|
|
||||||
|
#include "../Motor.h"
|
||||||
|
#include "../../../convert/Convert.h"
|
||||||
|
|
||||||
|
// the following would be in the pinmap normally and should trigger #error on compile here when not present
|
||||||
|
// for now, they fit your hardware as best as I can tell...
|
||||||
|
#ifndef ODRIVE_SERIAL
|
||||||
|
#define ODRIVE_SERIAL Serial3 // Teensy HW Serial3 (if used,) for example
|
||||||
|
#endif
|
||||||
|
#ifndef ODRIVE_SERIAL_BAUD
|
||||||
|
#define ODRIVE_SERIAL_BAUD 115200 // was 19200
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ODRIVE_RST_PIN
|
||||||
|
#define ODRIVE_RST_PIN 3
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// odrive update rate default 10Hz
|
||||||
|
#ifndef ODRIVE_UPDATE_MS
|
||||||
|
#define ODRIVE_UPDATE_MS 100 // was 3000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// odrive direct slewing ON or OFF (ODrive handles acceleration)
|
||||||
|
// ON to use ODrive trapezoidal move profile, OFF for OnStep move profile
|
||||||
|
#ifndef ODRIVE_SLEW_DIRECT
|
||||||
|
#define ODRIVE_SLEW_DIRECT OFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// odrive if using absolute encoders set to ON
|
||||||
|
#ifndef ODRIVE_ABSOLUTE
|
||||||
|
#define ODRIVE_ABSOLUTE ON // was OFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// odrive sync limit (for absolute encoders) OFF or specify the sync limit in arc-seconds
|
||||||
|
// this should, I hope, allow you to limit just how far from the encoders you can sync. (+/-) to fine-tune the origin
|
||||||
|
// with absolute encoders this protects you from exceeding the software min/max limits by > the amount specified
|
||||||
|
// in arc seconds..one encoder tick encoder resolution = 2^14 = 16380
|
||||||
|
// 16380/360=45.5 ticks/deg; 45.5/60=0.7583 ticks/min; 0.7583/60 = .00126 ticks/sec
|
||||||
|
// or 1/0.7583 = 1.32 arc-min/tick; 1.32*60 sec = 79.2 arc sec per encoder tick
|
||||||
|
#ifndef ODRIVE_SYNC_LIMIT
|
||||||
|
#define ODRIVE_SYNC_LIMIT 80 // was OFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Use OD_UART or OD_CAN...I2C may be added later
|
||||||
|
#ifndef ODRIVE_COMM_MODE
|
||||||
|
#define ODRIVE_COMM_MODE OD_CAN
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ODrive axis 0 = OnStep Axis2 = DEC or ALT
|
||||||
|
// ODrive axis 1 = OnStep Axis1 = RA or AZM
|
||||||
|
#ifndef ODRIVE_SWAP_AXES
|
||||||
|
#define ODRIVE_SWAP_AXES ON
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ODRIVE_COMM_MODE == OD_UART
|
||||||
|
#include <ODriveArduino.h> // https://github.com/odriverobotics/ODrive/tree/master/Arduino/ODriveArduino
|
||||||
|
// ODrive servo motor serial driver
|
||||||
|
extern ODriveArduino *_oDriveDriver;
|
||||||
|
#elif ODRIVE_COMM_MODE == OD_CAN
|
||||||
|
#include <FlexCAN_T4.h> // https://github.com/tonton81/FlexCAN_T4.git
|
||||||
|
// changes were required to this CAN library so it is local now
|
||||||
|
#include "src/plugins/DDScope/ODriveTeensyCAN/ODriveTeensyCAN.h" //https://github.com/Malaphor/ODriveTeensyCAN.git
|
||||||
|
extern ODriveTeensyCAN *_oDriveDriver;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct ODriveDriverSettings {
|
||||||
|
int16_t model;
|
||||||
|
int8_t status;
|
||||||
|
} ODriveDriverSettings;
|
||||||
|
|
||||||
|
class ODriveMotor : public Motor {
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
ODriveMotor(uint8_t axisNumber, int8_t reverse, const ODriveDriverSettings *Settings, float radsPerCount, bool useFastHardwareTimers = true);
|
||||||
|
|
||||||
|
// sets up the odrive motor
|
||||||
|
bool init();
|
||||||
|
|
||||||
|
// returns the number of parameters from the motor
|
||||||
|
uint8_t getParameterCount() { return Motor::getParameterCount() + numParameters; }
|
||||||
|
|
||||||
|
// returns the specified axis parameter
|
||||||
|
AxisParameter* getParameter(uint8_t number) {
|
||||||
|
if (number == Motor::getParameterCount() + 1) return &radsPerCount; else
|
||||||
|
if (number >= 1 && number <= Motor::getParameterCount()) return Motor::getParameter(number); else
|
||||||
|
return &invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set motor reverse state
|
||||||
|
void setReverse(int8_t state);
|
||||||
|
|
||||||
|
// sets motor enable on/off (if possible)
|
||||||
|
void enable(bool value);
|
||||||
|
|
||||||
|
bool hasAbsoluteEncoder() const override { return ODRIVE_ABSOLUTE == ON; }
|
||||||
|
|
||||||
|
// set instrument coordinate, in steps
|
||||||
|
void setInstrumentCoordinateSteps(long value);
|
||||||
|
|
||||||
|
// get the associated driver status
|
||||||
|
inline DriverStatus getDriverStatus() { if (ready) return status; else return errorStatus; }
|
||||||
|
|
||||||
|
// resets motor and target angular position in steps, also zeros backlash and index
|
||||||
|
void resetPositionSteps(long value);
|
||||||
|
|
||||||
|
// get tracking mode steps per slewing mode step
|
||||||
|
inline int getStepsPerStepSlewing() { return 64; }
|
||||||
|
|
||||||
|
// get movement frequency in steps per second
|
||||||
|
float getFrequencySteps();
|
||||||
|
|
||||||
|
// set frequency (+/-) in steps per second negative frequencies move reverse in direction (0 stops motion)
|
||||||
|
void setFrequencySteps(float frequency);
|
||||||
|
|
||||||
|
// set slewing state (hint that we are about to slew or are done slewing)
|
||||||
|
void setSlewing(bool state);
|
||||||
|
|
||||||
|
// get the motor name
|
||||||
|
const char* name() { return "ODRIVE"; }
|
||||||
|
|
||||||
|
// updates PID and sets servo motor power/direction
|
||||||
|
void poll();
|
||||||
|
|
||||||
|
// sets dir as required and moves coord toward target at setFrequencySteps() rate
|
||||||
|
void move();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// float o_position0 = 0;
|
||||||
|
// float o_position1 = 0;
|
||||||
|
|
||||||
|
#if ODRIVE_COMM_MODE == OD_UART
|
||||||
|
// special command to send high resolution position to odrive
|
||||||
|
void setPosition(int motor_number, float position) {
|
||||||
|
// if (motor_number == 0) o_position0 = position;
|
||||||
|
// if (motor_number == 1) o_position1 = position;
|
||||||
|
char command[32];
|
||||||
|
sprintF(command, "p n %1.8f\n", position);
|
||||||
|
command[2] = '0' + motor_number;
|
||||||
|
ODRIVE_SERIAL.print(command);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
unsigned long lastSetPositionTime = 0;
|
||||||
|
uint8_t oDriveMonitorHandle = 0;
|
||||||
|
uint8_t taskHandle = 0;
|
||||||
|
|
||||||
|
int stepSize = 1; // step size
|
||||||
|
volatile int homeSteps = 1; // step count for microstep sequence between home positions (driver indexer)
|
||||||
|
volatile bool takeStep = false; // should we take a step
|
||||||
|
|
||||||
|
float currentFrequency = 0.0F; // last frequency set
|
||||||
|
float lastFrequency = 0.0F; // last frequency requested
|
||||||
|
unsigned long lastPeriod = 0; // last timer period (in sub-micros)
|
||||||
|
|
||||||
|
volatile int absStep = 1; // absolute step size (unsigned)
|
||||||
|
|
||||||
|
void (*callback)() = NULL;
|
||||||
|
|
||||||
|
bool useFastHardwareTimers = true;
|
||||||
|
|
||||||
|
bool isSlewing = false;
|
||||||
|
|
||||||
|
DriverStatus status = { false, {false, false}, {false, false}, false, false, false, false };
|
||||||
|
|
||||||
|
// runtime adjustable settings
|
||||||
|
AxisParameter radsPerCount = {NAN, NAN, NAN, degToRadF(300.0), degToRadF(360000.0), AXP_FLOAT, AXPN_RADS_PER_COUNT};
|
||||||
|
|
||||||
|
const int numParameters = 1;
|
||||||
|
AxisParameter* parameter[2] = {&invalid, &radsPerCount};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
Executable
+220
@@ -0,0 +1,220 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis oDrive servo motor CanPlus interface
|
||||||
|
|
||||||
|
#include "ODriveCanPlus.h"
|
||||||
|
|
||||||
|
#ifdef ODRIVE_NEW_MOTOR_PRESENT
|
||||||
|
#ifdef ODRIVE_MOTOR_PRESENT
|
||||||
|
|
||||||
|
#include "../../../tasks/OnTask.h"
|
||||||
|
#include "../../../canPlus/CanPlus.h"
|
||||||
|
|
||||||
|
static void odHb0(uint8_t d[8]) { odriveCan.onHeartbeat(0, d); }
|
||||||
|
static void odEnc0(uint8_t d[8]) { odriveCan.onFeedbackPosVel(0, d); }
|
||||||
|
static void odHb1(uint8_t d[8]) { odriveCan.onHeartbeat(1, d); }
|
||||||
|
static void odEnc1(uint8_t d[8]) { odriveCan.onFeedbackPosVel(1, d); }
|
||||||
|
static void odVer0(uint8_t d[8]) { odriveCan.onGetVersion(0, d); }
|
||||||
|
static void odVer1(uint8_t d[8]) { odriveCan.onGetVersion(1, d); }
|
||||||
|
|
||||||
|
bool ODriveCanPlus::init(uint8_t node) {
|
||||||
|
if (!canPlus.ready) return false;
|
||||||
|
switch (node) {
|
||||||
|
case 0:
|
||||||
|
canPlus.callbackRegisterId(makeId(0, CMD_HEARTBEAT), odHb0);
|
||||||
|
canPlus.callbackRegisterId(makeId(0, CMD_GET_ENCODER_EST), odEnc0);
|
||||||
|
canPlus.callbackRegisterId(makeId(0, CMD_GET_VERSION), odVer0);
|
||||||
|
return true;
|
||||||
|
case 1:
|
||||||
|
canPlus.callbackRegisterId(makeId(1, CMD_HEARTBEAT), odHb1);
|
||||||
|
canPlus.callbackRegisterId(makeId(1, CMD_GET_ENCODER_EST), odEnc1);
|
||||||
|
canPlus.callbackRegisterId(makeId(1, CMD_GET_VERSION), odVer1);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ODriveCanPlus::getVersionSnapshot(uint8_t node,
|
||||||
|
uint8_t raw[8],
|
||||||
|
uint16_t& proto,
|
||||||
|
uint8_t& fw_major,
|
||||||
|
uint8_t& fw_minor,
|
||||||
|
uint8_t& fw_rev,
|
||||||
|
uint8_t& hw_variant,
|
||||||
|
uint8_t& hw_version) const {
|
||||||
|
if (node >= MaxNodes || raw == nullptr) return false;
|
||||||
|
|
||||||
|
uint8_t seen;
|
||||||
|
noInterrupts();
|
||||||
|
seen = cache_[node].seen;
|
||||||
|
if (!(seen & SEEN_VER)) { interrupts(); return false; }
|
||||||
|
|
||||||
|
proto = cache_[node].proto_ver;
|
||||||
|
fw_major = cache_[node].fw_major;
|
||||||
|
fw_minor = cache_[node].fw_minor;
|
||||||
|
fw_rev = cache_[node].fw_rev;
|
||||||
|
hw_variant = cache_[node].hw_variant;
|
||||||
|
hw_version = cache_[node].hw_version;
|
||||||
|
for (int i = 0; i < 8; i++) raw[i] = cache_[node].ver_raw[i];
|
||||||
|
interrupts();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ODriveCanPlus::hasFreshVersion(uint8_t node, uint32_t max_age_ms) const {
|
||||||
|
if (node >= MaxNodes) return false;
|
||||||
|
uint8_t seen;
|
||||||
|
uint32_t t;
|
||||||
|
noInterrupts();
|
||||||
|
seen = cache_[node].seen;
|
||||||
|
t = cache_[node].last_ver_ms;
|
||||||
|
interrupts();
|
||||||
|
if (!(seen & SEEN_VER)) return false;
|
||||||
|
return (uint32_t)(millis() - t) <= max_age_ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ODriveCanPlus::setAxisState(uint8_t node, uint32_t requested_state) {
|
||||||
|
if (!canPlus.ready || node >= MaxNodes) return false;
|
||||||
|
|
||||||
|
uint8_t d[8] = {0};
|
||||||
|
put_le32(&d[0], requested_state);
|
||||||
|
|
||||||
|
canPlus.txWait();
|
||||||
|
return canPlus.writePacket(makeId(node, CMD_SET_AXIS_STATE), d, 8) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t ODriveCanPlus::axisState(uint8_t node) const {
|
||||||
|
if (node >= MaxNodes) return 0;
|
||||||
|
noInterrupts();
|
||||||
|
uint8_t s = cache_[node].axis_state;
|
||||||
|
interrupts();
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ODriveCanPlus::setInputPos(uint8_t node, float pos_turns, float vel_ff_turns_s , float tq_ff_nm) {
|
||||||
|
if (!canPlus.ready || node >= MaxNodes) return;
|
||||||
|
|
||||||
|
uint8_t d[8] = {0};
|
||||||
|
|
||||||
|
const int32_t vel_i = lroundf(vel_ff_turns_s * 1000.0F);
|
||||||
|
const int32_t tq_i = lroundf(tq_ff_nm * 1000.0F);
|
||||||
|
|
||||||
|
put_f32(&d[0], pos_turns);
|
||||||
|
put_le16(&d[4], clamp_i16(vel_i));
|
||||||
|
put_le16(&d[6], clamp_i16(tq_i));
|
||||||
|
|
||||||
|
if (canPlus.txTryLock()) {
|
||||||
|
canPlus.writePacket(makeId(node, CMD_SET_INPUT_POS), d, 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float ODriveCanPlus::getPosTurns(uint8_t node) const {
|
||||||
|
if (node >= MaxNodes) return 0.0F;
|
||||||
|
noInterrupts();
|
||||||
|
float p = cache_[node].pos_turns;
|
||||||
|
interrupts();
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ODriveCanPlus::hasFreshTurns(uint8_t node, uint32_t max_age_ms) const {
|
||||||
|
if (node >= MaxNodes) return false;
|
||||||
|
uint8_t seen;
|
||||||
|
uint32_t t;
|
||||||
|
noInterrupts();
|
||||||
|
seen = cache_[node].seen;
|
||||||
|
t = cache_[node].last_enc_ms;
|
||||||
|
interrupts();
|
||||||
|
if (!(seen & SEEN_ENC)) return false;
|
||||||
|
return (uint32_t)(millis() - t) <= max_age_ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ODriveCanPlus::hasHeartbeat(uint8_t node, uint32_t max_age_ms) const {
|
||||||
|
if (node >= MaxNodes) return false;
|
||||||
|
uint8_t seen;
|
||||||
|
uint32_t t;
|
||||||
|
noInterrupts();
|
||||||
|
seen = cache_[node].seen;
|
||||||
|
t = cache_[node].last_hb_ms;
|
||||||
|
interrupts();
|
||||||
|
if (!(seen & SEEN_HB)) return false;
|
||||||
|
return (uint32_t)(millis() - t) <= max_age_ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ODriveCanPlus::lastHeartbeatMs(uint8_t node) const {
|
||||||
|
if (node >= MaxNodes) return 0;
|
||||||
|
noInterrupts();
|
||||||
|
uint32_t t = cache_[node].last_hb_ms;
|
||||||
|
interrupts();
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ODriveCanPlus::lastError(uint8_t node) const {
|
||||||
|
if (node >= MaxNodes) return 0;
|
||||||
|
noInterrupts();
|
||||||
|
uint32_t e = cache_[node].last_err;
|
||||||
|
interrupts();
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ODriveCanPlus::onHeartbeat(uint8_t node, const uint8_t* d, uint8_t len) {
|
||||||
|
if (node >= MaxNodes || len < 7) return;
|
||||||
|
|
||||||
|
cache_[node].last_hb_ms = millis();
|
||||||
|
cache_[node].last_err =
|
||||||
|
(uint32_t(d[0]) ) |
|
||||||
|
(uint32_t(d[1]) << 8) |
|
||||||
|
(uint32_t(d[2]) << 16) |
|
||||||
|
(uint32_t(d[3]) << 24);
|
||||||
|
cache_[node].axis_state = d[4];
|
||||||
|
|
||||||
|
ATOMIC_OR(cache_[node].seen, SEEN_HB);
|
||||||
|
|
||||||
|
// optionally store:
|
||||||
|
// cache_[node].procedure_result = d[5];
|
||||||
|
// cache_[node].traj_done = d[6];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ODriveCanPlus::requestVersion(uint8_t node) {
|
||||||
|
if (!canPlus.ready || node >= MaxNodes) return false;
|
||||||
|
return canPlus.writePacketRtr(makeId(node, CMD_GET_VERSION), 8) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ODriveCanPlus::requestTurns(uint8_t node) {
|
||||||
|
if (!canPlus.ready || node >= MaxNodes) return false;
|
||||||
|
return canPlus.writePacketRtr(makeId(node, CMD_GET_ENCODER_EST), 8) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ODriveCanPlus::onGetVersion(uint8_t node, const uint8_t* d, uint8_t len) {
|
||||||
|
if (node >= MaxNodes || len < 8) return;
|
||||||
|
|
||||||
|
const uint32_t now = millis();
|
||||||
|
|
||||||
|
for (int i = 0; i < 8; i++) cache_[node].ver_raw[i] = d[i];
|
||||||
|
|
||||||
|
cache_[node].proto_ver = get_u16_le(&d[0]);
|
||||||
|
cache_[node].fw_major = d[2];
|
||||||
|
cache_[node].fw_minor = d[3];
|
||||||
|
cache_[node].fw_rev = d[4];
|
||||||
|
cache_[node].hw_variant = d[5];
|
||||||
|
cache_[node].hw_version = d[6];
|
||||||
|
|
||||||
|
cache_[node].last_ver_ms = now; // write time first
|
||||||
|
|
||||||
|
ATOMIC_OR(cache_[node].seen, SEEN_VER);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ODriveCanPlus::onFeedbackPosVel(uint8_t node, const uint8_t* d, uint8_t len) {
|
||||||
|
if (node >= MaxNodes || len < 8) return;
|
||||||
|
|
||||||
|
// Example: pos_turns (f32) + vel_turns/s (f32)
|
||||||
|
cache_[node].pos_turns = get_f32(d + 0);
|
||||||
|
cache_[node].vel_turns_s = get_f32(d + 4);
|
||||||
|
cache_[node].last_enc_ms = millis();
|
||||||
|
|
||||||
|
ATOMIC_OR(cache_[node].seen, SEEN_ENC);
|
||||||
|
}
|
||||||
|
|
||||||
|
ODriveCanPlus odriveCan;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
Executable
+113
@@ -0,0 +1,113 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis oDrive servo motor CanPlus interface
|
||||||
|
#pragma once
|
||||||
|
#include "../../../../Common.h"
|
||||||
|
|
||||||
|
#ifdef ODRIVE_NEW_MOTOR_PRESENT
|
||||||
|
#ifdef ODRIVE_MOTOR_PRESENT
|
||||||
|
|
||||||
|
class ODriveCanPlus {
|
||||||
|
public:
|
||||||
|
bool init(uint8_t node);
|
||||||
|
|
||||||
|
bool getVersionSnapshot(uint8_t node,
|
||||||
|
uint8_t raw[8],
|
||||||
|
uint16_t& proto,
|
||||||
|
uint8_t& fw_major,
|
||||||
|
uint8_t& fw_minor,
|
||||||
|
uint8_t& fw_rev,
|
||||||
|
uint8_t& hw_variant,
|
||||||
|
uint8_t& hw_version) const;
|
||||||
|
|
||||||
|
bool setAxisState(uint8_t node, uint32_t requested_state);
|
||||||
|
uint8_t axisState(uint8_t node) const;
|
||||||
|
|
||||||
|
void setInputPos(uint8_t node, float pos_turns, float vel_ff_turns_s = 0.0F, float tq_ff_nm = 0.0F);
|
||||||
|
float getPosTurns(uint8_t node) const; // cached feedback
|
||||||
|
bool hasFreshTurns(uint8_t node, uint32_t max_age_ms = 250U) const;
|
||||||
|
|
||||||
|
void onGetVersion(uint8_t node, const uint8_t* d, uint8_t len = 8);
|
||||||
|
bool hasFreshVersion(uint8_t node, uint32_t max_age_ms = 1000U) const;
|
||||||
|
|
||||||
|
bool hasHeartbeat(uint8_t node, uint32_t max_age_ms = 250U) const;
|
||||||
|
uint32_t lastHeartbeatMs(uint8_t node) const;
|
||||||
|
uint32_t lastError(uint8_t node) const;
|
||||||
|
|
||||||
|
void onHeartbeat(uint8_t node, const uint8_t* d, uint8_t len = 8);
|
||||||
|
void onFeedbackPosVel(uint8_t node, const uint8_t* d, uint8_t len = 8);
|
||||||
|
|
||||||
|
bool requestVersion(uint8_t node);
|
||||||
|
bool requestTurns(uint8_t node);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// helpers
|
||||||
|
constexpr uint8_t CmdBits = 5;
|
||||||
|
static inline uint16_t makeId(uint8_t node, uint8_t cmd) { return (uint16_t(node) << CmdBits) | (cmd & 0x1F); }
|
||||||
|
|
||||||
|
static inline void put_le16(uint8_t* p, int16_t v) { p[0] = uint8_t(v & 0xFF); p[1] = uint8_t((v >> 8) & 0xFF); }
|
||||||
|
static inline void put_le32(uint8_t* p, uint32_t v) {
|
||||||
|
p[0]=(uint8_t)v;
|
||||||
|
p[1]=(uint8_t)(v>>8);
|
||||||
|
p[2]=(uint8_t)(v>>16);
|
||||||
|
p[3]=(uint8_t)(v>>24);
|
||||||
|
}
|
||||||
|
static inline void put_f32(uint8_t* p, float f) {
|
||||||
|
static_assert(sizeof(float) == 4, "float must be 32-bit");
|
||||||
|
uint32_t u;
|
||||||
|
memcpy(&u, &f, 4);
|
||||||
|
put_le32(p, u);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline float get_f32(const uint8_t* p) {
|
||||||
|
uint32_t u = (uint32_t(p[0])) |
|
||||||
|
(uint32_t(p[1]) << 8) |
|
||||||
|
(uint32_t(p[2]) << 16) |
|
||||||
|
(uint32_t(p[3]) << 24);
|
||||||
|
float f;
|
||||||
|
memcpy(&f, &u, 4);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
static inline uint16_t get_u16_le(const uint8_t* p) { return (uint16_t)p[0] | ((uint16_t)p[1] << 8); }
|
||||||
|
|
||||||
|
static inline int16_t clamp_i16(int32_t x) {
|
||||||
|
if (x > 32767) return 32767;
|
||||||
|
if (x < -32768) return -32768;
|
||||||
|
return (int16_t)x;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ODrive CMD IDs
|
||||||
|
static constexpr uint8_t CMD_GET_VERSION = 0x00;
|
||||||
|
static constexpr uint8_t CMD_HEARTBEAT = 0x01;
|
||||||
|
static constexpr uint8_t CMD_SET_AXIS_STATE = 0x07;
|
||||||
|
static constexpr uint8_t CMD_SET_INPUT_POS = 0x0C;
|
||||||
|
static constexpr uint8_t CMD_GET_ENCODER_EST = 0x09;
|
||||||
|
|
||||||
|
// startup state
|
||||||
|
static constexpr uint8_t SEEN_HB = 0x01;
|
||||||
|
static constexpr uint8_t SEEN_ENC = 0x02;
|
||||||
|
static constexpr uint8_t SEEN_VER = 0x04;
|
||||||
|
|
||||||
|
struct AxisCache {
|
||||||
|
volatile float pos_turns = 0.0F;
|
||||||
|
volatile float vel_turns_s = 0.0F;
|
||||||
|
volatile uint32_t last_hb_ms = 0;
|
||||||
|
volatile uint32_t last_err = 0;
|
||||||
|
volatile uint8_t axis_state = 0;
|
||||||
|
volatile uint32_t last_enc_ms = 0;
|
||||||
|
volatile uint32_t last_ver_ms = 0;
|
||||||
|
volatile uint8_t ver_raw[8] = {0};
|
||||||
|
volatile uint16_t proto_ver = 0;
|
||||||
|
volatile uint8_t fw_major = 0, fw_minor = 0, fw_rev = 0;
|
||||||
|
volatile uint8_t hw_variant = 0, hw_version = 0;
|
||||||
|
volatile uint8_t seen = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
static constexpr uint8_t MaxNodes = 2;
|
||||||
|
AxisCache cache_[MaxNodes];
|
||||||
|
};
|
||||||
|
|
||||||
|
extern ODriveCanPlus odriveCan;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
Executable
+437
@@ -0,0 +1,437 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// oDrive servo motor
|
||||||
|
// EXPERIMENTAL!!!
|
||||||
|
|
||||||
|
#include "ODriveNew.h"
|
||||||
|
|
||||||
|
#ifdef ODRIVE_NEW_MOTOR_PRESENT
|
||||||
|
#ifdef ODRIVE_MOTOR_PRESENT
|
||||||
|
|
||||||
|
#include "../../../tasks/OnTask.h"
|
||||||
|
#include "../../../gpioEx/GpioEx.h"
|
||||||
|
|
||||||
|
#include "ODriveCanPlus.h"
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
ODriveMotor::ODriveMotor(uint8_t axisNumber, int8_t reverse, const ODriveDriverSettings *Settings, float countsPerRad, bool useFastHardwareTimers)
|
||||||
|
:Motor(axisNumber, reverse) {
|
||||||
|
if (axisNumber < 1 || axisNumber > 2) return;
|
||||||
|
|
||||||
|
driverType = ODRIVER;
|
||||||
|
|
||||||
|
this->axisNumber = axisNumber;
|
||||||
|
this->useFastHardwareTimers = useFastHardwareTimers;
|
||||||
|
|
||||||
|
#if ODRIVE_SWAP_AXES == ON
|
||||||
|
oDriveNode = 2 - axisNumber;
|
||||||
|
#else
|
||||||
|
oDriveNode = axisNumber - 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
strcpy(axisPrefix, " Axis_oDrive, ");
|
||||||
|
axisPrefix[5] = '0' + this->axisNumber;
|
||||||
|
|
||||||
|
// set parameter default values during object creation
|
||||||
|
this->countsPerRad.valueDefault = countsPerRad;
|
||||||
|
|
||||||
|
// attach the function pointers to the callbacks
|
||||||
|
odriveMotorInstance[axisNumber - 1] = this;
|
||||||
|
switch (this->axisNumber) {
|
||||||
|
case 1: callback = moveODriveMotorAxis1; break;
|
||||||
|
case 2: callback = moveODriveMotorAxis2; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ODriveMotor::init() {
|
||||||
|
if (!Motor::init()) return false;
|
||||||
|
|
||||||
|
// reset the ODrive(s) via h/w pin
|
||||||
|
if (axisNumber == 1) {
|
||||||
|
pinModeEx(ODRIVE_RST_PIN, OUTPUT);
|
||||||
|
digitalWriteEx(ODRIVE_RST_PIN, LOW);
|
||||||
|
tasks.yield(10);
|
||||||
|
digitalWriteEx(ODRIVE_RST_PIN, HIGH);
|
||||||
|
|
||||||
|
// allow time for boot
|
||||||
|
tasks.yield(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!odriveCan.init(oDriveNode)) return false;
|
||||||
|
|
||||||
|
// request version info and
|
||||||
|
// let CAN poll task (priority 3) run to deliver the reply
|
||||||
|
odriveCan.requestVersion(oDriveNode);
|
||||||
|
const uint32_t t0 = millis();
|
||||||
|
while (!odriveCan.hasFreshVersion(oDriveNode, 1000) && (uint32_t)(millis() - t0) < 1000U) { tasks.yield(10); }
|
||||||
|
|
||||||
|
if (odriveCan.hasFreshVersion(oDriveNode, 1000)) {
|
||||||
|
uint8_t raw[8];
|
||||||
|
uint16_t proto;
|
||||||
|
uint8_t maj, min, rev, hwv, hww;
|
||||||
|
|
||||||
|
if (odriveCan.getVersionSnapshot(oDriveNode, raw, proto, maj, min, rev, hwv, hww)) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("ODrive version: node "); V(oDriveNode);
|
||||||
|
VF(" proto "); V(proto);
|
||||||
|
VF(" fw "); V(maj); VF("."); V(min); VF("."); V(rev);
|
||||||
|
VF(" hwVar "); V(hwv);
|
||||||
|
VF(" hwVer "); V(hww);
|
||||||
|
VLF("");
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("ODrive version raw: ");
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
if (raw[i] < 16) V("0");
|
||||||
|
VH(raw[i]);
|
||||||
|
if (i != 7) V(" ");
|
||||||
|
}
|
||||||
|
VLF("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// idle the ODrive
|
||||||
|
odriveCan.setAxisState(oDriveNode, AXIS_STATE_IDLE);
|
||||||
|
|
||||||
|
// request an encoder position update and
|
||||||
|
// let CAN poll task (priority 3) run to deliver the reply
|
||||||
|
odriveCan.requestTurns(oDriveNode);
|
||||||
|
lastEncoderUpdateRequestTime = millis();
|
||||||
|
tasks.yield(250);
|
||||||
|
|
||||||
|
// require an encoder sample
|
||||||
|
if (!odriveCan.hasFreshTurns(oDriveNode, 250)) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("no encoder reply at startup");
|
||||||
|
ready = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// local state: definitely disabled, no transition pending
|
||||||
|
ready = true;
|
||||||
|
enabled = false;
|
||||||
|
enablePending = false;
|
||||||
|
enableTarget = false;
|
||||||
|
enableDeadlineMs = 0;
|
||||||
|
|
||||||
|
// start the motion timer
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("start task to synthesize motion... ");
|
||||||
|
char timerName[] = "Ax_ODr";
|
||||||
|
timerName[2] = axisNumber + '0';
|
||||||
|
taskHandle = tasks.add(0, 0, true, 0, callback, timerName);
|
||||||
|
if (taskHandle) {
|
||||||
|
VF("success");
|
||||||
|
if (useFastHardwareTimers) {
|
||||||
|
if (!tasks.requestHardwareTimer(taskHandle, 0)) {
|
||||||
|
VF(" (no hardware timer!)");
|
||||||
|
} else {
|
||||||
|
maxFrequency = (1000000.0F/HAL_MAXRATE_LOWER_LIMIT)/2.0F;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
VLF("");
|
||||||
|
} else {
|
||||||
|
VLF("FAILED!");
|
||||||
|
ready = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
stopSyntheticMotion();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set motor reverse state
|
||||||
|
void ODriveMotor::setReverse(bool state) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
if (state) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("axis reversal must be accomplished with hardware or ODrive setup!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets motor enable on/off (if possible)
|
||||||
|
void ODriveMotor::enable(bool state) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
// If we're already in the requested steady-state AND no transition is pending, do nothing.
|
||||||
|
if (!enablePending && (state == enabled)) return;
|
||||||
|
|
||||||
|
// Always reset local motion first
|
||||||
|
if (!state) enabled = false;
|
||||||
|
stopSyntheticMotion();
|
||||||
|
resetToTrackingBaseline();
|
||||||
|
|
||||||
|
const uint32_t requestedState = state ? AXIS_STATE_CLOSED_LOOP_CONTROL
|
||||||
|
: AXIS_STATE_IDLE;
|
||||||
|
|
||||||
|
if (!odriveCan.setAxisState(oDriveNode, requestedState)) {
|
||||||
|
enabled = false;
|
||||||
|
enablePending = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!state) {
|
||||||
|
// disable: treat as immediate locally; no need to wait for heartbeats/encoder
|
||||||
|
enabled = false;
|
||||||
|
enablePending = false;
|
||||||
|
enableTarget = false;
|
||||||
|
enableDeadlineMs = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable: wait for confirmation
|
||||||
|
enablePending = true;
|
||||||
|
enableTarget = true;
|
||||||
|
enableDeadlineMs = millis() + 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ODriveMotor::setInstrumentCoordinateSteps(long value) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
#if ODRIVE_ABSOLUTE == ON && ODRIVE_SYNC_LIMIT != OFF
|
||||||
|
long index = value - ATOMIC_LOAD(motorSteps);
|
||||||
|
float indexRad = index/countsPerRad.value;
|
||||||
|
if (indexRad >= -degToRadF(ODRIVE_SYNC_LIMIT/3600.0F) && indexRad <= degToRadF(ODRIVE_SYNC_LIMIT/3600.0F))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Motor::setInstrumentCoordinateSteps(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// resets motor and target angular position in steps, also zeros backlash and index
|
||||||
|
void ODriveMotor::resetPositionSteps(long value) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
// make sure we have a recent encoder reading
|
||||||
|
if (!odriveCan.hasFreshTurns(oDriveNode, 250)) {
|
||||||
|
status.fault = true;
|
||||||
|
odriveCan.requestTurns(oDriveNode);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
status.fault = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert turns -> steps (countsPerRad is counts-per-radian)
|
||||||
|
const float posTurns = odriveCan.getPosTurns(oDriveNode);
|
||||||
|
const long oPositionSteps = lroundf(posTurns * TWO_PI * countsPerRad.value);
|
||||||
|
|
||||||
|
noInterrupts();
|
||||||
|
motorSteps = oPositionSteps;
|
||||||
|
targetSteps = motorSteps;
|
||||||
|
|
||||||
|
#if ODRIVE_ABSOLUTE == OFF
|
||||||
|
// For incremental encoders, keep an index offset so OnStepX can still align to "value".
|
||||||
|
indexSteps = value - motorSteps;
|
||||||
|
#else
|
||||||
|
UNUSED(value);
|
||||||
|
indexSteps = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
backlashSteps = 0;
|
||||||
|
interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
// set frequency (+/-) in steps per second negative frequencies move reverse in direction (0 stops motion)
|
||||||
|
void ODriveMotor::setFrequencySteps(float frequency) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
if (!enabled) { stopSyntheticMotion(); return; }
|
||||||
|
|
||||||
|
// negative frequency, convert to positive and reverse the direction
|
||||||
|
int dir = 0;
|
||||||
|
if (frequency > 0.0F) dir = 1; else if (frequency < 0.0F) { frequency = -frequency; dir = -1; }
|
||||||
|
|
||||||
|
// if in backlash override the frequency
|
||||||
|
if (inBacklash) frequency = backlashFrequency;
|
||||||
|
|
||||||
|
if (frequency != currentFrequency) {
|
||||||
|
if (frequency < maxFrequency) stepSize = 1; else
|
||||||
|
if (frequency < maxFrequency*2) stepSize = 2; else
|
||||||
|
if (frequency < maxFrequency*4) stepSize = 4; else
|
||||||
|
if (frequency < maxFrequency*8) stepSize = 8; else
|
||||||
|
if (frequency < maxFrequency*16) stepSize = 16; else
|
||||||
|
if (frequency < maxFrequency*32) stepSize = 32; else
|
||||||
|
if (frequency < maxFrequency*64) stepSize = 64; else
|
||||||
|
if (frequency < maxFrequency*128) stepSize = 128; else stepSize = 256;
|
||||||
|
|
||||||
|
// timer period in microseconds
|
||||||
|
float period = (1000000.0F*stepSize)/frequency;
|
||||||
|
|
||||||
|
// range is 0 to 134 seconds/step
|
||||||
|
if (!isnan(period) && period <= 130000000.0F) {
|
||||||
|
period *= 16.0F;
|
||||||
|
lastPeriod = (unsigned long)lroundf(period);
|
||||||
|
} else {
|
||||||
|
lastPeriod = 0;
|
||||||
|
frequency = 0.0F;
|
||||||
|
dir = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentFrequency = frequency;
|
||||||
|
|
||||||
|
// change the motor rate/direction
|
||||||
|
noInterrupts();
|
||||||
|
step = 0;
|
||||||
|
interrupts();
|
||||||
|
tasks.setPeriodSubMicros(taskHandle, lastPeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
noInterrupts();
|
||||||
|
step = dir * stepSize;
|
||||||
|
absStep = (int)labs(step);
|
||||||
|
interrupts();
|
||||||
|
|
||||||
|
if (dir == 0 || lastPeriod == 0 || frequency == 0.0F) {
|
||||||
|
feedForwardVelocity = 0.0F;
|
||||||
|
} else {
|
||||||
|
feedForwardVelocity = (dir > 0) ? frequency : -frequency;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float ODriveMotor::getFrequencySteps() {
|
||||||
|
if (!ready) return 0.0F;
|
||||||
|
|
||||||
|
if (lastPeriod == 0) return 0.0F;
|
||||||
|
return (16000000.0F / lastPeriod) * absStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set slewing state (hint that we are about to slew or are done slewing)
|
||||||
|
void ODriveMotor::setSlewing(bool state) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
isSlewing = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
// updates PID and sets odrive position
|
||||||
|
void ODriveMotor::poll() {
|
||||||
|
const uint32_t now = millis();
|
||||||
|
|
||||||
|
// grab a new encoder position update at 10Hz
|
||||||
|
if ((uint32_t)(now - lastEncoderUpdateRequestTime) >= 100U) {
|
||||||
|
odriveCan.requestTurns(oDriveNode);
|
||||||
|
lastEncoderUpdateRequestTime = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------
|
||||||
|
// handle enable/disable handshake (async confirmation)
|
||||||
|
// -------------------------
|
||||||
|
if (enablePending) {
|
||||||
|
// snapshot ODrive status
|
||||||
|
const uint8_t st = odriveCan.axisState(oDriveNode);
|
||||||
|
const uint32_t err = odriveCan.lastError(oDriveNode);
|
||||||
|
|
||||||
|
// hard faults during transition: lose heartbeat or error latched
|
||||||
|
if (!odriveCan.hasHeartbeat(oDriveNode, 250) || (err != 0)) {
|
||||||
|
enabled = false;
|
||||||
|
enablePending = false;
|
||||||
|
stopSyntheticMotion();
|
||||||
|
resetToTrackingBaseline();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// commit when we observe the desired steady state
|
||||||
|
if (enableTarget) {
|
||||||
|
if (st == AXIS_STATE_CLOSED_LOOP_CONTROL) {
|
||||||
|
enabled = true;
|
||||||
|
enablePending = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (st == AXIS_STATE_IDLE) {
|
||||||
|
enabled = false;
|
||||||
|
enablePending = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// deadline: if still pending after the window, fail closed
|
||||||
|
if (enablePending && (int32_t)(now - enableDeadlineMs) >= 0) {
|
||||||
|
enabled = false;
|
||||||
|
enablePending = false;
|
||||||
|
stopSyntheticMotion();
|
||||||
|
resetToTrackingBaseline();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------
|
||||||
|
// normal operation (only when truly enabled)
|
||||||
|
// -------------------------
|
||||||
|
if (!ready || !enabled) return;
|
||||||
|
|
||||||
|
// fail closed if we lose comms or an error appears while running
|
||||||
|
// (no encoder freshness requirement in this variant)
|
||||||
|
if (!odriveCan.hasHeartbeat(oDriveNode, 250) || (odriveCan.lastError(oDriveNode) != 0)) {
|
||||||
|
enabled = false;
|
||||||
|
enablePending = false;
|
||||||
|
stopSyntheticMotion();
|
||||||
|
resetToTrackingBaseline();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// rate-limit position commands
|
||||||
|
if (now - lastSetPositionTime < ODRIVE_UPDATE_MS) return;
|
||||||
|
lastSetPositionTime = now;
|
||||||
|
|
||||||
|
long target;
|
||||||
|
noInterrupts();
|
||||||
|
#if ODRIVE_SLEW_DIRECT == ON
|
||||||
|
target = targetSteps + backlashSteps;
|
||||||
|
#else
|
||||||
|
target = motorSteps + backlashSteps;
|
||||||
|
#endif
|
||||||
|
interrupts();
|
||||||
|
|
||||||
|
float vel_ff_turns_s = feedForwardVelocity/(TWO_PI*countsPerRad.value);
|
||||||
|
|
||||||
|
odriveCan.setInputPos(oDriveNode, target/(TWO_PI*countsPerRad.value), vel_ff_turns_s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ODriveMotor::stopSyntheticMotion() {
|
||||||
|
feedForwardVelocity = 0.0F;
|
||||||
|
|
||||||
|
if (lastPeriod == 0 && step == 0 && absStep == 0) return;
|
||||||
|
currentFrequency = 0.0F;
|
||||||
|
lastPeriod = 0;
|
||||||
|
feedForwardVelocity = 0.0F;
|
||||||
|
noInterrupts();
|
||||||
|
step = 0;
|
||||||
|
absStep = 0;
|
||||||
|
interrupts();
|
||||||
|
if (taskHandle) tasks.setPeriodSubMicros(taskHandle, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ODriveMotor::resetToTrackingBaseline() {
|
||||||
|
noInterrupts();
|
||||||
|
step = 0;
|
||||||
|
absStep = 0;
|
||||||
|
inBacklash = false;
|
||||||
|
backlashSteps = 0;
|
||||||
|
interrupts();
|
||||||
|
|
||||||
|
currentFrequency = 0.0F;
|
||||||
|
lastPeriod = 0;
|
||||||
|
stepSize = 1;
|
||||||
|
feedForwardVelocity = 0.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets dir as required and moves coord toward target at setFrequencySteps() rate
|
||||||
|
IRAM_ATTR void ODriveMotor::move() {
|
||||||
|
if (sync && !inBacklash) targetSteps += step;
|
||||||
|
|
||||||
|
if (motorSteps > targetSteps) {
|
||||||
|
if (backlashSteps > 0) {
|
||||||
|
backlashSteps -= absStep;
|
||||||
|
inBacklash = backlashSteps > 0;
|
||||||
|
} else {
|
||||||
|
motorSteps -= absStep;
|
||||||
|
inBacklash = false;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
|
||||||
|
if (motorSteps < targetSteps || inBacklash) {
|
||||||
|
if (backlashSteps < backlashAmountSteps) {
|
||||||
|
backlashSteps += absStep;
|
||||||
|
inBacklash = backlashSteps < backlashAmountSteps;
|
||||||
|
} else {
|
||||||
|
motorSteps += absStep;
|
||||||
|
inBacklash = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
Executable
+151
@@ -0,0 +1,151 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// oDrive servo motor
|
||||||
|
// EXPERIMENTAL!!!
|
||||||
|
#pragma once
|
||||||
|
#include "../../../../Common.h"
|
||||||
|
|
||||||
|
#ifdef ODRIVE_NEW_MOTOR_PRESENT
|
||||||
|
#ifdef ODRIVE_MOTOR_PRESENT
|
||||||
|
|
||||||
|
#include "../Motor.h"
|
||||||
|
#include "../../../convert/Convert.h"
|
||||||
|
|
||||||
|
#ifndef ODRIVE_RST_PIN
|
||||||
|
#define ODRIVE_RST_PIN 3
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// odrive update rate default 40Hz
|
||||||
|
#ifndef ODRIVE_UPDATE_MS
|
||||||
|
#define ODRIVE_UPDATE_MS CAN_SEND_RATE_MS // normally > about 5ms and < 100ms
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// odrive direct slewing ON or OFF (ODrive handles acceleration)
|
||||||
|
// ON to use ODrive trapezoidal move profile, OFF for OnStep move profile
|
||||||
|
#ifndef ODRIVE_SLEW_DIRECT
|
||||||
|
#define ODRIVE_SLEW_DIRECT OFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// odrive if using absolute encoders set to ON
|
||||||
|
#ifndef ODRIVE_ABSOLUTE
|
||||||
|
#define ODRIVE_ABSOLUTE ON // was OFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// odrive sync limit (for absolute encoders) OFF or specify the sync limit in arc-seconds
|
||||||
|
// this should, I hope, allow you to limit just how far from the encoders you can sync. (+/-) to fine-tune the origin
|
||||||
|
// with absolute encoders this protects you from exceeding the software min/max limits by > the amount specified
|
||||||
|
// in arc seconds..one encoder tick encoder resolution = 2^14 = 16384
|
||||||
|
// 16384/360=45.5 ticks/deg; 45.5/60=0.7583 ticks/min; 0.7583/60 = .00126 ticks/sec
|
||||||
|
// or 1/0.7583 = 1.32 arc-min/tick; 1.32*60 sec = 79.2 arc sec per encoder tick
|
||||||
|
#ifndef ODRIVE_SYNC_LIMIT
|
||||||
|
#define ODRIVE_SYNC_LIMIT 80 // was OFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Use OD_UART or OD_CAN...I2C may be added later
|
||||||
|
#ifndef ODRIVE_COMM_MODE
|
||||||
|
#define ODRIVE_COMM_MODE OD_CAN
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ODrive axis 0 = OnStep Axis2 = DEC or ALT
|
||||||
|
// ODrive axis 1 = OnStep Axis1 = RA or AZM
|
||||||
|
#ifndef ODRIVE_SWAP_AXES
|
||||||
|
#define ODRIVE_SWAP_AXES ON
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct ODriveDriverSettings {
|
||||||
|
int16_t model;
|
||||||
|
int8_t status;
|
||||||
|
} ODriveDriverSettings;
|
||||||
|
|
||||||
|
class ODriveMotor : public Motor {
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
ODriveMotor(uint8_t axisNumber, int8_t reverse, const ODriveDriverSettings *Settings, float countsPerRad, bool useFastHardwareTimers = true);
|
||||||
|
|
||||||
|
// sets up the odrive motor
|
||||||
|
bool init();
|
||||||
|
|
||||||
|
// returns the number of parameters from the motor
|
||||||
|
uint8_t getParameterCount() { return Motor::getParameterCount() + numParameters; }
|
||||||
|
|
||||||
|
// returns the specified axis parameter
|
||||||
|
AxisParameter* getParameter(uint8_t number) {
|
||||||
|
if (number == Motor::getParameterCount() + 1) return &countsPerRad; else
|
||||||
|
if (number >= 1 && number <= Motor::getParameterCount()) return Motor::getParameter(number); else
|
||||||
|
return &invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set motor reverse state
|
||||||
|
void setReverse(bool state);
|
||||||
|
|
||||||
|
// sets motor enable on/off (if possible)
|
||||||
|
void enable(bool value);
|
||||||
|
|
||||||
|
bool hasAbsoluteEncoder() const override { return ODRIVE_ABSOLUTE == ON; }
|
||||||
|
|
||||||
|
// set instrument coordinate, in steps
|
||||||
|
void setInstrumentCoordinateSteps(long value);
|
||||||
|
|
||||||
|
// get the associated driver status
|
||||||
|
inline DriverStatus getDriverStatus() { if (ready) return status; else return errorStatus; }
|
||||||
|
|
||||||
|
// resets motor and target angular position in steps, also zeros backlash and index
|
||||||
|
void resetPositionSteps(long value);
|
||||||
|
|
||||||
|
// get tracking mode steps per slewing mode step
|
||||||
|
inline int getStepsPerStepSlewing() { return 64; }
|
||||||
|
|
||||||
|
// get movement frequency in steps per second
|
||||||
|
float getFrequencySteps();
|
||||||
|
|
||||||
|
// set frequency (+/-) in steps per second negative frequencies move reverse in direction (0 stops motion)
|
||||||
|
void setFrequencySteps(float frequency);
|
||||||
|
|
||||||
|
// set slewing state (hint that we are about to slew or are done slewing)
|
||||||
|
void setSlewing(bool state);
|
||||||
|
|
||||||
|
// get the motor name
|
||||||
|
const char* name() { return "ODRIVE"; }
|
||||||
|
|
||||||
|
// updates PID and sets servo motor power/direction
|
||||||
|
void poll();
|
||||||
|
|
||||||
|
// sets dir as required and moves coord toward target at setFrequencySteps() rate
|
||||||
|
void move();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void stopSyntheticMotion();
|
||||||
|
void resetToTrackingBaseline();
|
||||||
|
|
||||||
|
float feedForwardVelocity = 0.0F;
|
||||||
|
unsigned long lastSetPositionTime = 0;
|
||||||
|
unsigned long lastEncoderUpdateRequestTime = 0;
|
||||||
|
uint8_t oDriveNode = 0; // ODrive node for this mount axis (swapped if ODRIVE_SWAP_AXES==ON)
|
||||||
|
uint8_t taskHandle = 0;
|
||||||
|
|
||||||
|
int stepSize = 1; // step size
|
||||||
|
|
||||||
|
unsigned long lastPeriod = 0; // last timer period (in sub-micros)
|
||||||
|
float maxFrequency = HAL_FRACTIONAL_SEC; // fastest timer rate
|
||||||
|
|
||||||
|
volatile int absStep = 0; // absolute step size (unsigned)
|
||||||
|
|
||||||
|
void (*callback)() = NULL;
|
||||||
|
|
||||||
|
bool useFastHardwareTimers = true;
|
||||||
|
|
||||||
|
bool enablePending = false;
|
||||||
|
bool enableTarget = false;
|
||||||
|
uint32_t enableDeadlineMs = 0;
|
||||||
|
bool isSlewing = false;
|
||||||
|
|
||||||
|
DriverStatus status = { false, {false, false}, {false, false}, false, false, false, false };
|
||||||
|
|
||||||
|
// runtime adjustable settings
|
||||||
|
AxisParameter countsPerRad = {NAN, NAN, NAN, 300.0*RAD_DEG_RATIO_F, 360000.0*RAD_DEG_RATIO_F, AXP_FLOAT, AXPN_COUNTS_PER_RAD};
|
||||||
|
|
||||||
|
const int numParameters = 1;
|
||||||
|
AxisParameter* parameter[2] = {&invalid, &countsPerRad};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
Executable
+525
@@ -0,0 +1,525 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis servo motor
|
||||||
|
|
||||||
|
#include "Servo.h"
|
||||||
|
|
||||||
|
#ifdef SERVO_MOTOR_PRESENT
|
||||||
|
|
||||||
|
#include "../../../tasks/OnTask.h"
|
||||||
|
#include "../Motor.h"
|
||||||
|
|
||||||
|
static ServoMotor *servoMotorInstance[9];
|
||||||
|
IRAM_ATTR void moveServoMotorAxis1() { servoMotorInstance[0]->move(); }
|
||||||
|
IRAM_ATTR void moveServoMotorAxis2() { servoMotorInstance[1]->move(); }
|
||||||
|
IRAM_ATTR void moveServoMotorAxis3() { servoMotorInstance[2]->move(); }
|
||||||
|
IRAM_ATTR void moveServoMotorAxis4() { servoMotorInstance[3]->move(); }
|
||||||
|
IRAM_ATTR void moveServoMotorAxis5() { servoMotorInstance[4]->move(); }
|
||||||
|
IRAM_ATTR void moveServoMotorAxis6() { servoMotorInstance[5]->move(); }
|
||||||
|
IRAM_ATTR void moveServoMotorAxis7() { servoMotorInstance[6]->move(); }
|
||||||
|
IRAM_ATTR void moveServoMotorAxis8() { servoMotorInstance[7]->move(); }
|
||||||
|
IRAM_ATTR void moveServoMotorAxis9() { servoMotorInstance[8]->move(); }
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
ServoMotor::ServoMotor(uint8_t axisNumber, int8_t reverse,
|
||||||
|
ServoDriver *Driver, Filter *filter,
|
||||||
|
Encoder *encoder, uint32_t encoderOrigin, bool encoderReverse,
|
||||||
|
Feedback *feedback, ServoControl *control,
|
||||||
|
bool useFastHardwareTimers)
|
||||||
|
:Motor(axisNumber, reverse) {
|
||||||
|
if (axisNumber < 1 || axisNumber > 9) return;
|
||||||
|
|
||||||
|
driverType = SERVO;
|
||||||
|
|
||||||
|
strcpy(axisPrefix, " Axis_Servo, ");
|
||||||
|
axisPrefix[5] = '0' + axisNumber;
|
||||||
|
|
||||||
|
this->filter = filter;
|
||||||
|
this->encoder = encoder;
|
||||||
|
this->feedback = feedback;
|
||||||
|
this->control = control;
|
||||||
|
|
||||||
|
if (axisNumber > 2) useFastHardwareTimers = false;
|
||||||
|
this->useFastHardwareTimers = useFastHardwareTimers;
|
||||||
|
|
||||||
|
this->driver = Driver;
|
||||||
|
|
||||||
|
this->encoderOrigin = encoderOrigin;
|
||||||
|
this->encoderReverse = encoderReverse;
|
||||||
|
this->encoderReverseDefault = encoderReverse;
|
||||||
|
|
||||||
|
// attach the function pointers to the callbacks
|
||||||
|
servoMotorInstance[axisNumber - 1] = this;
|
||||||
|
switch (axisNumber) {
|
||||||
|
case 1: callback = moveServoMotorAxis1; break;
|
||||||
|
case 2: callback = moveServoMotorAxis2; break;
|
||||||
|
case 3: callback = moveServoMotorAxis3; break;
|
||||||
|
case 4: callback = moveServoMotorAxis4; break;
|
||||||
|
case 5: callback = moveServoMotorAxis5; break;
|
||||||
|
case 6: callback = moveServoMotorAxis6; break;
|
||||||
|
case 7: callback = moveServoMotorAxis7; break;
|
||||||
|
case 8: callback = moveServoMotorAxis8; break;
|
||||||
|
case 9: callback = moveServoMotorAxis9; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ServoMotor::init() {
|
||||||
|
if (!Motor::init()) return false;
|
||||||
|
|
||||||
|
#ifdef CALIBRATE_SERVO_DC
|
||||||
|
calibrateVelocity = new ServoCalibrateTrackingVelocity(axisNumber);
|
||||||
|
driver->setTrackingMode(true);
|
||||||
|
driver->setBypassAccelOnTracking(true);
|
||||||
|
slewing = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (encoder->supportsTimeAlignedMotorSteps()) { encoder->setMotorStepsPtr(&motorSteps); }
|
||||||
|
|
||||||
|
if (!encoder->init()) { DF("ERR:"); D(axisPrefix); DLF("no encoder!"); return false; }
|
||||||
|
|
||||||
|
encoder->setOrigin(encoderOrigin);
|
||||||
|
|
||||||
|
if (!driver->init(normalizedReverse)) { DF("ERR:"); D(axisPrefix); DLF("no motor driver!"); return false; }
|
||||||
|
|
||||||
|
driver->enable(false);
|
||||||
|
|
||||||
|
// get the feedback control loop ready
|
||||||
|
feedback->init(axisNumber, control);
|
||||||
|
feedback->reset();
|
||||||
|
trackingFrequency = (AXIS1_STEPS_PER_DEGREE/240.0F)*SIDEREAL_RATIO_F;
|
||||||
|
|
||||||
|
// start the motion timer
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("start task to synthesize motion... ");
|
||||||
|
char timerName[] = "Ax_Svo";
|
||||||
|
timerName[2] = '0' + axisNumber;
|
||||||
|
taskHandle = tasks.add(0, 0, true, 0, callback, timerName);
|
||||||
|
if (taskHandle) {
|
||||||
|
VF("success");
|
||||||
|
if (useFastHardwareTimers) {
|
||||||
|
if (!tasks.requestHardwareTimer(taskHandle, 0)) {
|
||||||
|
VF(" (no hardware timer!)");
|
||||||
|
} else {
|
||||||
|
maxFrequency = (1000000.0F/HAL_MAXRATE_LOWER_LIMIT)/2.0F;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
VLF("");
|
||||||
|
} else {
|
||||||
|
VLF("FAILED!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ready = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoMotor::setReverse(int8_t state) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
feedback->setControlDirection(state);
|
||||||
|
if (state == ON) encoderReverse = encoderReverseDefault; else encoderReverse = !encoderReverseDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoMotor::enable(bool state) {
|
||||||
|
if (!ready || state == enabled) return;
|
||||||
|
|
||||||
|
if (state) {
|
||||||
|
driver->enable(true); // power up first
|
||||||
|
feedback->reset(); // clean start (PID state)
|
||||||
|
safetyShutdown = false;
|
||||||
|
|
||||||
|
stopSyntheticMotion(); // stop ISR/task
|
||||||
|
resetToTrackingBaseline(); // clear backlash/step state
|
||||||
|
enabled = true;
|
||||||
|
} else {
|
||||||
|
enabled = false; // close window
|
||||||
|
stopSyntheticMotion(); // stop ISR/task
|
||||||
|
resetToTrackingBaseline(); // clear backlash/step state
|
||||||
|
|
||||||
|
feedback->reset(); // clear PID state
|
||||||
|
driver->enable(false); // then power down
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef CALIBRATE_SERVO_DC
|
||||||
|
if (enabled && !encoder->isVirtual) {
|
||||||
|
calibrateVelocity->start(trackingFrequency, getInstrumentCoordinateSteps());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
DriverStatus ServoMotor::getDriverStatus() {
|
||||||
|
if (!ready) return errorStatus;
|
||||||
|
|
||||||
|
DriverStatus driverStatus;
|
||||||
|
if (ready) { driver->updateStatus(); driverStatus = driver->getStatus(); } else driverStatus.fault = true;
|
||||||
|
if (encoder->errorThresholdExceeded()) driverStatus.fault = true;
|
||||||
|
if (safetyShutdown) driverStatus.fault = true;
|
||||||
|
return driverStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
// resets motor and target angular position in steps, also zeros backlash and index
|
||||||
|
void ServoMotor::resetPositionSteps(long value) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
Motor::resetPositionSteps(value);
|
||||||
|
if (!encoder->isAbsolute()) {
|
||||||
|
encoder->write(value);
|
||||||
|
} else {
|
||||||
|
VF("MSG:"); V(axisPrefix); VL("absolute encoder ignored reset position");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// get instrument coordinate, in steps
|
||||||
|
long ServoMotor::getInstrumentCoordinateSteps() {
|
||||||
|
if (!ready) return 0;
|
||||||
|
|
||||||
|
return encoderRead() + indexSteps;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set instrument coordinate, in steps
|
||||||
|
void ServoMotor::setInstrumentCoordinateSteps(long value) {
|
||||||
|
bool startupOriginState = indexSteps == 0 && motorSteps == 0 && targetSteps == 0 && backlashSteps == 0;
|
||||||
|
|
||||||
|
noInterrupts();
|
||||||
|
indexSteps = value - motorSteps;
|
||||||
|
interrupts();
|
||||||
|
|
||||||
|
if (encoder->isAbsolute() && startupOriginState) homeSet = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// distance to target in steps (+/-)
|
||||||
|
long ServoMotor::getTargetDistanceSteps() {
|
||||||
|
if (!ready) return 0;
|
||||||
|
|
||||||
|
long encoderCounts = encoderRead();
|
||||||
|
noInterrupts();
|
||||||
|
long dist = targetSteps - encoderCounts;
|
||||||
|
interrupts();
|
||||||
|
return dist;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set frequency (+/-) in steps per second negative frequencies move reverse in direction (0 stops motion)
|
||||||
|
void ServoMotor::setFrequencySteps(float frequency) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
if (!enabled) { stopSyntheticMotion(); return; }
|
||||||
|
|
||||||
|
// negative frequency, convert to positive and reverse the direction
|
||||||
|
int dir = 0;
|
||||||
|
if (frequency > 0.0F) dir = 1; else if (frequency < 0.0F) { frequency = -frequency; dir = -1; }
|
||||||
|
|
||||||
|
// if in backlash override the frequency
|
||||||
|
if (inBacklash) frequency = backlashFrequency;
|
||||||
|
|
||||||
|
if (frequency != currentFrequency) {
|
||||||
|
// compensate for performace limitations by taking larger steps as needed
|
||||||
|
if (frequency < maxFrequency) stepSize = 1; else
|
||||||
|
if (frequency < maxFrequency*2) stepSize = 2; else
|
||||||
|
if (frequency < maxFrequency*4) stepSize = 4; else
|
||||||
|
if (frequency < maxFrequency*8) stepSize = 8; else
|
||||||
|
if (frequency < maxFrequency*16) stepSize = 16; else
|
||||||
|
if (frequency < maxFrequency*32) stepSize = 32; else
|
||||||
|
if (frequency < maxFrequency*64) stepSize = 64; else
|
||||||
|
if (frequency < maxFrequency*128) stepSize = 128; else stepSize = 256;
|
||||||
|
|
||||||
|
// timer period in microseconds
|
||||||
|
float period = (1000000.0F*stepSize)/frequency;
|
||||||
|
|
||||||
|
// range is 0 to 134 seconds/step
|
||||||
|
if (!isnan(period) && period <= 130000000.0F) {
|
||||||
|
period *= 16.0F;
|
||||||
|
lastPeriod = (unsigned long)lroundf(period);
|
||||||
|
} else {
|
||||||
|
lastPeriod = 0;
|
||||||
|
frequency = 0.0F;
|
||||||
|
dir = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentFrequency = frequency;
|
||||||
|
currentDirection = dir;
|
||||||
|
|
||||||
|
// change the motor rate/direction
|
||||||
|
noInterrupts();
|
||||||
|
step = 0;
|
||||||
|
interrupts();
|
||||||
|
tasks.setPeriodSubMicros(taskHandle, lastPeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
noInterrupts();
|
||||||
|
step = dir * stepSize;
|
||||||
|
absStep = abs(step);
|
||||||
|
interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
float ServoMotor::getFrequencySteps() {
|
||||||
|
if (!ready) return 0;
|
||||||
|
|
||||||
|
if (lastPeriod == 0) return 0;
|
||||||
|
return (16000000.0F / lastPeriod) * absStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set slewing state (hint that we are about to slew or are done slewing)
|
||||||
|
void ServoMotor::setSlewing(bool state) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
slewing = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set zero/origin of absolute encoders
|
||||||
|
uint32_t ServoMotor::encoderZero() {
|
||||||
|
if (!ready) return 0;
|
||||||
|
|
||||||
|
encoder->origin = 0;
|
||||||
|
encoder->index = 0;
|
||||||
|
|
||||||
|
uint32_t zero = (uint32_t)(-encoder->read());
|
||||||
|
encoder->origin = zero;
|
||||||
|
|
||||||
|
return zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t ServoMotor::encoderRead() {
|
||||||
|
int32_t encoderCounts = encoder->read();
|
||||||
|
if (encoderReverse) encoderCounts = -encoderCounts;
|
||||||
|
return encoderCounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
// updates PID and sets servo motor power/direction
|
||||||
|
void ServoMotor::poll() {
|
||||||
|
int32_t encoderCounts = encoder->read();
|
||||||
|
if (encoderReverse) encoderCounts = -encoderCounts;
|
||||||
|
|
||||||
|
// for absolute encoders initialize the motor position at startup
|
||||||
|
if (encoder->isAbsolute()) {
|
||||||
|
if (!motorStepsInitDone && homeSet) {
|
||||||
|
noInterrupts();
|
||||||
|
motorSteps = encoderCounts;
|
||||||
|
targetSteps = encoderCounts;
|
||||||
|
backlashSteps = 0;
|
||||||
|
interrupts();
|
||||||
|
motorStepsInitDone = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
long motorCounts;
|
||||||
|
if (encoder->hasMotorStepsAtLastRead()) {
|
||||||
|
motorCounts = encoder->motorStepsAtLastRead();
|
||||||
|
} else {
|
||||||
|
noInterrupts();
|
||||||
|
motorCounts = motorSteps;
|
||||||
|
interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
long unfilteredEncoderCounts = encoderCounts;
|
||||||
|
UNUSED(unfilteredEncoderCounts);
|
||||||
|
|
||||||
|
// find encoder velocity
|
||||||
|
float encoderVelocity = encoder->readVelocityCps();
|
||||||
|
if (encoderReverse) encoderVelocity = -encoderVelocity;
|
||||||
|
if (isnan(encoderVelocity)) {
|
||||||
|
const uint32_t nowUs = micros();
|
||||||
|
|
||||||
|
if (lastUs == 0) {
|
||||||
|
lastUs = nowUs;
|
||||||
|
lastEnc = unfilteredEncoderCounts;
|
||||||
|
encoderVelocity = 0.0F;
|
||||||
|
} else {
|
||||||
|
uint32_t dtUs = nowUs - lastUs;
|
||||||
|
if (dtUs == 0) dtUs = 1;
|
||||||
|
encoderVelocity = (unfilteredEncoderCounts - lastEnc)*(1000000.0F/(float)dtUs);
|
||||||
|
lastEnc = unfilteredEncoderCounts;
|
||||||
|
lastUs = nowUs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Eq mount tracking?
|
||||||
|
bool isTracking = (axisNumber == 1) && (fabsf(currentFrequency - trackingFrequency) < trackingFrequency*0.1F);
|
||||||
|
|
||||||
|
encoderCounts = filter->update(encoderCounts, motorCounts, isTracking);
|
||||||
|
|
||||||
|
control->set = motorCounts;
|
||||||
|
control->in = encoderCounts;
|
||||||
|
float velocity;
|
||||||
|
if (enabled) {
|
||||||
|
// directly use fixed PWM value during calibration
|
||||||
|
#ifdef CALIBRATE_SERVO_DC
|
||||||
|
if (calibrateVelocity->experimentMode) {
|
||||||
|
// Get unfiltered counts
|
||||||
|
calibrateVelocity->updateState(unfilteredEncoderCounts);
|
||||||
|
// experimentVel is in PERCENT of max velocity, convert to cps
|
||||||
|
velocity = (calibrateVelocity->experimentVelocity/100.0F)*velocityMax;
|
||||||
|
// disable the PID // or feedback->zeroOutputs()
|
||||||
|
control->out = 0.0f; // ensure PID output doesn't leak in
|
||||||
|
} else {
|
||||||
|
// your normal control path; keep whatever you used before
|
||||||
|
velocity = control->out + currentDirection*currentFrequency;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
feedback->poll();
|
||||||
|
velocity = control->out + currentDirection*currentFrequency;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} else velocity = 0.0F;
|
||||||
|
|
||||||
|
// for virtual encoders set the velocity and direction
|
||||||
|
if (encoder->isVirtual) {
|
||||||
|
encoderDirection = velocity < 0.0F ? -1 : 1;
|
||||||
|
encoder->setVelocity(abs(velocity));
|
||||||
|
encoder->setDirection(&encoderDirection);
|
||||||
|
}
|
||||||
|
|
||||||
|
// const float vmax = velocityMax;
|
||||||
|
// v_eff = driver->setMotorVelocity(velocity, encoderVelocity)*100.0F;
|
||||||
|
// velocityPercent = (vmax > 0.0F) ? (v_eff/vmax)*100.0F : 0.0F;
|
||||||
|
velocityPercent = (driver->setMotorVelocity(velocity, encoderVelocity)/velocityMax)*100.0F;
|
||||||
|
if (driver->getMotorDirection() == DIR_FORWARD) control->directionHint = 1; else control->directionHint = -1;
|
||||||
|
|
||||||
|
const unsigned long now = millis();
|
||||||
|
|
||||||
|
if (feedback->manuallySwitchParameters) {
|
||||||
|
if (!slewing && enabled) {
|
||||||
|
if (now - lastSlewingTime >= SERVO_SLEWING_TO_TRACKING_DELAY) feedback->selectTrackingParameters(); else feedback->selectSlewingParameters();
|
||||||
|
} else {
|
||||||
|
lastSlewingTime = now;
|
||||||
|
feedback->selectSlewingParameters();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
feedback->variableParameters(fabs(velocityPercent));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (velocityPercent < -33) wasBelow33 = true;
|
||||||
|
if (velocityPercent > 33) wasAbove33 = true;
|
||||||
|
|
||||||
|
if (now - lastCheckTime >= 1000U) {
|
||||||
|
delta = motorCounts - encoderCounts;
|
||||||
|
|
||||||
|
#ifndef SERVO_SAFETY_DISABLE
|
||||||
|
// if above SERVO_SAFETY_STALL_POWER (33% default) and we're not moving something is seriously wrong, so shut it down
|
||||||
|
if (labs(encoderCounts - lastEncoderCounts) < 10 && abs(velocityPercent) >= SERVO_SAFETY_STALL_POWER) {
|
||||||
|
DF("WRN:"); D(axisPrefix); DF("stall detected!");
|
||||||
|
DF(" control->in = "); D(control->in); DF(", control->set = "); D(control->set);
|
||||||
|
DF(", control->out = "); D(control->out); DF(", velocity % = "); DL(velocityPercent);
|
||||||
|
enable(false);
|
||||||
|
safetyShutdown = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if above 90% power for > three seconds and the distance to the target is increasing
|
||||||
|
// something is seriously wrong so shut it down
|
||||||
|
if (labs(delta - lastDelta) > lastTargetDistance && abs(velocityPercent) >= 90) {
|
||||||
|
movingAwaySeconds++;
|
||||||
|
if (movingAwaySeconds >= 3) {
|
||||||
|
DF("WRN:"); D(axisPrefix); DF("runaway detected!");
|
||||||
|
DLF(" > 90% power while moving away from the target!");
|
||||||
|
enable(false);
|
||||||
|
safetyShutdown = true;
|
||||||
|
}
|
||||||
|
} else movingAwaySeconds = 0;
|
||||||
|
lastTargetDistance = labs(delta - lastDelta);
|
||||||
|
|
||||||
|
// if we were below -33% and above 33% power in a one second period something is seriously wrong, so shut it down
|
||||||
|
if (wasBelow33 && wasAbove33) {
|
||||||
|
DF("WRN:"); D(axisPrefix); DF("oscillation detected!");
|
||||||
|
DLF(" below -33% and above 33% power in a 2 second period!");
|
||||||
|
enable(false);
|
||||||
|
safetyShutdown = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
wasAbove33 = false;
|
||||||
|
wasBelow33 = false;
|
||||||
|
lastEncoderCounts = encoderCounts;
|
||||||
|
lastDelta = delta;
|
||||||
|
lastCheckTime = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DEBUG != OFF && defined(DEBUG_AXIS) && DEBUG_AXIS != OFF
|
||||||
|
if (axisNumber == DEBUG_AXIS) {
|
||||||
|
static uint16_t count = 0;
|
||||||
|
count++;
|
||||||
|
if (count % 10 == 0) {
|
||||||
|
char s[256];
|
||||||
|
|
||||||
|
float spas = 0;
|
||||||
|
if (axisNumber == 1) spas = AXIS1_STEPS_PER_DEGREE/3600.0F; else if (axisNumber == 2) spas = AXIS2_STEPS_PER_DEGREE/3600.0F;
|
||||||
|
|
||||||
|
// snprintf(s, sizeof(s), "Ax%dSvo: Delta %6ld, Motor %6ld, Encoder %6ld, Ax%dSvo_Power: %6.3f%%\r\n", (int)axisNumber, (motorCounts - encoderCounts), motorCounts, (long)encoderCounts, (int)axisNumber, velocityPercent);
|
||||||
|
// snprintf(s, sizeof(s), "Ax%dSvo: Motor %6ld, Encoder %6ld\r\n", (int)axisNumber, motorCounts, (long)encoderCounts);
|
||||||
|
// snprintf(s, sizeof(s), "Ax%dSvo: Delta %0.2f\r\n", (int)axisNumber, (motorCounts - (long)encoderCounts)/12.9425);
|
||||||
|
// snprintf(s, sizeof(s), "Ax%dSvo: DeltaASf: %0.2f, DeltaAS: %0.2f, Ax%dSvo_Power: %6.3f%%\r\n", (int)axisNumber, (motorCounts - encoderCounts)/spas, (motorCounts - unfilteredEncoderCounts)/spas, (int)axisNumber, velocityPercent);
|
||||||
|
snprintf(s, sizeof(s), "%0.2f, %6.3f%%\r\n", (motorCounts - unfilteredEncoderCounts)/spas, velocityPercent);
|
||||||
|
|
||||||
|
D(s);
|
||||||
|
UNUSED(spas);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoMotor::stopSyntheticMotion() {
|
||||||
|
if (lastPeriod == 0 && step == 0 && absStep == 0) return;
|
||||||
|
currentFrequency = 0.0F;
|
||||||
|
currentDirection = 0;
|
||||||
|
lastPeriod = 0;
|
||||||
|
|
||||||
|
noInterrupts();
|
||||||
|
step = 0;
|
||||||
|
absStep = 0;
|
||||||
|
interrupts();
|
||||||
|
if (taskHandle) tasks.setPeriodSubMicros(taskHandle, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoMotor::resetToTrackingBaseline() {
|
||||||
|
noInterrupts();
|
||||||
|
step = 0;
|
||||||
|
absStep = 0;
|
||||||
|
inBacklash = false;
|
||||||
|
backlashSteps = 0;
|
||||||
|
interrupts();
|
||||||
|
|
||||||
|
currentFrequency = 0.0F;
|
||||||
|
currentDirection = 0;
|
||||||
|
lastPeriod = 0;
|
||||||
|
|
||||||
|
lastEnc = 0;
|
||||||
|
lastUs = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets dir as required and moves coord toward target at setFrequencySteps() rate
|
||||||
|
IRAM_ATTR void ServoMotor::move() {
|
||||||
|
|
||||||
|
#if SERVO_SLEW_DIRECT == ON
|
||||||
|
if (sync && !inBacklash) targetSteps += step;
|
||||||
|
|
||||||
|
if (motorSteps > targetSteps) {
|
||||||
|
motorSteps = targetSteps;
|
||||||
|
} else
|
||||||
|
|
||||||
|
if (motorSteps < targetSteps + backlashAmountSteps) {
|
||||||
|
motorSteps = targetSteps + backlashAmountSteps;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
if (sync && !inBacklash) targetSteps += step;
|
||||||
|
|
||||||
|
if (motorSteps > targetSteps) {
|
||||||
|
if (backlashSteps > 0) {
|
||||||
|
backlashSteps -= absStep;
|
||||||
|
inBacklash = backlashSteps > 0;
|
||||||
|
} else {
|
||||||
|
motorSteps -= absStep;
|
||||||
|
inBacklash = false;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
|
||||||
|
if (motorSteps < targetSteps || inBacklash) {
|
||||||
|
if (backlashSteps < backlashAmountSteps) {
|
||||||
|
backlashSteps += absStep;
|
||||||
|
inBacklash = backlashSteps < backlashAmountSteps;
|
||||||
|
} else {
|
||||||
|
motorSteps += absStep;
|
||||||
|
inBacklash = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+190
@@ -0,0 +1,190 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis servo motor
|
||||||
|
#pragma once
|
||||||
|
#include "../../../../Common.h"
|
||||||
|
|
||||||
|
#ifdef SERVO_MOTOR_PRESENT
|
||||||
|
|
||||||
|
#include "../../../encoder/Encoder.h"
|
||||||
|
#include "filter/Filter.h"
|
||||||
|
#include "feedback/Feedback.h"
|
||||||
|
#include "dc/calibration/TrackingVelocity.h"
|
||||||
|
|
||||||
|
#include "dc/eE/EE.h"
|
||||||
|
#include "dc/pE/PE.h"
|
||||||
|
#include "dc/tmc/tmc2130/Tmc2130.h"
|
||||||
|
#include "dc/tmc/tmc5160/Tmc5160.h"
|
||||||
|
#include "kTech/KTech.h"
|
||||||
|
#include "tmc/tmc2209/Tmc2209.h"
|
||||||
|
#include "tmc/tmc5160/Tmc5160.h"
|
||||||
|
|
||||||
|
#ifndef SERVO_SLEW_DIRECT
|
||||||
|
#define SERVO_SLEW_DIRECT OFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SERVO_SLEWING_TO_TRACKING_DELAY
|
||||||
|
#define SERVO_SLEWING_TO_TRACKING_DELAY 3000 // in milliseconds
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SERVO_SAFETY_STALL_POWER
|
||||||
|
#define SERVO_SAFETY_STALL_POWER 33 // in percent
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class ServoMotor : public Motor {
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
ServoMotor(uint8_t axisNumber, int8_t reverse, ServoDriver *Driver, Filter *filter, Encoder *encoder, uint32_t encoderOrigin, bool encoderReverse, Feedback *feedback, ServoControl *control, bool useFastHardwareTimers = true);
|
||||||
|
|
||||||
|
// sets up the servo motor
|
||||||
|
bool init();
|
||||||
|
|
||||||
|
// returns the number of parameters from the motor/driver
|
||||||
|
uint8_t getParameterCount() { return Motor::getParameterCount() + driver->getParameterCount() + feedback->getParameterCount(); }
|
||||||
|
|
||||||
|
// returns the specified axis parameter
|
||||||
|
AxisParameter* getParameter(uint8_t number) {
|
||||||
|
if (number > Motor::getParameterCount() + driver->getParameterCount()) return feedback->getParameter(number - (Motor::getParameterCount() + driver->getParameterCount())); else
|
||||||
|
if (number > Motor::getParameterCount()) return driver->getParameter(number - Motor::getParameterCount()); else
|
||||||
|
if (number >= 1 && number <= Motor::getParameterCount()) return Motor::getParameter(number); else
|
||||||
|
return &invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if parameter is valid
|
||||||
|
bool parameterIsValid(AxisParameter* parameter, bool next = false) { if (!Motor::parameterIsValid(parameter, next)) return false; else return driver->parameterIsValid(parameter, next); }
|
||||||
|
|
||||||
|
// sets reversal of axis directions
|
||||||
|
// \param state: true reverses the direction behavior specified in settings
|
||||||
|
void setReverse(int8_t state);
|
||||||
|
|
||||||
|
// sets motor enable on/off (if possible)
|
||||||
|
void enable(bool value);
|
||||||
|
|
||||||
|
// get the associated motor driver status
|
||||||
|
DriverStatus getDriverStatus();
|
||||||
|
|
||||||
|
// resets motor and target angular position in steps, also zeros backlash and index
|
||||||
|
void resetPositionSteps(long value);
|
||||||
|
|
||||||
|
// get instrument coordinate, in steps
|
||||||
|
long getInstrumentCoordinateSteps();
|
||||||
|
|
||||||
|
// set instrument coordinate, in steps
|
||||||
|
void setInstrumentCoordinateSteps(long value);
|
||||||
|
|
||||||
|
// distance to target in steps (+/-)
|
||||||
|
long getTargetDistanceSteps();
|
||||||
|
|
||||||
|
// get tracking mode steps per slewing mode step
|
||||||
|
inline int getStepsPerStepSlewing() { return 256; }
|
||||||
|
|
||||||
|
// sets overall maximum frequency (also allows for 10% over)
|
||||||
|
// \param frequency: rate of motion in steps (counts) per second
|
||||||
|
void setFrequencyMax(float frequency) {
|
||||||
|
velocityMax = frequency;
|
||||||
|
if (velocityMax < 1.0F) velocityMax = 1.0F;
|
||||||
|
driver->setFrequencyMax(frequency*1.1F);
|
||||||
|
feedback->setControlRange(frequency*1.1F);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get movement frequency in steps per second
|
||||||
|
float getFrequencySteps();
|
||||||
|
|
||||||
|
// set frequency (+/-) in steps per second negative frequencies move reverse in direction (0 stops motion)
|
||||||
|
void setFrequencySteps(float frequency);
|
||||||
|
|
||||||
|
// set slewing state (hint that we are about to slew or are done slewing)
|
||||||
|
void setSlewing(bool state);
|
||||||
|
|
||||||
|
// calibrate the motor driver
|
||||||
|
void calibrateDriver() { if (ready) driver->calibrateDriver(); }
|
||||||
|
|
||||||
|
// get encoder count
|
||||||
|
int32_t getEncoderCount() { if (ready) return encoder->count; else return 0; }
|
||||||
|
|
||||||
|
// set zero of absolute encoders
|
||||||
|
uint32_t encoderZero();
|
||||||
|
|
||||||
|
// set origin of absolute encoders
|
||||||
|
void encoderSetOrigin(uint32_t origin) { if (ready) encoder->setOrigin(origin); }
|
||||||
|
|
||||||
|
bool hasAbsoluteEncoder() const override { return encoder != nullptr && encoder->isAbsolute(); }
|
||||||
|
|
||||||
|
// read encoder
|
||||||
|
int32_t encoderRead();
|
||||||
|
|
||||||
|
// get the motor name
|
||||||
|
const char* name() { strcpy(nameStr, "Servo, "); strcat(nameStr, driver->name()); return nameStr; }
|
||||||
|
|
||||||
|
// updates PID and sets servo motor power/direction
|
||||||
|
void poll();
|
||||||
|
|
||||||
|
// sets dir as required and moves coord toward target at setFrequencySteps() rate
|
||||||
|
void move();
|
||||||
|
|
||||||
|
// servo motor driver
|
||||||
|
ServoDriver *driver;
|
||||||
|
|
||||||
|
// servo encoder
|
||||||
|
Encoder *encoder;
|
||||||
|
|
||||||
|
float velocityPercent = 0.0F;
|
||||||
|
long delta = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void stopSyntheticMotion();
|
||||||
|
void resetToTrackingBaseline();
|
||||||
|
|
||||||
|
Filter *filter;
|
||||||
|
|
||||||
|
void (*callback)() = NULL;
|
||||||
|
|
||||||
|
Feedback *feedback;
|
||||||
|
ServoControl *control;
|
||||||
|
#ifdef CALIBRATE_SERVO_DC
|
||||||
|
ServoCalibrateTrackingVelocity *calibrateVelocity;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uint8_t servoMonitorHandle = 0;
|
||||||
|
uint8_t taskHandle = 0;
|
||||||
|
|
||||||
|
float maxFrequency = HAL_FRACTIONAL_SEC; // fastest timer rate
|
||||||
|
float maxFrequency2, maxFrequency4, maxFrequency8, maxFrequency16, maxFrequency32, maxFrequency64, maxFrequency128;
|
||||||
|
bool useFastHardwareTimers = true;
|
||||||
|
|
||||||
|
bool encoderReverse = false;
|
||||||
|
bool encoderReverseDefault = false;
|
||||||
|
volatile int8_t encoderDirection = 0;
|
||||||
|
int32_t lastEnc = 0;
|
||||||
|
uint32_t lastUs = 0;
|
||||||
|
|
||||||
|
bool motorStepsInitDone = false; // help determining when absolute position is initialized
|
||||||
|
bool homeSet = false; // help determining when startup home/origin was established
|
||||||
|
uint32_t encoderOrigin = 0; // the starting position
|
||||||
|
|
||||||
|
int stepSize = 1; // step size
|
||||||
|
volatile int homeSteps = 1; // step count for microstep sequence between home positions (driver indexer)
|
||||||
|
volatile bool takeStep = false; // should we take a step
|
||||||
|
float trackingFrequency = 0; // help figure out if equatorial mount is tracking
|
||||||
|
bool slewing = false;
|
||||||
|
|
||||||
|
float currentDirection = 0.0F; // last direction
|
||||||
|
float currentFrequency = 0.0F; // last frequency set in encoder counts per second
|
||||||
|
float lastFrequency = 0.0F; // last frequency requested
|
||||||
|
unsigned long lastPeriod = 0; // last timer period (in sub-micros)
|
||||||
|
float velocityMax = 0.0F; // the maximum velocity allowed
|
||||||
|
|
||||||
|
volatile int absStep = 1; // absolute step size (unsigned)
|
||||||
|
// servo safety checks
|
||||||
|
unsigned long lastCheckTime = 0; // time since the last encoder position was checked
|
||||||
|
unsigned long startTime = 0; // time at start of servo polling
|
||||||
|
unsigned long lastSlewingTime = 0; // time when last slewing
|
||||||
|
long lastEncoderCounts = 0; // the last encoder position for stall check
|
||||||
|
long movingAwaySeconds = 0; // amount of time for runaway check
|
||||||
|
long lastTargetDistance = 0; // check if moving away from target for runaway check
|
||||||
|
long lastDelta = 0; // the last distance from target for runaway check
|
||||||
|
bool wasAbove33 = false; // check for oscillation
|
||||||
|
bool wasBelow33 = false; // check for oscillation
|
||||||
|
bool safetyShutdown = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+170
@@ -0,0 +1,170 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis servo motor driver
|
||||||
|
|
||||||
|
#include "ServoDriver.h"
|
||||||
|
|
||||||
|
#ifdef SERVO_MOTOR_PRESENT
|
||||||
|
|
||||||
|
// the various servo driver models
|
||||||
|
#define SERVO_DRIVER_MODEL_COUNT (SERVO_DRIVER_LAST - SERVO_DRIVER_FIRST + 1)
|
||||||
|
|
||||||
|
#include "../../../gpioEx/GpioEx.h"
|
||||||
|
|
||||||
|
#include "../Motor.h"
|
||||||
|
|
||||||
|
#if DEBUG != OFF
|
||||||
|
const char* SERVO_DRIVER_NAME[SERVO_DRIVER_MODEL_COUNT] =
|
||||||
|
{
|
||||||
|
"SERVO_PE", // Phase (Direction)/Enable
|
||||||
|
"SERVO_EE", // Enable/Enable
|
||||||
|
"SERVO_TMC2130_DC", // TMC2130 w/ DC motor
|
||||||
|
"SERVO_TMC5160_DC", // TMC5160 w/ DC motor
|
||||||
|
"SERVO_TMC2209", // TMC2209 w/ stepper motor
|
||||||
|
"SERVO_TMC5160", // TMC5160 w/ stepper motor
|
||||||
|
"SERVO_KTECH" // KTech servo motor using velocity control
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ServoDriver::ServoDriver(uint8_t axisNumber, const ServoPins *Pins, const ServoSettings *Settings) {
|
||||||
|
if (axisNumber < 1 || axisNumber > 9) return;
|
||||||
|
|
||||||
|
this->axisNumber = axisNumber;
|
||||||
|
|
||||||
|
this->Pins = Pins;
|
||||||
|
if (Pins != NULL) {
|
||||||
|
enablePin = Pins->enable;
|
||||||
|
enabledState = Pins->enabledState;
|
||||||
|
faultPin = Pins->fault;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->Settings = Settings;
|
||||||
|
driverModel = Settings->model;
|
||||||
|
statusMode = Settings->status;
|
||||||
|
|
||||||
|
acceleration.valueDefault = Settings->acceleration;
|
||||||
|
zeroDeadband.valueDefault = 0.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ServoDriver::init(bool reverse) {
|
||||||
|
#if DEBUG == VERBOSE
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("init model "); VL(SERVO_DRIVER_NAME[driverModel - SERVO_DRIVER_FIRST]);
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("en=");
|
||||||
|
if (enablePin == OFF) { VLF("OFF"); } else
|
||||||
|
if (enablePin == SHARED) { VLF("SHARED"); } else { VL(enablePin); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// init default driver control pins
|
||||||
|
if (enablePin != SHARED) {
|
||||||
|
pinModeEx(enablePin, OUTPUT);
|
||||||
|
digitalWriteEx(enablePin, !enabledState);
|
||||||
|
}
|
||||||
|
|
||||||
|
// automatically set fault status for known drivers
|
||||||
|
status.active = statusMode != OFF;
|
||||||
|
if (statusMode == ON) statusMode = LOW;
|
||||||
|
if (statusMode == LOW) pinModeEx(faultPin, INPUT_PULLUP);
|
||||||
|
#ifdef PULLDOWN
|
||||||
|
if (statusMode == HIGH) pinModeEx(faultPin, INPUT_PULLDOWN);
|
||||||
|
#else
|
||||||
|
if (statusMode == HIGH) pinModeEx(faultPin, INPUT);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
reversed = reverse;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoDriver::enable(bool state) {
|
||||||
|
enabled = state;
|
||||||
|
|
||||||
|
// Only touch a real, dedicated enable pin
|
||||||
|
if (enablePin != OFF && enablePin != SHARED) {
|
||||||
|
digitalWriteEx(enablePin, state ? enabledState : !enabledState);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default behavior: if disabled, force ramp to 0 so outputs converge quickly
|
||||||
|
if (!state) velocityRamp = 0.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoDriver::setFrequencyMax(float frequency) {
|
||||||
|
velocityMax = frequency;
|
||||||
|
InvVelocityMax = 1.0F/frequency;
|
||||||
|
|
||||||
|
normalizedAcceleration = (acceleration.value/100.0F)*velocityMax;
|
||||||
|
accelerationFs = normalizedAcceleration/FRACTIONAL_SEC;
|
||||||
|
|
||||||
|
// show velocity control settings
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("Vmax="); V(velocityMax); VLF(" steps/s");
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("Acceleration="); V(acceleration.value); VF("%/s/s ("); V(accelerationFs); VLF(" steps/s/fs)");
|
||||||
|
}
|
||||||
|
|
||||||
|
float ServoDriver::setMotorVelocity(float velocity) {
|
||||||
|
if (!enabled) velocity = 0.0F;
|
||||||
|
|
||||||
|
if (zeroDeadband.value > 0.0F && fabsf(velocity) < zeroDeadband.value) velocity = 0.0F;
|
||||||
|
|
||||||
|
if (velocity > velocityMax) velocity = velocityMax; else
|
||||||
|
if (velocity < -velocityMax) velocity = -velocityMax;
|
||||||
|
|
||||||
|
if(bypassAccelOnTracking)
|
||||||
|
velocityRamp = velocity;
|
||||||
|
else {
|
||||||
|
// ramp velocity
|
||||||
|
if (velocity > velocityRamp) {
|
||||||
|
velocityRamp += accelerationFs;
|
||||||
|
if (velocityRamp > velocity) velocityRamp = velocity;
|
||||||
|
} else
|
||||||
|
if (velocity < velocityRamp) {
|
||||||
|
velocityRamp -= accelerationFs;
|
||||||
|
if (velocityRamp < velocity) velocityRamp = velocity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (velocityRamp >= 0.0F) motorDirection = DIR_FORWARD; else motorDirection = DIR_REVERSE;
|
||||||
|
|
||||||
|
return velocityRamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// update status info. for driver
|
||||||
|
void ServoDriver::updateStatus() {
|
||||||
|
if (statusMode == ON) {
|
||||||
|
const unsigned long now = millis();
|
||||||
|
|
||||||
|
if ((long)(now - timeLastStatusUpdate) > 200L) {
|
||||||
|
readStatus();
|
||||||
|
|
||||||
|
// open load indication is not reliable in standstill
|
||||||
|
if (status.outputA.shortToGround ||
|
||||||
|
status.outputB.shortToGround ||
|
||||||
|
status.overTemperatureWarning ||
|
||||||
|
status.overTemperature) status.fault = true; else status.fault = false;
|
||||||
|
|
||||||
|
timeLastStatusUpdate = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DEBUG == VERBOSE
|
||||||
|
if (status.standstill) { status.outputA.openLoad = false; status.outputB.openLoad = false; status.standstill = false; }
|
||||||
|
if ((status.outputA.shortToGround != lastStatus.outputA.shortToGround) ||
|
||||||
|
(status.outputA.openLoad != lastStatus.outputA.openLoad) ||
|
||||||
|
(status.outputB.shortToGround != lastStatus.outputB.shortToGround) ||
|
||||||
|
(status.outputB.openLoad != lastStatus.outputB.openLoad) ||
|
||||||
|
(status.overTemperatureWarning != lastStatus.overTemperatureWarning) ||
|
||||||
|
(status.overTemperature != lastStatus.overTemperature) ||
|
||||||
|
(status.standstill != lastStatus.standstill) ||
|
||||||
|
(status.fault != lastStatus.fault)) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("status change ");
|
||||||
|
VF("SGA"); if (status.outputA.shortToGround) VF("< "); else VF(". ");
|
||||||
|
VF("OLA"); if (status.outputA.openLoad) VF("< "); else VF(". ");
|
||||||
|
VF("SGB"); if (status.outputB.shortToGround) VF("< "); else VF(". ");
|
||||||
|
VF("OLB"); if (status.outputB.openLoad) VF("< "); else VF(". ");
|
||||||
|
VF("OTP"); if (status.overTemperatureWarning) VF("< "); else VF(". ");
|
||||||
|
VF("OTE"); if (status.overTemperature) VF("< "); else VF(". ");
|
||||||
|
VF("SST"); if (status.standstill) VF("< "); else VF(". ");
|
||||||
|
VF("FLT"); if (status.fault) VLF("<"); else VLF(".");
|
||||||
|
}
|
||||||
|
lastStatus = status;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+135
@@ -0,0 +1,135 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis servo motor driver
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "../../../../Common.h"
|
||||||
|
|
||||||
|
#include "../Drivers.h"
|
||||||
|
#include "../Motor.h"
|
||||||
|
|
||||||
|
#ifdef SERVO_MOTOR_PRESENT
|
||||||
|
|
||||||
|
typedef struct ServoPins {
|
||||||
|
int16_t ph1; // step
|
||||||
|
int16_t ph1State;
|
||||||
|
int16_t ph2; // dir
|
||||||
|
int16_t ph2State;
|
||||||
|
int16_t enable;
|
||||||
|
uint8_t enabledState;
|
||||||
|
int16_t m0;
|
||||||
|
int16_t m1;
|
||||||
|
int16_t m2;
|
||||||
|
int16_t m3;
|
||||||
|
int16_t fault;
|
||||||
|
} ServoPins;
|
||||||
|
|
||||||
|
typedef struct ServoSettings {
|
||||||
|
int16_t model;
|
||||||
|
int8_t status;
|
||||||
|
int32_t acceleration; // acceleration in encoder %/s/s
|
||||||
|
} ServoSettings;
|
||||||
|
|
||||||
|
class ServoDriver {
|
||||||
|
public:
|
||||||
|
ServoDriver(uint8_t axisNumber, const ServoPins *Pins, const ServoSettings *Settings);
|
||||||
|
|
||||||
|
// decodes driver model and sets up the pin modes
|
||||||
|
virtual bool init(bool reverse);
|
||||||
|
|
||||||
|
// returns the number of axis parameters
|
||||||
|
virtual uint8_t getParameterCount() { return numParameters; }
|
||||||
|
|
||||||
|
// returns the specified axis parameter
|
||||||
|
virtual AxisParameter* getParameter(uint8_t number) { if (number > numParameters) return &invalid; else return parameter[number]; }
|
||||||
|
|
||||||
|
// check if axis parameter is valid
|
||||||
|
virtual bool parameterIsValid(AxisParameter* parameter, bool next = false) { return true; }
|
||||||
|
|
||||||
|
// alternate mode for movement
|
||||||
|
virtual void alternateMode(bool state) { UNUSED(state); }
|
||||||
|
|
||||||
|
// enable or disable the driver using the enable pin or other method
|
||||||
|
virtual void enable(bool state);
|
||||||
|
|
||||||
|
// sets frequency corrosponding to the fastest allowed slew rate
|
||||||
|
// \param frequency: rate of motion in steps (counts) per second
|
||||||
|
void setFrequencyMax(float frequency);
|
||||||
|
|
||||||
|
// set motor velocity
|
||||||
|
// \param velocity as needed to reach the target position, in signed encoder counts per second
|
||||||
|
virtual float setMotorVelocity(float velocity);
|
||||||
|
|
||||||
|
// set motor velocity
|
||||||
|
// \param velocity as needed to reach the target position, in signed encoder counts per second
|
||||||
|
// \param encoderVelocity in signed encoder counts per second
|
||||||
|
// \returns velocity in effect, in signed encoder counts per second
|
||||||
|
virtual float setMotorVelocity(float velocity, float encoderVelocity) {
|
||||||
|
UNUSED(encoderVelocity);
|
||||||
|
return setMotorVelocity(velocity);
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns motor direction (DIR_FORWARD or DIR_REVERSE)
|
||||||
|
Direction getMotorDirection() { return motorDirection; };
|
||||||
|
|
||||||
|
// update status info. for driver
|
||||||
|
// this is a required method for the Axis class
|
||||||
|
virtual void updateStatus();
|
||||||
|
|
||||||
|
// get status info.
|
||||||
|
// this is a required method for the Axis class
|
||||||
|
DriverStatus getStatus() { return status; }
|
||||||
|
|
||||||
|
// do not use acceleration while trackings
|
||||||
|
void setBypassAccelOnTracking(bool on) { bypassAccelOnTracking = on; }
|
||||||
|
|
||||||
|
// calibrate the motor if required
|
||||||
|
virtual void calibrateDriver() {}
|
||||||
|
|
||||||
|
// get the driver name
|
||||||
|
virtual const char* name() { return NULL; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void readStatus() {}
|
||||||
|
|
||||||
|
int axisNumber;
|
||||||
|
char axisPrefix[32]; // prefix for debug messages
|
||||||
|
|
||||||
|
int16_t driverModel;
|
||||||
|
int16_t statusMode;
|
||||||
|
|
||||||
|
DriverStatus status = { false, {false, false}, {false, false}, false, false, false, false };
|
||||||
|
#if DEBUG != OFF
|
||||||
|
DriverStatus lastStatus = {false, {false, false}, {false, false}, false, false, false, false};
|
||||||
|
#endif
|
||||||
|
unsigned long timeLastStatusUpdate = 0;
|
||||||
|
|
||||||
|
float normalizedAcceleration; // in encoder counts/s/s
|
||||||
|
float accelerationFs; // in encoder counts/s/fs
|
||||||
|
float velocityRamp = 1.0F; // regulate velocity changes
|
||||||
|
float velocityMax = 1.0F; // frequency corrosponding to the fastest allowed slew rate, in encoder counts/s
|
||||||
|
float InvVelocityMax = 1.0F;
|
||||||
|
|
||||||
|
Direction motorDirection = DIR_FORWARD;
|
||||||
|
bool reversed = false;
|
||||||
|
|
||||||
|
int16_t enablePin = OFF;
|
||||||
|
uint8_t enabledState = LOW;
|
||||||
|
bool enabled = false;
|
||||||
|
int16_t faultPin = OFF;
|
||||||
|
bool bypassAccelOnTracking = false;
|
||||||
|
|
||||||
|
const ServoPins *Pins;
|
||||||
|
const ServoSettings *Settings;
|
||||||
|
|
||||||
|
// runtime adjustable settings
|
||||||
|
AxisParameter invalid = {NAN, NAN, NAN, NAN, NAN, AXP_INVALID, ""};
|
||||||
|
AxisParameter acceleration = {NAN, NAN, NAN, 0, 100000, AXP_FLOAT, AXPN_MAX_ACCEL};
|
||||||
|
AxisParameter zeroDeadband = {NAN, NAN, NAN, 0.0, 500.0, AXP_FLOAT_IMMEDIATE, "Deadband, cps"};
|
||||||
|
|
||||||
|
// this array list isn't used if overridden, just a place holder!
|
||||||
|
const int numParameters = 2;
|
||||||
|
AxisParameter* parameter[3] = {&invalid, &acceleration, &zeroDeadband};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
+167
@@ -0,0 +1,167 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis servo DC motor driver
|
||||||
|
|
||||||
|
#include "DcServoDriver.h"
|
||||||
|
|
||||||
|
#if defined(SERVO_PE_PRESENT) || defined(SERVO_EE_PRESENT) || \
|
||||||
|
defined(SERVO_TMC2130_DC_PRESENT) || defined(SERVO_TMC5160_DC_PRESENT)
|
||||||
|
|
||||||
|
#include "../../../../gpioEx/GpioEx.h"
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
ServoDcDriver::ServoDcDriver(uint8_t axisNumber, const ServoPins *Pins, const ServoSettings *Settings,
|
||||||
|
float pwmMinimum, float pwmMaximum)
|
||||||
|
:ServoDriver(axisNumber, Pins, Settings) {
|
||||||
|
if (axisNumber < 1 || axisNumber > 9) return;
|
||||||
|
|
||||||
|
this->pwmMinimum.valueDefault = pwmMinimum;
|
||||||
|
this->pwmMaximum.valueDefault = pwmMaximum;
|
||||||
|
|
||||||
|
dirDeadTimeMs.valueDefault = 0.0F;
|
||||||
|
#if SERVO_DC_VPID == ON
|
||||||
|
velKp.valueDefault = 0.2F;
|
||||||
|
velKi.valueDefault = 0.5F;
|
||||||
|
velIMax.valueDefault = 0.2F;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if SERVO_DC_VPID == ON
|
||||||
|
|
||||||
|
float ServoDcDriver::setMotorVelocity(float velocity, float encoderVelocity) {
|
||||||
|
velocity = ServoDriver::setMotorVelocity(velocity);
|
||||||
|
|
||||||
|
if (velocity == 0.0F) {
|
||||||
|
pwmUpdate(0.0F);
|
||||||
|
vI = 0.0F;
|
||||||
|
velLastUs = 0;
|
||||||
|
lastEffectiveDirection = 0;
|
||||||
|
return 0.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
const float vmag = fabsf(velocity);
|
||||||
|
const int8_t dir = (velocity > 0.0F) ? 1 : -1;
|
||||||
|
|
||||||
|
const unsigned long nowMs = millis();
|
||||||
|
if (lastEffectiveDirection != 0 && dir != lastEffectiveDirection) {
|
||||||
|
const unsigned long dtMs = (unsigned long)lroundf(dirDeadTimeMs.value);
|
||||||
|
if (dtMs) dirHoldUntilMs = nowMs + dtMs;
|
||||||
|
vI = 0.0F;
|
||||||
|
velLastUs = 0;
|
||||||
|
}
|
||||||
|
lastEffectiveDirection = dir;
|
||||||
|
|
||||||
|
if ((long)(dirHoldUntilMs - nowMs) > 0) {
|
||||||
|
pwmUpdate(0.0F);
|
||||||
|
return 0.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
const float dMin = pwmMinimum.value * 0.01F;
|
||||||
|
const float dMax0 = pwmMaximum.value * 0.01F;
|
||||||
|
const float dMax = (dMax0 >= dMin) ? dMax0 : dMin;
|
||||||
|
const float dSpan = dMax - dMin;
|
||||||
|
|
||||||
|
float vcmd01 = vmag * InvVelocityMax;
|
||||||
|
if (vcmd01 > 1.0F) vcmd01 = 1.0F;
|
||||||
|
|
||||||
|
const uint32_t nowUs = micros();
|
||||||
|
uint32_t dUs = nowUs - velLastUs;
|
||||||
|
if (velLastUs == 0) dUs = 0;
|
||||||
|
velLastUs = nowUs;
|
||||||
|
|
||||||
|
// measured velocity projected onto commanded direction and normalized
|
||||||
|
encoderVelocity *= (float)dir;
|
||||||
|
const float vmeas01 = encoderVelocity * InvVelocityMax;
|
||||||
|
const float error01 = vcmd01 - vmeas01;
|
||||||
|
|
||||||
|
float u01 = vcmd01 + (velKp.value * error01) + vI;
|
||||||
|
|
||||||
|
float uSat = u01;
|
||||||
|
if (uSat < 0.0F) uSat = 0.0F;
|
||||||
|
else if (uSat > 1.0F) uSat = 1.0F;
|
||||||
|
|
||||||
|
if (velKi.value > 0.0F && dUs > 0 && dUs <= 200000U) {
|
||||||
|
const bool atLo = (uSat <= 0.0F);
|
||||||
|
const bool atHi = (uSat >= 1.0F);
|
||||||
|
const bool allowI =
|
||||||
|
(!atLo && !atHi) ||
|
||||||
|
(atLo && error01 > 0.0F) ||
|
||||||
|
(atHi && error01 < 0.0F);
|
||||||
|
|
||||||
|
if (allowI) {
|
||||||
|
vI += velKi.value * error01 * (dUs * 0.000001F);
|
||||||
|
|
||||||
|
const float imax = velIMax.value;
|
||||||
|
if (vI > imax) vI = imax;
|
||||||
|
else if (vI < -imax) vI = -imax;
|
||||||
|
|
||||||
|
u01 = vcmd01 + (velKp.value * error01) + vI;
|
||||||
|
uSat = u01;
|
||||||
|
if (uSat < 0.0F) uSat = 0.0F;
|
||||||
|
else if (uSat > 1.0F) uSat = 1.0F;
|
||||||
|
}
|
||||||
|
} else if (dUs > 200000U) {
|
||||||
|
vI = 0.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
float dutyMag01 = 0.0F;
|
||||||
|
if (uSat > 0.0F) {
|
||||||
|
dutyMag01 = dMin + dSpan * uSat;
|
||||||
|
if (dutyMag01 > dMax) dutyMag01 = dMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
pwmUpdate(dutyMag01 * (float)dir);
|
||||||
|
return velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
float ServoDcDriver::setMotorVelocity(float velocity, float /*encoderVelocity*/) {
|
||||||
|
velocity = ServoDriver::setMotorVelocity(velocity);
|
||||||
|
|
||||||
|
if (velocity == 0.0F) {
|
||||||
|
pwmUpdate(0.0F);
|
||||||
|
velLastUs = 0;
|
||||||
|
lastEffectiveDirection = 0;
|
||||||
|
return 0.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
const float vmag = fabsf(velocity);
|
||||||
|
const int8_t dir = (velocity > 0.0F) ? 1 : -1;
|
||||||
|
|
||||||
|
const unsigned long nowMs = millis();
|
||||||
|
if (lastEffectiveDirection != 0 && dir != lastEffectiveDirection) {
|
||||||
|
const unsigned long dtMs = (unsigned long)lroundf(dirDeadTimeMs.value);
|
||||||
|
if (dtMs) dirHoldUntilMs = nowMs + dtMs;
|
||||||
|
velLastUs = 0;
|
||||||
|
}
|
||||||
|
lastEffectiveDirection = dir;
|
||||||
|
|
||||||
|
if ((long)(dirHoldUntilMs - nowMs) > 0) {
|
||||||
|
pwmUpdate(0.0F);
|
||||||
|
return 0.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
const float dMin = pwmMinimum.value * 0.01F;
|
||||||
|
const float dMax0 = pwmMaximum.value * 0.01F;
|
||||||
|
const float dMax = (dMax0 >= dMin) ? dMax0 : dMin;
|
||||||
|
const float dSpan = dMax - dMin;
|
||||||
|
|
||||||
|
float vcmd01 = vmag * InvVelocityMax;
|
||||||
|
if (vcmd01 > 1.0F) vcmd01 = 1.0F;
|
||||||
|
|
||||||
|
// feedforward-only: uSat = vcmd01
|
||||||
|
const float uSat = vcmd01;
|
||||||
|
|
||||||
|
float dutyMag01 = 0.0F;
|
||||||
|
if (uSat > 0.0F) {
|
||||||
|
dutyMag01 = dMin + dSpan * uSat;
|
||||||
|
if (dutyMag01 > dMax) dutyMag01 = dMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
pwmUpdate(dutyMag01 * (float)dir);
|
||||||
|
return velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+65
@@ -0,0 +1,65 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis servo DC motor driver
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "../../../../../Common.h"
|
||||||
|
|
||||||
|
#if defined(SERVO_PE_PRESENT) || defined(SERVO_EE_PRESENT) || defined(SERVO_TMC2130_DC_PRESENT) || defined(SERVO_TMC5160_DC_PRESENT)
|
||||||
|
|
||||||
|
#include "../ServoDriver.h"
|
||||||
|
|
||||||
|
#ifndef SERVO_DC_VPID
|
||||||
|
#if ENCODER_VELOCITY == ON
|
||||||
|
#define SERVO_DC_VPID ON
|
||||||
|
#else
|
||||||
|
#define SERVO_DC_VPID OFF
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class ServoDcDriver : public ServoDriver {
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
ServoDcDriver(uint8_t axisNumber, const ServoPins *Pins, const ServoSettings *Settings, float pwmMinimum, float pwmMaximum);
|
||||||
|
|
||||||
|
// returns the number of axis parameters
|
||||||
|
uint8_t getParameterCount() { return numParameters; }
|
||||||
|
|
||||||
|
// returns the specified axis parameter
|
||||||
|
AxisParameter* getParameter(uint8_t number) { if (number > numParameters) return &invalid; else return parameter[number]; }
|
||||||
|
|
||||||
|
// set motor velocity
|
||||||
|
// \param velocity as needed to reach the target position, in signed encoder counts per second
|
||||||
|
// \param encoderVelocity in signed encoder counts per second
|
||||||
|
// \returns velocity in effect, in signed encoder counts per second
|
||||||
|
float setMotorVelocity(float velocity, float encoderVelocity) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// motor control pwm update
|
||||||
|
// \param power01 in -1.0 to 1.0 units
|
||||||
|
virtual void pwmUpdate(float power01) { }
|
||||||
|
|
||||||
|
// runtime adjustable settings
|
||||||
|
AxisParameter pwmMinimum = {NAN, NAN, NAN, 0.0, 100.0, AXP_FLOAT_IMMEDIATE, AXPN_MIN_PWR};
|
||||||
|
AxisParameter pwmMaximum = {NAN, NAN, NAN, 1.0, 100.0, AXP_FLOAT_IMMEDIATE, AXPN_MAX_PWR};
|
||||||
|
AxisParameter dirDeadTimeMs = {NAN, NAN, NAN, 0.0, 50.0, AXP_FLOAT_IMMEDIATE, "Deadtime, ms"};
|
||||||
|
#if SERVO_DC_VPID == ON
|
||||||
|
AxisParameter velKp = {NAN, NAN, NAN, 0.0, 10.0, AXP_FLOAT_IMMEDIATE, "Vel Kp"};
|
||||||
|
AxisParameter velKi = {NAN, NAN, NAN, 0.0, 10.0, AXP_FLOAT_IMMEDIATE, "Vel Ki"};
|
||||||
|
AxisParameter velIMax = {NAN, NAN, NAN, 0.0, 1.0, AXP_FLOAT_IMMEDIATE, "Vel Imax"};
|
||||||
|
const int numParameters = 8;
|
||||||
|
AxisParameter* parameter[9] = {&invalid, &acceleration, &zeroDeadband, &pwmMinimum, &pwmMaximum, &dirDeadTimeMs, &velKp, &velKi, &velIMax};
|
||||||
|
#else
|
||||||
|
const int numParameters = 5;
|
||||||
|
AxisParameter* parameter[6] = {&invalid, &acceleration, &zeroDeadband, &pwmMinimum, &pwmMaximum, &dirDeadTimeMs};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
float vI = 0.0F;
|
||||||
|
uint32_t velLastUs = 0;
|
||||||
|
uint32_t dirHoldUntilMs = 0;
|
||||||
|
int8_t lastEffectiveDirection = 0; // -1,0,+1
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,746 @@
|
|||||||
|
// ============================== TrackingVelocity.cpp ===============================
|
||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// Servo Tracking Velocity Calibration — Overview
|
||||||
|
//
|
||||||
|
// Goal
|
||||||
|
// Calibrate, per direction, the minimum open-loop *driver command percent* (“u”, % of
|
||||||
|
// the driver’s velocity range) that:
|
||||||
|
// • breaks stiction from rest (u_break)
|
||||||
|
// • sustains motion after a short kick (u_hold)
|
||||||
|
//
|
||||||
|
// Mode (Open-loop)
|
||||||
|
// While calibration is active (experimentMode=true) the axis runs open-loop:
|
||||||
|
// • Tracking/PID/hysteresis/nonlinear helpers are disabled in this TU
|
||||||
|
// • The driver is fed a fixed *command %* (experimentVelocity), interpreted as a
|
||||||
|
// fraction of the driver’s max velocity capability (not a PWM duty cycle)
|
||||||
|
// • “Velocity” in the logs means encoder-derived steps/s (not a PID setpoint)
|
||||||
|
//
|
||||||
|
// Per-direction phases
|
||||||
|
// 1) Stiction Break (u_break)
|
||||||
|
// - Staircase upward from SERVO_CALIBRATION_START_VELOCITY_PERCENT.
|
||||||
|
// - Between steps, STOP and wait SERVO_CALIBRATION_MOTOR_SETTLE_TIME ms to kill carry-over.
|
||||||
|
// - Acceptance rule: must meet the SAME consecutive-moving requirement as u_hold
|
||||||
|
// (SERVO_CALIBRATION_REQUIRED_MOVING_SAMPLES). UB additionally enforces a hard
|
||||||
|
// per-candidate sample cap (SERVO_CAL_UB_MAX_SAMPLES) to avoid indefinite waiting.
|
||||||
|
// 2) Velocity Hold (u_hold)
|
||||||
|
// - From u_break, staircase downward to find the minimum command % that keeps moving.
|
||||||
|
// - Each candidate is kick-started at u_break, then held at the candidate %.
|
||||||
|
// - Acceptance rule: SAME consecutive-moving requirement. Any failed sample
|
||||||
|
// immediately stalls the candidate.
|
||||||
|
//
|
||||||
|
// Reporting/imbalance
|
||||||
|
// After both directions finish, an imbalance warning is logged if FWD/REV u_hold
|
||||||
|
// differ beyond SERVO_CALIBRATION_IMBALANCE_ERROR_THRESHOLD.
|
||||||
|
//
|
||||||
|
// ------------------------------ How the state machine works -------------------------
|
||||||
|
// There are TWO interleaved state machines:
|
||||||
|
//
|
||||||
|
// (A) High-level PHASE machine (per axis) [CalibrationState]:
|
||||||
|
// IDLE → U_BREAK → U_HOLD → (flip direction) → U_BREAK → U_HOLD → CHECK_IMBALANCE
|
||||||
|
// ↘ (if both axes enabled) WAIT_PEER
|
||||||
|
// If both axes are enabled, we serialize execution RA first, DEC second via WAIT_TURN.
|
||||||
|
//
|
||||||
|
// (B) Motor SUB-STATE machine (per axis) [MotorState]:
|
||||||
|
// STOPPED ↔ SETTLING → (start test) → KICKING → HOLDING → RUNNING_STEADY
|
||||||
|
//
|
||||||
|
// - SETTLING: enforced pause after STOP to let motion decay.
|
||||||
|
// - KICKING: briefly command u_break to overcome stiction for a u_hold test.
|
||||||
|
// - HOLDING: hold candidate % and sample velocity at fixed cadence.
|
||||||
|
// - RUNNING_STEADY: means “accepted as moving” (name kept for API compatibility).
|
||||||
|
//
|
||||||
|
// ------------------------------ “Motor moved?” decision -----------------------------
|
||||||
|
// At each HOLDING sample (every SERVO_CALIBRATION_VELOCITY_SETTLE_CHECK_INTERVAL ms):
|
||||||
|
// - Compute instantaneous velocity from encoder/step deltas.
|
||||||
|
// - Accept a single sample as MOVING if BOTH are true:
|
||||||
|
// • |velocity| > SERVO_CALIBRATION_MIN_DETECTABLE_VELOCITY (noise floor guard)
|
||||||
|
// • |deltaCounts| ≥ SERVO_CALIBRATION_MIN_COUNTS_PER_SAMPLE (minimum progress)
|
||||||
|
//
|
||||||
|
// Acceptance rule (shared by UB & UH):
|
||||||
|
// - Require SERVO_CALIBRATION_REQUIRED_MOVING_SAMPLES consecutive MOVING samples
|
||||||
|
// to accept the candidate as RUNNING_STEADY.
|
||||||
|
// - For u_hold (UH): any non-moving sample immediately fails the candidate.
|
||||||
|
// - For u_break (UB): keep sampling until a small cap (SERVO_CAL_UB_MAX_SAMPLES);
|
||||||
|
// if we still haven’t reached the consecutive requirement, fail the candidate.
|
||||||
|
//
|
||||||
|
// ------------------------------ Two-axis coordination ------------------------------
|
||||||
|
// - Selection mask: CALIBRATE_SERVO_AXIS_SELECT (bit0=Axis1, bit1=Axis2). In this .cpp,
|
||||||
|
// 0 expands to “both” via SERVO_CAL_ALL_AXES_MASK (0x03).
|
||||||
|
// - Turn-taking: If both axes are enabled, Axis 1 runs first while Axis 2 waits
|
||||||
|
// in WAIT_TURN. When Axis 1 ends, it grants the turn to Axis 2.
|
||||||
|
// - Joint report: First finisher waits (WAIT_PEER) for the other; then a single
|
||||||
|
// combined report is printed.
|
||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "TrackingVelocity.h"
|
||||||
|
|
||||||
|
#if defined(SERVO_MOTOR_PRESENT) && defined(CALIBRATE_SERVO_DC)
|
||||||
|
|
||||||
|
// ---------- Compact logging helpers (one-line logs) ----------
|
||||||
|
static inline void LOG_HDR(const char* axisPrefix) { V(axisPrefix); VF(" "); }
|
||||||
|
static inline void LOG_DIR(bool fwd){ VF(fwd ? "F " : "R "); } // F=forward, R=reverse
|
||||||
|
static inline const char* PHASE_UB(){ return "UB"; } // u_break
|
||||||
|
static inline const char* PHASE_UH(){ return "UH"; } // u_hold
|
||||||
|
|
||||||
|
// Disable servo helpers during calibration (we want raw behavior)
|
||||||
|
#ifdef SERVO_HYSTERESIS_ENABLE
|
||||||
|
#undef SERVO_HYSTERESIS_ENABLE
|
||||||
|
#endif
|
||||||
|
#ifdef SERVO_STICTION_KICK
|
||||||
|
#undef SERVO_STICTION_KICK
|
||||||
|
#endif
|
||||||
|
#ifdef SERVO_NONLINEAR_ENABLE
|
||||||
|
#undef SERVO_NONLINEAR_ENABLE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TRACK_AUTOSTART
|
||||||
|
#undef TRACK_AUTOSTART
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ------------------------ UB sampling cap (avoid infinite wait) ---------------------
|
||||||
|
// UB uses the same consecutive requirement as UH, but we also enforce a hard cap on the
|
||||||
|
// total number of samples we will take for a single UB candidate before declaring STALLED.
|
||||||
|
#ifndef SERVO_CAL_UB_MAX_SAMPLES
|
||||||
|
#define SERVO_CAL_UB_MAX_SAMPLES 6
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// -------------------- Joint calibration coordination (for 2 axes) -------------------
|
||||||
|
struct AxisCalibSnapshot {
|
||||||
|
bool valid = false;
|
||||||
|
ServoCalibrateTrackingVelocity::DirectionData fwd;
|
||||||
|
ServoCalibrateTrackingVelocity::DirectionData rev;
|
||||||
|
char axisPrefix[32] = {0};
|
||||||
|
};
|
||||||
|
|
||||||
|
// 1-based index: [1] and [2] used; [0] unused
|
||||||
|
static volatile bool g_axisEnabledForCal[3] = {false,false,false};
|
||||||
|
static volatile bool g_axisDone[3] = {false,false,false};
|
||||||
|
static AxisCalibSnapshot g_snapshot[3];
|
||||||
|
static volatile bool g_jointReportPrinted = false;
|
||||||
|
|
||||||
|
// Turn-taking: 0 = none yet, 1 = Axis 1's turn, 2 = Axis 2's turn
|
||||||
|
static volatile uint8_t g_currentAxisTurn = 0;
|
||||||
|
|
||||||
|
static inline uint8_t otherAxis(uint8_t axis) { return axis == 1 ? 2 : 1; }
|
||||||
|
|
||||||
|
// Save final per-axis results for the joint report
|
||||||
|
static void snapshotAxisData(uint8_t axis,
|
||||||
|
const char* axisPrefix,
|
||||||
|
const ServoCalibrateTrackingVelocity::DirectionData& fwd,
|
||||||
|
const ServoCalibrateTrackingVelocity::DirectionData& rev) {
|
||||||
|
AxisCalibSnapshot &s = g_snapshot[axis];
|
||||||
|
s.valid = true;
|
||||||
|
s.fwd = fwd;
|
||||||
|
s.rev = rev;
|
||||||
|
snprintf(s.axisPrefix, sizeof(s.axisPrefix), "%s", axisPrefix ? axisPrefix : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print one axis table
|
||||||
|
static void printOneAxisTable(const AxisCalibSnapshot& s) {
|
||||||
|
ServoCalibrateTrackingVelocity::printReport(s.axisPrefix, s.fwd, s.rev);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print the combined report for both axes (if present)
|
||||||
|
static void printJointReport() {
|
||||||
|
VLF("\n===== Joint Servo Calibration =====");
|
||||||
|
if (g_snapshot[1].valid) printOneAxisTable(g_snapshot[1]);
|
||||||
|
if (g_snapshot[2].valid) printOneAxisTable(g_snapshot[2]);
|
||||||
|
|
||||||
|
if (g_snapshot[1].valid && g_snapshot[2].valid) {
|
||||||
|
float a1 = (g_snapshot[1].fwd.u_hold + g_snapshot[1].rev.u_hold) / 2.0f;
|
||||||
|
float a2 = (g_snapshot[2].fwd.u_hold + g_snapshot[2].rev.u_hold) / 2.0f;
|
||||||
|
float delta = fabsf(a1 - a2);
|
||||||
|
VF("Cross-axis avg u_hold delta: "); V(delta); VLF("%");
|
||||||
|
(void)delta; // silence if logs trimmed
|
||||||
|
}
|
||||||
|
VLF("==================================\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------
|
||||||
|
// Class methods
|
||||||
|
// ------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ServoCalibrateTrackingVelocity::ServoCalibrateTrackingVelocity(uint8_t axisNumber) {
|
||||||
|
this->axisNumber = axisNumber;
|
||||||
|
snprintf(axisPrefix, sizeof(axisPrefix), "Axis%d ServoCalibrate", axisNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoCalibrateTrackingVelocity::init() {
|
||||||
|
experimentVelocity = 0.0f;
|
||||||
|
experimentMode = false;
|
||||||
|
calibrationState = CALIBRATION_IDLE;
|
||||||
|
motorState = MOTOR_STOPPED;
|
||||||
|
|
||||||
|
resetCalibrationValues();
|
||||||
|
|
||||||
|
lastStateChangeTime = lastVelocityTime = settleStartTime =
|
||||||
|
calibrationStepStartTime = kickStartTime = 0;
|
||||||
|
currentTicks = calibrationStepStartTicks = lastTicks = 0;
|
||||||
|
lastVelocityMeasurement = 0.0f;
|
||||||
|
lastDeltaCounts = 0;
|
||||||
|
steadySinceMs = 0;
|
||||||
|
steadyStartTicks = 0;
|
||||||
|
lastCheckTime = 0;
|
||||||
|
|
||||||
|
staircaseIters = 0;
|
||||||
|
currentSearchVelocity = 0.0f;
|
||||||
|
foundValidMotion = false;
|
||||||
|
|
||||||
|
hasQueuedTest = false;
|
||||||
|
queuedState = CALIBRATION_IDLE;
|
||||||
|
queuedVelocity = 0.0f;
|
||||||
|
|
||||||
|
consecutiveMovingSamples = 0;
|
||||||
|
candidateSampleCount = 0;
|
||||||
|
|
||||||
|
if (axisNumber == 1) {
|
||||||
|
g_axisDone[1] = g_axisDone[2] = false;
|
||||||
|
g_axisEnabledForCal[1] = g_axisEnabledForCal[2] = false; // set in start()
|
||||||
|
g_snapshot[1] = AxisCalibSnapshot();
|
||||||
|
g_snapshot[2] = AxisCalibSnapshot();
|
||||||
|
g_jointReportPrinted = false;
|
||||||
|
g_currentAxisTurn = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
setVelocity(0);
|
||||||
|
startSettling();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoCalibrateTrackingVelocity::start(float trackingFrequency, long /*instrumentCoordinateSteps*/) {
|
||||||
|
// Expand 0 → all-axes mask, otherwise use the provided mask
|
||||||
|
const uint8_t effectiveMask =
|
||||||
|
(CALIBRATE_SERVO_AXIS_SELECT == 0) ? SERVO_CAL_ALL_AXES_MASK
|
||||||
|
: CALIBRATE_SERVO_AXIS_SELECT;
|
||||||
|
|
||||||
|
// Respect axis selection bitmask (skip if not requested)
|
||||||
|
if (!(effectiveMask & (1U << (axisNumber - 1)))) {
|
||||||
|
LOG_HDR(axisPrefix); VLF("skip");
|
||||||
|
g_axisEnabledForCal[axisNumber] = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_axisEnabledForCal[axisNumber] = true;
|
||||||
|
|
||||||
|
LOG_HDR(axisPrefix); VLF("start");
|
||||||
|
|
||||||
|
enabled = true;
|
||||||
|
experimentMode = true;
|
||||||
|
calibrationDirectionIsForward = true;
|
||||||
|
calibrationState = CALIBRATION_U_BREAK; // may be overridden to WAIT_TURN
|
||||||
|
motorState = MOTOR_STOPPED;
|
||||||
|
calibrationVelocity = SERVO_CALIBRATION_START_VELOCITY_PERCENT;
|
||||||
|
targetVelocity = trackingFrequency;
|
||||||
|
lastStateChangeTime = millis();
|
||||||
|
|
||||||
|
staircaseIters = 0;
|
||||||
|
currentSearchVelocity = calibrationVelocity;
|
||||||
|
foundValidMotion = false;
|
||||||
|
|
||||||
|
const bool bothEnabled = (effectiveMask == SERVO_CAL_ALL_AXES_MASK);
|
||||||
|
if (bothEnabled) {
|
||||||
|
if (g_currentAxisTurn == 0) {
|
||||||
|
g_currentAxisTurn = 1; // Axis 1 starts
|
||||||
|
}
|
||||||
|
if (axisNumber != g_currentAxisTurn) {
|
||||||
|
LOG_HDR(axisPrefix); VLF("wait-turn");
|
||||||
|
calibrationState = CALIBRATION_WAIT_TURN;
|
||||||
|
setVelocity(0);
|
||||||
|
startSettling();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setVelocity(0);
|
||||||
|
startSettling();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoCalibrateTrackingVelocity::updateState(long instrumentCoordinateSteps) {
|
||||||
|
if(!enabled || !experimentMode) return;
|
||||||
|
|
||||||
|
currentTime = millis();
|
||||||
|
currentTicks = instrumentCoordinateSteps;
|
||||||
|
|
||||||
|
handleMotorState();
|
||||||
|
|
||||||
|
if (currentTime - lastStateChangeTime > SERVO_CALIBRATION_TIMEOUT) {
|
||||||
|
LOG_HDR(axisPrefix); VLF("timeout → reset");
|
||||||
|
handleCalibrationFailure();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (calibrationState == CALIBRATION_WAIT_TURN) {
|
||||||
|
if (g_currentAxisTurn == axisNumber) {
|
||||||
|
calibrationState = CALIBRATION_U_BREAK;
|
||||||
|
hasQueuedTest = false;
|
||||||
|
queueNextTest(CALIBRATION_U_BREAK, calibrationDirectionIsForward
|
||||||
|
? SERVO_CALIBRATION_START_VELOCITY_PERCENT
|
||||||
|
: -SERVO_CALIBRATION_START_VELOCITY_PERCENT);
|
||||||
|
if (motorState != MOTOR_SETTLING) {
|
||||||
|
setVelocity(0);
|
||||||
|
startSettling();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (calibrationState == CALIBRATION_WAIT_PEER) {
|
||||||
|
uint8_t other = otherAxis(axisNumber);
|
||||||
|
if (!g_axisEnabledForCal[other] || g_axisDone[other]) {
|
||||||
|
if (!g_jointReportPrinted) {
|
||||||
|
g_jointReportPrinted = true;
|
||||||
|
printJointReport();
|
||||||
|
}
|
||||||
|
experimentMode = false;
|
||||||
|
calibrationState = CALIBRATION_IDLE;
|
||||||
|
setVelocity(0);
|
||||||
|
LOG_HDR(axisPrefix); VLF("done");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only run phase logic when a candidate outcome is resolvable
|
||||||
|
if (motorState != MOTOR_RUNNING_STEADY && motorState != MOTOR_STOPPED) return;
|
||||||
|
|
||||||
|
switch (calibrationState) {
|
||||||
|
case CALIBRATION_U_BREAK: processUBreak(); break;
|
||||||
|
case CALIBRATION_U_HOLD: processUHold(); break;
|
||||||
|
case CALIBRATION_CHECK_IMBALANCE: processImbalanceCheck(); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------- Motor sub-state machine ---------------------------
|
||||||
|
void ServoCalibrateTrackingVelocity::handleMotorState() {
|
||||||
|
switch (motorState) {
|
||||||
|
case MOTOR_SETTLING: {
|
||||||
|
float currentVelocity = calculateInstantaneousVelocity();
|
||||||
|
if (currentTime - settleStartTime >= SERVO_CALIBRATION_MOTOR_SETTLE_TIME) {
|
||||||
|
motorState = MOTOR_STOPPED;
|
||||||
|
LOG_HDR(axisPrefix); VF("settled v="); V(currentVelocity); VLF(" sps");
|
||||||
|
if (hasQueuedTest) {
|
||||||
|
calibrationState = queuedState;
|
||||||
|
hasQueuedTest = false;
|
||||||
|
startTest(queuedVelocity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastVelocityMeasurement = currentVelocity;
|
||||||
|
lastVelocityTime = currentTime;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case MOTOR_KICKING:
|
||||||
|
if (currentTime - kickStartTime >= SERVO_CALIBRATION_KICK_DURATION_MS) {
|
||||||
|
setVelocity(calibrationVelocity);
|
||||||
|
motorState = MOTOR_HOLDING;
|
||||||
|
calibrationStepStartTime = currentTime;
|
||||||
|
calibrationStepStartTicks = currentTicks;
|
||||||
|
lastVelocityTime = currentTime;
|
||||||
|
lastVelocityMeasurement = 0;
|
||||||
|
consecutiveMovingSamples = 0;
|
||||||
|
candidateSampleCount = 0;
|
||||||
|
|
||||||
|
LOG_HDR(axisPrefix); LOG_DIR(calibrationDirectionIsForward);
|
||||||
|
VF("kick→hold @"); V(calibrationVelocity); VLF("%");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MOTOR_HOLDING:
|
||||||
|
// Both UB and UH require N consecutive moving samples.
|
||||||
|
// UB additionally has a hard sample cap to avoid endless waiting.
|
||||||
|
if (currentTime - lastVelocityTime >= SERVO_CALIBRATION_VELOCITY_SETTLE_CHECK_INTERVAL) {
|
||||||
|
float v_now = calculateInstantaneousVelocity();
|
||||||
|
long dCounts = lastDeltaCounts;
|
||||||
|
|
||||||
|
const bool isUB = (calibrationState == CALIBRATION_U_BREAK);
|
||||||
|
const int requiredConsec = SERVO_CALIBRATION_REQUIRED_MOVING_SAMPLES;
|
||||||
|
|
||||||
|
const bool movingNow =
|
||||||
|
(fabsf(v_now) > SERVO_CALIBRATION_MIN_DETECTABLE_VELOCITY) &&
|
||||||
|
(labs(dCounts) >= SERVO_CALIBRATION_MIN_COUNTS_PER_SAMPLE);
|
||||||
|
|
||||||
|
// count total samples in this candidate (UB and UH)
|
||||||
|
candidateSampleCount++;
|
||||||
|
|
||||||
|
if (movingNow) {
|
||||||
|
consecutiveMovingSamples++;
|
||||||
|
LOG_HDR(axisPrefix); LOG_DIR(calibrationDirectionIsForward);
|
||||||
|
VF(isUB ? PHASE_UB() : PHASE_UH());
|
||||||
|
VF(" hold@"); V(calibrationVelocity); VF("% sps="); V(v_now);
|
||||||
|
VF(" cnt="); V(dCounts); VF(" ok "); V(consecutiveMovingSamples);
|
||||||
|
VF("/"); V(requiredConsec);
|
||||||
|
if (consecutiveMovingSamples >= requiredConsec) VF(" → MOVE");
|
||||||
|
VL("");
|
||||||
|
|
||||||
|
if (consecutiveMovingSamples >= requiredConsec) {
|
||||||
|
motorState = MOTOR_RUNNING_STEADY; // accept candidate
|
||||||
|
steadySinceMs = currentTime;
|
||||||
|
steadyStartTicks = currentTicks;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// failed sample → reset the consecutive counter for BOTH UB and UH
|
||||||
|
consecutiveMovingSamples = 0;
|
||||||
|
|
||||||
|
if (isUB) {
|
||||||
|
// UB: keep sampling until cap, then fail if we never reached requiredConsec
|
||||||
|
if (candidateSampleCount >= SERVO_CAL_UB_MAX_SAMPLES) {
|
||||||
|
motorState = MOTOR_STOPPED;
|
||||||
|
LOG_HDR(axisPrefix); VLF("HOLD_STALLED (UB: no consecutive move within cap)");
|
||||||
|
}
|
||||||
|
// else: keep waiting for next sample
|
||||||
|
} else {
|
||||||
|
// UH: strict — any failure cancels this candidate immediately
|
||||||
|
motorState = MOTOR_STOPPED;
|
||||||
|
LOG_HDR(axisPrefix); VLF("HOLD_STALLED");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lastVelocityMeasurement = v_now;
|
||||||
|
lastVelocityTime = currentTime;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MOTOR_RUNNING_STEADY:
|
||||||
|
// Nothing to do; phase logic will treat as "moved"
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MOTOR_STOPPED:
|
||||||
|
// Idle; phase logic will interpret as "not moved"
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute instantaneous velocity in steps/s using elapsed time.
|
||||||
|
float ServoCalibrateTrackingVelocity::calculateInstantaneousVelocity() {
|
||||||
|
if (lastCheckTime == 0) {
|
||||||
|
lastCheckTime = currentTime;
|
||||||
|
lastTicks = currentTicks;
|
||||||
|
lastDeltaCounts = 0;
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
float elapsed = (currentTime - lastCheckTime) / 1000.0f;
|
||||||
|
if (elapsed <= 0) return 0.0f;
|
||||||
|
|
||||||
|
long dCounts = (currentTicks - lastTicks);
|
||||||
|
float velocity = dCounts / elapsed;
|
||||||
|
|
||||||
|
#ifdef SERVO_CAL_DEBUG
|
||||||
|
VF("DBG: "); V(axisPrefix); VF(" vel%="); V(calibrationVelocity);
|
||||||
|
VF(", dTicks="); V(dCounts); VF(", Vel="); V(velocity); VL(" steps/s");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
lastTicks = currentTicks;
|
||||||
|
lastCheckTime = currentTime;
|
||||||
|
lastDeltaCounts = dCounts;
|
||||||
|
|
||||||
|
return velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------- Helpers & Phase handlers ---------------------------
|
||||||
|
|
||||||
|
ServoCalibrateTrackingVelocity::DirectionData&
|
||||||
|
ServoCalibrateTrackingVelocity::currentDirectionData() {
|
||||||
|
return calibrationDirectionIsForward ? fwdData : revData;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ServoCalibrateTrackingVelocity::DirectionData&
|
||||||
|
ServoCalibrateTrackingVelocity::currentDirectionData() const {
|
||||||
|
return calibrationDirectionIsForward ? fwdData : revData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoCalibrateTrackingVelocity::recordMovementData(float velocity, long counts) {
|
||||||
|
DirectionData& data = currentDirectionData();
|
||||||
|
if (calibrationState == CALIBRATION_U_BREAK) {
|
||||||
|
data.breakVel = velocity;
|
||||||
|
data.breakCounts = counts;
|
||||||
|
} else {
|
||||||
|
data.holdVel = velocity;
|
||||||
|
data.holdCounts = counts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoCalibrateTrackingVelocity::logTestResult(const char* phase, bool moved) {
|
||||||
|
LOG_HDR(axisPrefix); LOG_DIR(calibrationDirectionIsForward);
|
||||||
|
V(phase); VF(": "); VF(moved ? "MOVE" : "STALL");
|
||||||
|
VF(" @"); V(calibrationVelocity); VF("%");
|
||||||
|
if (moved) { VF(" v≈"); V(lastVelocityMeasurement); VF(" sps"); }
|
||||||
|
VL("");
|
||||||
|
}
|
||||||
|
|
||||||
|
// u_break: staircase upward from rest until we get a "moved" or hit limits
|
||||||
|
void ServoCalibrateTrackingVelocity::processUBreak() {
|
||||||
|
if (++staircaseIters > SERVO_CALIBRATION_REFINE_MAX_ITERATIONS) {
|
||||||
|
LOG_HDR(axisPrefix); VLF("UB iter-limit");
|
||||||
|
if (!foundValidMotion) {
|
||||||
|
currentDirectionData().u_break = SERVO_CALIBRATION_STOP_VELOCITY_PERCENT;
|
||||||
|
LOG_HDR(axisPrefix); VF("UB none→max="); V(currentDirectionData().u_break); VLF("%");
|
||||||
|
}
|
||||||
|
proceedToUHold();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (motorState != MOTOR_RUNNING_STEADY && motorState != MOTOR_STOPPED) return;
|
||||||
|
|
||||||
|
const bool moved = (motorState == MOTOR_RUNNING_STEADY);
|
||||||
|
const float currentAbsVelocity = fabsf(calibrationVelocity);
|
||||||
|
|
||||||
|
LOG_HDR(axisPrefix); LOG_DIR(calibrationDirectionIsForward);
|
||||||
|
VF("UB "); VF(moved ? "OK" : "NO"); VF(" @"); V(currentAbsVelocity); VLF("%");
|
||||||
|
|
||||||
|
if (moved) {
|
||||||
|
foundValidMotion = true;
|
||||||
|
recordMovementData(lastVelocityMeasurement, lastDeltaCounts);
|
||||||
|
currentDirectionData().u_break = currentAbsVelocity;
|
||||||
|
currentDirectionData().everMoved = true;
|
||||||
|
|
||||||
|
LOG_HDR(axisPrefix); LOG_DIR(calibrationDirectionIsForward);
|
||||||
|
VF("UB set="); V(currentAbsVelocity); VF("% v≈"); V(lastVelocityMeasurement); VLF(" sps");
|
||||||
|
proceedToUHold();
|
||||||
|
} else {
|
||||||
|
const float nextAbsVelocity = currentAbsVelocity + SERVO_CALIBRATION_STAIRCASE_STEP_PERCENT;
|
||||||
|
|
||||||
|
if (nextAbsVelocity > SERVO_CALIBRATION_STOP_VELOCITY_PERCENT) {
|
||||||
|
if (!foundValidMotion) {
|
||||||
|
currentDirectionData().u_break = SERVO_CALIBRATION_STOP_VELOCITY_PERCENT;
|
||||||
|
LOG_HDR(axisPrefix); VF("UB none→max="); V(currentDirectionData().u_break); VLF("%");
|
||||||
|
}
|
||||||
|
proceedToUHold();
|
||||||
|
} else {
|
||||||
|
calibrationVelocity = calibrationDirectionIsForward ? nextAbsVelocity : -nextAbsVelocity;
|
||||||
|
startTest(calibrationVelocity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// u_hold: staircase downward; each candidate must meet the N-consecutive-moving rule
|
||||||
|
void ServoCalibrateTrackingVelocity::processUHold() {
|
||||||
|
if (++staircaseIters > SERVO_CALIBRATION_REFINE_MAX_ITERATIONS) {
|
||||||
|
LOG_HDR(axisPrefix); VLF("UH iter-limit");
|
||||||
|
finishUHold();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (motorState != MOTOR_RUNNING_STEADY && motorState != MOTOR_STOPPED) return;
|
||||||
|
|
||||||
|
const bool moved = (motorState == MOTOR_RUNNING_STEADY);
|
||||||
|
const float currentAbsVelocity = fabsf(calibrationVelocity);
|
||||||
|
const float u_break = currentDirectionData().u_break;
|
||||||
|
|
||||||
|
if (moved) {
|
||||||
|
recordMovementData(lastVelocityMeasurement, lastDeltaCounts);
|
||||||
|
currentDirectionData().u_hold = currentAbsVelocity;
|
||||||
|
|
||||||
|
logTestResult("u_hold", true);
|
||||||
|
|
||||||
|
const float nextAbsVelocity = currentAbsVelocity - SERVO_CALIBRATION_STAIRCASE_STEP_PERCENT;
|
||||||
|
|
||||||
|
if (nextAbsVelocity < SERVO_CALIBRATION_START_VELOCITY_PERCENT) {
|
||||||
|
LOG_HDR(axisPrefix); VF("UH min="); V(currentDirectionData().u_hold); VLF("%");
|
||||||
|
finishUHold();
|
||||||
|
} else {
|
||||||
|
// Kick at u_break to overcome stiction, then test the next-lower candidate
|
||||||
|
calibrationVelocity = calibrationDirectionIsForward ? nextAbsVelocity : -nextAbsVelocity;
|
||||||
|
setVelocity(calibrationDirectionIsForward ? u_break : -u_break);
|
||||||
|
motorState = MOTOR_KICKING;
|
||||||
|
kickStartTime = currentTime;
|
||||||
|
lastStateChangeTime = currentTime;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logTestResult("u_hold", false);
|
||||||
|
|
||||||
|
if (currentDirectionData().u_hold == 0.0f) {
|
||||||
|
currentDirectionData().u_hold = u_break; // fall back
|
||||||
|
LOG_HDR(axisPrefix); VF("UH use UB="); V(currentDirectionData().u_hold); VLF("%");
|
||||||
|
}
|
||||||
|
finishUHold();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoCalibrateTrackingVelocity::proceedToUHold() {
|
||||||
|
// Transition to u_hold: stop, settle, then queue first test below u_break
|
||||||
|
setVelocity(0);
|
||||||
|
startSettling();
|
||||||
|
|
||||||
|
calibrationState = CALIBRATION_U_HOLD;
|
||||||
|
staircaseIters = 0;
|
||||||
|
|
||||||
|
const float u_break = currentDirectionData().u_break;
|
||||||
|
currentSearchVelocity = max(u_break - SERVO_CALIBRATION_STAIRCASE_STEP_PERCENT,
|
||||||
|
SERVO_CALIBRATION_START_VELOCITY_PERCENT);
|
||||||
|
|
||||||
|
LOG_HDR(axisPrefix); VF("UH first="); V(currentSearchVelocity); VLF("%");
|
||||||
|
|
||||||
|
queueNextTest(CALIBRATION_U_HOLD, calibrationDirectionIsForward ? currentSearchVelocity : -currentSearchVelocity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoCalibrateTrackingVelocity::finishUHold() {
|
||||||
|
setVelocity(0);
|
||||||
|
startSettling();
|
||||||
|
switchDirectionOrComplete();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoCalibrateTrackingVelocity::switchDirectionOrComplete() {
|
||||||
|
if (calibrationDirectionIsForward) {
|
||||||
|
calibrationDirectionIsForward = false;
|
||||||
|
calibrationState = CALIBRATION_U_BREAK;
|
||||||
|
staircaseIters = 0;
|
||||||
|
calibrationVelocity = -SERVO_CALIBRATION_START_VELOCITY_PERCENT;
|
||||||
|
currentSearchVelocity = fabsf(calibrationVelocity);
|
||||||
|
foundValidMotion = false;
|
||||||
|
|
||||||
|
queueNextTest(CALIBRATION_U_BREAK, calibrationVelocity);
|
||||||
|
LOG_HDR(axisPrefix); VLF("→ REVERSE");
|
||||||
|
} else {
|
||||||
|
calibrationState = CALIBRATION_CHECK_IMBALANCE;
|
||||||
|
processImbalanceCheck();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoCalibrateTrackingVelocity::processImbalanceCheck() {
|
||||||
|
snapshotAxisData(axisNumber, axisPrefix, fwdData, revData);
|
||||||
|
|
||||||
|
if (fwdData.u_hold > 0 && revData.u_hold > 0) {
|
||||||
|
float avgTracking = (fwdData.u_hold + revData.u_hold) / 2.0f;
|
||||||
|
float imbalance = fabsf(fwdData.u_hold - revData.u_hold) / avgTracking * 100.0f;
|
||||||
|
|
||||||
|
if (imbalance > SERVO_CALIBRATION_IMBALANCE_ERROR_THRESHOLD) {
|
||||||
|
LOG_HDR(axisPrefix); VF("imbalance "); V(imbalance); VLF("%");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g_axisDone[axisNumber] = true;
|
||||||
|
|
||||||
|
uint8_t other = otherAxis(axisNumber);
|
||||||
|
if (g_axisEnabledForCal[other] && !g_axisDone[other]) {
|
||||||
|
g_currentAxisTurn = other; // pass the turn
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool peerEnabled = g_axisEnabledForCal[other];
|
||||||
|
const bool peerDone = g_axisDone[other];
|
||||||
|
|
||||||
|
if (peerEnabled && !peerDone) {
|
||||||
|
calibrationState = CALIBRATION_WAIT_PEER;
|
||||||
|
setVelocity(0);
|
||||||
|
startSettling();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_jointReportPrinted) {
|
||||||
|
g_jointReportPrinted = true;
|
||||||
|
printJointReport();
|
||||||
|
}
|
||||||
|
|
||||||
|
experimentMode = false;
|
||||||
|
calibrationState = CALIBRATION_IDLE;
|
||||||
|
setVelocity(0);
|
||||||
|
LOG_HDR(axisPrefix); VLF("done");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoCalibrateTrackingVelocity::handleCalibrationFailure() {
|
||||||
|
LOG_HDR(axisPrefix); VLF("ERR reset");
|
||||||
|
experimentMode = false;
|
||||||
|
calibrationState = CALIBRATION_IDLE;
|
||||||
|
setVelocity(0);
|
||||||
|
resetCalibrationValues();
|
||||||
|
hasQueuedTest = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoCalibrateTrackingVelocity::startSettling() {
|
||||||
|
settleStartTime = currentTime;
|
||||||
|
motorState = MOTOR_SETTLING;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoCalibrateTrackingVelocity::startTest(float velocity) {
|
||||||
|
calibrationVelocity = velocity;
|
||||||
|
lastVelocityTime = currentTime;
|
||||||
|
lastVelocityMeasurement = 0;
|
||||||
|
lastStateChangeTime = currentTime;
|
||||||
|
|
||||||
|
consecutiveMovingSamples = 0;
|
||||||
|
candidateSampleCount = 0;
|
||||||
|
|
||||||
|
if (calibrationState == CALIBRATION_U_BREAK) {
|
||||||
|
setVelocity(calibrationVelocity);
|
||||||
|
motorState = MOTOR_HOLDING;
|
||||||
|
calibrationStepStartTime = currentTime;
|
||||||
|
calibrationStepStartTicks = currentTicks;
|
||||||
|
|
||||||
|
LOG_HDR(axisPrefix); LOG_DIR(calibrationDirectionIsForward);
|
||||||
|
VF(PHASE_UB()); VF(" test @"); V(velocity); VLF("%");
|
||||||
|
} else {
|
||||||
|
float u_break = currentDirectionData().u_break;
|
||||||
|
setVelocity(calibrationDirectionIsForward ? u_break : -u_break);
|
||||||
|
motorState = MOTOR_KICKING;
|
||||||
|
kickStartTime = currentTime;
|
||||||
|
|
||||||
|
LOG_HDR(axisPrefix); LOG_DIR(calibrationDirectionIsForward);
|
||||||
|
VF(PHASE_UH()); VF(" kick@"); V(u_break); VF("% → hold@"); V(velocity); VLF("%");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoCalibrateTrackingVelocity::setVelocity(float velocityPercent) {
|
||||||
|
experimentVelocity = constrain(velocityPercent,
|
||||||
|
-SERVO_CALIBRATION_STOP_VELOCITY_PERCENT,
|
||||||
|
+SERVO_CALIBRATION_STOP_VELOCITY_PERCENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------- Getters -------------------------------------------------------------------
|
||||||
|
float ServoCalibrateTrackingVelocity::getU_break(bool forward) {
|
||||||
|
return forward ? fwdData.u_break : revData.u_break;
|
||||||
|
}
|
||||||
|
|
||||||
|
float ServoCalibrateTrackingVelocity::getU_hold(bool forward) {
|
||||||
|
return forward ? fwdData.u_hold : revData.u_hold;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------- Reports -------------------------------------------------------------------
|
||||||
|
void ServoCalibrateTrackingVelocity::printReport(const char* prefix,
|
||||||
|
const DirectionData& fwd,
|
||||||
|
const DirectionData& rev) {
|
||||||
|
VF("\n=== Calibration Report: "); V(prefix); VLF(" ===");
|
||||||
|
VLF("Dir | u_break | u_hold");
|
||||||
|
VLF("-----+---------------------------------+---------------------------------");
|
||||||
|
|
||||||
|
auto printRow = [&](const char* dir, const DirectionData& data) {
|
||||||
|
VF(dir); VF(" | ");
|
||||||
|
VF("pct "); V(data.u_break); VF("%, v "); V(data.breakVel); VF(" steps/s, cnt "); V(data.breakCounts); VF(" | ");
|
||||||
|
VF("pct "); V(data.u_hold); VF("%, v "); V(data.holdVel); VF(" steps/s, cnt "); V(data.holdCounts); VL("");
|
||||||
|
};
|
||||||
|
|
||||||
|
printRow("FWD", fwd);
|
||||||
|
printRow("REV", rev);
|
||||||
|
|
||||||
|
float breakDeltaAbs = fabsf(fwd.u_break - rev.u_break);
|
||||||
|
float holdDeltaAbs = fabsf(rev.u_hold - fwd.u_hold);
|
||||||
|
|
||||||
|
VF("Δ u_break: "); V(breakDeltaAbs); VF("%, ");
|
||||||
|
VF("Δ u_hold: "); V(holdDeltaAbs); VLF("%");
|
||||||
|
|
||||||
|
if (fwd.u_hold > 0.0f && rev.u_hold > 0.0f) {
|
||||||
|
float avgTracking = (fwd.u_hold + rev.u_hold) / 2.0f;
|
||||||
|
float holdImbalancePct = (avgTracking > 0.0f)
|
||||||
|
? (fabsf(fwd.u_hold - rev.u_hold) / avgTracking * 100.0f)
|
||||||
|
: 0.0f;
|
||||||
|
|
||||||
|
VF("u_hold imbalance vs avg: "); V(holdImbalancePct); VLF("%");
|
||||||
|
|
||||||
|
if (holdImbalancePct > SERVO_CALIBRATION_IMBALANCE_ERROR_THRESHOLD) {
|
||||||
|
VF("WARN: "); V(prefix); VF(" Imbalance: "); V(holdImbalancePct); VL("%");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fwd.u_hold >= SERVO_CALIBRATION_STOP_VELOCITY_PERCENT - 0.1f) VLF("WARN: FWD velocity at calibration limit");
|
||||||
|
if (rev.u_hold >= SERVO_CALIBRATION_STOP_VELOCITY_PERCENT - 0.1f) VLF("WARN: REV velocity at calibration limit");
|
||||||
|
|
||||||
|
VF("=== End Report ===\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoCalibrateTrackingVelocity::printReport() {
|
||||||
|
printReport(axisPrefix, fwdData, revData);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoCalibrateTrackingVelocity::resetCalibrationValues() {
|
||||||
|
fwdData = DirectionData();
|
||||||
|
revData = DirectionData();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SERVO_MOTOR_PRESENT && CALIBRATE_SERVO_DC
|
||||||
+192
@@ -0,0 +1,192 @@
|
|||||||
|
// ============================== TrackingVelocity.h ==============================
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "../../../../../../Common.h"
|
||||||
|
|
||||||
|
#if defined(SERVO_MOTOR_PRESENT) && defined(CALIBRATE_SERVO_DC)
|
||||||
|
|
||||||
|
#include "../DcServoDriver.h"
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Axis selection mask:
|
||||||
|
// - Bit 0 -> Axis 1, Bit 1 -> Axis 2 (i.e., 1=Axis1, 2=Axis2, 3=both).
|
||||||
|
// - 0 also means all axes using SERVO_CAL_ALL_AXES_MASK
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
#ifndef CALIBRATE_SERVO_AXIS_SELECT
|
||||||
|
#define CALIBRATE_SERVO_AXIS_SELECT 0
|
||||||
|
#endif
|
||||||
|
// When CALIBRATE_SERVO_AXIS_SELECT==0, use it as both axes
|
||||||
|
#define SERVO_CAL_ALL_AXES_MASK 0x03 // bit0=axis1, bit1=axis2
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Configuration constants (tuning and safety limits)
|
||||||
|
// All units are either percentages of PWM duty (for velocities) or milliseconds
|
||||||
|
// for timing, unless stated otherwise.
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
#define SERVO_CALIBRATION_START_VELOCITY_PERCENT 2.5f // Initial staircase % for u_break (per direction)
|
||||||
|
#define SERVO_CALIBRATION_STOP_VELOCITY_PERCENT 12.0f // Safety cap for commanded % during tests
|
||||||
|
#define SERVO_CALIBRATION_STAIRCASE_STEP_PERCENT 0.1f // Step size for staircase up/down
|
||||||
|
#define SERVO_CALIBRATION_MOTOR_SETTLE_TIME 300 // ms to wait after STOP to remove transients
|
||||||
|
#define SERVO_CALIBRATION_VELOCITY_SETTLE_CHECK_INTERVAL 200 // ms between HOLD samples
|
||||||
|
#define SERVO_CALIBRATION_REQUIRED_MOVING_SAMPLES 1 // need this many consecutive moving samples to accept
|
||||||
|
#define SERVO_CALIBRATION_MIN_COUNTS_PER_SAMPLE 2L // min raw encoder/step counts per sample to accept "moving" (tune for encoder)
|
||||||
|
#define SERVO_CALIBRATION_MIN_DETECTABLE_VELOCITY 0.1f // steps/s—below this we treat as "not moving"
|
||||||
|
#define SERVO_CALIBRATION_REFINE_MAX_ITERATIONS 200 // Max steps per phase (u_break/u_hold) to avoid endless loops
|
||||||
|
#define SERVO_CALIBRATION_KICK_DURATION_MS 300 // ms to apply kick at u_break before HOLD
|
||||||
|
#define SERVO_CALIBRATION_IMBALANCE_ERROR_THRESHOLD 2.0f // % threshold (vs. avg) to warn about FWD/REV imbalance
|
||||||
|
#define SERVO_CALIBRATION_TIMEOUT 10000000 // ms guard for state timing (very generous)
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// High-level calibration states (per-axis)
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
enum CalibrationState {
|
||||||
|
CALIBRATION_IDLE, // Not running
|
||||||
|
CALIBRATION_U_BREAK, // Staircase upward to overcome stiction from rest
|
||||||
|
CALIBRATION_U_HOLD, // Staircase downward to find minimum % that sustains motion
|
||||||
|
CALIBRATION_CHECK_IMBALANCE, // Compute/report per-axis FWD/REV imbalance and snapshot data
|
||||||
|
CALIBRATION_WAIT_PEER, // Finished this axis; waiting for the other axis to finish (joint report)
|
||||||
|
CALIBRATION_WAIT_TURN // Both axes selected; wait here until it's this axis' turn to start
|
||||||
|
};
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Motor sub-states (lifecycle around each test step)
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
enum MotorState {
|
||||||
|
MOTOR_STOPPED, // At rest; used to delimit tests or indicate failure to move (after HOLD sample)
|
||||||
|
MOTOR_SETTLING, // Waiting for transients to decay after STOP/changes (enforced pause)
|
||||||
|
MOTOR_KICKING, // Brief kick at u_break to overcome stiction for u_hold tests
|
||||||
|
MOTOR_HOLDING, // Holding candidate % and sampling velocity periodically
|
||||||
|
MOTOR_RUNNING_STEADY // ACCEPTED MOVING (kept name for compatibility)
|
||||||
|
};
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Calibrator class (per axis instance)
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
class ServoCalibrateTrackingVelocity {
|
||||||
|
public:
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Per-direction compact record of results/telemetry for reporting
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
struct DirectionData {
|
||||||
|
float u_break = 0.0f; // % that first produced motion from rest (staircase up)
|
||||||
|
float u_hold = 0.0f; // % that minimally sustains motion (after kick; staircase down)
|
||||||
|
float breakVel = 0.0f; // measured steps/s at u_break
|
||||||
|
float holdVel = 0.0f; // measured steps/s at u_hold
|
||||||
|
long breakCounts= 0; // raw delta counts measured at u_break (for diagnostics)
|
||||||
|
long holdCounts = 0; // raw delta counts measured at u_hold (for diagnostics)
|
||||||
|
bool everMoved = false;// whether any motion was detected in this direction
|
||||||
|
};
|
||||||
|
|
||||||
|
// axisNumber is 1-based (1=RA, 2=DEC in common mounts)
|
||||||
|
ServoCalibrateTrackingVelocity(uint8_t axisNumber);
|
||||||
|
|
||||||
|
// One-time per-run init: clears state, resets local accumulators
|
||||||
|
void init();
|
||||||
|
|
||||||
|
// Start the calibration sequence for this axis.
|
||||||
|
// - trackingFrequency: target sidereal steps/s reference (informational).
|
||||||
|
// - instrumentCoordinateSteps: current encoder/step count baseline (unused here, caller passes live counts in updateState).
|
||||||
|
void start(float trackingFrequency, long instrumentCoordinateSteps);
|
||||||
|
|
||||||
|
// Drive the state machine; call frequently from the main control loop.
|
||||||
|
void updateState(long instrumentCoordinateSteps);
|
||||||
|
|
||||||
|
// Readouts for the final tuned duty % values
|
||||||
|
float getU_break(bool forward); // forward=true -> FWD, false -> REV
|
||||||
|
float getU_hold(bool forward); // forward=true -> FWD, false -> REV
|
||||||
|
|
||||||
|
// Exposed experiment flags/telemetry (read-only from outside in normal use)
|
||||||
|
bool experimentMode = false; // true while calibration is running
|
||||||
|
float experimentVelocity = 0.0f; // last commanded velocity % (signed)
|
||||||
|
bool enabled = false; // axis was selected and started
|
||||||
|
|
||||||
|
// Reports
|
||||||
|
static void printReport(const char* axisPrefix,
|
||||||
|
const struct DirectionData& fwd,
|
||||||
|
const struct DirectionData& rev);
|
||||||
|
void printReport();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// --------------------------- Phase handlers --------------------------------
|
||||||
|
void handleMotorState(); // sub-state machine for settle/kick/hold
|
||||||
|
void processUBreak(); // staircase upward search
|
||||||
|
void processUHold(); // staircase downward refinement
|
||||||
|
void processImbalanceCheck(); // per-axis FWD/REV imbalance + joint sync/report
|
||||||
|
void handleCalibrationFailure(); // timeout/fault recovery
|
||||||
|
|
||||||
|
// --------------------------- Utilities -------------------------------------
|
||||||
|
float calculateInstantaneousVelocity(); // steps/s from delta counts/time
|
||||||
|
void startSettling(); // enter MOTOR_SETTLING and timestamp
|
||||||
|
void startTest(float velocityPercent); // begin a test step (kick/hold based on phase)
|
||||||
|
void setVelocity(float velocityPercent); // clamp+store experimentVelocity (signed %)
|
||||||
|
void resetCalibrationValues(); // clear DirectionData (FWD/REV)
|
||||||
|
void proceedToUHold(); // transition helper (after u_break success)
|
||||||
|
void finishUHold(); // transition helper (after u_hold completes)
|
||||||
|
void switchDirectionOrComplete(); // flip FWD↔REV or exit to imbalance stage
|
||||||
|
|
||||||
|
// --------------------------- Helpers ---------------------------------------
|
||||||
|
DirectionData& currentDirectionData(); // FWD or REV ref (mutable)
|
||||||
|
const DirectionData& currentDirectionData() const; // FWD or REV ref (const)
|
||||||
|
void recordMovementData(float velocity, long counts); // write last measurement
|
||||||
|
void logTestResult(const char* phase, bool moved); // compact progress log
|
||||||
|
|
||||||
|
// Queue the next test to start right after settling
|
||||||
|
void queueNextTest(CalibrationState st, float velocity) {
|
||||||
|
queuedState = st;
|
||||||
|
queuedVelocity = velocity;
|
||||||
|
hasQueuedTest = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------------- Hardware/context ------------------------------
|
||||||
|
ServoDcDriver* driver = nullptr; // optional driver hook if needed by platform
|
||||||
|
uint8_t axisNumber; // 1-based axis id
|
||||||
|
char axisPrefix[32]; // used in logs (e.g., "Axis1 ServoCalibration")
|
||||||
|
|
||||||
|
// --------------------------- State -----------------------------------------
|
||||||
|
CalibrationState calibrationState = CALIBRATION_IDLE;
|
||||||
|
MotorState motorState = MOTOR_STOPPED;
|
||||||
|
bool calibrationDirectionIsForward = true; // FWD=true, REV=false
|
||||||
|
int candidateSampleCount = 0; // samples taken in current HOLDING candidate (UB/UH)
|
||||||
|
|
||||||
|
|
||||||
|
// --------------------------- Timing/telemetry -------------------------------
|
||||||
|
unsigned long currentTime = 0;
|
||||||
|
unsigned long lastStateChangeTime = 0;
|
||||||
|
unsigned long settleStartTime = 0;
|
||||||
|
unsigned long calibrationStepStartTime = 0;
|
||||||
|
unsigned long lastVelocityTime = 0;
|
||||||
|
unsigned long kickStartTime = 0;
|
||||||
|
|
||||||
|
long currentTicks = 0; // caller-provided instrument steps
|
||||||
|
long calibrationStepStartTicks = 0; // ticks at the start of a test step
|
||||||
|
float lastVelocityMeasurement = 0.0f; // steps/s
|
||||||
|
|
||||||
|
unsigned long steadySinceMs = 0; // time we accepted the candidate
|
||||||
|
long steadyStartTicks = 0; // ticks when we accepted the candidate
|
||||||
|
|
||||||
|
long lastDeltaCounts = 0; // raw delta counts from last sample
|
||||||
|
|
||||||
|
float calibrationVelocity = 0.0f; // signed % (positive FWD, negative REV)
|
||||||
|
float targetVelocity = 0.0f; // sidereal target (steps/s), informational
|
||||||
|
|
||||||
|
// --------------------------- Results ----------------------------------------
|
||||||
|
DirectionData fwdData; // accumulated forward-direction results
|
||||||
|
DirectionData revData; // accumulated reverse-direction results
|
||||||
|
|
||||||
|
// --------------------------- Search bookkeeping ----------------------------
|
||||||
|
int staircaseIters = 0; // steps taken within current phase
|
||||||
|
float currentSearchVelocity = 0.0f; // helper for proposed % values
|
||||||
|
bool foundValidMotion = false; // latched once motion is first observed
|
||||||
|
|
||||||
|
long lastTicks = 0; // sample baseline
|
||||||
|
unsigned long lastCheckTime = 0; // sample timestamp
|
||||||
|
int consecutiveMovingSamples = 0; // counts consecutive moving samples for a candidate
|
||||||
|
|
||||||
|
// --------------------------- Deferred start of next test --------------------
|
||||||
|
bool hasQueuedTest = false; // true if next test is queued
|
||||||
|
CalibrationState queuedState = CALIBRATION_IDLE; // queued phase
|
||||||
|
float queuedVelocity = 0.0f; // queued signed %
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SERVO_MOTOR_PRESENT && CALIBRATE_SERVO_DC
|
||||||
Executable
+92
@@ -0,0 +1,92 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis servo DC EE motor driver
|
||||||
|
|
||||||
|
#include "EE.h"
|
||||||
|
|
||||||
|
#ifdef SERVO_EE_PRESENT
|
||||||
|
|
||||||
|
#include "../../../../../gpioEx/GpioEx.h"
|
||||||
|
#include "../../../../../analog/Analog.h"
|
||||||
|
|
||||||
|
ServoEE::ServoEE(uint8_t axisNumber, const ServoPins *Pins, const ServoSettings *Settings, float pwmMinimum, float pwmMaximum)
|
||||||
|
:ServoDcDriver(axisNumber, Pins, Settings, pwmMinimum, pwmMaximum) {
|
||||||
|
if (axisNumber < 1 || axisNumber > 9) return;
|
||||||
|
|
||||||
|
strcpy(axisPrefix, " Axis_ServoEE, ");
|
||||||
|
axisPrefix[5] = '0' + axisNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ServoEE::init(bool reverse) {
|
||||||
|
if (!ServoDcDriver::init(reverse)) return false;
|
||||||
|
|
||||||
|
#if DEBUG == VERBOSE
|
||||||
|
VF("MSG:"); V(axisPrefix);
|
||||||
|
V("pins pwm1="); if (Pins->ph1 == OFF) VF("OFF"); else V(Pins->ph1);
|
||||||
|
V(", pwm2="); if (Pins->ph2 == OFF) VLF("OFF"); else VL(Pins->ph2);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// init default driver control pins
|
||||||
|
pinModeEx(Pins->ph1, OUTPUT);
|
||||||
|
digitalWriteF(Pins->ph1, Pins->ph1State); // either ph1 or direction, state should default to inactive
|
||||||
|
pinModeEx(Pins->ph2, OUTPUT);
|
||||||
|
digitalWriteF(Pins->ph2, Pins->ph2State); // either ph2 or step (PWM,) state should default to inactive
|
||||||
|
|
||||||
|
// set PWM range & frequency
|
||||||
|
AnalogPwmConfig scfg{};
|
||||||
|
#ifdef SERVO_ANALOG_WRITE_FREQUENCY
|
||||||
|
scfg.hz = SERVO_ANALOG_WRITE_FREQUENCY;
|
||||||
|
#endif
|
||||||
|
#ifdef SERVO_ANALOG_WRITE_RANGE
|
||||||
|
scfg.range = SERVO_ANALOG_WRITE_RANGE;
|
||||||
|
#endif
|
||||||
|
if (!analog.pwmInit(Pins->ph1, scfg)) return false;
|
||||||
|
if (!analog.pwmInit(Pins->ph2, scfg)) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// enable or disable the driver using the enable pin or other method
|
||||||
|
void ServoEE::enable(bool state) {
|
||||||
|
ServoDriver::enable(state);
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix);
|
||||||
|
if (!enabled) {
|
||||||
|
VF("EE outputs off");
|
||||||
|
|
||||||
|
// force both outputs inactive
|
||||||
|
analog.write(Pins->ph1, off1());
|
||||||
|
analog.write(Pins->ph2, off2());
|
||||||
|
|
||||||
|
VLF("");
|
||||||
|
} else {
|
||||||
|
VLF("EE enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
ServoDriver::updateStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoEE::pwmUpdate(float power01) {
|
||||||
|
if (!enabled) return;
|
||||||
|
|
||||||
|
if (reversed) power01 = -power01;
|
||||||
|
float duty01 = fabsf(power01);
|
||||||
|
|
||||||
|
if (power01 >= 0.0F) {
|
||||||
|
if (Pins->ph2State == HIGH) duty01 = 1.0F - duty01;
|
||||||
|
analog.write(Pins->ph1, off1());
|
||||||
|
analog.write(Pins->ph2, duty01);
|
||||||
|
} else {
|
||||||
|
if (Pins->ph1State == HIGH) duty01 = 1.0F - duty01;
|
||||||
|
analog.write(Pins->ph1, duty01);
|
||||||
|
analog.write(Pins->ph2, off2());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update status info. for driver
|
||||||
|
void ServoEE::updateStatus() {
|
||||||
|
if (statusMode == LOW || statusMode == HIGH) {
|
||||||
|
status.fault = digitalReadEx(faultPin) == statusMode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+41
@@ -0,0 +1,41 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis servo DC EE motor driver
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "../../../../../../Common.h"
|
||||||
|
|
||||||
|
#ifdef SERVO_EE_PRESENT
|
||||||
|
|
||||||
|
#include "../DcServoDriver.h"
|
||||||
|
|
||||||
|
class ServoEE : public ServoDcDriver {
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
ServoEE(uint8_t axisNumber, const ServoPins *Pins, const ServoSettings *Settings, float pwmMinimum, float pwmMaximum);
|
||||||
|
|
||||||
|
// decodes driver model and sets up the pin modes
|
||||||
|
bool init(bool reverse);
|
||||||
|
|
||||||
|
// enable or disable the driver using the enable pin or other method
|
||||||
|
void enable(bool state);
|
||||||
|
|
||||||
|
// update status info. for driver
|
||||||
|
void updateStatus();
|
||||||
|
|
||||||
|
// get the driver name
|
||||||
|
const char* name() {
|
||||||
|
if (driverModel == SERVO_EE) return "DC Enable/Enable"; else
|
||||||
|
return "?";
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// motor control pwm update
|
||||||
|
// \param power01 in -1.0 to 1.0 units
|
||||||
|
void pwmUpdate(float power01) override;
|
||||||
|
|
||||||
|
inline float off1() { return (Pins->ph1State == HIGH) ? 1.0F : 0.0F; }
|
||||||
|
inline float off2() { return (Pins->ph2State == HIGH) ? 1.0F : 0.0F; }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+95
@@ -0,0 +1,95 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis servo DC PE motor driver
|
||||||
|
|
||||||
|
#include "PE.h"
|
||||||
|
|
||||||
|
#ifdef SERVO_PE_PRESENT
|
||||||
|
|
||||||
|
// for a Teensy4.1 you can have one additional PWM channel on a pin (for example pin 38)
|
||||||
|
// for example in Config.h:
|
||||||
|
//
|
||||||
|
// #define PWM_CUSTOM_PIN 38
|
||||||
|
// #define PWM_CUSTOM_ANALOG_WRITE_RANGE 4095
|
||||||
|
// #define PWM_CUSTOM_ANALOG_WRITE_FREQUENCY 10000
|
||||||
|
//
|
||||||
|
// then use the AXISn_SERVO_PHn_PIN as you normally would (AXIS1_SERVO_PH2_PIN 38, for example)
|
||||||
|
|
||||||
|
#include "../../../../../gpioEx/GpioEx.h"
|
||||||
|
#include "../../../../../analog/Analog.h"
|
||||||
|
|
||||||
|
ServoPE::ServoPE(uint8_t axisNumber, const ServoPins *Pins, const ServoSettings *Settings, float pwmMinimum, float pwmMaximum)
|
||||||
|
:ServoDcDriver(axisNumber, Pins, Settings, pwmMinimum, pwmMaximum) {
|
||||||
|
if (axisNumber < 1 || axisNumber > 9) return;
|
||||||
|
|
||||||
|
strcpy(axisPrefix, " Axis_ServoPE, ");
|
||||||
|
axisPrefix[5] = '0' + axisNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ServoPE::init(bool reverse) {
|
||||||
|
if (!ServoDcDriver::init(reverse)) return false;
|
||||||
|
|
||||||
|
#if DEBUG == VERBOSE
|
||||||
|
VF("MSG:"); V(axisPrefix);
|
||||||
|
V("pins dir="); if (Pins->ph1 == OFF) VF("OFF"); else V(Pins->ph1);
|
||||||
|
V(", pwm="); if (Pins->ph2 == OFF) VLF("OFF"); else VL(Pins->ph2);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// init default driver control pins
|
||||||
|
pinModeEx(Pins->ph1, OUTPUT);
|
||||||
|
digitalWriteF(Pins->ph1, Pins->ph1State); // either ph1 or direction, state should default to inactive
|
||||||
|
pinModeEx(Pins->ph2, OUTPUT);
|
||||||
|
digitalWriteF(Pins->ph2, Pins->ph2State); // either ph2 or step (PWM,) state should default to inactive
|
||||||
|
|
||||||
|
// set PWM range & frequency
|
||||||
|
AnalogPwmConfig scfg{};
|
||||||
|
#ifdef SERVO_ANALOG_WRITE_FREQUENCY
|
||||||
|
scfg.hz = SERVO_ANALOG_WRITE_FREQUENCY;
|
||||||
|
#endif
|
||||||
|
#ifdef SERVO_ANALOG_WRITE_RANGE
|
||||||
|
scfg.range = SERVO_ANALOG_WRITE_RANGE;
|
||||||
|
#endif
|
||||||
|
if (!analog.pwmInit(Pins->ph2, scfg)) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// enable or disable the driver using the enable pin or other method
|
||||||
|
void ServoPE::enable(bool state) {
|
||||||
|
ServoDriver::enable(state);
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix);
|
||||||
|
if (!enabled) {
|
||||||
|
VF("PE outputs off");
|
||||||
|
|
||||||
|
// force outputs inactive
|
||||||
|
digitalWriteF(Pins->ph1, Pins->ph1State);
|
||||||
|
analog.write(Pins->ph2, off2());
|
||||||
|
|
||||||
|
VLF("");
|
||||||
|
} else {
|
||||||
|
VLF("PE enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
ServoDriver::updateStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoPE::pwmUpdate(float power01) {
|
||||||
|
if (!enabled) return;
|
||||||
|
|
||||||
|
if (reversed) power01 = -power01;
|
||||||
|
float duty01 = fabsf(power01);
|
||||||
|
|
||||||
|
digitalWriteF(Pins->ph1, power01 >= 0.0F ? Pins->ph1State : !Pins->ph1State);
|
||||||
|
|
||||||
|
if (Pins->ph2State == HIGH) duty01 = 1.0F - duty01;
|
||||||
|
analog.write(Pins->ph2, duty01);
|
||||||
|
}
|
||||||
|
|
||||||
|
// update status info. for driver
|
||||||
|
void ServoPE::updateStatus() {
|
||||||
|
if (statusMode == LOW || statusMode == HIGH) {
|
||||||
|
status.fault = digitalReadEx(faultPin) == statusMode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+40
@@ -0,0 +1,40 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis servo DC motor driver
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "../../../../../../Common.h"
|
||||||
|
|
||||||
|
#ifdef SERVO_PE_PRESENT
|
||||||
|
|
||||||
|
#include "../DcServoDriver.h"
|
||||||
|
|
||||||
|
class ServoPE : public ServoDcDriver {
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
ServoPE(uint8_t axisNumber, const ServoPins *Pins, const ServoSettings *Settings, float pwmMinimum, float pwmMaximum);
|
||||||
|
|
||||||
|
// decodes driver model and sets up the pin modes
|
||||||
|
bool init(bool reverse);
|
||||||
|
|
||||||
|
// enable or disable the driver using the enable pin or other method
|
||||||
|
void enable(bool state);
|
||||||
|
|
||||||
|
// update status info. for driver
|
||||||
|
void updateStatus();
|
||||||
|
|
||||||
|
// get the driver name
|
||||||
|
const char* name() {
|
||||||
|
if (driverModel == SERVO_PE) return "DC Phase/Enable" ; else
|
||||||
|
return "?";
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// motor control pwm update
|
||||||
|
// \param power01 -1.0 to 1.0
|
||||||
|
void pwmUpdate(float power01) override;
|
||||||
|
|
||||||
|
inline float off2() { return (Pins->ph2State == HIGH) ? 1.0F : 0.0F; }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
+103
@@ -0,0 +1,103 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis servo TMC2130 DC motor driver
|
||||||
|
|
||||||
|
#include "Tmc2130.h"
|
||||||
|
|
||||||
|
#ifdef SERVO_TMC2130_DC_PRESENT
|
||||||
|
|
||||||
|
#include "../../../../../tasks/OnTask.h"
|
||||||
|
#include "../../../../../gpioEx/GpioEx.h"
|
||||||
|
|
||||||
|
// help with pin names
|
||||||
|
#define mosi m0
|
||||||
|
#define sck m1
|
||||||
|
#define cs m2
|
||||||
|
#define miso m3
|
||||||
|
|
||||||
|
ServoTmc2130DC::ServoTmc2130DC(uint8_t axisNumber, const ServoPins *Pins, const ServoSettings *Settings, float pwmMinimum, float pwmMaximum)
|
||||||
|
:ServoDcDriver(axisNumber, Pins, Settings, pwmMinimum, pwmMaximum) {
|
||||||
|
if (axisNumber < 1 || axisNumber > 9) return;
|
||||||
|
|
||||||
|
strcpy(axisPrefix, " Axis_ServoTmc2130DC, ");
|
||||||
|
axisPrefix[5] = '0' + axisNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ServoTmc2130DC::init(bool reverse) {
|
||||||
|
if (!ServoDcDriver::init(reverse)) return false;
|
||||||
|
|
||||||
|
// get TMC SPI driver ready
|
||||||
|
pinModeEx(Pins->ph1, OUTPUT); // step
|
||||||
|
pinModeEx(Pins->ph2, OUTPUT); // dir
|
||||||
|
|
||||||
|
// set S/D motion pins to known, fixed state
|
||||||
|
digitalWriteEx(Pins->ph1, LOW); // step
|
||||||
|
digitalWriteEx(Pins->ph2, LOW); // dir
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("TMC current control at max (IHOLD, IRUN, and IGOTO ignored)");
|
||||||
|
|
||||||
|
driver = new TMC2130Stepper(Pins->cs, Pins->mosi, Pins->miso, Pins->sck);
|
||||||
|
driver->begin();
|
||||||
|
driver->direct_mode(true);
|
||||||
|
driver->en_pwm_mode(true);
|
||||||
|
driver->pwm_autoscale(false);
|
||||||
|
driver->pwm_ampl(255);
|
||||||
|
driver->pwm_grad(4);
|
||||||
|
driver->ihold(0);
|
||||||
|
driver->irun(31);
|
||||||
|
driver->toff(5);
|
||||||
|
|
||||||
|
driver->XDIRECT((uint32_t)(lround(0) & 0b111111111));
|
||||||
|
|
||||||
|
// check to see if the driver is there and ok
|
||||||
|
#ifdef MOTOR_DRIVER_DETECT
|
||||||
|
#ifndef DRIVER_TMC_STEPPER_HW_SPI
|
||||||
|
if (Pins->miso != OFF)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
readStatus();
|
||||||
|
if (!status.standstill || status.overTemperature) { DF("ERR:"); D(axisPrefix); DLF("no driver detected!"); return false; }
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// enable or disable the driver using the enable pin or other method
|
||||||
|
void ServoTmc2130DC::enable(bool state) {
|
||||||
|
ServoDriver::enable(state);
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("powered "); if (state) { VF("up"); } else { VF("down"); } VLF(" using SPI");
|
||||||
|
|
||||||
|
if (state) { driver->ihold(31); } else { driver->ihold(0); }
|
||||||
|
|
||||||
|
ServoDriver::updateStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoTmc2130DC::pwmUpdate(float power01) {
|
||||||
|
|
||||||
|
// signed 9-bit value: -255..+255 (avoid -256)
|
||||||
|
int32_t power = (int32_t)lroundf(power01 * 255.0F);
|
||||||
|
if (power > 255) power = 255; else
|
||||||
|
if (power < -255) power = -255;
|
||||||
|
|
||||||
|
if (reversed) power = -power;
|
||||||
|
|
||||||
|
driver->XDIRECT((uint32_t)(power & 0x1FF)); // 9-bit two's complement
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoTmc2130DC::readStatus() {
|
||||||
|
TMC2130_n::DRV_STATUS_t status_result;
|
||||||
|
status_result.sr = 0;
|
||||||
|
|
||||||
|
status_result.sr = driver->DRV_STATUS();
|
||||||
|
|
||||||
|
status.outputA.shortToGround = status_result.s2ga;
|
||||||
|
status.outputA.openLoad = status_result.ola;
|
||||||
|
status.outputB.shortToGround = false;
|
||||||
|
status.outputB.openLoad = false;
|
||||||
|
status.overTemperatureWarning= status_result.otpw;
|
||||||
|
status.overTemperature = status_result.ot;
|
||||||
|
status.standstill = status_result.stst;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis servo TMC2130 DC motor driver
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "../../../../../../../Common.h"
|
||||||
|
|
||||||
|
#ifdef SERVO_TMC2130_DC_PRESENT
|
||||||
|
|
||||||
|
#include "../../DcServoDriver.h"
|
||||||
|
|
||||||
|
#include <TMCStepper.h> // https://github.com/teemuatlut/TMCStepper
|
||||||
|
|
||||||
|
class ServoTmc2130DC : public ServoDcDriver {
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
ServoTmc2130DC(uint8_t axisNumber, const ServoPins *Pins, const ServoSettings *Settings, float pwmMinimum, float pwmMaximum);
|
||||||
|
|
||||||
|
// decodes driver model and sets up the pin modes
|
||||||
|
bool init(bool reverse);
|
||||||
|
|
||||||
|
// enable or disable the driver using the enable pin or other method
|
||||||
|
void enable(bool state);
|
||||||
|
|
||||||
|
// get the driver name
|
||||||
|
const char* name() { return "DC TMC2130 (SPI)"; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
// motor control pwm update
|
||||||
|
// \param power01 in -1.0 to 1.0 units
|
||||||
|
void pwmUpdate(float power01);
|
||||||
|
|
||||||
|
// read status info. from driver
|
||||||
|
void readStatus();
|
||||||
|
|
||||||
|
TMC2130Stepper *driver;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
+103
@@ -0,0 +1,103 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis servo TMC5160 DC motor driver
|
||||||
|
|
||||||
|
#include "Tmc5160.h"
|
||||||
|
|
||||||
|
#ifdef SERVO_TMC5160_DC_PRESENT
|
||||||
|
|
||||||
|
#include "../../../../../tasks/OnTask.h"
|
||||||
|
#include "../../../../../gpioEx/GpioEx.h"
|
||||||
|
|
||||||
|
// help with pin names
|
||||||
|
#define mosi m0
|
||||||
|
#define sck m1
|
||||||
|
#define cs m2
|
||||||
|
#define miso m3
|
||||||
|
|
||||||
|
ServoTmc5160DC::ServoTmc5160DC(uint8_t axisNumber, const ServoPins *Pins, const ServoSettings *Settings, float pwmMinimum, float pwmMaximum)
|
||||||
|
:ServoDcDriver(axisNumber, Pins, Settings, pwmMinimum, pwmMaximum) {
|
||||||
|
if (axisNumber < 1 || axisNumber > 9) return;
|
||||||
|
|
||||||
|
strcpy(axisPrefix, " Axis_ServoTmc5160DC, ");
|
||||||
|
axisPrefix[5] = '0' + axisNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ServoTmc5160DC::init(bool reverse) {
|
||||||
|
if (!ServoDcDriver::init(reverse)) return false;
|
||||||
|
|
||||||
|
// get TMC SPI driver ready
|
||||||
|
pinModeEx(Pins->ph1, OUTPUT); // step
|
||||||
|
pinModeEx(Pins->ph2, OUTPUT); // dir
|
||||||
|
|
||||||
|
// set S/D motion pins to known, fixed state
|
||||||
|
digitalWriteEx(Pins->ph1, LOW); // step
|
||||||
|
digitalWriteEx(Pins->ph2, LOW); // dir
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("TMC current control at max (IHOLD, IRUN, and IGOTO ignored)");
|
||||||
|
|
||||||
|
driver = new TMC5160Stepper(Pins->cs, Pins->mosi, Pins->miso, Pins->sck);
|
||||||
|
driver->begin();
|
||||||
|
driver->direct_mode(true);
|
||||||
|
driver->en_pwm_mode(true);
|
||||||
|
driver->pwm_autoscale(false);
|
||||||
|
driver->pwm_ofs(255);
|
||||||
|
driver->pwm_grad(4);
|
||||||
|
driver->ihold(0);
|
||||||
|
driver->irun(31);
|
||||||
|
driver->toff(5);
|
||||||
|
|
||||||
|
driver->XTARGET((uint32_t)(lround(0) & 0b111111111));
|
||||||
|
|
||||||
|
// check to see if the driver is there and ok
|
||||||
|
#ifdef MOTOR_DRIVER_DETECT
|
||||||
|
#ifndef DRIVER_TMC_STEPPER_HW_SPI
|
||||||
|
if (Pins->miso != OFF)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
readStatus();
|
||||||
|
if (!status.standstill || status.overTemperature) { DF("ERR:"); D(axisPrefix); DLF("no driver detected!"); return false; }
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// enable or disable the driver using the enable pin or other method
|
||||||
|
void ServoTmc5160DC::enable(bool state) {
|
||||||
|
ServoDriver::enable(state);
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("powered "); if (state) { VF("up"); } else { VF("down"); } VLF(" using SPI");
|
||||||
|
|
||||||
|
if (state) { driver->ihold(31); } else { driver->ihold(0); }
|
||||||
|
|
||||||
|
ServoDriver::updateStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoTmc5160DC::pwmUpdate(float power01) {
|
||||||
|
|
||||||
|
// signed 9-bit value: -255..+255
|
||||||
|
int32_t power = (int32_t)lroundf(power01 * 255.0F);
|
||||||
|
if (power > 255) power = 255; else
|
||||||
|
if (power < -255) power = -255;
|
||||||
|
if (reversed) power = -power;
|
||||||
|
|
||||||
|
driver->XTARGET((uint32_t)(power & 0x1FF)); // 9-bit two's complement
|
||||||
|
}
|
||||||
|
|
||||||
|
// read status info. from driver
|
||||||
|
void ServoTmc5160DC::readStatus() {
|
||||||
|
TMC2130_n::DRV_STATUS_t status_result;
|
||||||
|
status_result.sr = 0;
|
||||||
|
|
||||||
|
status_result.sr = driver->DRV_STATUS();
|
||||||
|
|
||||||
|
status.outputA.shortToGround = status_result.s2ga;
|
||||||
|
status.outputA.openLoad = status_result.ola;
|
||||||
|
status.outputB.shortToGround = false;
|
||||||
|
status.outputB.openLoad = false;
|
||||||
|
status.overTemperatureWarning= status_result.otpw;
|
||||||
|
status.overTemperature = status_result.ot;
|
||||||
|
status.standstill = status_result.stst;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// axis servo TMC5160 DC motor driver
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "../../../../../../../Common.h"
|
||||||
|
|
||||||
|
#ifdef SERVO_TMC5160_DC_PRESENT
|
||||||
|
|
||||||
|
#include "../../DcServoDriver.h"
|
||||||
|
|
||||||
|
#include <TMCStepper.h> // https://github.com/teemuatlut/TMCStepper
|
||||||
|
|
||||||
|
class ServoTmc5160DC : public ServoDcDriver {
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
ServoTmc5160DC(uint8_t axisNumber, const ServoPins *Pins, const ServoSettings *Settings, float pwmMinimum, float pwmMaximum);
|
||||||
|
|
||||||
|
// decodes driver model and sets up the pin modes
|
||||||
|
bool init(bool reverse);
|
||||||
|
|
||||||
|
// enable or disable the driver using the enable pin or other method
|
||||||
|
void enable(bool state);
|
||||||
|
|
||||||
|
// get the driver name
|
||||||
|
const char* name() {return "DC TMC5160 (SPI)"; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
// motor control pwm update
|
||||||
|
// \param power01 in -1.0 to 1.0 units
|
||||||
|
void pwmUpdate(float power01);
|
||||||
|
|
||||||
|
// read status info. from driver
|
||||||
|
void readStatus();
|
||||||
|
|
||||||
|
TMC5160Stepper *driver;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
+118
@@ -0,0 +1,118 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// servo motor PID feedback
|
||||||
|
|
||||||
|
#include "DualPid.h"
|
||||||
|
|
||||||
|
#ifdef SERVO_MOTOR_PRESENT
|
||||||
|
|
||||||
|
#if AXIS1_SERVO_FEEDBACK == DUAL_PID || AXIS2_SERVO_FEEDBACK == DUAL_PID || AXIS3_SERVO_FEEDBACK == DUAL_PID || \
|
||||||
|
AXIS4_SERVO_FEEDBACK == DUAL_PID || AXIS5_SERVO_FEEDBACK == DUAL_PID || AXIS6_SERVO_FEEDBACK == DUAL_PID || \
|
||||||
|
AXIS7_SERVO_FEEDBACK == DUAL_PID || AXIS8_SERVO_FEEDBACK == DUAL_PID || AXIS9_SERVO_FEEDBACK == DUAL_PID
|
||||||
|
|
||||||
|
DualPid::DualPid(const float P, const float I, const float D, const float P_goto, const float I_goto, const float D_goto, const float sensitivity) {
|
||||||
|
trackingP.valueDefault = P;
|
||||||
|
trackingI.valueDefault = I;
|
||||||
|
trackingD.valueDefault = D;
|
||||||
|
|
||||||
|
slewingP.valueDefault = P_goto;
|
||||||
|
slewingI.valueDefault = I_goto;
|
||||||
|
slewingD.valueDefault = D_goto;
|
||||||
|
|
||||||
|
manuallySwitchParameters = (sensitivity == 0);
|
||||||
|
if (manuallySwitchParameters) this->sensitivity = 100; else this->sensitivity = sensitivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
// initialize PID control and parameters
|
||||||
|
void DualPid::init(uint8_t axisNumber, ServoControl *control) {
|
||||||
|
if (ready) return;
|
||||||
|
|
||||||
|
Feedback::init(axisNumber, control);
|
||||||
|
|
||||||
|
axisPrefix[5] = '0' + axisNumber;
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix); if (manuallySwitchParameters) { VL("using manual parameter switching"); } else { VL("using auto parameter scaling"); }
|
||||||
|
|
||||||
|
pid = new QuickPID(&control->in, &control->out, &control->set,
|
||||||
|
0, 0, 0,
|
||||||
|
QuickPID::pMode::PID_PMODE, QuickPID::dMode::PID_DMODE, QuickPID::iAwMode::PID_IMODE,
|
||||||
|
QuickPID::Action::direct);
|
||||||
|
pid->SetSampleTimeUs(PID_SAMPLE_TIME_US);
|
||||||
|
pid->Initialize();
|
||||||
|
pid->SetMode(QuickPID::Control::automatic);
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset feedback control and parameters
|
||||||
|
void DualPid::reset() {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("reset");
|
||||||
|
control->in = 0;
|
||||||
|
control->set = 0;
|
||||||
|
control->out = 0;
|
||||||
|
trackingSelected = false;
|
||||||
|
selectTrackingParameters();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DualPid::setControlDirection(int8_t state) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
if (state == ON) pid->SetControllerDirection(QuickPID::Action::reverse); else pid->SetControllerDirection(QuickPID::Action::direct);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DualPid::setControlRange(float controlRange) {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("setting feedback range +/-"); VL(controlRange);
|
||||||
|
pid->SetOutputLimits(-controlRange, controlRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
// select PID param set for tracking
|
||||||
|
void DualPid::selectTrackingParameters() {
|
||||||
|
if (!trackingSelected) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VL("tracking selected");
|
||||||
|
trackingSelected = true;
|
||||||
|
parameterSelectPercent = 0;
|
||||||
|
pid->Reset();
|
||||||
|
pid->SetTunings(trackingP.value, trackingI.value, trackingD.value);
|
||||||
|
lastP = trackingP.value;
|
||||||
|
lastI = trackingI.value;
|
||||||
|
lastD = trackingD.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// select PID param set for slewing
|
||||||
|
void DualPid::selectSlewingParameters() {
|
||||||
|
if (trackingSelected) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VL("slewing selected");
|
||||||
|
trackingSelected = false;
|
||||||
|
parameterSelectPercent = 100;
|
||||||
|
pid->Reset();
|
||||||
|
pid->SetTunings(slewingP.value, slewingI.value, slewingD.value);
|
||||||
|
lastP = slewingP.value;
|
||||||
|
lastI = slewingI.value;
|
||||||
|
lastD = slewingD.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// manage feedback, variable PID params
|
||||||
|
void DualPid::variableParameters(float percent) {
|
||||||
|
float s = percent/sensitivity;
|
||||||
|
if (s < 0.0F) s = 0.0F;
|
||||||
|
if (s > 1.0F) s = 1.0F;
|
||||||
|
float p = trackingP.value + (slewingP.value - trackingP.value)*s;
|
||||||
|
float i = trackingI.value + (slewingI.value - trackingI.value)*s;
|
||||||
|
float d = trackingD.value + (slewingD.value - trackingD.value)*s;
|
||||||
|
if (lastP != p || lastI != i || lastD != d) {
|
||||||
|
// VF("MSG:"); V(axisPrefix);
|
||||||
|
// V("variable parameters");
|
||||||
|
// V(" P="); V(p); V(", I="); V(i); V(", D="); VL(d);
|
||||||
|
pid->SetTunings(p, i, d);
|
||||||
|
lastP = p;
|
||||||
|
lastI = i;
|
||||||
|
lastD = d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
+107
@@ -0,0 +1,107 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// servo motor PID feedback
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../FeedbackBase.h"
|
||||||
|
|
||||||
|
#ifdef SERVO_MOTOR_PRESENT
|
||||||
|
|
||||||
|
#if AXIS1_SERVO_FEEDBACK == DUAL_PID || AXIS2_SERVO_FEEDBACK == DUAL_PID || AXIS3_SERVO_FEEDBACK == DUAL_PID || \
|
||||||
|
AXIS4_SERVO_FEEDBACK == DUAL_PID || AXIS5_SERVO_FEEDBACK == DUAL_PID || AXIS6_SERVO_FEEDBACK == DUAL_PID || \
|
||||||
|
AXIS7_SERVO_FEEDBACK == DUAL_PID || AXIS8_SERVO_FEEDBACK == DUAL_PID || AXIS9_SERVO_FEEDBACK == DUAL_PID
|
||||||
|
|
||||||
|
#include <QuickPID.h> // https://github.com/Dlloydev/QuickPID
|
||||||
|
|
||||||
|
// various options for QuickPID read about them here https://github.com/Dlloydev/QuickPID
|
||||||
|
#ifndef PID_SLEWING_TO_TRACKING_TIME_MS
|
||||||
|
#define PID_SLEWING_TO_TRACKING_TIME_MS 1000 // time to switch from PID slewing to tracking parameters in milliseconds
|
||||||
|
#endif
|
||||||
|
#ifndef PID_SAMPLE_TIME_US
|
||||||
|
#define PID_SAMPLE_TIME_US 10000 // PID sample time in microseconds (defaults to 10 milliseconds)
|
||||||
|
#endif
|
||||||
|
#ifndef PID_PMODE
|
||||||
|
#define PID_PMODE pOnError // http://brettbeauregard.com/blog/2017/06/introducing-proportional-on-measurement/
|
||||||
|
#endif
|
||||||
|
#ifndef PID_IMODE
|
||||||
|
#define PID_IMODE iAwCondition
|
||||||
|
#endif
|
||||||
|
#ifndef PID_DMODE
|
||||||
|
#define PID_DMODE dOnMeas
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class DualPid : public Feedback {
|
||||||
|
public:
|
||||||
|
DualPid(const float P, const float I, const float D, const float P_goto, const float I_goto, const float D_goto, const float sensitivity = 0);
|
||||||
|
|
||||||
|
// initialize PID control and parameters
|
||||||
|
void init(uint8_t axisNumber, ServoControl *control);
|
||||||
|
|
||||||
|
// reset feedback control and parameters
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
// returns the number of axis parameters
|
||||||
|
uint8_t getParameterCount() { return numParameters; }
|
||||||
|
|
||||||
|
// returns the specified axis parameter
|
||||||
|
AxisParameter* getParameter(uint8_t number) { if (number > numParameters) return &invalid; else return parameter[number]; }
|
||||||
|
|
||||||
|
// set feedback control direction
|
||||||
|
void setControlDirection(int8_t state);
|
||||||
|
|
||||||
|
// set feedback control range
|
||||||
|
void setControlRange(float controlRange);
|
||||||
|
|
||||||
|
// select PID param set for tracking
|
||||||
|
void selectTrackingParameters();
|
||||||
|
|
||||||
|
// select PID param set for slewing
|
||||||
|
void selectSlewingParameters();
|
||||||
|
|
||||||
|
// variable feedback, variable PID params
|
||||||
|
void variableParameters(float percent);
|
||||||
|
|
||||||
|
inline void poll() {
|
||||||
|
pid->Compute();
|
||||||
|
|
||||||
|
if (manuallySwitchParameters) {
|
||||||
|
if ((long)(millis() - nextSelectIncrementTime) > 0) {
|
||||||
|
if (trackingSelected) parameterSelectPercent--;
|
||||||
|
if (parameterSelectPercent < 0) parameterSelectPercent = 0;
|
||||||
|
variableParameters(parameterSelectPercent);
|
||||||
|
nextSelectIncrementTime = millis() + round(PID_SLEWING_TO_TRACKING_TIME_MS/100.0F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QuickPID *pid;
|
||||||
|
|
||||||
|
char axisPrefix[26] = " Axis_ServoFeedbackDPID, "; // prefix for debug messages
|
||||||
|
|
||||||
|
float sensitivity;
|
||||||
|
float lastP = 0;
|
||||||
|
float lastI = 0;
|
||||||
|
float lastD = 0;
|
||||||
|
|
||||||
|
unsigned long timeSinceLastUpdate = 0; // for varaible pid update
|
||||||
|
|
||||||
|
int parameterSelectPercent = 0;
|
||||||
|
bool trackingSelected = true;
|
||||||
|
unsigned long nextSelectIncrementTime = 0;
|
||||||
|
|
||||||
|
// runtime adjustable settings
|
||||||
|
AxisParameter trackingP = {NAN, NAN, NAN, 0.0, 10000.0, AXP_FLOAT_IMMEDIATE, AXPN_PID_P};
|
||||||
|
AxisParameter trackingI = {NAN, NAN, NAN, 0.0, 10000.0, AXP_FLOAT_IMMEDIATE, AXPN_PID_I};
|
||||||
|
AxisParameter trackingD = {NAN, NAN, NAN, 0.0, 10000.0, AXP_FLOAT_IMMEDIATE, AXPN_PID_D};
|
||||||
|
|
||||||
|
AxisParameter slewingP = {NAN, NAN, NAN, 0.0, 10000.0, AXP_FLOAT_IMMEDIATE, AXPN_PID_SLEWING_P};
|
||||||
|
AxisParameter slewingI = {NAN, NAN, NAN, 0.0, 10000.0, AXP_FLOAT_IMMEDIATE, AXPN_PID_SLEWING_I};
|
||||||
|
AxisParameter slewingD = {NAN, NAN, NAN, 0.0, 10000.0, AXP_FLOAT_IMMEDIATE, AXPN_PID_SLEWING_D};
|
||||||
|
|
||||||
|
const int numParameters = 6;
|
||||||
|
AxisParameter* parameter[7] = {&invalid, &trackingP, &trackingI, &trackingD, &slewingP, &slewingI, &slewingD};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// servo motor feedback
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "DualPid/DualPid.h"
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// servo motor feedback
|
||||||
|
|
||||||
|
#include "FeedbackBase.h"
|
||||||
|
|
||||||
|
#ifdef SERVO_MOTOR_PRESENT
|
||||||
|
|
||||||
|
// initialize feedback control and parameters
|
||||||
|
void Feedback::init(uint8_t axisNumber, ServoControl *control) {
|
||||||
|
this->axisNumber = axisNumber;
|
||||||
|
|
||||||
|
this->control = control;
|
||||||
|
control->in = 0;
|
||||||
|
control->set = 0;
|
||||||
|
|
||||||
|
ready = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// servo motor feedback
|
||||||
|
#pragma once
|
||||||
|
#include "../../../../../Common.h"
|
||||||
|
|
||||||
|
#ifdef SERVO_MOTOR_PRESENT
|
||||||
|
|
||||||
|
#include "../../Drivers.h"
|
||||||
|
|
||||||
|
#ifndef AXIS1_SERVO_FEEDBACK
|
||||||
|
#define AXIS1_SERVO_FEEDBACK DUAL_PID
|
||||||
|
#endif
|
||||||
|
#ifndef AXIS2_SERVO_FEEDBACK
|
||||||
|
#define AXIS2_SERVO_FEEDBACK DUAL_PID
|
||||||
|
#endif
|
||||||
|
#ifndef AXIS3_SERVO_FEEDBACK
|
||||||
|
#define AXIS3_SERVO_FEEDBACK DUAL_PID
|
||||||
|
#endif
|
||||||
|
#ifndef AXIS4_SERVO_FEEDBACK
|
||||||
|
#define AXIS4_SERVO_FEEDBACK DUAL_PID
|
||||||
|
#endif
|
||||||
|
#ifndef AXIS5_SERVO_FEEDBACK
|
||||||
|
#define AXIS5_SERVO_FEEDBACK DUAL_PID
|
||||||
|
#endif
|
||||||
|
#ifndef AXIS6_SERVO_FEEDBACK
|
||||||
|
#define AXIS6_SERVO_FEEDBACK DUAL_PID
|
||||||
|
#endif
|
||||||
|
#ifndef AXIS7_SERVO_FEEDBACK
|
||||||
|
#define AXIS7_SERVO_FEEDBACK DUAL_PID
|
||||||
|
#endif
|
||||||
|
#ifndef AXIS8_SERVO_FEEDBACK
|
||||||
|
#define AXIS8_SERVO_FEEDBACK DUAL_PID
|
||||||
|
#endif
|
||||||
|
#ifndef AXIS9_SERVO_FEEDBACK
|
||||||
|
#define AXIS9_SERVO_FEEDBACK DUAL_PID
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct ServoControl {
|
||||||
|
float in;
|
||||||
|
float out;
|
||||||
|
float set;
|
||||||
|
volatile int8_t directionHint;
|
||||||
|
} ServoControl;
|
||||||
|
|
||||||
|
class Feedback {
|
||||||
|
public:
|
||||||
|
// initialize feedback control and parameters
|
||||||
|
virtual void init(uint8_t axisNumber, ServoControl *control);
|
||||||
|
|
||||||
|
// reset feedback control and parameters
|
||||||
|
virtual void reset();
|
||||||
|
|
||||||
|
// returns the number of axis parameters
|
||||||
|
virtual uint8_t getParameterCount() { return 0; }
|
||||||
|
|
||||||
|
// returns the specified axis parameter
|
||||||
|
virtual AxisParameter* getParameter(uint8_t number) { return &invalid; }
|
||||||
|
|
||||||
|
// select feedback PID param set for tracking
|
||||||
|
virtual void selectTrackingParameters();
|
||||||
|
|
||||||
|
// select feedback PID param set for slewing
|
||||||
|
virtual void selectSlewingParameters();
|
||||||
|
|
||||||
|
// variable feedback PID params
|
||||||
|
virtual void variableParameters(float percent);
|
||||||
|
|
||||||
|
// set feedback control direction
|
||||||
|
virtual void setControlDirection(int8_t state);
|
||||||
|
|
||||||
|
// set feedback control range controlRange, +/- the maximum encoder counts/s
|
||||||
|
virtual void setControlRange(float controlRange);
|
||||||
|
|
||||||
|
virtual void poll();
|
||||||
|
|
||||||
|
bool manuallySwitchParameters = true;
|
||||||
|
|
||||||
|
// true if the feedback instance is ready to use
|
||||||
|
bool ready = false;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
uint8_t axisNumber = 0;
|
||||||
|
|
||||||
|
ServoControl *control;
|
||||||
|
|
||||||
|
// runtime adjustable settings
|
||||||
|
AxisParameter invalid = {NAN, NAN, NAN, NAN, NAN, AXP_INVALID, ""};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
+81
@@ -0,0 +1,81 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// servo motor PID feedback
|
||||||
|
|
||||||
|
#include "Pid.h"
|
||||||
|
|
||||||
|
#ifdef SERVO_MOTOR_PRESENT
|
||||||
|
|
||||||
|
#if AXIS1_SERVO_FEEDBACK == PID || AXIS2_SERVO_FEEDBACK == PID || AXIS3_SERVO_FEEDBACK == PID || \
|
||||||
|
AXIS4_SERVO_FEEDBACK == PID || AXIS5_SERVO_FEEDBACK == PID || AXIS6_SERVO_FEEDBACK == PID || \
|
||||||
|
AXIS7_SERVO_FEEDBACK == PID || AXIS8_SERVO_FEEDBACK == PID || AXIS9_SERVO_FEEDBACK == PID
|
||||||
|
|
||||||
|
Pid::Pid(const float P, const float I, const float D) {
|
||||||
|
trackingP.valueDefault = P;
|
||||||
|
trackingI.valueDefault = I;
|
||||||
|
trackingD.valueDefault = D;
|
||||||
|
}
|
||||||
|
|
||||||
|
// initialize PID control and parameters
|
||||||
|
void DualPid::init(uint8_t axisNumber, ServoControl *control) {
|
||||||
|
if (ready) return;
|
||||||
|
|
||||||
|
Feedback::init(axisNumber, control);
|
||||||
|
|
||||||
|
axisPrefix[5] = '0' + axisNumber;
|
||||||
|
|
||||||
|
pid = new QuickPID(&control->in, &control->out, &control->set,
|
||||||
|
0, 0, 0,
|
||||||
|
QuickPID::pMode::PID_PMODE, QuickPID::dMode::PID_DMODE, QuickPID::iAwMode::PID_IMODE,
|
||||||
|
QuickPID::Action::direct);
|
||||||
|
pid->SetSampleTimeUs(PID_SAMPLE_TIME_US);
|
||||||
|
pid->Initialize();
|
||||||
|
pid->SetMode(QuickPID::Control::automatic);
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset feedback control and parameters
|
||||||
|
void Pid::reset() {
|
||||||
|
VF("MSG:"); V(axisPrefix); VLF("reset");
|
||||||
|
control->in = 0;
|
||||||
|
control->set = 0;
|
||||||
|
control->out = 0;
|
||||||
|
trackingSelected = false;
|
||||||
|
selectTrackingParameters();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DualPid::setControlDirection(int8_t state) {
|
||||||
|
if (state == ON) pid->SetControllerDirection(QuickPID::Action::reverse); else pid->SetControllerDirection(QuickPID::Action::direct);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pid::setControlRange(float controlRange) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VF("setting feedback range +/-"); VL(controlRange);
|
||||||
|
pid->SetOutputLimits(-controlRange, controlRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
// select PID param set for tracking
|
||||||
|
void Pid::selectTrackingParameters() {
|
||||||
|
if (!trackingSelected) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VL("tracking selected");
|
||||||
|
trackingSelected = true;
|
||||||
|
pid->Reset();
|
||||||
|
pid->SetTunings(P.value, I.value, D.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// select PID param set for slewing
|
||||||
|
void Pid::selectSlewingParameters() {
|
||||||
|
if (trackingSelected) {
|
||||||
|
VF("MSG:"); V(axisPrefix); VL("slewing selected");
|
||||||
|
trackingSelected = false;
|
||||||
|
pid->Reset();
|
||||||
|
pid->SetTunings(P.value, I.value, D.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// variable PID params isn't used
|
||||||
|
void Pid::variableParameters(float percent) {
|
||||||
|
UNUSED(percent);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+80
@@ -0,0 +1,80 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// servo motor PID feedback
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../FeedbackBase.h"
|
||||||
|
|
||||||
|
#ifdef SERVO_MOTOR_PRESENT
|
||||||
|
|
||||||
|
#if AXIS1_SERVO_FEEDBACK == PID || AXIS2_SERVO_FEEDBACK == PID || AXIS3_SERVO_FEEDBACK == PID || \
|
||||||
|
AXIS4_SERVO_FEEDBACK == PID || AXIS5_SERVO_FEEDBACK == PID || AXIS6_SERVO_FEEDBACK == PID || \
|
||||||
|
AXIS7_SERVO_FEEDBACK == PID || AXIS8_SERVO_FEEDBACK == PID || AXIS9_SERVO_FEEDBACK == PID
|
||||||
|
|
||||||
|
#include <QuickPID.h> // https://github.com/Dlloydev/QuickPID
|
||||||
|
|
||||||
|
// various options for QuickPID read about them here https://github.com/Dlloydev/QuickPID
|
||||||
|
#ifndef PID_SAMPLE_TIME_US
|
||||||
|
#define PID_SAMPLE_TIME_US 10000 // PID sample time in microseconds (defaults to 10 milliseconds)
|
||||||
|
#endif
|
||||||
|
#ifndef PID_PMODE
|
||||||
|
#define PID_PMODE pOnError // http://brettbeauregard.com/blog/2017/06/introducing-proportional-on-measurement/
|
||||||
|
#endif
|
||||||
|
#ifndef PID_IMODE
|
||||||
|
#define PID_IMODE iAwCondition
|
||||||
|
#endif
|
||||||
|
#ifndef PID_DMODE
|
||||||
|
#define PID_DMODE dOnMeas
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class Pid : public Feedback {
|
||||||
|
public:
|
||||||
|
Pid(const float P, const float I, const float D);
|
||||||
|
|
||||||
|
// initialize PID control and parameters
|
||||||
|
void init(uint8_t axisNumber, ServoControl *control);
|
||||||
|
|
||||||
|
// reset feedback control and parameters
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
// returns the number of axis parameters
|
||||||
|
uint8_t getParameterCount() { return numParameters; }
|
||||||
|
|
||||||
|
// returns the specified axis parameter
|
||||||
|
AxisParameter* getParameter(uint8_t number) { if (number > numParameters) return &invalid; else return parameter[number]; }
|
||||||
|
|
||||||
|
// set feedback control direction
|
||||||
|
void setControlDirection(int8_t state);
|
||||||
|
|
||||||
|
// set feedback control range
|
||||||
|
void setControlRange(float controlRange);
|
||||||
|
|
||||||
|
// select PID param set for tracking
|
||||||
|
void selectTrackingParameters();
|
||||||
|
|
||||||
|
// select PID param set for slewing
|
||||||
|
void selectSlewingParameters();
|
||||||
|
|
||||||
|
// variable feedback, variable PID params
|
||||||
|
void variableParameters(float percent);
|
||||||
|
|
||||||
|
inline void poll() { }
|
||||||
|
|
||||||
|
private:
|
||||||
|
QuickPID *pid;
|
||||||
|
|
||||||
|
char axisPrefix[26] = " Axis_ServoFeedbackPID, "; // prefix for debug messages
|
||||||
|
|
||||||
|
bool trackingSelected = true;
|
||||||
|
|
||||||
|
// runtime adjustable settings
|
||||||
|
AxisParameter P = {NAN, NAN, NAN, 0.0, 10000.0, AXP_FLOAT_IMMEDIATE, "P"};
|
||||||
|
AxisParameter I = {NAN, NAN, NAN, 0.0, 10000.0, AXP_FLOAT_IMMEDIATE, "I"};
|
||||||
|
AxisParameter D = {NAN, NAN, NAN, 0.0, 10000.0, AXP_FLOAT_IMMEDIATE, "D"};
|
||||||
|
|
||||||
|
const int numParameters = 3;
|
||||||
|
AxisParameter* parameter[4] = {&invalid, &P, &I, &D};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// servo filter
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Kalman/Kalman.h"
|
||||||
|
#include "Learning/Learning.h"
|
||||||
|
#include "Rolling/Rolling.h"
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// servo filter
|
||||||
|
|
||||||
|
#include "FilterBase.h"
|
||||||
Executable
+41
@@ -0,0 +1,41 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// servo filter
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../../../../../Common.h"
|
||||||
|
|
||||||
|
#ifndef AXIS1_SERVO_FLTR
|
||||||
|
#define AXIS1_SERVO_FLTR OFF
|
||||||
|
#endif
|
||||||
|
#ifndef AXIS2_SERVO_FLTR
|
||||||
|
#define AXIS2_SERVO_FLTR OFF
|
||||||
|
#endif
|
||||||
|
#ifndef AXIS3_SERVO_FLTR
|
||||||
|
#define AXIS3_SERVO_FLTR OFF
|
||||||
|
#endif
|
||||||
|
#ifndef AXIS4_SERVO_FLTR
|
||||||
|
#define AXIS4_SERVO_FLTR OFF
|
||||||
|
#endif
|
||||||
|
#ifndef AXIS5_SERVO_FLTR
|
||||||
|
#define AXIS5_SERVO_FLTR OFF
|
||||||
|
#endif
|
||||||
|
#ifndef AXIS6_SERVO_FLTR
|
||||||
|
#define AXIS6_SERVO_FLTR OFF
|
||||||
|
#endif
|
||||||
|
#ifndef AXIS7_SERVO_FLTR
|
||||||
|
#define AXIS7_SERVO_FLTR OFF
|
||||||
|
#endif
|
||||||
|
#ifndef AXIS8_SERVO_FLTR
|
||||||
|
#define AXIS8_SERVO_FLTR OFF
|
||||||
|
#endif
|
||||||
|
#ifndef AXIS9_SERVO_FLTR
|
||||||
|
#define AXIS9_SERVO_FLTR OFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class Filter {
|
||||||
|
public:
|
||||||
|
virtual long update(long encoderCounts, long motorCounts, bool isTracking) { UNUSED(motorCounts); UNUSED(isTracking); return encoderCounts; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool initialized = false;
|
||||||
|
};
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// kalman filter
|
||||||
|
|
||||||
|
#include "Kalman.h"
|
||||||
|
|
||||||
|
#if AXIS1_SERVO_FLTR == KALMAN || AXIS2_SERVO_FLTR == KALMAN || AXIS3_SERVO_FLTR == KALMAN || \
|
||||||
|
AXIS4_SERVO_FLTR == KALMAN || AXIS5_SERVO_FLTR == KALMAN || AXIS6_SERVO_FLTR == KALMAN || \
|
||||||
|
AXIS7_SERVO_FLTR == KALMAN || AXIS8_SERVO_FLTR == KALMAN || AXIS9_SERVO_FLTR == KALMAN
|
||||||
|
|
||||||
|
KalmanFilter::KalmanFilter(float measurementUncertainty, float variance) {
|
||||||
|
kalmanFilter = new SimpleKalmanFilter(measurementUncertainty, measurementUncertainty, variance);
|
||||||
|
}
|
||||||
|
|
||||||
|
long KalmanFilter::update(long encoderCounts, long motorCounts, bool isTracking) {
|
||||||
|
UNUSED(isTracking);
|
||||||
|
|
||||||
|
long delta = encoderCounts - motorCounts;
|
||||||
|
|
||||||
|
if (!initialized) {
|
||||||
|
result = encoderCounts - motorCounts;
|
||||||
|
initialized = true;
|
||||||
|
} else {
|
||||||
|
result = kalmanFilter->updateEstimate(delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result + motorCounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// kalman filter
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../FilterBase.h"
|
||||||
|
|
||||||
|
#if AXIS1_SERVO_FLTR == KALMAN || AXIS2_SERVO_FLTR == KALMAN || AXIS3_SERVO_FLTR == KALMAN || \
|
||||||
|
AXIS4_SERVO_FLTR == KALMAN || AXIS5_SERVO_FLTR == KALMAN || AXIS6_SERVO_FLTR == KALMAN || \
|
||||||
|
AXIS7_SERVO_FLTR == KALMAN || AXIS8_SERVO_FLTR == KALMAN || AXIS9_SERVO_FLTR == KALMAN
|
||||||
|
|
||||||
|
#include <SimpleKalmanFilter.h> // https://github.com/denyssene/SimpleKalmanFilter
|
||||||
|
|
||||||
|
class KalmanFilter : public Filter {
|
||||||
|
public:
|
||||||
|
KalmanFilter(float measurementUncertainty, float variance);
|
||||||
|
|
||||||
|
long update(long encoderCounts, long motorCounts, bool isTracking);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool initialized = false;
|
||||||
|
long long result;
|
||||||
|
|
||||||
|
SimpleKalmanFilter *kalmanFilter;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user