Instrument Neutral Distributed Interface INDI 2.2.5
rotator_simulator.cpp
Go to the documentation of this file.
1/*
2 INDI Rotator Simulator
3 Copyright (C) 2020 Jasem Mutlaq ([email protected])
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19*/
20
21#include "rotator_simulator.h"
22#include "indicom.h"
23
24#include <memory>
25#include <cmath>
26#include <math.h>
27
28std::unique_ptr<RotatorSimulator> rotatorSimulator(new RotatorSimulator());
29
34
36{
37 return "Rotator Simulator";
38}
39
41{
43 return true;
44}
45
47{
48 return true;
49}
50
52{
53 if (ReverseRotatorSP[INDI_ENABLED].getState() == ISS_ON)
54 m_TargetAngle = range360(360 - angle);
55 else
56 m_TargetAngle = range360(angle);
57 return IPS_BUSY;
58}
59
61{
62 GotoRotatorNP[0].setValue(angle);
64 return true;
65}
66
68{
69 return true;
70}
71
73{
74 INDI_UNUSED(enabled);
75 return true;
76}
77
79{
80 if (!isConnected())
81 {
83 return;
84 }
85
87 {
88 if (std::fabs(m_TargetAngle - GotoRotatorNP[0].getValue()) <= ROTATION_RATE)
89 {
90 GotoRotatorNP[0].setValue(m_TargetAngle);
92 }
93 else
94 {
95 // Find shortest distance given target degree
96 double a = m_TargetAngle;
97 double b = GotoRotatorNP[0].getValue();
98 int sign = (a - b >= 0 && a - b <= 180) || (a - b <= -180 && a - b >= -360) ? 1 : -1;
99 double diff = ROTATION_RATE * sign;
100 GotoRotatorNP[0].setValue(GotoRotatorNP[0].getValue() + diff);
101 GotoRotatorNP[0].setValue(range360(GotoRotatorNP[0].getValue()));
102 }
103
105 }
106
108}
bool isConnected() const
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
void SetCapability(uint32_t cap)
SetRotatorCapability sets the Rotator capabilities. All capabilities must be initialized.
INDI::PropertySwitch ReverseRotatorSP
INDI::PropertyNumber GotoRotatorNP
virtual bool AbortRotator() override
AbortRotator Abort all motion.
virtual IPState MoveRotator(double angle) override
MoveRotator Go to specific angle.
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
const char * getDefaultName() override
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
virtual bool Disconnect() override
Disconnect from device.
virtual bool SyncRotator(double angle) override
SyncRotator Set current angle as the supplied angle without moving the rotator.
virtual bool ReverseRotator(bool enabled) override
ReverseRotator Reverse the direction of the rotator. CW is usually the normal direction,...
@ ISS_ON
Definition indiapi.h:150
IPState
Property state.
Definition indiapi.h:158
@ IPS_BUSY
Definition indiapi.h:161
@ IPS_OK
Definition indiapi.h:160
double range360(double r)
range360 Limits an angle to be between 0-360 degrees.
Definition indicom.c:1321
Implementations for common driver routines.
#define INDI_UNUSED(x)
Definition indidevapi.h:132
std::unique_ptr< RotatorSimulator > rotatorSimulator(new RotatorSimulator())