Instrument Neutral Distributed Interface INDI 2.2.5
avalon_upas.h
Go to the documentation of this file.
1/*******************************************************************************
2 Avalon Instruments Universal Polar Alignment System (UPAS)
3
4 Copyright (C) 2026 Jasem Mutlaq ([email protected])
5
6 GRBL-based serial 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
56{
57 public:
58 AvalonUPAS();
59 virtual ~AvalonUPAS() override = default;
60
61 const char *getDefaultName() override;
62
63 bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
64 bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
65
66 protected:
67 bool initProperties() override;
68 bool updateProperties() override;
69 bool saveConfigItems(FILE *fp) override;
70
71 bool Handshake();
72 void TimerHit() override;
73
74 // PACInterface – axis movement
75 IPState MoveAZ(double degrees) override;
76 IPState MoveALT(double degrees) override;
77 IPState MoveBoth(double azDegrees, double altDegrees) override;
78
79 // PACInterface – abort, speed and reverse
80 bool AbortMotion() override;
81 bool SetPACSpeed(uint16_t speed) override;
82 bool ReverseAZ(bool enabled) override;
83 bool ReverseALT(bool enabled) override;
84
85 // PACInterface – backlash (applied in software, see class description)
86 bool SetBacklashEnabled(bool enabled) override;
87 bool SetBacklashAZ(int32_t steps) override;
88 bool SetBacklashALT(int32_t steps) override;
89
90 private:
94
103 bool sendCommand(const char *cmd, char *res = nullptr, int cmd_len = -1, int res_len = -1);
104
106 bool parseStatus(const char *response);
107
109 bool readReverseFlags();
110
111 void hexDump(char *buf, const char *data, int size);
112
114 double feedRateFor(double azMM, double altMM);
115
119
120 bool sendJog(double azMM, double altMM);
121
123 IPState jogWithBacklash(double azMM, double altMM);
124
131 double finalApproachMM(int axis, double &mm);
132
139 bool belowMinimum(const char *axis, double degrees);
140
144
145 // Gear ratio (mm per arcminute) for each axis; converts PAC interface degrees to GRBL mm.
146 INDI::PropertyNumber GearRatioNP {2};
147 enum
148 {
149 GEAR_AZ,
150 GEAR_ALT
151 };
152
153 // GRBL feed rate (mm/min) for each axis.
154 INDI::PropertyNumber FeedRateNP {2};
155 enum
156 {
157 FEED_AZ,
158 FEED_ALT
159 };
160
161 // Moves below this many arcminutes are skipped; 0 disables the check.
162 INDI::PropertyNumber MinMoveNP {1};
163
164 // Direction in which every move ends when backlash compensation is enabled.
165 INDI::PropertySwitch AZApproachSP {2};
166 INDI::PropertySwitch ALTApproachSP {2};
167 enum
168 {
169 APPROACH_POSITIVE,
170 APPROACH_NEGATIVE
171 };
172
173 // Read-only firmware version string returned at connect.
174 INDI::PropertyText FirmwareTP {1};
175
179 bool m_IsMoving {false};
180 bool m_IsFault {false};
181 uint8_t m_ReverseFlags {0};
182
183 int PortFD {-1};
184 Connection::Serial *serialConnection {nullptr};
185
189 static constexpr uint8_t DRIVER_TIMEOUT {3};
190 static constexpr uint8_t DRIVER_LEN {128};
191 static constexpr char DRIVER_STOP_CHAR {'\n'};
192};
bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
bool SetBacklashEnabled(bool enabled) override
SetBacklashEnabled Enable or disable hardware backlash compensation.
bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
bool Handshake()
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
bool AbortMotion() override
AbortMotion Abort all axis motion immediately.
IPState MoveAZ(double degrees) override
Move the azimuth axis by the given number of degrees.
IPState MoveBoth(double azDegrees, double altDegrees) override
MoveBoth Move both axes in a single coordinated operation.
bool ReverseAZ(bool enabled) override
ReverseAZ Reverse the direction of azimuth axis movement.
bool ReverseALT(bool enabled) override
ReverseALT Reverse the direction of altitude axis movement.
const char * getDefaultName() override
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual ~AvalonUPAS() override=default
bool SetBacklashAZ(int32_t steps) override
SetBacklashAZ Set the azimuth axis backlash compensation value in steps.
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
IPState MoveALT(double degrees) override
MoveALT Move the altitude axis by the given number of degrees.
bool SetBacklashALT(int32_t steps) override
SetBacklashALT Set the altitude axis backlash compensation value in steps.
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
bool SetPACSpeed(uint16_t speed) override
SetPACSpeed Set the motor speed used for axis movements.
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
*brief user defined string literal for JSON values *sa std::size_t n
uint8_t cmd[4]
Definition pwc-ioctl.h:2