Instrument Neutral Distributed Interface INDI 2.2.5
test_guide_simulator.cpp
Go to the documentation of this file.
1#include "indilogger.h"
2
3#include <gtest/gtest.h>
4
5#include "guide_simulator.h"
6
7char _me[] = "MockGuideSimDriver";
8char *me = _me;
9
11{
12 public:
18
20 {
21 auto p = getNumber("SIMULATOR_SETTINGS");
22 ASSERT_TRUE(p.isValid());
23 ASSERT_NE(p.findWidgetByName("SIM_XRES"), nullptr);
24 ASSERT_NE(p.findWidgetByName("SIM_YRES"), nullptr);
25 ASSERT_NE(p.findWidgetByName("SIM_XSIZE"), nullptr);
26 ASSERT_NE(p.findWidgetByName("SIM_YSIZE"), nullptr);
27 ASSERT_NE(p.findWidgetByName("SIM_MAXVAL"), nullptr);
28 ASSERT_NE(p.findWidgetByName("SIM_SATURATION"), nullptr);
29 ASSERT_NE(p.findWidgetByName("SIM_LIMITINGMAG"), nullptr);
30 ASSERT_NE(p.findWidgetByName("SIM_NOISE"), nullptr);
31 ASSERT_NE(p.findWidgetByName("SIM_SKYGLOW"), nullptr);
32 ASSERT_NE(p.findWidgetByName("SIM_OAGOFFSET"), nullptr);
33 ASSERT_NE(p.findWidgetByName("SIM_POLAR"), nullptr);
34 ASSERT_NE(p.findWidgetByName("SIM_POLARDRIFT"), nullptr);
35 ASSERT_NE(p.findWidgetByName("SIM_KING_GAMMA"), nullptr);
36 ASSERT_NE(p.findWidgetByName("SIM_KING_THETA"), nullptr);
37 ASSERT_NE(p.findWidgetByName("SIM_RA_DRIFT"), nullptr);
38 ASSERT_NE(p.findWidgetByName("SIM_DEC_DRIFT"), nullptr);
39 }
40
42 {
43 EXPECT_EQ(m_GuideRate, 7 /* arcsec/s */);
44 EXPECT_EQ(m_GuideNSOffset, 0);
45 EXPECT_EQ(m_GuideWEOffset, 0);
46
47 double const arcsec = 1.0 / 3600.0;
48
49 EXPECT_EQ(GuideNorth(1000.0), IPS_OK);
50 EXPECT_NEAR(m_GuideNSOffset, +7 * arcsec, 1 * arcsec);
51 EXPECT_EQ(GuideSouth(1000.0), IPS_OK);
52 EXPECT_NEAR(m_GuideNSOffset, +0 * arcsec, 1 * arcsec);
53 EXPECT_EQ(GuideSouth(1000.0), IPS_OK);
54 EXPECT_NEAR(m_GuideNSOffset, -7 * arcsec, 1 * arcsec);
55 EXPECT_EQ(GuideNorth(1000.0), IPS_OK);
56 EXPECT_NEAR(m_GuideNSOffset, +0 * arcsec, 1 * arcsec);
57
58 m_CurrentDEC = 0;
59
60 EXPECT_EQ(GuideWest(1000.0), IPS_OK);
61 EXPECT_NEAR(m_GuideWEOffset, +7 * arcsec, 15 * arcsec);
62 EXPECT_EQ(GuideEast(1000.0), IPS_OK);
63 EXPECT_NEAR(m_GuideWEOffset, +0 * arcsec, 15 * arcsec);
64 EXPECT_EQ(GuideEast(1000.0), IPS_OK);
65 EXPECT_NEAR(m_GuideWEOffset, -7 * arcsec, 15 * arcsec);
66 EXPECT_EQ(GuideWest(1000.0), IPS_OK);
67 EXPECT_NEAR(m_GuideWEOffset, +0 * arcsec, 15 * arcsec);
68 }
69
71 {
72 ScopeInfoNP[FOCAL_LENGTH].setValue(400.0);
73 ScopeInfoNP[APERTURE].setValue(60.0);
74
75 auto p = getNumber("SIMULATOR_SETTINGS");
76 p.findWidgetByName("SIM_NOISE")->setValue(0.0);
77 p.findWidgetByName("SIM_SKYGLOW")->setValue(15.0);
78 p.findWidgetByName("SIM_BIAS")->setValue(0.0);
79
80 SetupParms();
82 }
83
85 {
86 uint16_t *fb = reinterpret_cast<uint16_t *>(PrimaryCCD.getFrameBuffer());
87 int const n = PrimaryCCD.getXRes() * PrimaryCCD.getYRes();
88 int peak = 0;
89 for (int i = 0; i < n; i++)
90 if (fb[i] > peak) peak = fb[i];
91 return peak;
92 }
93
94 // Render a frame with renderStars=false (no GSC dependency).
95 // Exercises the full DrawCcdFrame pipeline: coordinate math, config
96 // setup, renderFrame, and readout noise.
98 {
100
101 RA = 6.0;
102 Dec = 30.0;
103 pierSide = 0;
104
105 ASSERT_TRUE(StartExposure(1.0f));
106
107 EXPECT_GT(peakPixel(), 0)
108 << "frame must contain sky glow even without GSC stars";
109 }
110
111 // Exercise the King cone-error path. With m_KingGamma > 0 the
112 // coordinate transform runs before renderFrame. Verify it does not
113 // crash or produce a blank frame.
115 {
117
118 auto p = getNumber("SIMULATOR_SETTINGS");
119 p.findWidgetByName("SIM_KING_GAMMA")->setValue(0.5);
120 p.findWidgetByName("SIM_KING_THETA")->setValue(45.0);
121 SetupParms();
123
124 RA = 6.0;
125 Dec = 30.0;
126 Longitude = -100.0;
127 pierSide = 0;
128
129 ASSERT_TRUE(StartExposure(1.0f));
130
131 EXPECT_GT(peakPixel(), 0)
132 << "King path must still produce sky glow";
133 }
134
135 // Exercise the polar drift code path with non-zero polar error
136 // and dec drift. Verifies the path runs without crashing.
138 {
140
141 auto p = getNumber("SIMULATOR_SETTINGS");
142 p.findWidgetByName("SIM_POLAR")->setValue(10.0);
143 p.findWidgetByName("SIM_POLARDRIFT")->setValue(1.0);
144 p.findWidgetByName("SIM_OAGOFFSET")->setValue(20.0);
145 p.findWidgetByName("SIM_RA_DRIFT")->setValue(0.5);
146 p.findWidgetByName("SIM_DEC_DRIFT")->setValue(0.3);
147 SetupParms();
149
150 RA = 6.0;
151 Dec = 30.0;
152 pierSide = 0;
153
154 ASSERT_TRUE(StartExposure(1.0f));
155
156 EXPECT_GT(peakPixel(), 0)
157 << "frame must contain sky glow with polar drift active";
158 }
159};
160
161TEST(GuideSimulatorDriverTest, test_properties)
162{
164}
165
166TEST(GuideSimulatorDriverTest, test_guide_api)
167{
169}
170
171TEST(GuideSimulatorDriverTest, draw_ccd_frame_smoke_test)
172{
174}
175
176TEST(GuideSimulatorDriverTest, king_transform_smoke_test)
177{
179}
180
181TEST(GuideSimulatorDriverTest, polar_drift_smoke_test)
182{
184}
185
186int main(int argc, char **argv)
187{
190
191 ::testing::InitGoogleTest(&argc, argv);
192 return RUN_ALL_TESTS();
193}
The GuideSim class provides an advanced simulator for a CCD that includes a dedicated on-board guide ...
double m_CurrentDEC
virtual IPState GuideNorth(uint32_t) override
Guide northward for ms milliseconds.
virtual IPState GuideEast(uint32_t) override
Guide easward for ms milliseconds.
float m_GuideRate
float m_GuideNSOffset
float m_GuideWEOffset
void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual IPState GuideSouth(uint32_t) override
Guide southward for ms milliseconds.
bool StartExposure(float duration) override
Start exposing primary CCD chip.
virtual IPState GuideWest(uint32_t) override
Guide westward for ms milliseconds.
bool SetupParms()
INDI::PropertyNumber getNumber(const char *name) const
int getXRes() const
getXRes Get the horizontal resolution in pixels of the CCD Chip.
Definition indiccdchip.h:81
uint8_t * getFrameBuffer()
getFrameBuffer Get raw frame buffer of the CCD chip.
int getFrameBufferSize() const
getFrameBufferSize Get allocated frame buffer size to hold the CCD image frame.
int getYRes() const
Get the vertical resolution in pixels of the CCD Chip.
Definition indiccdchip.h:90
double Longitude
Definition indiccd.h:597
CCDChip PrimaryCCD
Definition indiccd.h:621
INDI::PropertyNumber ScopeInfoNP
Definition indiccd.h:720
int pierSide
Definition indiccd.h:554
@ FOCAL_LENGTH
Definition indiccd.h:723
double RA
Definition indiccd.h:551
double Dec
Definition indiccd.h:551
int main()
@ IPS_OK
Definition indiapi.h:160
static const loggerConf file_off
Definition indilogger.h:219
void configure(const std::string &outputFile, const loggerConf configuration, const int fileVerbosityLevel, const int screenVerbosityLevel)
Method to configure the logger. Called by the DEBUG_CONF() macro. To make implementation easier,...
static Logger & getInstance()
Method to get a reference to the object (i.e., Singleton) It is a static method.
TEST(GuideSimulatorDriverTest, test_properties)
char _me[]
char * me