Skip to content

Commit b75b719

Browse files
committed
Alternate refactoring of the Constants namespaces
1 parent c95995a commit b75b719

File tree

1 file changed

+60
-32
lines changed

1 file changed

+60
-32
lines changed

include/liboculus/Constants.h

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -46,66 +46,94 @@ const uint16_t DataPort = 52100;
4646
const uint8_t PacketHeaderLSB = (OCULUS_CHECK_ID & 0x00FF);
4747
const uint8_t PacketHeaderMSB = (OCULUS_CHECK_ID & 0xFF00) >> 8;
4848

49-
namespace Oculus_750KHz {
49+
#define DEG2RAD(x) (x * M_PI / 180.0)
50+
51+
//===================================================================
52+
//
53+
// New constants API which separates constants by both model
54+
// and frequency band
55+
56+
namespace Oculus_M750d {
57+
namespace Freq_750kHz {
5058
const float ElevationBeamwidthDeg = 20.0;
51-
const float ElevationBeamwidthRad = 20.0 * M_PI / 180.0;
59+
const float ElevationBeamwidthRad = DEG2RAD(ElevationBeamwidthDeg);
5260

5361
const float AzimuthBeamwidthDeg = 1.0;
54-
const float AzimuthBeamwidthRad = 1.0 * M_PI / 180.0;
62+
const float AzimuthBeamwidthRad = DEG2RAD(AzimuthBeamwidthDeg);
5563

56-
const float MaxRange = 120; // meters
57-
}; // namespace Oculus_750KHz
64+
const float MaxRange = 120;
65+
}; // namespace Freq_750kHz
5866

59-
namespace Oculus_1200MHz_Old {
67+
namespace Freq_1200kHz {
6068
const float ElevationBeamwidthDeg = 12.0;
61-
const float ElevationBeamwidthRad = 12.0 * M_PI / 180.0;
69+
const float ElevationBeamwidthRad = DEG2RAD(ElevationBeamwidthDeg);
6270

6371
const float AzimuthBeamwidthDeg = 0.6;
64-
const float AzimuthBeamwidthRad = 0.6 * M_PI / 180.0;
72+
const float AzimuthBeamwidthRad = DEG2RAD(AzimuthBeamwidthDeg);
6573

66-
//! NOTE:(by LinZhao) for old generation 1.2MHz,
74+
//! NOTE:(by LinZhao) for old generation 1.2MHz,
6775
// M750d max range is 40m, M1200d max range is 30m
6876
// Maybe set a specfic name for 1.2MHz, since
69-
// the beamwidth changes between generation and model ?
77+
// the beamwidth changes between generation and model ?
7078
const float MaxRange = 40;
71-
}; // namespace Oculus_1200MHz_Old
79+
}; // namespace Freq_1200kHz
80+
}; // namespace Oculus_M750d
7281

73-
namespace Oculus_1200MHz {
82+
namespace Oculus_M1200d {
83+
namespace Freq_1200kHz {
7484
const float ElevationBeamwidthDeg = 20.0;
75-
const float ElevationBeamwidthRad = 20.0 * M_PI / 180.0;
85+
const float ElevationBeamwidthRad = DEG2RAD(ElevationBeamwidthDeg);
7686

7787
const float AzimuthBeamwidthDeg = 0.6;
78-
const float AzimuthBeamwidthRad = 0.6 * M_PI / 180.0;
88+
const float AzimuthBeamwidthRad = DEG2RAD(AzimuthBeamwidthDeg);
7989

80-
// NOTE(lindzey): According to the spec sheet, max range is 30 m
81-
// at 1.2 MHz on the M3000d, but 40 m on the M1200d.
8290
const float MaxRange = 40;
83-
}; // namespace Oculus_1200MHz
91+
}; // namespace Freq_1200kHz
8492

85-
namespace Oculus_2100MHz {
93+
namespace Freq_2100kHz {
8694
const float ElevationBeamwidthDeg = 12.0;
87-
const float ElevationBeamwidthRad = 12.0 * M_PI / 180.0;
95+
const float ElevationBeamwidthRad = DEG2RAD(ElevationBeamwidthDeg);
8896

8997
const float AzimuthBeamwidthDeg = 0.4;
90-
const float AzimuthBeamwidthRad = 0.4 * M_PI / 180.0;
98+
const float AzimuthBeamwidthRad = DEG2RAD(AzimuthBeamwidthDeg);
9199

92-
// \todo These shouldn't be fixed, should read from Oculus.h
93-
// But I don't feel like dealing with their data structure
94-
const float MaxRange = 10; // meters
95-
}; // namespace Oculus_2100MHz
100+
const float MaxRange = 10;
101+
}; // namespace Freq_2100kHz
102+
}; // namespace Oculus_M1200d
96103

97-
namespace Oculus_3000MHz {
104+
namespace Oculus_M3000d {
105+
namespace Freq_1200kHz {
98106
const float ElevationBeamwidthDeg = 20.0;
99-
const float ElevationBeamwidthRad = 20.0 * M_PI / 180.0;
107+
const float ElevationBeamwidthRad = DEG2RAD(ElevationBeamwidthDeg);
100108

101-
const float AzimuthBeamwidthDeg = 0.4;
102-
const float AzimuthBeamwidthRad = 0.4 * M_PI / 180.0;
109+
const float AzimuthBeamwidthDeg = 0.6;
110+
const float AzimuthBeamwidthRad = DEG2RAD(AzimuthBeamwidthDeg);
103111

104-
// \todo These shouldn't be fixed, should read from Oculus.h
105-
// But I don't feel like dealing with their data structure
106-
const float MaxRange = 5; // meters
107-
}; // namespace Oculus_3000MHz
112+
const float MaxRange = 30;
113+
}; // namespace Freq_1200kHz
108114

115+
namespace Freq_3000kHz {
116+
const float ElevationBeamwidthDeg = 20.0;
117+
const float ElevationBeamwidthRad = DEG2RAD(ElevationBeamwidthDeg);
118+
119+
const float AzimuthBeamwidthDeg = 0.4;
120+
const float AzimuthBeamwidthRad = DEG2RAD(AzimuthBeamwidthDeg);
121+
122+
const float MaxRange = 5;
123+
}; // namespace Freq_3000kHz
124+
}; // namespace Oculus_M3000d
125+
126+
//===================================================================
127+
//
128+
// "Old"" constants API which only considered nominal frequency.
129+
// So it can't handle the case where different models may have
130+
// different performance at the same nominal center frequency.
131+
132+
// For backwards compatibility
133+
namespace Oculus_750KHz = Oculus_M750d::Freq_750kHz;
134+
namespace Oculus_1200MHz = Oculus_M1200d::Freq_1200kHz;
135+
namespace Oculus_2100MHz = Oculus_M1200d::Freq_2100kHz;
136+
namespace Oculus_3000MHz = Oculus_M3000d::Freq_3000kHz;
109137
struct FlagBits {
110138
// bit 0: 0 = interpret range as percent, 1 = interpret range as meters
111139
// bit 1: 0 = 8 bit data, 1 = 16 bit data

0 commit comments

Comments
 (0)