From 2a4e2e158634493cdb700c727af57af2eb9d045a Mon Sep 17 00:00:00 2001 From: Frank Wang <103447783+WandererAstro@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:45:49 +0800 Subject: [PATCH] Driver for WandererRotator Mini V1/V2 and Lite V2 updated (#2005) * Driver for WandererRotator Mini and Lite updated * Driver for WandererRotator Mini and Lite updated --------- Co-authored-by: WandererAstro --- drivers.xml | 4 + drivers/rotator/CMakeLists.txt | 8 + drivers/rotator/wanderer_rotator_lite_v2.cpp | 409 +++++++++++++++++++ drivers/rotator/wanderer_rotator_lite_v2.h | 85 ++++ drivers/rotator/wanderer_rotator_mini.cpp | 142 ++++--- drivers/rotator/wanderer_rotator_mini.h | 14 +- 6 files changed, 604 insertions(+), 58 deletions(-) create mode 100644 drivers/rotator/wanderer_rotator_lite_v2.cpp create mode 100644 drivers/rotator/wanderer_rotator_lite_v2.h diff --git a/drivers.xml b/drivers.xml index 642fc737e5..a0f443a53d 100644 --- a/drivers.xml +++ b/drivers.xml @@ -443,6 +443,10 @@ indi_wanderer_rotator_mini + 1.1 + + + indi_wanderer_rotator_lite_v2 1.0 diff --git a/drivers/rotator/CMakeLists.txt b/drivers/rotator/CMakeLists.txt index 6b2ee9e293..7a614262dc 100644 --- a/drivers/rotator/CMakeLists.txt +++ b/drivers/rotator/CMakeLists.txt @@ -70,6 +70,14 @@ add_executable(indi_wanderer_rotator_mini ${WandererRotatorMini_SRC}) target_link_libraries(indi_wanderer_rotator_mini indidriver) install(TARGETS indi_wanderer_rotator_mini RUNTIME DESTINATION bin) +# ############### Wanderer Rotator Lite V2 ################ +SET(WandererRotatorLiteV2_SRC + wanderer_rotator_lite_v2.cpp) + +add_executable(indi_wanderer_rotator_lite_v2 ${WandererRotatorLiteV2_SRC}) +target_link_libraries(indi_wanderer_rotator_lite_v2 indidriver) +install(TARGETS indi_wanderer_rotator_lite_v2 RUNTIME DESTINATION bin) + # ############### Integra85 Focusing Rotator ################ SET(integra_SRC diff --git a/drivers/rotator/wanderer_rotator_lite_v2.cpp b/drivers/rotator/wanderer_rotator_lite_v2.cpp new file mode 100644 index 0000000000..ad54666778 --- /dev/null +++ b/drivers/rotator/wanderer_rotator_lite_v2.cpp @@ -0,0 +1,409 @@ +/******************************************************************************* + Copyright(c) 2024 Frank Wang. All rights reserved. + + WandererRotator Lite V2 + + 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 2 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 Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + The full GNU General Public License is included in this distribution in the + file called LICENSE. +*******************************************************************************/ + +#include "wanderer_rotator_lite_v2.h" +#include "indicom.h" +#include "connectionplugins/connectionserial.h" +#include +#include +#include +#include +#include +#include +#include +#include + + +// We declare an auto pointer to WandererRotatorLiteV2. +static std::unique_ptr wandererrotatorlitev2(new WandererRotatorLiteV2()); + +WandererRotatorLiteV2::WandererRotatorLiteV2() +{ + setVersion(1, 0); + +} +bool WandererRotatorLiteV2::initProperties() +{ + + INDI::Rotator::initProperties(); + + SetCapability(ROTATOR_CAN_REVERSE | ROTATOR_CAN_ABORT | ROTATOR_CAN_HOME); + + addAuxControls(); + // Calibrate + SetZeroSP[0].fill("Set_Zero", "Mechanical Zero", ISS_OFF); + SetZeroSP.fill(getDeviceName(), "Set_Zero", "Set Current As", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1,60, IPS_IDLE); + + // BACKLASH + BacklashNP[BACKLASH].fill( "BACKLASH", "Degree", "%.2f", 0, 3, 0.1, 0); + BacklashNP.fill(getDeviceName(), "BACKLASH", "Backlash", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE); + + serialConnection->setDefaultBaudRate(Connection::Serial::B_19200); + + + return true; +} + +bool WandererRotatorLiteV2::updateProperties() +{ + INDI::Rotator::updateProperties(); + + if (isConnected()) + { + defineProperty(SetZeroSP); + defineProperty(BacklashNP); + } + else + { + deleteProperty(SetZeroSP); + deleteProperty(BacklashNP); + } + return true; +} + +bool WandererRotatorLiteV2::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) +{ + + if (dev && !strcmp(dev, getDeviceName())) + { + if (SetZeroSP.isNameMatch(name)) + { + SetZeroSP.setState(sendCommand("1500002") ? IPS_OK : IPS_ALERT); + SetZeroSP.apply(); + GotoRotatorN[0].value=0; + IDSetNumber(&GotoRotatorNP, nullptr); + LOG_INFO("Virtual Mechanical Angle is set to zero."); + return true; + } + } + return Rotator::ISNewSwitch(dev, name, states, names, n); +} + +bool WandererRotatorLiteV2::ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n) +{ + if (dev && !strcmp(dev, getDeviceName())) + { + // backlash + if (BacklashNP.isNameMatch(name)) + { + bool rc1 = false; + BacklashNP.update(values, names, n); + backlash=BacklashNP[BACKLASH].value; + + char cmd[16]; + snprintf(cmd, 16, "%d", (int)(backlash*10+1600000)); + rc1=sendCommand(cmd); + + BacklashNP.setState( (rc1) ? IPS_OK : IPS_ALERT); + if (BacklashNP.getState() == IPS_OK) + BacklashNP.update(values, names, n); + BacklashNP.apply(); + LOG_INFO("Backlash Set"); + return true; + } + + } + return Rotator::ISNewNumber(dev, name, values, names, n); +} + +const char *WandererRotatorLiteV2::getDefaultName() +{ + return "WandererRotator Lite V2"; +} + +bool WandererRotatorLiteV2::Handshake() +{ + PortFD = serialConnection->getPortFD(); + tcflush(PortFD, TCIOFLUSH); + int nbytes_read_name = 0,nbytes_written=0,rc=-1; + char name[64] = {0}; + + if ((rc = tty_write_string(PortFD, "1500001", &nbytes_written)) != TTY_OK) + { + char errorMessage[MAXRBUF]; + tty_error_msg(rc, errorMessage, MAXRBUF); + LOGF_ERROR("Serial write error: %s", errorMessage); + return false; + } + + //Device Model////////////////////////////////////////////////////////////////////////////////////////////////////// + if ((rc = tty_read_section(PortFD, name, 'A', 3, &nbytes_read_name)) != TTY_OK) + { + tcflush(PortFD, TCIOFLUSH); + if ((rc = tty_write_string(PortFD, "1500001", &nbytes_written)) != TTY_OK) + { + char errorMessage[MAXRBUF]; + tty_error_msg(rc, errorMessage, MAXRBUF); + LOGF_ERROR("Serial write error: %s", errorMessage); + return false; + } + if ((rc = tty_read_section(PortFD, name, 'A', 3, &nbytes_read_name)) != TTY_OK) + { + char errorMessage[MAXRBUF]; + tty_error_msg(rc, errorMessage, MAXRBUF); + LOGF_INFO("No data received, the device may not be WandererRotator, please check the serial port!","Updated"); + LOGF_ERROR("Device read error: %s", errorMessage); + return false; + } + } + name[nbytes_read_name - 1] = '\0'; + if(strcmp(name, "WandererRotatorLiteV2")!=0) + { + LOGF_ERROR("The device is not WandererRotator Lite V2!","Updated"); + LOGF_INFO("The device is %s",name); + return false; + } + // Frimware version///////////////////////////////////////////////////////////////////////////////////////////// + int nbytes_read_version = 0; + char version[64] = {0}; + tty_read_section(PortFD, version, 'A', 5, &nbytes_read_version); + + version[nbytes_read_version - 1] = '\0'; + LOGF_INFO("Firmware Version:%s", version); + firmware=std::atoi(version); + if(firmware<20240226) + { + LOG_ERROR("The firmware is outdated, please upgrade to the latest firmware!"); + return false; + } + + // Angle////////////////////////////////////////////////////////////////////////////////////////// + char M_angle[64] = {0}; + int nbytes_read_M_angle= 0; + tty_read_section(PortFD, M_angle, 'A', 5, &nbytes_read_M_angle); + M_angle[nbytes_read_M_angle - 1] = '\0'; + M_angleread = std::strtod(M_angle,NULL); + + if(abs(M_angleread)>400000) + { + rc=sendCommand("1500002"); + LOG_WARN("Virtual Mechanical Angle is too large, it is now set to zero!"); + rc=sendCommand("1500001"); + rc=tty_read_section(PortFD, M_angle, 'A', 5, &nbytes_read_M_angle); + rc=tty_read_section(PortFD, M_angle, 'A', 5, &nbytes_read_M_angle); + rc=tty_read_section(PortFD, M_angle, 'A', 5, &nbytes_read_M_angle); + M_angle[nbytes_read_M_angle - 1] = '\0'; + M_angleread = std::strtod(M_angle,NULL); + } + GotoRotatorN[0].value=abs(M_angleread/1000); + //backlash///////////////////////////////////////////////////////////////////// + char M_backlash[64] = {0}; + int nbytes_read_M_backlash= 0; + tty_read_section(PortFD, M_backlash, 'A', 5, &nbytes_read_M_backlash); + M_backlash[nbytes_read_M_angle - 1] = '\0'; + M_backlashread = std::strtod(M_backlash,NULL); + + BacklashNP[BACKLASH].setValue(M_backlashread); + BacklashNP.setState(IPS_OK); + BacklashNP.apply(); + //reverse///////////////////////////////////////////////////////////////////// + char M_reverse[64] = {0}; + int nbytes_read_M_reverse= 0; + tty_read_section(PortFD, M_reverse, 'A', 5, &nbytes_read_M_reverse); + M_reverse[nbytes_read_M_angle - 1] = '\0'; + M_reverseread = std::strtod(M_reverse,NULL); + if(M_reverseread==0) + { + ReverseRotator(false); + } + else + { + ReverseRotator(true); + } + + tcflush(PortFD, TCIOFLUSH); + return true; +} + + +IPState WandererRotatorLiteV2::MoveRotator(double angle) +{ + angle = angle - GotoRotatorN[0].value; + + char cmd[16]; + int position = (int)(angle * 1199+1000000); + positionhistory = angle; + snprintf(cmd, 16, "%d", position); + Move(cmd); + + return IPS_BUSY; +} + + +bool WandererRotatorLiteV2::AbortRotator() +{ + + + if (GotoRotatorNP.s == IPS_BUSY) + { + haltcommand = true; + int nbytes_written = 0, rc = -1; + tcflush(PortFD, TCIOFLUSH); + if ((rc = tty_write_string(PortFD, "Stop", &nbytes_written)) != TTY_OK) + { + char errorMessage[MAXRBUF]; + tty_error_msg(rc, errorMessage, MAXRBUF); + LOGF_ERROR("Serial write error: %s", errorMessage); + return false; + } + SetTimer(100); + } + return true; +} + +////////////////////////////////////////////////////////////////////////////////////////////// +/// \brief WandererRotatorLiteV2::HomeRotator +/// \return +/// +IPState WandererRotatorLiteV2::HomeRotator() +{ + if(GotoRotatorN[0].value!=0) + { + double angle = -1 * GotoRotatorN[0].value; + + char cmd[16]; + int position = (int)(angle * 1199+1000000); + snprintf(cmd, 16, "%d", position); + GotoRotatorNP.s = IPS_BUSY; + Move(cmd); + LOG_INFO("Moving to zero..."); + } + return IPS_OK; +} + + +bool WandererRotatorLiteV2::ReverseRotator(bool enabled) +{ + + if (enabled) + { + char cmd[16]; + snprintf(cmd, 16, "%d", 1700001); + if (sendCommand(cmd)!= true) + { + LOG_ERROR("Serial write error."); + return false; + } + ReverseState = true; + return true; + } + else + { + char cmd[16]; + snprintf(cmd, 16, "%d", 1700000); + if (sendCommand(cmd)!= true) + { + LOG_ERROR("Serial write error."); + return false; + } + ReverseState = false; + return true; + } + return false; +} + + + +void WandererRotatorLiteV2::TimerHit() +{ + + if (GotoRotatorNP.s == IPS_BUSY || haltcommand == true) + { + + if(nowtime", cmd); + if ((rc = tty_write_string(PortFD, cmd, &nbytes_written)) != TTY_OK) + { + char errorMessage[MAXRBUF]; + tty_error_msg(rc, errorMessage, MAXRBUF); + LOGF_ERROR("Serial write error: %s", errorMessage); + return false; + } + SetTimer(2000); + nowtime=0; + estime=abs((std::atoi(cmd)-1000000)/1199*240); + return true; +} + + +bool WandererRotatorLiteV2::sendCommand(std::string command) +{ + int nbytes_written = 0, rc = -1; + std::string command_termination = "\n"; + LOGF_DEBUG("CMD: %s", command.c_str()); + if ((rc = tty_write_string(PortFD, (command + command_termination).c_str(), &nbytes_written)) != TTY_OK) + { + char errorMessage[MAXRBUF]; + tty_error_msg(rc, errorMessage, MAXRBUF); + LOGF_ERROR("Serial write error: %s", errorMessage); + return false; + } + return true; +} + + diff --git a/drivers/rotator/wanderer_rotator_lite_v2.h b/drivers/rotator/wanderer_rotator_lite_v2.h new file mode 100644 index 0000000000..f2c16279eb --- /dev/null +++ b/drivers/rotator/wanderer_rotator_lite_v2.h @@ -0,0 +1,85 @@ +/******************************************************************************* + Copyright(c) 2024 Frank Wang. All rights reserved. + + WandererRotator Lite V2 + + 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 2 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 Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + The full GNU General Public License is included in this distribution in the + file called LICENSE. +*******************************************************************************/ + +#pragma once + +#include "defaultdevice.h" +#include "indirotator.h" +#include "indirotatorinterface.h" +#include "indipropertyswitch.h" +class WandererRotatorLiteV2 : public INDI::Rotator +{ +public: + WandererRotatorLiteV2(); + + virtual bool initProperties() override; + virtual bool updateProperties() override; + virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override; + virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; + + + + +protected: + const char * getDefaultName() override; + virtual IPState MoveRotator(double angle) override; + virtual IPState HomeRotator() override; + virtual bool ReverseRotator(bool enabled) override; + + virtual bool AbortRotator() override; + virtual void TimerHit() override; + + + + + +private: + int firmware=0; + double M_angleread=0; + double M_backlashread=0; + double M_reverseread=0; + double initangle=0; + bool Handshake() override; + INDI::PropertySwitch SetZeroSP{1}; + bool sendCommand(std::string command); + bool Move(const char *cmd); + bool haltcommand = false; + bool ReverseState=false; + double backlash=0.5; + double positionhistory=0; + int estime=0; + int nowtime=0; + + INDI::PropertyNumber BacklashNP{1}; + enum + { + BACKLASH, + }; + +}; + + + + + diff --git a/drivers/rotator/wanderer_rotator_mini.cpp b/drivers/rotator/wanderer_rotator_mini.cpp index 4c3e4758d1..c5780de18a 100644 --- a/drivers/rotator/wanderer_rotator_mini.cpp +++ b/drivers/rotator/wanderer_rotator_mini.cpp @@ -40,7 +40,7 @@ static std::unique_ptr wandererrotatormini(new WandererRota WandererRotatorMini::WandererRotatorMini() { - setVersion(1, 0); + setVersion(1, 1); } bool WandererRotatorMini::initProperties() @@ -48,13 +48,16 @@ bool WandererRotatorMini::initProperties() INDI::Rotator::initProperties(); - SetCapability(ROTATOR_CAN_REVERSE | ROTATOR_CAN_ABORT | ROTATOR_CAN_HOME | ROTATOR_HAS_BACKLASH); + SetCapability(ROTATOR_CAN_REVERSE | ROTATOR_CAN_ABORT | ROTATOR_CAN_HOME); addAuxControls(); // Calibrate SetZeroSP[0].fill("Set_Zero", "Mechanical Zero", ISS_OFF); SetZeroSP.fill(getDeviceName(), "Set_Zero", "Set Current As", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1,60, IPS_IDLE); + // BACKLASH + BacklashNP[BACKLASH].fill( "BACKLASH", "Degree", "%.2f", 0, 3, 0.1, 0); + BacklashNP.fill(getDeviceName(), "BACKLASH", "Backlash", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE); serialConnection->setDefaultBaudRate(Connection::Serial::B_19200); @@ -69,14 +72,12 @@ bool WandererRotatorMini::updateProperties() if (isConnected()) { defineProperty(SetZeroSP); - if(firmware<20240208) - { - LOG_ERROR("The firmware is outdated, please upgrade to the latest firmware, or the driver cannot function properly!"); - } + defineProperty(BacklashNP); } else { deleteProperty(SetZeroSP); + deleteProperty(BacklashNP); } return true; } @@ -99,7 +100,32 @@ bool WandererRotatorMini::ISNewSwitch(const char *dev, const char *name, ISState return Rotator::ISNewSwitch(dev, name, states, names, n); } +bool WandererRotatorMini::ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n) +{ + if (dev && !strcmp(dev, getDeviceName())) + { + // backlash + if (BacklashNP.isNameMatch(name)) + { + bool rc1 = false; + BacklashNP.update(values, names, n); + backlash=BacklashNP[BACKLASH].value; + + char cmd[16]; + snprintf(cmd, 16, "%d", (int)(backlash*10+1600000)); + rc1=sendCommand(cmd); + + BacklashNP.setState( (rc1) ? IPS_OK : IPS_ALERT); + if (BacklashNP.getState() == IPS_OK) + BacklashNP.update(values, names, n); + BacklashNP.apply(); + LOG_INFO("Backlash Set"); + return true; + } + } + return Rotator::ISNewNumber(dev, name, values, names, n); +} const char *WandererRotatorMini::getDefaultName() { @@ -124,7 +150,7 @@ bool WandererRotatorMini::Handshake() //Device Model////////////////////////////////////////////////////////////////////////////////////////////////////// if ((rc = tty_read_section(PortFD, name, 'A', 3, &nbytes_read_name)) != TTY_OK) { - tcflush(PortFD, TCIOFLUSH); + tcflush(PortFD, TCIOFLUSH); if ((rc = tty_write_string(PortFD, "1500001", &nbytes_written)) != TTY_OK) { char errorMessage[MAXRBUF]; @@ -156,6 +182,12 @@ bool WandererRotatorMini::Handshake() version[nbytes_read_version - 1] = '\0'; LOGF_INFO("Firmware Version:%s", version); firmware=std::atoi(version); + if(firmware<20240226) + { + LOG_ERROR("The firmware is outdated, please upgrade to the latest firmware!"); + return false; + } + // Angle////////////////////////////////////////////////////////////////////////////////////////// char M_angle[64] = {0}; int nbytes_read_M_angle= 0; @@ -173,9 +205,33 @@ bool WandererRotatorMini::Handshake() rc=tty_read_section(PortFD, M_angle, 'A', 5, &nbytes_read_M_angle); M_angle[nbytes_read_M_angle - 1] = '\0'; M_angleread = std::strtod(M_angle,NULL); - } GotoRotatorN[0].value=abs(M_angleread/1000); + //backlash///////////////////////////////////////////////////////////////////// + char M_backlash[64] = {0}; + int nbytes_read_M_backlash= 0; + tty_read_section(PortFD, M_backlash, 'A', 5, &nbytes_read_M_backlash); + M_backlash[nbytes_read_M_angle - 1] = '\0'; + M_backlashread = std::strtod(M_backlash,NULL); + + BacklashNP[BACKLASH].setValue(M_backlashread); + BacklashNP.setState(IPS_OK); + BacklashNP.apply(); + //reverse///////////////////////////////////////////////////////////////////// + char M_reverse[64] = {0}; + int nbytes_read_M_reverse= 0; + tty_read_section(PortFD, M_reverse, 'A', 5, &nbytes_read_M_reverse); + M_reverse[nbytes_read_M_angle - 1] = '\0'; + M_reverseread = std::strtod(M_reverse,NULL); + if(M_reverseread==0) + { + ReverseRotator(false); + } + else + { + ReverseRotator(true); + } + tcflush(PortFD, TCIOFLUSH); return true; } @@ -184,16 +240,9 @@ bool WandererRotatorMini::Handshake() IPState WandererRotatorMini::MoveRotator(double angle) { angle = angle - GotoRotatorN[0].value; - if (angle * positionhistory < 0 && angle > 0) - { - angle = angle + backlash; - } - if (angle * positionhistory < 0 && angle < 0) - { - angle = angle - backlash; - } + char cmd[16]; - int position = (int)(reversecoefficient * angle * 1142); + int position = (int)(angle * 1142+1000000); positionhistory = angle; snprintf(cmd, 16, "%d", position); Move(cmd); @@ -202,12 +251,13 @@ IPState WandererRotatorMini::MoveRotator(double angle) } - bool WandererRotatorMini::AbortRotator() { - haltcommand = true; + if (GotoRotatorNP.s == IPS_BUSY) + { + haltcommand = true; int nbytes_written = 0, rc = -1; tcflush(PortFD, TCIOFLUSH); if ((rc = tty_write_string(PortFD, "Stop", &nbytes_written)) != TTY_OK) @@ -217,8 +267,8 @@ bool WandererRotatorMini::AbortRotator() LOGF_ERROR("Serial write error: %s", errorMessage); return false; } - SetTimer(100); + } return true; } @@ -228,15 +278,17 @@ bool WandererRotatorMini::AbortRotator() /// IPState WandererRotatorMini::HomeRotator() { + if(GotoRotatorN[0].value!=0) + { + double angle = -1 * GotoRotatorN[0].value; - double angle = -1 * reversecoefficient * GotoRotatorN[0].value; - positionhistory = -1* GotoRotatorN[0].value; char cmd[16]; - int position = (int)(angle * 1142); + int position = (int)(angle * 1142+1000000); snprintf(cmd, 16, "%d", position); GotoRotatorNP.s = IPS_BUSY; Move(cmd); LOG_INFO("Moving to zero..."); + } return IPS_OK; } @@ -246,23 +298,25 @@ bool WandererRotatorMini::ReverseRotator(bool enabled) if (enabled) { - if(M_angleread>0) + char cmd[16]; + snprintf(cmd, 16, "%d", 1700001); + if (sendCommand(cmd)!= true) { - HomeRotator(); - LOG_WARN("The rotator will first move to zero and then reverse the rotation direction to prevent cable wrap..."); + LOG_ERROR("Serial write error."); + return false; } - reversecoefficient = -1; ReverseState = true; return true; } else { - if(M_angleread<0) + char cmd[16]; + snprintf(cmd, 16, "%d", 1700000); + if (sendCommand(cmd)!= true) { - HomeRotator(); - LOG_WARN("The rotator will first move to zero and then reverse the rotation direction to prevent cable wrap..."); + LOG_ERROR("Serial write error."); + return false; } - reversecoefficient = 1; ReverseState = false; return true; } @@ -281,8 +335,8 @@ void WandererRotatorMini::TimerHit() { GotoRotatorN[0].value=GotoRotatorN[0].value+1*positionhistory/abs(positionhistory); IDSetNumber(&GotoRotatorNP, nullptr); - nowtime=nowtime+270; - SetTimer(270); + nowtime=nowtime+220; + SetTimer(220); return; } else @@ -332,7 +386,7 @@ bool WandererRotatorMini::Move(const char *cmd) } SetTimer(2000); nowtime=0; - estime=abs(std::atoi(cmd)/1142*260); + estime=abs((std::atoi(cmd)-1000000)/1142*220); return true; } @@ -353,23 +407,3 @@ bool WandererRotatorMini::sendCommand(std::string command) } -bool WandererRotatorMini::SetRotatorBacklash(int32_t steps) -{ - backlash = (double)(steps / 1142); - return true; -} - -bool WandererRotatorMini::SetRotatorBacklashEnabled(bool enabled) -{ - if(enabled) - { - return SetRotatorBacklash(RotatorBacklashN[0].value); - } - else - { - return SetRotatorBacklash(0); - } - -} - - diff --git a/drivers/rotator/wanderer_rotator_mini.h b/drivers/rotator/wanderer_rotator_mini.h index 280ba1deb7..eb2c34bea1 100644 --- a/drivers/rotator/wanderer_rotator_mini.h +++ b/drivers/rotator/wanderer_rotator_mini.h @@ -36,6 +36,7 @@ class WandererRotatorMini : public INDI::Rotator virtual bool initProperties() override; virtual bool updateProperties() override; virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override; + virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; @@ -48,8 +49,7 @@ class WandererRotatorMini : public INDI::Rotator virtual bool AbortRotator() override; virtual void TimerHit() override; - virtual bool SetRotatorBacklash(int32_t steps) override; - virtual bool SetRotatorBacklashEnabled(bool enabled) override; + @@ -57,6 +57,8 @@ class WandererRotatorMini : public INDI::Rotator private: int firmware=0; double M_angleread=0; + double M_backlashread=0; + double M_reverseread=0; double initangle=0; bool Handshake() override; INDI::PropertySwitch SetZeroSP{1}; @@ -64,14 +66,18 @@ class WandererRotatorMini : public INDI::Rotator bool Move(const char *cmd); bool haltcommand = false; bool ReverseState=false; - int reversecoefficient=1; double backlash=0.5; double positionhistory=0; int estime=0; int nowtime=0; -}; + INDI::PropertyNumber BacklashNP{1}; + enum + { + BACKLASH, + }; +};