Instrument Neutral Distributed Interface INDI  1.9.5
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 {
32  // We do not have absolute ticks
34 }
35 
37 {
38  return "Rotator Simulator";
39 }
40 
42 {
44  return true;
45 }
46 
48 {
49  return true;
50 }
51 
53 {
54  m_TargetAngle = range360(angle);
55  return IPS_BUSY;
56 }
57 
59 {
60  INDI_UNUSED(angle);
61  return true;
62 }
63 
65 {
66  return true;
67 }
68 
70 {
71  if (!isConnected())
72  {
74  return;
75  }
76 
77  if (GotoRotatorNP.s == IPS_BUSY)
78  {
79  if (std::fabs(m_TargetAngle - GotoRotatorN[0].value) <= ROTATION_RATE)
80  {
81  GotoRotatorN[0].value = m_TargetAngle;
83  }
84  else
85  {
86  // Find shortest distance given target degree
87  double a = m_TargetAngle;
88  double b = GotoRotatorN[0].value;
89  int sign = (a - b >= 0 && a - b <= 180) || (a - b <= -180 && a - b >= -360) ? 1 : -1;
90  double diff = ROTATION_RATE * sign;
91  GotoRotatorN[0].value += diff;
92  GotoRotatorN[0].value = range360(GotoRotatorN[0].value);
93  }
94 
95  IDSetNumber(&GotoRotatorNP, nullptr);
96  }
98 }
RotatorSimulator
Definition: rotator_simulator.h:25
IPState
IPState
Property state.
Definition: indiapi.h:158
IPS_OK
@ IPS_OK
Definition: indiapi.h:161
RotatorSimulator::AbortRotator
virtual bool AbortRotator() override
AbortRotator Abort all motion.
Definition: rotator_simulator.cpp:64
_INumberVectorProperty::s
IPState s
Definition: indiapi.h:332
indicom.h
Implementations for common driver routines.
INDI::RotatorInterface::ROTATOR_CAN_ABORT
@ ROTATOR_CAN_ABORT
Definition: indirotatorinterface.h:55
INDI_UNUSED
#define INDI_UNUSED(x)
Definition: indidevapi.h:799
rotator_simulator.h
INDI::RotatorInterface::GotoRotatorN
INumber GotoRotatorN[1]
Definition: indirotatorinterface.h:197
RotatorSimulator::RotatorSimulator
RotatorSimulator()
Definition: rotator_simulator.cpp:30
range360
double range360(double r)
range360 Limits an angle to be between 0-360 degrees.
Definition: indicom.c:1495
RotatorSimulator::Connect
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
Definition: rotator_simulator.cpp:41
INDI::DefaultDevice::getCurrentPollingPeriod
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
Definition: defaultdevice.cpp:1139
RotatorSimulator::Disconnect
virtual bool Disconnect() override
Disconnect from device.
Definition: rotator_simulator.cpp:47
INDI::DefaultDevice::SetTimer
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
Definition: defaultdevice.cpp:865
RotatorSimulator::MoveRotator
virtual IPState MoveRotator(double angle) override
MoveRotator Go to specific angle.
Definition: rotator_simulator.cpp:52
IPS_BUSY
@ IPS_BUSY
Definition: indiapi.h:162
rotatorSimulator
std::unique_ptr< RotatorSimulator > rotatorSimulator(new RotatorSimulator())
INDI::RotatorInterface::ROTATOR_CAN_SYNC
@ ROTATOR_CAN_SYNC
Definition: indirotatorinterface.h:57
INDI::BaseDevice::isConnected
bool isConnected() const
Definition: basedevice.cpp:518
INDI::RotatorInterface::GotoRotatorNP
INumberVectorProperty GotoRotatorNP
Definition: indirotatorinterface.h:198
RotatorSimulator::getDefaultName
const char * getDefaultName() override
Definition: rotator_simulator.cpp:36
INDI::RotatorInterface::SetCapability
void SetCapability(uint32_t cap)
SetRotatorCapability sets the Rotator capabilities. All capabilities must be initialized.
Definition: indirotatorinterface.h:74
RotatorSimulator::SyncRotator
virtual bool SyncRotator(double angle) override
SyncRotator Set current angle as the supplied angle without moving the rotator.
Definition: rotator_simulator.cpp:58
RotatorSimulator::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: rotator_simulator.cpp:69
IDSetNumber
void void void IDSetNumber(const INumberVectorProperty *n, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing number vector property.