Instrument Neutral Distributed Interface INDI  2.0.2
rotator_simulator.cpp
Go to the documentation of this file.
1 /*
2  INDI Rotator Simulator
3  Copyright (C) 2020 Jasem Mutlaq (mutlaqja@ikarustech.com)
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 
28 std::unique_ptr<RotatorSimulator> rotatorSimulator(new RotatorSimulator());
29 
31 {
33 }
34 
36 {
37  return "Rotator Simulator";
38 }
39 
41 {
43  return true;
44 }
45 
47 {
48  return true;
49 }
50 
52 {
54  m_TargetAngle = range360(360 - angle);
55  else
56  m_TargetAngle = range360(angle);
57  return IPS_BUSY;
58 }
59 
61 {
62  INDI_UNUSED(angle);
63  return true;
64 }
65 
67 {
68  return true;
69 }
70 
72 {
73  INDI_UNUSED(enabled);
74  return true;
75 }
76 
78 {
79  if (!isConnected())
80  {
82  return;
83  }
84 
85  if (GotoRotatorNP.s == IPS_BUSY)
86  {
87  if (std::fabs(m_TargetAngle - GotoRotatorN[0].value) <= ROTATION_RATE)
88  {
89  GotoRotatorN[0].value = m_TargetAngle;
91  }
92  else
93  {
94  // Find shortest distance given target degree
95  double a = m_TargetAngle;
96  double b = GotoRotatorN[0].value;
97  int sign = (a - b >= 0 && a - b <= 180) || (a - b <= -180 && a - b >= -360) ? 1 : -1;
98  double diff = ROTATION_RATE * sign;
99  GotoRotatorN[0].value += diff;
100  GotoRotatorN[0].value = range360(GotoRotatorN[0].value);
101  }
102 
103  IDSetNumber(&GotoRotatorNP, nullptr);
104  }
105 
107 }
bool isConnected() const
Definition: basedevice.cpp:520
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.
INumberVectorProperty GotoRotatorNP
void SetCapability(uint32_t cap)
SetRotatorCapability sets the Rotator capabilities. All capabilities must be initialized.
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:152
IPState
Property state.
Definition: indiapi.h:160
@ IPS_BUSY
Definition: indiapi.h:163
@ IPS_OK
Definition: indiapi.h:162
double range360(double r)
range360 Limits an angle to be between 0-360 degrees.
Definition: indicom.c:1245
Implementations for common driver routines.
#define INDI_UNUSED(x)
Definition: indidevapi.h:131
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
Definition: indidriver.c:1211
std::unique_ptr< RotatorSimulator > rotatorSimulator(new RotatorSimulator())