vsspdefs.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, ATR, Atsushi Watanabe
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef VSSPDEFS_H
31 #define VSSPDEFS_H
32 
33 #include <cstdint>
34 #include <cmath>
35 
36 namespace vssp
37 {
38 
39 static const uint32_t VSSP_MARK = ('V' << 0) | ('S' << 8) | ('S' << 16) | ('P' << 24);
40 static const uint32_t STATUS_OK = ('0' << 0) | ('0' << 8) | ('0' << 16) | (0xA << 24);
41 static const uint32_t STATUS_COMMAND_UNKNOWN = ('1' << 0) | ('0' << 8) | ('1' << 16) | (0xA << 24);
42 static const uint32_t STATUS_COMMAND_INVALID = ('1' << 0) | ('0' << 8) | ('2' << 16) | (0xA << 24);
43 static const uint32_t STATUS_COMMAND_INVALUD_METHOD = ('1' << 0) | ('0' << 8) | ('3' << 16) | (0xA << 24);
44 static const uint32_t STATUS_COMMAND_OUT_OF_RANGE = ('1' << 0) | ('0' << 8) | ('4' << 16) | (0xA << 24);
45 static const uint32_t STATUS_COMMUNICATION_FAILURE = ('2' << 0) | ('0' << 8) | ('1' << 16) | (0xA << 24);
46 static const uint32_t STATUS_UNKNOWN_ERROR = ('3' << 0) | ('0' << 8) | ('1' << 16) | (0xA << 24);
47 
48 static const uint32_t TYPE_GET = ('G' << 0) | ('E' << 8) | ('T' << 16) | (':' << 24);
49 static const uint32_t TYPE_SET = ('S' << 0) | ('E' << 8) | ('T' << 16) | (':' << 24);
50 static const uint32_t TYPE_DAT = ('D' << 0) | ('A' << 8) | ('T' << 16) | (':' << 24);
51 static const uint32_t TYPE_VER = ('V' << 0) | ('E' << 8) | ('R' << 16) | (':' << 24);
52 static const uint32_t TYPE_PNG = ('P' << 0) | ('N' << 8) | ('G' << 16) | (':' << 24);
53 static const uint32_t TYPE_ERR = ('E' << 0) | ('R' << 8) | ('R' << 16) | (':' << 24);
54 static const uint32_t TYPE_RI = ('_' << 0) | ('r' << 8) | ('i' << 16) | (':' << 24);
55 static const uint32_t TYPE_RO = ('_' << 0) | ('r' << 8) | ('o' << 16) | (':' << 24);
56 static const uint32_t TYPE_AX = ('_' << 0) | ('a' << 8) | ('x' << 16) | (':' << 24);
57 static const uint32_t TYPE_ER = ('_' << 0) | ('e' << 8) | ('r' << 16) | (':' << 24);
58 
59 enum AuxId
60 {
73 };
74 static const uint32_t AX_MASK_ANGVEL = (1 << AX_MASK_ANGVEL_X) | (1 << AX_MASK_ANGVEL_Y) | (1 << AX_MASK_ANGVEL_Z);
75 static const uint32_t AX_MASK_LINACC = (1 << AX_MASK_LINACC_X) | (1 << AX_MASK_LINACC_Y) | (1 << AX_MASK_LINACC_Z);
76 static const uint32_t AX_MASK_MAG = (1 << AX_MASK_MAG_X) | (1 << AX_MASK_MAG_Y) | (1 << AX_MASK_MAG_Z);
77 
78 #pragma pack(push, 1)
79 struct Header
80 {
81  uint32_t mark;
82  uint32_t type;
83  uint32_t status;
84  uint16_t header_length;
85  uint16_t length;
86  uint32_t received_time_ms;
87  uint32_t send_time_ms;
88 };
90 {
91  uint16_t header_length;
96  uint8_t frame;
97  uint8_t field;
98  uint16_t line;
99  uint16_t spot;
100 };
102 {
103  uint8_t vertical_field;
105 };
107  {
108  0, 1
109  };
111 {
112  uint16_t index_length;
113  uint16_t nspots;
114 };
116 {
117  uint16_t range_mm;
118  uint16_t intensity;
119 };
121 {
122  uint16_t range_mm;
123 };
124 struct AuxHeader
125 {
126  uint16_t header_length;
127  uint32_t timestamp_ms;
128  uint32_t data_bitfield;
129  uint8_t data_count;
130  uint8_t data_ms;
131 };
132 struct AuxData
133 {
134  int32_t val;
135 };
136 #pragma pack(pop)
137 
139 {
140 public:
141  double operator[](AuxId id) const
142  {
143  return k_[static_cast<int>(id)];
144  }
145  double k_[AX_MASK_LAST + 1];
146 };
148 {
149  double s;
150  double c;
151 };
152 struct XYZ
153 {
154  double x;
155  double y;
156  double z;
157 };
158 class XYZI
159 {
160 public:
161  double x;
162  double y;
163  double z;
164  double i;
165  double r;
166 
168  {
169  }
170  XYZI(const double &v_sin, const double &v_cos, const double &h_sin, const double &h_cos)
171  {
172  i = 0;
173  r = 0;
174  x = v_cos * h_cos;
175  y = v_cos * h_sin;
176  z = v_sin;
177  }
178  XYZI operator*(const DataRangeIntensity &data) const
179  {
180  XYZI ret = *this;
181  double r = data.range_mm * 0.001;
182  ret.i = data.intensity;
183  ret.x *= r;
184  ret.y *= r;
185  ret.z *= r;
186  ret.r = r;
187  return ret;
188  }
189  XYZI operator*(const DataRangeOnly &data) const
190  {
191  XYZI ret = *this;
192  double r = data.range_mm * 0.001;
193  ret.i = 0;
194  ret.x *= r;
195  ret.y *= r;
196  ret.z *= r;
197  ret.r = r;
198  return *this;
199  }
200 };
201 class Aux
202 {
203 public:
207  double temp;
208 
209  Aux()
210  {
211  ang_vel.x = ang_vel.y = ang_vel.z = 0.0;
212  lin_acc.x = lin_acc.y = lin_acc.z = 0.0;
213  mag.x = mag.y = mag.z = 0.0;
214  temp = 0.0;
215  }
216  double operator[](AuxId id) const
217  {
218  return operator[](id);
219  }
220  double &operator[](AuxId id)
221  {
222  switch (id)
223  {
225  return ang_vel.x;
227  return ang_vel.y;
229  return ang_vel.z;
231  return lin_acc.x;
233  return lin_acc.y;
235  return lin_acc.z;
236  case vssp::AX_MASK_MAG_X:
237  return mag.x;
238  case vssp::AX_MASK_MAG_Y:
239  return mag.y;
240  case vssp::AX_MASK_MAG_Z:
241  return mag.z;
242  case vssp::AX_MASK_TEMP:
243  return temp;
244  }
245  throw "Invalid AUX data id";
246  }
247 };
248 
249 static const double G = 9.807;
250 static const double DEG = (M_PI / 180.0);
251 
252 // Default value of Aux data scaling factor
253 // note: there is no way to get these values in communication
254 // with prototype edition of the HOKUYO 3D sensor
256  {
257  {
258  1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
259  1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
260  1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
261  1.0, // Temperature [?]
262  0.6e-6, 0.6e-6, 0.6e-6, // Magnetometer [T]
263  G / 8192.0, G / 8192.0, G / 8192.0, // Accelerometer [m/ss]
264  DEG / 65.5, DEG / 65.5, DEG / 65.5 // Gyrometer [rad/s]
265  }
266  };
267 
268 } // namespace vssp
269 
270 #endif // VSSPDEFS_H
static const uint32_t TYPE_PNG
Definition: vsspdefs.h:52
static const uint32_t STATUS_COMMAND_INVALID
Definition: vsspdefs.h:42
static const uint32_t TYPE_SET
Definition: vsspdefs.h:49
Definition: vssp.h:48
uint16_t header_length
Definition: vsspdefs.h:91
static const uint32_t AX_MASK_MAG
Definition: vsspdefs.h:76
uint8_t data_count
Definition: vsspdefs.h:129
double x
Definition: vsspdefs.h:154
static const uint32_t STATUS_COMMUNICATION_FAILURE
Definition: vsspdefs.h:45
uint16_t header_length
Definition: vsspdefs.h:84
double z
Definition: vsspdefs.h:156
double z
Definition: vsspdefs.h:163
static const uint32_t STATUS_COMMAND_OUT_OF_RANGE
Definition: vsspdefs.h:44
static const uint32_t TYPE_AX
Definition: vsspdefs.h:56
uint32_t send_time_ms
Definition: vsspdefs.h:87
static const uint32_t AX_MASK_ANGVEL
Definition: vsspdefs.h:74
static const double G
Definition: vsspdefs.h:249
uint16_t line
Definition: vsspdefs.h:98
double i
Definition: vsspdefs.h:164
XYZI operator*(const DataRangeIntensity &data) const
Definition: vsspdefs.h:178
uint32_t line_head_timestamp_ms
Definition: vsspdefs.h:92
uint32_t mark
Definition: vsspdefs.h:81
uint8_t field
Definition: vsspdefs.h:97
double operator[](AuxId id) const
Definition: vsspdefs.h:141
XYZ lin_acc
Definition: vsspdefs.h:205
XYZ mag
Definition: vsspdefs.h:206
static const double DEG
Definition: vsspdefs.h:250
static const AuxFactorArray AUX_FACTOR_DEFAULT
Definition: vsspdefs.h:255
XYZI(const double &v_sin, const double &v_cos, const double &h_sin, const double &h_cos)
Definition: vsspdefs.h:170
uint8_t data_ms
Definition: vsspdefs.h:130
double operator[](AuxId id) const
Definition: vsspdefs.h:216
int16_t line_tail_h_angle_ratio
Definition: vsspdefs.h:95
static const uint32_t STATUS_COMMAND_UNKNOWN
Definition: vsspdefs.h:41
uint16_t spot
Definition: vsspdefs.h:99
uint32_t data_bitfield
Definition: vsspdefs.h:128
static const uint32_t TYPE_RI
Definition: vsspdefs.h:54
uint8_t frame
Definition: vsspdefs.h:96
uint16_t nspots
Definition: vsspdefs.h:113
uint8_t vertical_field
Definition: vsspdefs.h:103
static const uint32_t STATUS_UNKNOWN_ERROR
Definition: vsspdefs.h:46
static const uint32_t AX_MASK_LINACC
Definition: vsspdefs.h:75
static const uint32_t TYPE_ERR
Definition: vsspdefs.h:53
uint32_t timestamp_ms
Definition: vsspdefs.h:127
uint16_t length
Definition: vsspdefs.h:85
XYZ ang_vel
Definition: vsspdefs.h:204
static const uint32_t TYPE_DAT
Definition: vsspdefs.h:50
int16_t line_head_h_angle_ratio
Definition: vsspdefs.h:94
static const uint32_t TYPE_RO
Definition: vsspdefs.h:55
static const uint32_t TYPE_ER
Definition: vsspdefs.h:57
double y
Definition: vsspdefs.h:162
double x
Definition: vsspdefs.h:161
const RangeHeaderV2R1 RANGE_HEADER_V2R1_DEFAULT
Definition: vsspdefs.h:106
AuxId
Definition: vsspdefs.h:59
uint32_t line_tail_timestamp_ms
Definition: vsspdefs.h:93
int32_t val
Definition: vsspdefs.h:134
uint16_t range_mm
Definition: vsspdefs.h:122
uint32_t received_time_ms
Definition: vsspdefs.h:86
static const uint32_t STATUS_OK
Definition: vsspdefs.h:40
double y
Definition: vsspdefs.h:155
static const uint32_t STATUS_COMMAND_INVALUD_METHOD
Definition: vsspdefs.h:43
static const uint32_t VSSP_MARK
Definition: vsspdefs.h:39
uint8_t vertical_interlace
Definition: vsspdefs.h:104
static const uint32_t TYPE_VER
Definition: vsspdefs.h:51
uint32_t status
Definition: vsspdefs.h:83
double temp
Definition: vsspdefs.h:207
double & operator[](AuxId id)
Definition: vsspdefs.h:220
uint32_t type
Definition: vsspdefs.h:82
double r
Definition: vsspdefs.h:165
XYZI operator*(const DataRangeOnly &data) const
Definition: vsspdefs.h:189
uint16_t header_length
Definition: vsspdefs.h:126
uint16_t index_length
Definition: vsspdefs.h:112
static const uint32_t TYPE_GET
Definition: vsspdefs.h:48


hokuyo3d
Author(s): Atsushi Watanabe
autogenerated on Sat Jun 8 2019 04:42:00