This commit is contained in:
2025-02-08 19:48:44 +03:00
parent 55d8d359b4
commit d7df8e5bf1
8 changed files with 387 additions and 92 deletions

View File

@@ -18,10 +18,12 @@
#pragma once
#include <math.h>
#include <stdint.h>
#include "sidservo.h"
#if 0
// ASCII commands
#define U8P(x) ((uint8_t*)x)
// get binary data of all statistics
@@ -50,26 +52,70 @@
#define CMD_GETYAEPR U8P("XXZ")
// exit ASCII checksum mode
#define CMD_EXITACM U8P("YXY0\r\xb8")
#endif
// get binary data of all statistics
#define CMD_GETSTAT ("XXS")
// send short command
#define CMD_SHORTCMD ("XXR")
// send long command
#define CMD_LONGCMD ("YXR")
// get/set X/Y in motsteps
#define CMD_MOTX ("X")
#define CMD_MOTY ("Y")
// -//- in encoders' ticks
#define CMD_ENCX ("XZ")
#define CMD_ENCY ("YZ")
// normal stop X/Y
#define CMD_STOPX ("XN")
#define CMD_STOPY ("YN")
// emergency stop
#define CMD_EMSTOPX ("XG")
#define CMD_EMSTOPY ("YG")
// getters of motor's encoders per rev
#define CMD_GETXMEPR ("XXU")
#define CMD_GETYMEPR ("XXV")
// -//- axis encoders
#define CMD_GETXAEPR ("XXT")
#define CMD_GETYAEPR ("XXZ")
// exit ASCII checksum mode
#define CMD_EXITACM ("YXY0\r\xb8")
// timeout (seconds) of reading answer (from last symbol read)
#define READTIMEOUT (0.05)
// steps per revolution; TODO: move to Conf
#define HA_MOT_STEPSPERREV (4394294)
#define DEC_MOT_STEPSPERREV (3325291)
// steps per revolution
#define X_MOT_STEPSPERREV (4394294.)
#define Y_MOT_STEPSPERREV (3325291.)
// encoder's tolerance (ticks); TODO: move to Conf
#define HAENCTOL (25)
#define DECENCTOL (25)
// motor position to radians and back
#define X_MOT2RAD(n) (2.*M_PI * (double)n / X_MOT_STEPSPERREV)
#define Y_MOT2RAD(n) (2.*M_PI * (double)n / Y_MOT_STEPSPERREV)
#define X_RAD2MOT(r) ((uint32_t)(r / 2./M_PI * X_MOT_STEPSPERREV))
#define Y_RAD2MOT(r) ((uint32_t)(r / 2./M_PI * Y_MOT_STEPSPERREV))
// encoder per revolution
#define X_ENC_STEPSPERREV (67108863.)
#define Y_ENC_STEPSPERREV (67108863.)
// encoder position to radians and back
#define X_ENC2RAD(n) (2.*M_PI * (double)n / X_ENC_STEPSPERREV)
#define Y_ENC2RAD(n) (2.*M_PI * (double)n / Y_ENC_STEPSPERREV)
#define X_RAD2ENC(r) ((uint32_t)(r / 2./M_PI * X_ENC_STEPSPERREV))
#define Y_RAD2ENC(r) ((uint32_t)(r / 2./M_PI * Y_ENC_STEPSPERREV))
// encoder's tolerance (ticks)
#define YencTOL (25.)
#define XencTOL (25.)
// all need data in one
typedef struct{ // 41 bytes
uint8_t ctrlAddr; // 0 a8 + controller address
int32_t DECmot; // 1 Dec/HA motor position
int32_t HAmot; // 5
int32_t DECenc; // 9 Dec/HA encoder position
int32_t HAenc; // 13
int32_t Xmot; // 1 Dec/HA motor position
int32_t Ymot; // 5
int32_t Xenc; // 9 Dec/HA encoder position
int32_t Yenc; // 13
uint8_t keypad; // 17 keypad status
uint8_t XBits; // 18
uint8_t YBits; // 19
@@ -79,16 +125,16 @@ typedef struct{ // 41 bytes
uint32_t millis; // 25 milliseconds clock
int8_t tF; // 29 temperature (degF)
uint8_t voltage; // 30 input voltage *10 (RA worm phase?)
uint32_t DecLast; // 31 Alt/Dec motor location at last Alt/Dec scope encoder location change
uint32_t HALast; // 35 Az/RA motor location at last Az/RA scope encoder location change
uint32_t XLast; // 31 Alt/Dec motor location at last Alt/Dec scope encoder location change
uint32_t YLast; // 35 Az/RA motor location at last Az/RA scope encoder location change
uint16_t checksum; // 39 checksum, H inverted
}__attribute__((packed)) SSstat;
typedef struct{
int32_t DECmot; // 0 DEC motor position
int32_t DECspeed; // 4 DEC speed
int32_t HAmot; // 8
int32_t HAspeed; // 12
int32_t Xmot; // 0 DEC motor position
int32_t Xspeed; // 4 DEC speed
int32_t Ymot; // 8
int32_t Yspeed; // 12
uint8_t xychange; // 16 change Xbits/Ybits value
uint8_t XBits; // 17
uint8_t YBits; // 18
@@ -96,18 +142,23 @@ typedef struct{
} __attribute__((packed)) SSscmd; // short command
typedef struct{
int32_t DECmot; // 0 DEC motor position
int32_t DECspeed; // 4 DEC speed
int32_t HAmot; // 8
int32_t HAspeed; // 12
int32_t DECadder; // 16 - DEC adder
int32_t HAadder; // 20
int32_t DECatime; // 24 DEC adder time
int32_t HAatime; // 28
int32_t Xmot; // 0 DEC motor position
int32_t Xspeed; // 4 DEC speed
int32_t Ymot; // 8
int32_t Yspeed; // 12
int32_t Xadder; // 16 - DEC adder
int32_t Yadder; // 20
int32_t Xatime; // 24 DEC adder time
int32_t Yatime; // 28
uint16_t checksum; // 32
} __attribute__((packed)) SSlcmd; // long command
int SScmdS(SSscmd *cmd);
int SScmdL(SSlcmd *cmd);
uint16_t SScalcChecksum(uint8_t *buf, int len);
void SSconvstat(const SSstat *status, mountdata_t *mountdata);
void SSconvstat(const SSstat *status, mountdata_t *mountdata, struct timeval *tdat);
int SStextcmd(const char *cmd, data_t *answer);
int SSgetint(const char *cmd, int64_t *ans);
int SSXmoveto(double pos);
int SSYmoveto(double pos);
int SSemergStop();