Instrument Neutral Distributed Interface INDI 2.2.5
dome_simulator.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Dome Simulator
3 Copyright(c) 2014 Jasem Mutlaq. All rights reserved.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
8 .
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13 .
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*******************************************************************************/
19#include "dome_simulator.h"
20
21#include "indicom.h"
22
23#include <cmath>
24#include <memory>
25#include <unistd.h>
26
27// We declare an auto pointer to domeSim.
28static std::unique_ptr<DomeSim> domeSim(new DomeSim());
29
41
46{
48
49 SpeedNP[Dome].fill("DOME", "Dome (deg/s)", "%.2f", 0.1, 10, 1, 5);
50 SpeedNP[Shutter].fill("SHUTTER", "Shutter (m/s)", "%.2f", 0.01, 1, 0.1, 0.1);
51 SpeedNP.fill(getDeviceName(), "SPEEDS", "Speeds", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE);
52
54
55 // The simulator traditionally closes the shutter on park and opens it on unpark.
56 // Keep that as the default, unless the user saved a different policy.
60
62
63 return true;
64}
65
69bool DomeSim::SetupParms()
70{
71 targetAz = 0;
72 DomeAbsPosNP[0].setValue(0);
74
75 if (InitPark())
76 {
77 // If loading parking data is successful, we just set the default parking values.
79 }
80 else
81 {
82 // Otherwise, we set all parking data to default in case no parking data is found.
83 SetAxis1Park(90);
85 }
86
87 return true;
88}
89
94{
95 return "Dome Simulator";
96}
97
102{
104
105 if (isConnected())
106 {
107 defineProperty(SpeedNP);
108 SetupParms();
109 }
110 else
111 {
112 deleteProperty(SpeedNP);
113 }
114
115 return true;
116}
117
122{
123 SetTimer(1000);
124 return true;
125}
126
131{
132 return true;
133}
134
138bool DomeSim::ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n)
139{
140 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
141 {
142 if (SpeedNP.isNameMatch(name))
143 {
144 SpeedNP.update(values, names, n);
145 SpeedNP.setState(IPS_OK);
146 SpeedNP.apply();
147 saveConfig(SpeedNP);
148 return true;
149 }
150 }
151
152 return INDI::Dome::ISNewNumber(dev, name, values, names, n);
153}
154
159{
160 if (!isConnected())
161 return;
162
163 auto domeSpeed = SpeedNP[Dome].getValue();
164 auto shutterSpeed = SpeedNP[Shutter].getValue();
165
166 if (DomeAbsPosNP.getState() == IPS_BUSY)
167 {
168 double b = DomeAbsPosNP[0].getValue();
169
170 if (m_MoveDirection != 0)
171 {
172 // Continuous jog: DOME_CW increases azimuth, DOME_CCW decreases it.
173 DomeAbsPosNP[0].setValue(range360(b + domeSpeed * m_MoveDirection));
174 }
175 else
176 {
177 // Find shortest distance given target degree
178 double a = targetAz;
179 int sign = (a - b >= 0 && a - b <= 180) || (a - b <= -180 && a - b >= -360) ? 1 : -1;
180 DomeAbsPosNP[0].setValue(range360(b + domeSpeed * sign));
181
182 if (std::abs(targetAz - DomeAbsPosNP[0].getValue()) <= domeSpeed)
183 {
184 DomeAbsPosNP[0].setValue(targetAz);
185 LOG_INFO("Dome reached requested azimuth angle.");
186
187 if (getDomeState() == DOME_PARKING)
188 SetParked(true);
189 else if (getDomeState() == DOME_UNPARKING)
190 SetParked(false);
191 else
193 }
194 }
195
196 DomeAbsPosNP.apply();
197 }
198
199 // Dome shutter, we decrease by shutter speed in meters/second
200 if (DomeShutterSP.getState() == IPS_BUSY)
201 {
202 m_ShutterDistance -= shutterSpeed;
203
204 if (m_ShutterDistance <= 0)
205 {
206 m_ShutterDistance = 0;
207 auto opened = DomeShutterSP[SHUTTER_OPEN].getState() == ISS_ON;
208 LOGF_INFO("Shutter is %s.", opened ? "open" : "closed");
210 }
211 }
212
214}
215
220{
221 if (operation == MOTION_START)
222 {
223 // DOME_CW increases the azimuth, DOME_CCW decreases it (see INDI::Dome convention).
224 m_MoveDirection = (dir == DOME_CW) ? 1 : -1;
225 DomeAbsPosNP.setState(IPS_BUSY);
226 }
227 else
228 {
229 m_MoveDirection = 0;
230 targetAz = DomeAbsPosNP[0].getValue();
231 DomeAbsPosNP.setState(IPS_IDLE);
232 }
233
234 DomeAbsPosNP.apply();
235 return ((operation == MOTION_START) ? IPS_BUSY : IPS_OK);
236}
237
242{
243 m_MoveDirection = 0;
244 targetAz = az;
245
246 // Requested position is within one cycle, let's declare it done
247 if (std::abs(az - DomeAbsPosNP[0].getValue()) < SpeedNP[Dome].getValue())
248 return IPS_OK;
249
250 // It will take a few cycles to reach final position
251 return IPS_BUSY;
252}
253
258{
259 m_MoveDirection = 0;
260 targetAz = range360(DomeAbsPosNP[0].getValue() + azDiff);
261
262 // Requested position is within one cycle, let's declare it done
263 if (std::abs(targetAz - DomeAbsPosNP[0].value) < SpeedNP[Dome].getValue())
264 return IPS_OK;
265
266 // It will take a few cycles to reach final position
267 return IPS_BUSY;
268}
269
274{
275 // The shutter is closed by INDI::Dome according to the shutter park policy.
276 return MoveAbs(GetAxis1Park());
277}
278
283{
284 // The shutter is opened by INDI::Dome according to the shutter park policy.
285 return IPS_OK;
286}
287
292{
293 INDI_UNUSED(operation);
294 // If shutter width = 1 meter, then we only need to open half of that since we presume
295 // two sides are moving at the same speed closing or opening.
296 m_ShutterDistance = DomeMeasurementsNP[DM_SHUTTER_WIDTH].getValue() / 2;
297 return IPS_BUSY;
298}
299
304{
305 // If we abort while in the middle of opening/closing shutter, alert.
306 if (DomeShutterSP.getState() == IPS_BUSY)
307 {
308 DomeShutterSP.setState(IPS_ALERT);
309 LOG_ERROR("Shutter operation aborted. Status: unknown.");
310 DomeShutterSP.apply();
311 return false;
312 }
313
314 return true;
315}
316
321{
322 SetAxis1Park(DomeAbsPosNP[0].getValue());
323 return true;
324}
325
330{
331 // By default set position to 90
332 SetAxis1Park(90);
333 return true;
334}
335
340{
342 SpeedNP.save(fp);
343 return true;
344}
The DomeSim class provides an absolute position dome that supports parking, unparking,...
virtual bool Abort() override
Abort all dome motion.
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual IPState Park() override
Goto Park Position. The park position is an absolute azimuth value.
virtual const char * getDefaultName() override
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
bool Disconnect() override
Disconnect from device.
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual IPState UnPark() override
UnPark dome. The action of the Unpark command is dome specific, but it may include opening the shutte...
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Dome Presets in the configuration file
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual IPState MoveAbs(double az) override
Move the Dome to an absolute azimuth.
virtual IPState MoveRel(double azDiff) override
Move the Dome to an relative position.
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
virtual IPState ControlShutter(ShutterOperation operation) override
Open or Close shutter.
virtual IPState Move(DomeDirection dir, DomeMotionCommand operation) override
Move the Dome in a particular direction.
bool isConnected() const
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
uint32_t getPollingPeriod() const
getPollingPeriod Return the polling period.
void defineProperty(INumberVectorProperty *property)
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
double prev_alt
Definition indidome.h:624
void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
void SetDomeCapability(uint32_t cap)
SetDomeCapability set the dome capabilities. All capabilities must be initialized.
INDI::PropertySwitch ShutterParkPolicySP
Definition indidome.h:588
@ SHUTTER_OPEN_ON_UNPARK
Definition indidome.h:592
@ SHUTTER_CLOSE_ON_PARK
Definition indidome.h:591
@ DOME_UNPARKING
Definition indidome.h:135
void SetAxis1Park(double value)
SetRAPark Set current AZ parking position. The data park file (stored in ~/.indi/ParkData....
ShutterOperation
Shutter operation command.
Definition indidome.h:114
void SetAxis1ParkDefault(double steps)
SetAxis1Park Set default AZ parking position.
DomeMotionCommand
Definition indidome.h:97
@ MOTION_START
Definition indidome.h:98
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
Definition indidome.cpp:108
double prev_az
Definition indidome.h:624
INDI::PropertyNumber DomeMeasurementsNP
Definition indidome.h:598
double GetAxis1Park()
@ SHUTTER_OPENED
Definition indidome.h:147
@ SHUTTER_CLOSED
Definition indidome.h:148
@ DOME_CAN_PARK
Definition indidome.h:159
@ DOME_CAN_ABS_MOVE
Definition indidome.h:157
@ DOME_HAS_SHUTTER
Definition indidome.h:161
@ DOME_CAN_REL_MOVE
Definition indidome.h:158
@ DOME_CAN_ABORT
Definition indidome.h:156
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition indidome.cpp:287
INDI::PropertyNumber DomeAbsPosNP
Definition indidome.h:558
@ DM_SHUTTER_WIDTH
Definition indidome.h:84
void setShutterState(const ShutterState &value)
void setDomeState(const DomeState &value)
bool InitPark()
InitPark Loads parking data (stored in ~/.indi/ParkData.xml) that contains parking status and parking...
void SetParkDataType(DomeParkData type)
setParkDataType Sets the type of parking data stored in the park data file and presented to the user.
INDI::PropertySwitch DomeShutterSP
Definition indidome.h:568
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition indidome.cpp:399
DomeState getDomeState() const
Definition indidome.h:285
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
@ ISS_ON
Definition indiapi.h:150
@ IP_RW
Definition indiapi.h:184
IPState
Property state.
Definition indiapi.h:158
@ IPS_BUSY
Definition indiapi.h:161
@ IPS_ALERT
Definition indiapi.h:162
@ IPS_IDLE
Definition indiapi.h:159
@ 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
*brief user defined string literal for JSON values *sa std::size_t n
#define LOGF_INFO(fmt,...)
Definition indilogger.h:82
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
Definition indilogger.h:72
#define LOG_INFO(txt)
Definition indilogger.h:74
#define getDeviceName