1 #ifndef QRK_C_URG_CTRL_H
2 #define QRK_C_URG_CTRL_H
8 \author Satofumi KAMIMURA
10 $Id: urg_ctrl.h 1723 2010-02-24 23:30:34Z satofumi $
12 \todo Define examples for each functions
19 \brief Parameter for object
22 UrgLineWidth = 64 + 1 + 1, /*!< Maximum length of a line */
23 UrgInfinityTimes = 0, /*!< continuous data transmission */
28 \brief Command type of URG
31 URG_GD, /*!< GD command */
32 URG_GD_INTENSITY, /*!< GD command(Inclusing intensity data) */
33 URG_GS, /*!< GS command */
34 URG_MD, /*!< MD command */
35 URG_MD_INTENSITY, /*!< MD command(Inclusing intensity data) */
36 URG_MS, /*!< MS command */
41 \brief To omit URG data range specification
44 URG_FIRST = -1, /*!< starting position when complete data is to be acquired */
45 URG_LAST = -1, /*!< end position when complete data is to be acquired */
47 UrgInvalidTimestamp = -1, /*!< Error value of timestamp */
51 extern void urg_initialize(urg_t *urg);
57 \param[in,out] urg Structure of URG control
58 \param[in] device Connection device
59 \param[in] baudrate Baudrate
64 \see gd_scan.c, md_scan.c
71 if (urg_connect(&urg, "COM3", 115200) < 0) {
72 printf("urg_connect: %s\n", urg_error(&urg));
78 urg_disconnect(&urg); \endcode
80 extern int urg_connect(urg_t *urg, const char *device, long baudrate);
86 \param[in,out] urg Structure of URG control
89 \see gd_scan.c, md_scan.c
91 extern void urg_disconnect(urg_t *urg);
95 \brief Checks whether connected or not and returns the result
97 \param[in,out] urg Structure of URG control
99 \retval 0 if connected
100 \retval <0 if disconnected
102 \see urg_connect(), urg_disconnect()
106 if (urg_isConnected(&urg) < 0) {
107 printf("not connected.\n");
109 printf("connected.\n");
112 extern int urg_isConnected(const urg_t *urg);
116 \brief Get error message
118 \param[in,out] urg Structure of URG control
120 \return Error message
123 \see gd_scan.c, md_scan.c
125 extern const char *urg_error(const urg_t *urg);
129 \brief Get string containing version information
131 \param[in,out] urg Structure of URG control
132 \param[out] lines Buffer having version information
133 \param[in] lines_max Maximum lines in buffer
138 \attention The length of a line in the buffer should be equal to more than # UrgLineWidth[byte].
140 \see get_version_lines.c
142 extern int urg_versionLines(urg_t *urg, char* lines[], int lines_max);
146 \brief URG Returns parameter
148 \param[in,out] urg Structure of URG control
149 \param[out] parameters Structure of URG parameter
154 \see urg_maxDistance(), urg_minDistance(), urg_scanMsec(), urg_dataMax()
156 Execution example of get_parameters.c (Classic-URG)
159 urg_getParameters: No Error.
168 urg_getDistanceMax(): 5600
169 urg_getDistanceMin(): 20
170 urg_getScanMsec(): 100
171 urg_getDataMax(): 726 \endverbatim
173 extern int urg_parameters(urg_t *urg, urg_parameter_t* parameters);
177 \brief URG Returns the sensor type
179 \param[in,out] urg Structure of URG control
181 \retval URG sensor type
184 printf("URG type: %s\n", urg_model(&urg)); \endcode
186 extern const char* urg_model(const urg_t *urg);
190 \brief Returns the number of maximum data obtained in one scan
192 \param[in,out] urg Structure of URG control
194 \retval >=0 number of maximum data obtained in one scan
201 enum { BufferSize = 2048 };
202 long data[BufferSize];
206 // Checks whether number of maximum data obtained by URG sensor does not exceeds receive buffer
207 // (This is not necessary if size of buffer is dynamically allocated.)
208 int data_max = urg_dataMax(&urg);
209 ASSERT(BufferSize >= data_max);
212 extern int urg_dataMax(const urg_t *urg);
216 \brief Returns measurement time taken for one scan
218 Returns measurement time when motor speed is 100% as specified.
220 \param[in,out] urg Structure of URG control
222 \retval >=0 measurement time taken for one scan [msec]
225 \see urg_setMotorSpeed()
229 extern int urg_scanMsec(const urg_t *urg);
233 \brief Maximum measurable distance
235 \param[in,out] urg Structure of URG control
237 \retval >=0 Maximum measurable distance [mm]
245 n = urg_receiveData(&urg, data, data_max);
247 min_distance = urg_minDistance(&urg);
248 max_distance = urg_minDistance(&urg);
250 // Output only valid data
251 for (i = 0; i < n; ++i) {
252 long length = data[i];
253 if ((length > min_distance) && (length < max_distance)) {
254 printf("%d:%d\n", i, length);
259 extern long urg_maxDistance(const urg_t *urg);
263 \brief Minimum measureable distance
265 \param[in,out] urg Structure of URG control
267 \retval >=0 Minimum measurable distance [mm]
272 extern long urg_minDistance(const urg_t *urg);
275 /* ---------------------------------------------------------------------- */
279 \brief Sets the number of lines to be skiped.
281 The volume of acquire data can be reduced by skipping the lines .
283 \param[in,out] urg Structure of URG control
284 \param[in] lines Number of lines to be skiped.
289 extern int urg_setSkipLines(urg_t *urg, int lines);
293 \brief Sets number of scans to be skipped.
295 \param[in,out] urg Structure of URG control
296 \param[in] frames Number of skipped frames.
301 \attention Valid only with MD/MS command.
303 extern int urg_setSkipFrames(urg_t *urg, int frames);
307 \brief Sets number of times the data to be acquired .
309 \param[in,out] urg Structure of URG control
310 \param[in] times Number of scan data
315 \attention Valid only with MD/MS command
316 \attention Specify #UrgInfinityTimes to acquire data more than 100 times
320 // Data is supplied indefinitely
321 urg_setCaptureTimes(&urg, UrgInfinityTimes);
325 // Data acquistion is stopped if laser is switched off.
329 extern int urg_setCaptureTimes(urg_t *urg, int times);
333 \brief Get number of remaining times on MD/MS capture
335 \param[in,out] urg Structure of URG control
337 \retval remaining times. (100 means infinity times)
341 extern int urg_remainCaptureTimes(const urg_t *urg);
345 \brief Request for distance data
347 Request for distance data of [first_index, last_index]. Return all scan data when specified URG_FIRST, URG_LAST.
349 \param[in,out] urg Structure of URG control
350 \param[in] request_type Received data type.
351 \param[in] first_index Index of the first data stored
352 \param[in] last_index Index of the last received data stored.
357 \see urg_receiveData()
358 \see gd_scan.c, md_scan.c
362 // Get one scan data from GD command
363 urg_requestData(&urg, URG_GD, URG_FIRST, URG_LAST);
364 n = urg_receiveData(&urg, data, data_max);
366 // Get data continuously from MD scan
367 urg_requestData(&urg, URG_MD, URG_FIRST, URG_LAST);
369 n = urg_receiveData(&urg, data, data_max);
376 extern int urg_requestData(urg_t *urg,
377 urg_request_type request_type,
383 \brief Receive URG data
385 \param[in,out] urg Structure of URG control
386 \param[out] data Storage location of received data
387 \param[in] data_max Maximum number of data that can be received
389 \retval 0 > Number of data received
392 \see urg_requestData()
394 extern int urg_receiveData(urg_t *urg, long data[], int data_max);
398 \brief Get data with intensity.
400 \param[in,out] urg Structure of URG control
401 \param[out] data Storage location of received data
402 \param[in] data_max Maximum number of data that can be received
403 \param[out] intensity Storage location of intensity of received data.
405 \attention Applicable only to Classic-URG (currently 2008-12-24)
407 extern int urg_receiveDataWithIntensity(urg_t *urg, long data[], int data_max,
412 \brief Get partial URG data
414 \param[in,out] urg Structure of URG control
415 \param[out] data Storage location of received data
416 \param[in] data_max Maximum number of data that can be received
417 \param[in] first_index Index of the first data stored.
418 \param[in] last_index Index of the last data stored
420 \retval 0 > Number of data received
423 \see gd_scan.c, md_scan.c
425 extern int urg_receivePartialData(urg_t *urg, long data[], int data_max,
426 int first_index, int last_index);
430 \brief Receive time stamp
432 \param[in,out] urg Structure of URG control
434 \retval Time stamp [msec]
440 urg_requestData(&urg, URG_GD, URG_FIRST, URG_LAST);
441 n = urg_receiveData(&urg, data, data_max);
443 long timestamp = urg_recentTimestamp(&urg);
444 printf("timestamp: %d\n", timestamp);
450 extern long urg_recentTimestamp(const urg_t *urg);
453 /* ---------------------------------------------------------------------- */
457 \brief Change index value into angle (radian)
459 \image html urg_sensor_radian.png Front of the sensor is a positive in X axis
461 \param[in,out] urg Structure of URG control
462 \param[in] index Index value
464 \return angle[radian]
468 // To operate urg_index2rad(), data from 0 to last_index is stored.
469 // The data of the step not measured becomes -1.
470 urg_requestData(&urg, URG_GD, first_index, last_index);
471 n = urg_receiveData(&urg, data, data_max);
472 for (i = 0; i < n; ++i) {
474 if (l > min_distance) {
475 double rad = urg_index2rad(&urg, i);
476 double x = data[i] * cos(rad);
477 double y = data[i] * sin(rad);
478 printf("%f, %f\n", x, y);
484 extern double urg_index2rad(const urg_t *urg, int index);
488 \brief Change index into angle(degree)
490 \param[in,out] urg Structure of URG control
491 \param[in] index Index value
493 \return Angle [degree]
497 extern int urg_index2deg(const urg_t *urg, int index);
501 \brief Angle(radian) is converted to index value
503 \image html urg_sensor_radian.png Front of the sensor is a positive in X axis
505 \param[in,out] urg Structure of URG control
506 \param[in] Angle(radian)
512 extern int urg_rad2index(const urg_t *urg, double radian);
516 \brief Angle(degree) is converted into index
518 \param[in,out] urg Structure of URG control
519 \param[in] Angle(degre)
525 extern int urg_deg2index(const urg_t *urg, int degree);
528 /* ---------------------------------------------------------------------- */
532 \brief Directs laser to switch on
534 \param[in,out] urg Structure of URG control
541 extern int urg_laserOn(urg_t *urg);
545 \brief Directs laser to switch off
547 \param[in,out] urg Structure of URG control
552 extern int urg_laserOff(urg_t *urg);
561 \attention Only Top-URG (2010-02-04)
563 extern int urg_reboot(urg_t *urg);
567 \deprecated use reboot() function.
569 extern int urg_reset(urg_t *urg);
572 /* ---------------------------------------------------------------------- */
576 \brief Enters into time stamp mode
578 \param[in,out] urg Structure of URG control
583 extern int urg_enableTimestampMode(urg_t *urg);
587 \brief Comes out of time stamp mode
589 \param[in,out] urg Structure of URG control
594 extern int urg_disableTimestampMode(urg_t *urg);
598 \brief Get time stamp
600 Returns TM1 response.
602 \param[in,out] urg Structure of URG control
604 \retval >=0 Timestamp [msec]
609 // Enters into time stamp
610 urg_enableTimestampMode(&urg);
612 // Get URG time stamp continuously.
613 for (i = 0; i < 5; ++i) {
614 long timestamp = urg_currentTimestamp(&urg);
615 printf("timestamp: %ld\n", timestamp)
618 // leave tiemstamp mode
619 urg_disableTimestampMode(&urg); \endcode
621 extern long urg_currentTimestamp(urg_t *urg);
623 #endif /* !QRK_C_URG_CTRL_H */