Instrument Neutral Distributed Interface INDI 2.2.5
mlastro_rpa.h
Go to the documentation of this file.
1/*******************************************************************************
2 MLAstro Robotic Polar Alignment (RPA)
3
4 Copyright (C) 2026 Jasem Mutlaq ([email protected])
5
6 ESP32-based serial protocol (MLAstroRPA custom protocol).
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21*******************************************************************************/
22
23#pragma once
24
25#include "defaultdevice.h"
26#include "indipacinterface.h"
28
71{
72 public:
73 MLAstroRPA();
74 virtual ~MLAstroRPA() override = default;
75
76 const char *getDefaultName() override;
77
78 bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
79 bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
80 bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
81
82 protected:
83 bool initProperties() override;
84 bool updateProperties() override;
85 bool saveConfigItems(FILE *fp) override;
86
87 bool Handshake();
88 void TimerHit() override;
89
93 IPState MoveAZ(double degrees) override;
94 IPState MoveALT(double degrees) override;
95 IPState MoveBoth(double azDegrees, double altDegrees) override;
96
98 double applyCorrectionAZ(double azDegrees) const;
102 double applyCorrectionALT(double altDegrees) const;
103
107 bool AbortMotion() override;
108 bool SetPACSpeed(uint16_t speed) override;
109 bool ReverseAZ(bool enabled) override;
110 bool ReverseALT(bool enabled) override;
111
115 bool SetHome() override;
116 IPState GoHome() override;
117 bool ResetHome() override;
118
122 bool SyncAZ(double degrees) override;
123 bool SyncALT(double degrees) override;
124
128 bool SetBacklashEnabled(bool enabled) override;
129 bool SetBacklashAZ(int32_t steps) override;
130 bool SetBacklashALT(int32_t steps) override;
131
132 private:
136
142 bool sendCommand(const char *cmd, char *res = nullptr);
143
149 bool parseTelemetry(const char *response);
150
159 static void degreesToDMS(double degrees, int &d, int &m, int &s, bool &positive);
160
168 IPState sendRelativeMove(double degrees, const char *cmdPos, const char *cmdNeg);
169
170 void hexDump(char *buf, const char *data, int size);
171
175
176 void checkMotionComplete();
177
181
182 // ── Main Control tab ──────────────────────────────────────────────
184 INDI::PropertyText StatusTP {1};
185
187 INDI::PropertyLight WiFiLP {1};
188
190 INDI::PropertyLight HomedLP {1};
191
192 // ── Options tab ───────────────────────────────────────────────────
194 INDI::PropertyNumber AzSoftLimitsNP {2};
195 enum { AZ_LIMIT_MIN, AZ_LIMIT_MAX };
196
198 INDI::PropertyNumber AltSoftLimitsNP {2};
199 enum { ALT_LIMIT_MIN, ALT_LIMIT_MAX };
200
202 INDI::PropertySwitch AltOvershootSP {2};
203 enum { ALT_OVERSHOOT_ENABLED, ALT_OVERSHOOT_DISABLED };
204
206 INDI::PropertySwitch AltOvershootDirSP {2};
207 enum { ALT_OVERSHOOT_UP, ALT_OVERSHOOT_DOWN };
208
210 INDI::PropertyNumber AltOvershootAmountNP {1};
211
212 // ── Correction tab ────────────────────────────────────────────────
213 // Driver-side (client) correction shaping, mirroring MLAstro's N.I.N.A.
214 // implementation: the requested AZ/ALT correction is scaled by a safety
215 // factor, and optionally the altitude axis applies 100% of the error and
216 // then travels an overshoot distance past the target so it always settles
217 // from the same direction.
218
221 INDI::PropertyNumber CorrectionPercentNP {1};
222
224 INDI::PropertySwitch CorrectionOvershootSP {2};
225 enum { CORR_OVERSHOOT_ENABLED, CORR_OVERSHOOT_DISABLED };
226
228 INDI::PropertySwitch CorrectionOvershootDirSP {2};
229 enum { CORR_OVERSHOOT_UP, CORR_OVERSHOOT_DOWN };
230
232 INDI::PropertyNumber CorrectionOvershootAmountNP {1};
233
234 // ── Motor Config tab ──────────────────────────────────────────────
236 INDI::PropertyNumber AzMotorNP {9};
237 enum
238 {
239 AZ_RUN_CURRENT,
240 AZ_HOLD_CURRENT,
241 AZ_MICROSTEPS,
242 AZ_ACCEL,
243 AZ_DECEL,
244 AZ_STEPS_PER_DEG,
245 AZ_START_BOOST,
246 AZ_COOL_STEP,
247 AZ_RUN_MODE,
248 };
249
251 INDI::PropertyNumber AltMotorNP {9};
252 enum
253 {
254 ALT_RUN_CURRENT,
255 ALT_HOLD_CURRENT,
256 ALT_MICROSTEPS,
257 ALT_ACCEL,
258 ALT_DECEL,
259 ALT_STEPS_PER_DEG,
260 ALT_START_BOOST,
261 ALT_COOL_STEP,
262 ALT_RUN_MODE,
263 };
264
266 INDI::PropertySwitch SaveRebootSP {1};
267
268 // ── Network tab ──────────────────────────────────────────────────
271 INDI::PropertyText StationSSIDTP {1};
272
275 INDI::PropertyText StationPasswordTP {1};
276
278 INDI::PropertyText APConfigTP {2};
279 enum { AP_SSID, AP_IP };
280
283 INDI::PropertyText APPasswordTP {1};
284
285 // ── Info tab ──────────────────────────────────────────────────────
289 INDI::PropertyText FirmwareInfoTP {2};
290 enum { FIRMWARE_VERSION, FIRMWARE_SERIAL };
291
293 INDI::PropertyText WiFiInfoTP {6};
294 enum { WIFI_INFO_AP_SSID, WIFI_INFO_AP_IP, WIFI_INFO_AP_MAC,
295 WIFI_INFO_STA_SSID, WIFI_INFO_STA_IP, WIFI_INFO_STA_MAC };
296
300 bool m_IsMoving {false};
301 bool m_IsHoming {false};
302 bool m_IsHomed {false};
303
305 bool m_BacklashLogged {false};
306
308 double m_OvshD {0}, m_OvshM {0}, m_OvshS {0};
309
310 int PortFD {-1};
311 Connection::Serial *serialConnection {nullptr};
312
316 static constexpr uint8_t DRIVER_TIMEOUT {5};
317 static constexpr uint16_t DRIVER_LEN {2048};
318 static constexpr char DRIVER_STOP_CHAR {'\n'};
319 static constexpr const char *MOTOR_CONFIG_TAB {"Motor Config"};
320 static constexpr const char *NETWORK_TAB {"Network"};
321 static constexpr const char *INFO_TAB {"Info"};
322 static constexpr const char *CORRECTION_TAB {"Correction"};
323};
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
The MLAstroRPA class drives the MLAstro Robotic Polar Alignment controller via its ESP32-based serial...
Definition mlastro_rpa.h:71
IPState GoHome() override
GoHome.
bool updateProperties() override
updateProperties
bool ReverseALT(bool enabled) override
ReverseALT.
bool SetBacklashALT(int32_t steps) override
SetBacklashALT.
bool AbortMotion() override
PACInterface – abort, speed and reverse.
bool initProperties() override
initProperties
void TimerHit() override
TimerHit.
IPState MoveAZ(double degrees) override
PACInterface – axis movement.
bool SyncALT(double degrees) override
SyncALT – same mechanism as SyncAZ.
IPState MoveBoth(double azDegrees, double altDegrees) override
bool saveConfigItems(FILE *fp) override
saveConfigItems
IPState MoveALT(double degrees) override
MoveALT.
bool SyncAZ(double degrees) override
PACInterface – sync.
bool SetHome() override
PACInterface – home management.
double applyCorrectionAZ(double azDegrees) const
Scale a requested azimuth step by the configured correction percentage.
MLAstroRPA()
Constructor.
double applyCorrectionALT(double altDegrees) const
applyCorrectionALT – correction percentage, or full error + overshoot
bool ReverseAZ(bool enabled) override
ReverseAZ.
bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
ISNewText.
bool Handshake()
Handshake.
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
ISNewSwitch.
const char * getDefaultName() override
Basic device info.
bool ResetHome() override
ResetHome.
bool SetBacklashAZ(int32_t steps) override
SetBacklashAZ.
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
ISNewNumber.
virtual ~MLAstroRPA() override=default
bool SetBacklashEnabled(bool enabled) override
PACInterface – backlash.
bool SetPACSpeed(uint16_t speed) override
SetPACSpeed (SLvl: 1–5)
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
uint8_t cmd[4]
Definition pwc-ioctl.h:2