Fawkes API Fawkes Development Version
PanTiltInterface.cpp
1
2/***************************************************************************
3 * PanTiltInterface.cpp - Fawkes BlackBoard Interface - PanTiltInterface
4 *
5 * Templated created: Thu Oct 12 10:49:19 2006
6 * Copyright 2009 Tim Niemueller
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24#include <interfaces/PanTiltInterface.h>
25
26#include <core/exceptions/software.h>
27
28#include <map>
29#include <string>
30#include <cstring>
31#include <cstdlib>
32
33namespace fawkes {
34
35/** @class PanTiltInterface <interfaces/PanTiltInterface.h>
36 * PanTiltInterface Fawkes BlackBoard Interface.
37 *
38 Interface to access pan/tilt units.
39
40 * @ingroup FawkesInterfaces
41 */
42
43
44/** FLAG_SUPPORTS_PAN constant */
45const uint32_t PanTiltInterface::FLAG_SUPPORTS_PAN = 1u;
46/** FLAG_SUPPORTS_TILT constant */
47const uint32_t PanTiltInterface::FLAG_SUPPORTS_TILT = 2u;
48/** ERROR_NONE constant */
49const uint32_t PanTiltInterface::ERROR_NONE = 0u;
50/** ERROR_UNSPECIFIC constant */
51const uint32_t PanTiltInterface::ERROR_UNSPECIFIC = 1u;
52/** ERROR_COMMUNICATION constant */
54/** ERROR_PAN_OUTOFRANGE constant */
56/** ERROR_TILT_OUTOFRANGE constant */
58
59/** Constructor */
60PanTiltInterface::PanTiltInterface() : Interface()
61{
62 data_size = sizeof(PanTiltInterface_data_t);
63 data_ptr = malloc(data_size);
64 data = (PanTiltInterface_data_t *)data_ptr;
65 data_ts = (interface_data_ts_t *)data_ptr;
66 memset(data_ptr, 0, data_size);
67 add_fieldinfo(IFT_UINT32, "flags", 1, &data->flags);
68 add_fieldinfo(IFT_FLOAT, "pan", 1, &data->pan);
69 add_fieldinfo(IFT_FLOAT, "tilt", 1, &data->tilt);
70 add_fieldinfo(IFT_UINT32, "msgid", 1, &data->msgid);
71 add_fieldinfo(IFT_BOOL, "final", 1, &data->final);
72 add_fieldinfo(IFT_UINT32, "error_code", 1, &data->error_code);
73 add_fieldinfo(IFT_BOOL, "enabled", 1, &data->enabled);
74 add_fieldinfo(IFT_BOOL, "calibrated", 1, &data->calibrated);
75 add_fieldinfo(IFT_FLOAT, "min_pan", 1, &data->min_pan);
76 add_fieldinfo(IFT_FLOAT, "max_pan", 1, &data->max_pan);
77 add_fieldinfo(IFT_FLOAT, "min_tilt", 1, &data->min_tilt);
78 add_fieldinfo(IFT_FLOAT, "max_tilt", 1, &data->max_tilt);
79 add_fieldinfo(IFT_FLOAT, "max_pan_velocity", 1, &data->max_pan_velocity);
80 add_fieldinfo(IFT_FLOAT, "max_tilt_velocity", 1, &data->max_tilt_velocity);
81 add_fieldinfo(IFT_FLOAT, "pan_velocity", 1, &data->pan_velocity);
82 add_fieldinfo(IFT_FLOAT, "tilt_velocity", 1, &data->tilt_velocity);
83 add_fieldinfo(IFT_FLOAT, "pan_margin", 1, &data->pan_margin);
84 add_fieldinfo(IFT_FLOAT, "tilt_margin", 1, &data->tilt_margin);
85 add_messageinfo("StopMessage");
86 add_messageinfo("FlushMessage");
87 add_messageinfo("CalibrateMessage");
88 add_messageinfo("ParkMessage");
89 add_messageinfo("GotoMessage");
90 add_messageinfo("TimedGotoMessage");
91 add_messageinfo("SetEnabledMessage");
92 add_messageinfo("SetVelocityMessage");
93 add_messageinfo("SetMarginMessage");
94 unsigned char tmp_hash[] = {0x3, 0xd7, 0x3b, 0xa8, 0x9f, 0x6d, 00, 0xb9, 0xf5, 0xf2, 0x2f, 0x92, 0x25, 0x1b, 0x87, 0x8e};
95 set_hash(tmp_hash);
96}
97
98/** Destructor */
99PanTiltInterface::~PanTiltInterface()
100{
101 free(data_ptr);
102}
103/* Methods */
104/** Get flags value.
105 * Flags.
106 * @return flags value
107 */
108uint32_t
109PanTiltInterface::flags() const
110{
111 return data->flags;
112}
113
114/** Get maximum length of flags value.
115 * @return length of flags value, can be length of the array or number of
116 * maximum number of characters for a string
117 */
118size_t
119PanTiltInterface::maxlenof_flags() const
120{
121 return 1;
122}
123
124/** Set flags value.
125 * Flags.
126 * @param new_flags new flags value
127 */
128void
129PanTiltInterface::set_flags(const uint32_t new_flags)
130{
131 set_field(data->flags, new_flags);
132}
133
134/** Get pan value.
135 * Current pan.
136 * @return pan value
137 */
138float
139PanTiltInterface::pan() const
140{
141 return data->pan;
142}
143
144/** Get maximum length of pan value.
145 * @return length of pan value, can be length of the array or number of
146 * maximum number of characters for a string
147 */
148size_t
149PanTiltInterface::maxlenof_pan() const
150{
151 return 1;
152}
153
154/** Set pan value.
155 * Current pan.
156 * @param new_pan new pan value
157 */
158void
159PanTiltInterface::set_pan(const float new_pan)
160{
161 set_field(data->pan, new_pan);
162}
163
164/** Get tilt value.
165 * Current tilt.
166 * @return tilt value
167 */
168float
169PanTiltInterface::tilt() const
170{
171 return data->tilt;
172}
173
174/** Get maximum length of tilt value.
175 * @return length of tilt value, can be length of the array or number of
176 * maximum number of characters for a string
177 */
178size_t
179PanTiltInterface::maxlenof_tilt() const
180{
181 return 1;
182}
183
184/** Set tilt value.
185 * Current tilt.
186 * @param new_tilt new tilt value
187 */
188void
189PanTiltInterface::set_tilt(const float new_tilt)
190{
191 set_field(data->tilt, new_tilt);
192}
193
194/** Get msgid value.
195 * The ID of the message that is currently being
196 processed, or 0 if no message is being processed.
197 * @return msgid value
198 */
199uint32_t
200PanTiltInterface::msgid() const
201{
202 return data->msgid;
203}
204
205/** Get maximum length of msgid value.
206 * @return length of msgid value, can be length of the array or number of
207 * maximum number of characters for a string
208 */
209size_t
210PanTiltInterface::maxlenof_msgid() const
211{
212 return 1;
213}
214
215/** Set msgid value.
216 * The ID of the message that is currently being
217 processed, or 0 if no message is being processed.
218 * @param new_msgid new msgid value
219 */
220void
221PanTiltInterface::set_msgid(const uint32_t new_msgid)
222{
223 set_field(data->msgid, new_msgid);
224}
225
226/** Get final value.
227 * True, if the last goto command has been finished,
228 false if it is still running
229 * @return final value
230 */
231bool
232PanTiltInterface::is_final() const
233{
234 return data->final;
235}
236
237/** Get maximum length of final value.
238 * @return length of final value, can be length of the array or number of
239 * maximum number of characters for a string
240 */
241size_t
242PanTiltInterface::maxlenof_final() const
243{
244 return 1;
245}
246
247/** Set final value.
248 * True, if the last goto command has been finished,
249 false if it is still running
250 * @param new_final new final value
251 */
252void
253PanTiltInterface::set_final(const bool new_final)
254{
255 set_field(data->final, new_final);
256}
257
258/** Get error_code value.
259 * Failure code set if
260 final is true. 0 if no error occured, an error code from ERROR_*
261 constants otherwise (or a bit-wise combination).
262 * @return error_code value
263 */
264uint32_t
265PanTiltInterface::error_code() const
266{
267 return data->error_code;
268}
269
270/** Get maximum length of error_code value.
271 * @return length of error_code value, can be length of the array or number of
272 * maximum number of characters for a string
273 */
274size_t
275PanTiltInterface::maxlenof_error_code() const
276{
277 return 1;
278}
279
280/** Set error_code value.
281 * Failure code set if
282 final is true. 0 if no error occured, an error code from ERROR_*
283 constants otherwise (or a bit-wise combination).
284 * @param new_error_code new error_code value
285 */
286void
287PanTiltInterface::set_error_code(const uint32_t new_error_code)
288{
289 set_field(data->error_code, new_error_code);
290}
291
292/** Get enabled value.
293 * Is the pan/tilt unit enabled?
294 * @return enabled value
295 */
296bool
297PanTiltInterface::is_enabled() const
298{
299 return data->enabled;
300}
301
302/** Get maximum length of enabled value.
303 * @return length of enabled value, can be length of the array or number of
304 * maximum number of characters for a string
305 */
306size_t
307PanTiltInterface::maxlenof_enabled() const
308{
309 return 1;
310}
311
312/** Set enabled value.
313 * Is the pan/tilt unit enabled?
314 * @param new_enabled new enabled value
315 */
316void
317PanTiltInterface::set_enabled(const bool new_enabled)
318{
319 set_field(data->enabled, new_enabled);
320}
321
322/** Get calibrated value.
323 * Is the pan/tilt unit calibrated?
324 * @return calibrated value
325 */
326bool
327PanTiltInterface::is_calibrated() const
328{
329 return data->calibrated;
330}
331
332/** Get maximum length of calibrated value.
333 * @return length of calibrated value, can be length of the array or number of
334 * maximum number of characters for a string
335 */
336size_t
337PanTiltInterface::maxlenof_calibrated() const
338{
339 return 1;
340}
341
342/** Set calibrated value.
343 * Is the pan/tilt unit calibrated?
344 * @param new_calibrated new calibrated value
345 */
346void
347PanTiltInterface::set_calibrated(const bool new_calibrated)
348{
349 set_field(data->calibrated, new_calibrated);
350}
351
352/** Get min_pan value.
353 * Minimum pan possible.
354 * @return min_pan value
355 */
356float
357PanTiltInterface::min_pan() const
358{
359 return data->min_pan;
360}
361
362/** Get maximum length of min_pan value.
363 * @return length of min_pan value, can be length of the array or number of
364 * maximum number of characters for a string
365 */
366size_t
367PanTiltInterface::maxlenof_min_pan() const
368{
369 return 1;
370}
371
372/** Set min_pan value.
373 * Minimum pan possible.
374 * @param new_min_pan new min_pan value
375 */
376void
377PanTiltInterface::set_min_pan(const float new_min_pan)
378{
379 set_field(data->min_pan, new_min_pan);
380}
381
382/** Get max_pan value.
383 * Maximum pan possible.
384 * @return max_pan value
385 */
386float
387PanTiltInterface::max_pan() const
388{
389 return data->max_pan;
390}
391
392/** Get maximum length of max_pan value.
393 * @return length of max_pan value, can be length of the array or number of
394 * maximum number of characters for a string
395 */
396size_t
397PanTiltInterface::maxlenof_max_pan() const
398{
399 return 1;
400}
401
402/** Set max_pan value.
403 * Maximum pan possible.
404 * @param new_max_pan new max_pan value
405 */
406void
407PanTiltInterface::set_max_pan(const float new_max_pan)
408{
409 set_field(data->max_pan, new_max_pan);
410}
411
412/** Get min_tilt value.
413 * Minimum tilt possible.
414 * @return min_tilt value
415 */
416float
417PanTiltInterface::min_tilt() const
418{
419 return data->min_tilt;
420}
421
422/** Get maximum length of min_tilt value.
423 * @return length of min_tilt value, can be length of the array or number of
424 * maximum number of characters for a string
425 */
426size_t
427PanTiltInterface::maxlenof_min_tilt() const
428{
429 return 1;
430}
431
432/** Set min_tilt value.
433 * Minimum tilt possible.
434 * @param new_min_tilt new min_tilt value
435 */
436void
437PanTiltInterface::set_min_tilt(const float new_min_tilt)
438{
439 set_field(data->min_tilt, new_min_tilt);
440}
441
442/** Get max_tilt value.
443 * Maximum tilt possible.
444 * @return max_tilt value
445 */
446float
447PanTiltInterface::max_tilt() const
448{
449 return data->max_tilt;
450}
451
452/** Get maximum length of max_tilt value.
453 * @return length of max_tilt value, can be length of the array or number of
454 * maximum number of characters for a string
455 */
456size_t
457PanTiltInterface::maxlenof_max_tilt() const
458{
459 return 1;
460}
461
462/** Set max_tilt value.
463 * Maximum tilt possible.
464 * @param new_max_tilt new max_tilt value
465 */
466void
467PanTiltInterface::set_max_tilt(const float new_max_tilt)
468{
469 set_field(data->max_tilt, new_max_tilt);
470}
471
472/** Get max_pan_velocity value.
473 * Maximum supported pan velocity.
474 * @return max_pan_velocity value
475 */
476float
477PanTiltInterface::max_pan_velocity() const
478{
479 return data->max_pan_velocity;
480}
481
482/** Get maximum length of max_pan_velocity value.
483 * @return length of max_pan_velocity value, can be length of the array or number of
484 * maximum number of characters for a string
485 */
486size_t
487PanTiltInterface::maxlenof_max_pan_velocity() const
488{
489 return 1;
490}
491
492/** Set max_pan_velocity value.
493 * Maximum supported pan velocity.
494 * @param new_max_pan_velocity new max_pan_velocity value
495 */
496void
497PanTiltInterface::set_max_pan_velocity(const float new_max_pan_velocity)
498{
499 set_field(data->max_pan_velocity, new_max_pan_velocity);
500}
501
502/** Get max_tilt_velocity value.
503 * Maximum supported tilt velocity.
504 * @return max_tilt_velocity value
505 */
506float
507PanTiltInterface::max_tilt_velocity() const
508{
509 return data->max_tilt_velocity;
510}
511
512/** Get maximum length of max_tilt_velocity value.
513 * @return length of max_tilt_velocity value, can be length of the array or number of
514 * maximum number of characters for a string
515 */
516size_t
517PanTiltInterface::maxlenof_max_tilt_velocity() const
518{
519 return 1;
520}
521
522/** Set max_tilt_velocity value.
523 * Maximum supported tilt velocity.
524 * @param new_max_tilt_velocity new max_tilt_velocity value
525 */
526void
527PanTiltInterface::set_max_tilt_velocity(const float new_max_tilt_velocity)
528{
529 set_field(data->max_tilt_velocity, new_max_tilt_velocity);
530}
531
532/** Get pan_velocity value.
533 * Maximum pan velocity currently reached.
534 * @return pan_velocity value
535 */
536float
537PanTiltInterface::pan_velocity() const
538{
539 return data->pan_velocity;
540}
541
542/** Get maximum length of pan_velocity value.
543 * @return length of pan_velocity value, can be length of the array or number of
544 * maximum number of characters for a string
545 */
546size_t
547PanTiltInterface::maxlenof_pan_velocity() const
548{
549 return 1;
550}
551
552/** Set pan_velocity value.
553 * Maximum pan velocity currently reached.
554 * @param new_pan_velocity new pan_velocity value
555 */
556void
557PanTiltInterface::set_pan_velocity(const float new_pan_velocity)
558{
559 set_field(data->pan_velocity, new_pan_velocity);
560}
561
562/** Get tilt_velocity value.
563 * Maximum tilt velocity currently reached.
564 * @return tilt_velocity value
565 */
566float
567PanTiltInterface::tilt_velocity() const
568{
569 return data->tilt_velocity;
570}
571
572/** Get maximum length of tilt_velocity value.
573 * @return length of tilt_velocity value, can be length of the array or number of
574 * maximum number of characters for a string
575 */
576size_t
577PanTiltInterface::maxlenof_tilt_velocity() const
578{
579 return 1;
580}
581
582/** Set tilt_velocity value.
583 * Maximum tilt velocity currently reached.
584 * @param new_tilt_velocity new tilt_velocity value
585 */
586void
587PanTiltInterface::set_tilt_velocity(const float new_tilt_velocity)
588{
589 set_field(data->tilt_velocity, new_tilt_velocity);
590}
591
592/** Get pan_margin value.
593 * Margin in radians around a
594 target pan value to consider the motion as final.
595 * @return pan_margin value
596 */
597float
598PanTiltInterface::pan_margin() const
599{
600 return data->pan_margin;
601}
602
603/** Get maximum length of pan_margin value.
604 * @return length of pan_margin value, can be length of the array or number of
605 * maximum number of characters for a string
606 */
607size_t
608PanTiltInterface::maxlenof_pan_margin() const
609{
610 return 1;
611}
612
613/** Set pan_margin value.
614 * Margin in radians around a
615 target pan value to consider the motion as final.
616 * @param new_pan_margin new pan_margin value
617 */
618void
619PanTiltInterface::set_pan_margin(const float new_pan_margin)
620{
621 set_field(data->pan_margin, new_pan_margin);
622}
623
624/** Get tilt_margin value.
625 * Margin in radians around a
626 target tilt value to consider the motion as final.
627 * @return tilt_margin value
628 */
629float
630PanTiltInterface::tilt_margin() const
631{
632 return data->tilt_margin;
633}
634
635/** Get maximum length of tilt_margin value.
636 * @return length of tilt_margin value, can be length of the array or number of
637 * maximum number of characters for a string
638 */
639size_t
640PanTiltInterface::maxlenof_tilt_margin() const
641{
642 return 1;
643}
644
645/** Set tilt_margin value.
646 * Margin in radians around a
647 target tilt value to consider the motion as final.
648 * @param new_tilt_margin new tilt_margin value
649 */
650void
651PanTiltInterface::set_tilt_margin(const float new_tilt_margin)
652{
653 set_field(data->tilt_margin, new_tilt_margin);
654}
655
656/* =========== message create =========== */
657Message *
658PanTiltInterface::create_message(const char *type) const
659{
660 if ( strncmp("StopMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
661 return new StopMessage();
662 } else if ( strncmp("FlushMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
663 return new FlushMessage();
664 } else if ( strncmp("CalibrateMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
665 return new CalibrateMessage();
666 } else if ( strncmp("ParkMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
667 return new ParkMessage();
668 } else if ( strncmp("GotoMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
669 return new GotoMessage();
670 } else if ( strncmp("TimedGotoMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
671 return new TimedGotoMessage();
672 } else if ( strncmp("SetEnabledMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
673 return new SetEnabledMessage();
674 } else if ( strncmp("SetVelocityMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
675 return new SetVelocityMessage();
676 } else if ( strncmp("SetMarginMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
677 return new SetMarginMessage();
678 } else {
679 throw UnknownTypeException("The given type '%s' does not match any known "
680 "message type for this interface type.", type);
681 }
682}
683
684
685/** Copy values from other interface.
686 * @param other other interface to copy values from
687 */
688void
689PanTiltInterface::copy_values(const Interface *other)
690{
691 const PanTiltInterface *oi = dynamic_cast<const PanTiltInterface *>(other);
692 if (oi == NULL) {
693 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
694 type(), other->type());
695 }
696 memcpy(data, oi->data, sizeof(PanTiltInterface_data_t));
697}
698
699const char *
700PanTiltInterface::enum_tostring(const char *enumtype, int val) const
701{
702 throw UnknownTypeException("Unknown enum type %s", enumtype);
703}
704
705/* =========== messages =========== */
706/** @class PanTiltInterface::StopMessage <interfaces/PanTiltInterface.h>
707 * StopMessage Fawkes BlackBoard Interface Message.
708 *
709
710 */
711
712
713/** Constructor */
714PanTiltInterface::StopMessage::StopMessage() : Message("StopMessage")
715{
716 data_size = sizeof(StopMessage_data_t);
717 data_ptr = malloc(data_size);
718 memset(data_ptr, 0, data_size);
719 data = (StopMessage_data_t *)data_ptr;
721}
722
723/** Destructor */
725{
726 free(data_ptr);
727}
728
729/** Copy constructor.
730 * @param m message to copy from
731 */
733{
734 data_size = m->data_size;
735 data_ptr = malloc(data_size);
736 memcpy(data_ptr, m->data_ptr, data_size);
737 data = (StopMessage_data_t *)data_ptr;
739}
740
741/* Methods */
742/** Clone this message.
743 * Produces a message of the same type as this message and copies the
744 * data to the new message.
745 * @return clone of this message
746 */
747Message *
749{
750 return new PanTiltInterface::StopMessage(this);
751}
752/** @class PanTiltInterface::FlushMessage <interfaces/PanTiltInterface.h>
753 * FlushMessage Fawkes BlackBoard Interface Message.
754 *
755
756 */
757
758
759/** Constructor */
761{
762 data_size = sizeof(FlushMessage_data_t);
763 data_ptr = malloc(data_size);
764 memset(data_ptr, 0, data_size);
765 data = (FlushMessage_data_t *)data_ptr;
767}
768
769/** Destructor */
771{
772 free(data_ptr);
773}
774
775/** Copy constructor.
776 * @param m message to copy from
777 */
779{
780 data_size = m->data_size;
781 data_ptr = malloc(data_size);
782 memcpy(data_ptr, m->data_ptr, data_size);
783 data = (FlushMessage_data_t *)data_ptr;
785}
786
787/* Methods */
788/** Clone this message.
789 * Produces a message of the same type as this message and copies the
790 * data to the new message.
791 * @return clone of this message
792 */
793Message *
795{
796 return new PanTiltInterface::FlushMessage(this);
797}
798/** @class PanTiltInterface::CalibrateMessage <interfaces/PanTiltInterface.h>
799 * CalibrateMessage Fawkes BlackBoard Interface Message.
800 *
801
802 */
803
804
805/** Constructor */
807{
808 data_size = sizeof(CalibrateMessage_data_t);
809 data_ptr = malloc(data_size);
810 memset(data_ptr, 0, data_size);
811 data = (CalibrateMessage_data_t *)data_ptr;
813}
814
815/** Destructor */
817{
818 free(data_ptr);
819}
820
821/** Copy constructor.
822 * @param m message to copy from
823 */
825{
826 data_size = m->data_size;
827 data_ptr = malloc(data_size);
828 memcpy(data_ptr, m->data_ptr, data_size);
829 data = (CalibrateMessage_data_t *)data_ptr;
831}
832
833/* Methods */
834/** Clone this message.
835 * Produces a message of the same type as this message and copies the
836 * data to the new message.
837 * @return clone of this message
838 */
839Message *
841{
842 return new PanTiltInterface::CalibrateMessage(this);
843}
844/** @class PanTiltInterface::ParkMessage <interfaces/PanTiltInterface.h>
845 * ParkMessage Fawkes BlackBoard Interface Message.
846 *
847
848 */
849
850
851/** Constructor */
853{
854 data_size = sizeof(ParkMessage_data_t);
855 data_ptr = malloc(data_size);
856 memset(data_ptr, 0, data_size);
857 data = (ParkMessage_data_t *)data_ptr;
859}
860
861/** Destructor */
863{
864 free(data_ptr);
865}
866
867/** Copy constructor.
868 * @param m message to copy from
869 */
871{
872 data_size = m->data_size;
873 data_ptr = malloc(data_size);
874 memcpy(data_ptr, m->data_ptr, data_size);
875 data = (ParkMessage_data_t *)data_ptr;
877}
878
879/* Methods */
880/** Clone this message.
881 * Produces a message of the same type as this message and copies the
882 * data to the new message.
883 * @return clone of this message
884 */
885Message *
887{
888 return new PanTiltInterface::ParkMessage(this);
889}
890/** @class PanTiltInterface::GotoMessage <interfaces/PanTiltInterface.h>
891 * GotoMessage Fawkes BlackBoard Interface Message.
892 *
893
894 */
895
896
897/** Constructor with initial values.
898 * @param ini_pan initial value for pan
899 * @param ini_tilt initial value for tilt
900 */
901PanTiltInterface::GotoMessage::GotoMessage(const float ini_pan, const float ini_tilt) : Message("GotoMessage")
902{
903 data_size = sizeof(GotoMessage_data_t);
904 data_ptr = malloc(data_size);
905 memset(data_ptr, 0, data_size);
906 data = (GotoMessage_data_t *)data_ptr;
908 data->pan = ini_pan;
909 data->tilt = ini_tilt;
910 add_fieldinfo(IFT_FLOAT, "pan", 1, &data->pan);
911 add_fieldinfo(IFT_FLOAT, "tilt", 1, &data->tilt);
912}
913/** Constructor */
915{
916 data_size = sizeof(GotoMessage_data_t);
917 data_ptr = malloc(data_size);
918 memset(data_ptr, 0, data_size);
919 data = (GotoMessage_data_t *)data_ptr;
921 add_fieldinfo(IFT_FLOAT, "pan", 1, &data->pan);
922 add_fieldinfo(IFT_FLOAT, "tilt", 1, &data->tilt);
923}
924
925/** Destructor */
927{
928 free(data_ptr);
929}
930
931/** Copy constructor.
932 * @param m message to copy from
933 */
935{
936 data_size = m->data_size;
937 data_ptr = malloc(data_size);
938 memcpy(data_ptr, m->data_ptr, data_size);
939 data = (GotoMessage_data_t *)data_ptr;
941}
942
943/* Methods */
944/** Get pan value.
945 * Current pan.
946 * @return pan value
947 */
948float
950{
951 return data->pan;
952}
953
954/** Get maximum length of pan value.
955 * @return length of pan value, can be length of the array or number of
956 * maximum number of characters for a string
957 */
958size_t
960{
961 return 1;
962}
963
964/** Set pan value.
965 * Current pan.
966 * @param new_pan new pan value
967 */
968void
970{
971 set_field(data->pan, new_pan);
972}
973
974/** Get tilt value.
975 * Current tilt.
976 * @return tilt value
977 */
978float
980{
981 return data->tilt;
982}
983
984/** Get maximum length of tilt value.
985 * @return length of tilt value, can be length of the array or number of
986 * maximum number of characters for a string
987 */
988size_t
990{
991 return 1;
992}
993
994/** Set tilt value.
995 * Current tilt.
996 * @param new_tilt new tilt value
997 */
998void
1000{
1001 set_field(data->tilt, new_tilt);
1002}
1003
1004/** Clone this message.
1005 * Produces a message of the same type as this message and copies the
1006 * data to the new message.
1007 * @return clone of this message
1008 */
1009Message *
1011{
1012 return new PanTiltInterface::GotoMessage(this);
1013}
1014/** @class PanTiltInterface::TimedGotoMessage <interfaces/PanTiltInterface.h>
1015 * TimedGotoMessage Fawkes BlackBoard Interface Message.
1016 *
1017
1018 */
1019
1020
1021/** Constructor with initial values.
1022 * @param ini_time_sec initial value for time_sec
1023 * @param ini_pan initial value for pan
1024 * @param ini_tilt initial value for tilt
1025 */
1026PanTiltInterface::TimedGotoMessage::TimedGotoMessage(const float ini_time_sec, const float ini_pan, const float ini_tilt) : Message("TimedGotoMessage")
1027{
1028 data_size = sizeof(TimedGotoMessage_data_t);
1029 data_ptr = malloc(data_size);
1030 memset(data_ptr, 0, data_size);
1031 data = (TimedGotoMessage_data_t *)data_ptr;
1033 data->time_sec = ini_time_sec;
1034 data->pan = ini_pan;
1035 data->tilt = ini_tilt;
1036 add_fieldinfo(IFT_FLOAT, "time_sec", 1, &data->time_sec);
1037 add_fieldinfo(IFT_FLOAT, "pan", 1, &data->pan);
1038 add_fieldinfo(IFT_FLOAT, "tilt", 1, &data->tilt);
1039}
1040/** Constructor */
1042{
1043 data_size = sizeof(TimedGotoMessage_data_t);
1044 data_ptr = malloc(data_size);
1045 memset(data_ptr, 0, data_size);
1046 data = (TimedGotoMessage_data_t *)data_ptr;
1048 add_fieldinfo(IFT_FLOAT, "time_sec", 1, &data->time_sec);
1049 add_fieldinfo(IFT_FLOAT, "pan", 1, &data->pan);
1050 add_fieldinfo(IFT_FLOAT, "tilt", 1, &data->tilt);
1051}
1052
1053/** Destructor */
1055{
1056 free(data_ptr);
1057}
1058
1059/** Copy constructor.
1060 * @param m message to copy from
1061 */
1063{
1064 data_size = m->data_size;
1065 data_ptr = malloc(data_size);
1066 memcpy(data_ptr, m->data_ptr, data_size);
1067 data = (TimedGotoMessage_data_t *)data_ptr;
1069}
1070
1071/* Methods */
1072/** Get time_sec value.
1073 * Time in seconds when to reach
1074 the final position.
1075 * @return time_sec value
1076 */
1077float
1079{
1080 return data->time_sec;
1081}
1082
1083/** Get maximum length of time_sec value.
1084 * @return length of time_sec value, can be length of the array or number of
1085 * maximum number of characters for a string
1086 */
1087size_t
1089{
1090 return 1;
1091}
1092
1093/** Set time_sec value.
1094 * Time in seconds when to reach
1095 the final position.
1096 * @param new_time_sec new time_sec value
1097 */
1098void
1100{
1101 set_field(data->time_sec, new_time_sec);
1102}
1103
1104/** Get pan value.
1105 * Current pan.
1106 * @return pan value
1107 */
1108float
1110{
1111 return data->pan;
1112}
1113
1114/** Get maximum length of pan value.
1115 * @return length of pan value, can be length of the array or number of
1116 * maximum number of characters for a string
1117 */
1118size_t
1120{
1121 return 1;
1122}
1123
1124/** Set pan value.
1125 * Current pan.
1126 * @param new_pan new pan value
1127 */
1128void
1130{
1131 set_field(data->pan, new_pan);
1132}
1133
1134/** Get tilt value.
1135 * Current tilt.
1136 * @return tilt value
1137 */
1138float
1140{
1141 return data->tilt;
1142}
1143
1144/** Get maximum length of tilt value.
1145 * @return length of tilt value, can be length of the array or number of
1146 * maximum number of characters for a string
1147 */
1148size_t
1150{
1151 return 1;
1152}
1153
1154/** Set tilt value.
1155 * Current tilt.
1156 * @param new_tilt new tilt value
1157 */
1158void
1160{
1161 set_field(data->tilt, new_tilt);
1162}
1163
1164/** Clone this message.
1165 * Produces a message of the same type as this message and copies the
1166 * data to the new message.
1167 * @return clone of this message
1168 */
1169Message *
1171{
1172 return new PanTiltInterface::TimedGotoMessage(this);
1173}
1174/** @class PanTiltInterface::SetEnabledMessage <interfaces/PanTiltInterface.h>
1175 * SetEnabledMessage Fawkes BlackBoard Interface Message.
1176 *
1177
1178 */
1179
1180
1181/** Constructor with initial values.
1182 * @param ini_enabled initial value for enabled
1183 */
1184PanTiltInterface::SetEnabledMessage::SetEnabledMessage(const bool ini_enabled) : Message("SetEnabledMessage")
1185{
1186 data_size = sizeof(SetEnabledMessage_data_t);
1187 data_ptr = malloc(data_size);
1188 memset(data_ptr, 0, data_size);
1189 data = (SetEnabledMessage_data_t *)data_ptr;
1191 data->enabled = ini_enabled;
1192 add_fieldinfo(IFT_BOOL, "enabled", 1, &data->enabled);
1193}
1194/** Constructor */
1196{
1197 data_size = sizeof(SetEnabledMessage_data_t);
1198 data_ptr = malloc(data_size);
1199 memset(data_ptr, 0, data_size);
1200 data = (SetEnabledMessage_data_t *)data_ptr;
1202 add_fieldinfo(IFT_BOOL, "enabled", 1, &data->enabled);
1203}
1204
1205/** Destructor */
1207{
1208 free(data_ptr);
1209}
1210
1211/** Copy constructor.
1212 * @param m message to copy from
1213 */
1215{
1216 data_size = m->data_size;
1217 data_ptr = malloc(data_size);
1218 memcpy(data_ptr, m->data_ptr, data_size);
1219 data = (SetEnabledMessage_data_t *)data_ptr;
1221}
1222
1223/* Methods */
1224/** Get enabled value.
1225 * Is the pan/tilt unit enabled?
1226 * @return enabled value
1227 */
1228bool
1230{
1231 return data->enabled;
1232}
1233
1234/** Get maximum length of enabled value.
1235 * @return length of enabled value, can be length of the array or number of
1236 * maximum number of characters for a string
1237 */
1238size_t
1240{
1241 return 1;
1242}
1243
1244/** Set enabled value.
1245 * Is the pan/tilt unit enabled?
1246 * @param new_enabled new enabled value
1247 */
1248void
1250{
1251 set_field(data->enabled, new_enabled);
1252}
1253
1254/** Clone this message.
1255 * Produces a message of the same type as this message and copies the
1256 * data to the new message.
1257 * @return clone of this message
1258 */
1259Message *
1261{
1262 return new PanTiltInterface::SetEnabledMessage(this);
1263}
1264/** @class PanTiltInterface::SetVelocityMessage <interfaces/PanTiltInterface.h>
1265 * SetVelocityMessage Fawkes BlackBoard Interface Message.
1266 *
1267
1268 */
1269
1270
1271/** Constructor with initial values.
1272 * @param ini_pan_velocity initial value for pan_velocity
1273 * @param ini_tilt_velocity initial value for tilt_velocity
1274 */
1275PanTiltInterface::SetVelocityMessage::SetVelocityMessage(const float ini_pan_velocity, const float ini_tilt_velocity) : Message("SetVelocityMessage")
1276{
1277 data_size = sizeof(SetVelocityMessage_data_t);
1278 data_ptr = malloc(data_size);
1279 memset(data_ptr, 0, data_size);
1280 data = (SetVelocityMessage_data_t *)data_ptr;
1282 data->pan_velocity = ini_pan_velocity;
1283 data->tilt_velocity = ini_tilt_velocity;
1284 add_fieldinfo(IFT_FLOAT, "pan_velocity", 1, &data->pan_velocity);
1285 add_fieldinfo(IFT_FLOAT, "tilt_velocity", 1, &data->tilt_velocity);
1286}
1287/** Constructor */
1289{
1290 data_size = sizeof(SetVelocityMessage_data_t);
1291 data_ptr = malloc(data_size);
1292 memset(data_ptr, 0, data_size);
1293 data = (SetVelocityMessage_data_t *)data_ptr;
1295 add_fieldinfo(IFT_FLOAT, "pan_velocity", 1, &data->pan_velocity);
1296 add_fieldinfo(IFT_FLOAT, "tilt_velocity", 1, &data->tilt_velocity);
1297}
1298
1299/** Destructor */
1301{
1302 free(data_ptr);
1303}
1304
1305/** Copy constructor.
1306 * @param m message to copy from
1307 */
1309{
1310 data_size = m->data_size;
1311 data_ptr = malloc(data_size);
1312 memcpy(data_ptr, m->data_ptr, data_size);
1313 data = (SetVelocityMessage_data_t *)data_ptr;
1315}
1316
1317/* Methods */
1318/** Get pan_velocity value.
1319 * Maximum pan velocity currently reached.
1320 * @return pan_velocity value
1321 */
1322float
1324{
1325 return data->pan_velocity;
1326}
1327
1328/** Get maximum length of pan_velocity value.
1329 * @return length of pan_velocity value, can be length of the array or number of
1330 * maximum number of characters for a string
1331 */
1332size_t
1334{
1335 return 1;
1336}
1337
1338/** Set pan_velocity value.
1339 * Maximum pan velocity currently reached.
1340 * @param new_pan_velocity new pan_velocity value
1341 */
1342void
1344{
1345 set_field(data->pan_velocity, new_pan_velocity);
1346}
1347
1348/** Get tilt_velocity value.
1349 * Maximum tilt velocity currently reached.
1350 * @return tilt_velocity value
1351 */
1352float
1354{
1355 return data->tilt_velocity;
1356}
1357
1358/** Get maximum length of tilt_velocity value.
1359 * @return length of tilt_velocity value, can be length of the array or number of
1360 * maximum number of characters for a string
1361 */
1362size_t
1364{
1365 return 1;
1366}
1367
1368/** Set tilt_velocity value.
1369 * Maximum tilt velocity currently reached.
1370 * @param new_tilt_velocity new tilt_velocity value
1371 */
1372void
1374{
1375 set_field(data->tilt_velocity, new_tilt_velocity);
1376}
1377
1378/** Clone this message.
1379 * Produces a message of the same type as this message and copies the
1380 * data to the new message.
1381 * @return clone of this message
1382 */
1383Message *
1385{
1386 return new PanTiltInterface::SetVelocityMessage(this);
1387}
1388/** @class PanTiltInterface::SetMarginMessage <interfaces/PanTiltInterface.h>
1389 * SetMarginMessage Fawkes BlackBoard Interface Message.
1390 *
1391
1392 */
1393
1394
1395/** Constructor with initial values.
1396 * @param ini_pan_margin initial value for pan_margin
1397 * @param ini_tilt_margin initial value for tilt_margin
1398 */
1399PanTiltInterface::SetMarginMessage::SetMarginMessage(const float ini_pan_margin, const float ini_tilt_margin) : Message("SetMarginMessage")
1400{
1401 data_size = sizeof(SetMarginMessage_data_t);
1402 data_ptr = malloc(data_size);
1403 memset(data_ptr, 0, data_size);
1404 data = (SetMarginMessage_data_t *)data_ptr;
1406 data->pan_margin = ini_pan_margin;
1407 data->tilt_margin = ini_tilt_margin;
1408 add_fieldinfo(IFT_FLOAT, "pan_margin", 1, &data->pan_margin);
1409 add_fieldinfo(IFT_FLOAT, "tilt_margin", 1, &data->tilt_margin);
1410}
1411/** Constructor */
1413{
1414 data_size = sizeof(SetMarginMessage_data_t);
1415 data_ptr = malloc(data_size);
1416 memset(data_ptr, 0, data_size);
1417 data = (SetMarginMessage_data_t *)data_ptr;
1419 add_fieldinfo(IFT_FLOAT, "pan_margin", 1, &data->pan_margin);
1420 add_fieldinfo(IFT_FLOAT, "tilt_margin", 1, &data->tilt_margin);
1421}
1422
1423/** Destructor */
1425{
1426 free(data_ptr);
1427}
1428
1429/** Copy constructor.
1430 * @param m message to copy from
1431 */
1433{
1434 data_size = m->data_size;
1435 data_ptr = malloc(data_size);
1436 memcpy(data_ptr, m->data_ptr, data_size);
1437 data = (SetMarginMessage_data_t *)data_ptr;
1439}
1440
1441/* Methods */
1442/** Get pan_margin value.
1443 * Margin in radians around a
1444 target pan value to consider the motion as final.
1445 * @return pan_margin value
1446 */
1447float
1449{
1450 return data->pan_margin;
1451}
1452
1453/** Get maximum length of pan_margin value.
1454 * @return length of pan_margin value, can be length of the array or number of
1455 * maximum number of characters for a string
1456 */
1457size_t
1459{
1460 return 1;
1461}
1462
1463/** Set pan_margin value.
1464 * Margin in radians around a
1465 target pan value to consider the motion as final.
1466 * @param new_pan_margin new pan_margin value
1467 */
1468void
1470{
1471 set_field(data->pan_margin, new_pan_margin);
1472}
1473
1474/** Get tilt_margin value.
1475 * Margin in radians around a
1476 target tilt value to consider the motion as final.
1477 * @return tilt_margin value
1478 */
1479float
1481{
1482 return data->tilt_margin;
1483}
1484
1485/** Get maximum length of tilt_margin value.
1486 * @return length of tilt_margin value, can be length of the array or number of
1487 * maximum number of characters for a string
1488 */
1489size_t
1491{
1492 return 1;
1493}
1494
1495/** Set tilt_margin value.
1496 * Margin in radians around a
1497 target tilt value to consider the motion as final.
1498 * @param new_tilt_margin new tilt_margin value
1499 */
1500void
1502{
1503 set_field(data->tilt_margin, new_tilt_margin);
1504}
1505
1506/** Clone this message.
1507 * Produces a message of the same type as this message and copies the
1508 * data to the new message.
1509 * @return clone of this message
1510 */
1511Message *
1513{
1514 return new PanTiltInterface::SetMarginMessage(this);
1515}
1516/** Check if message is valid and can be enqueued.
1517 * @param message Message to check
1518 * @return true if the message is valid, false otherwise.
1519 */
1520bool
1522{
1523 const StopMessage *m0 = dynamic_cast<const StopMessage *>(message);
1524 if ( m0 != NULL ) {
1525 return true;
1526 }
1527 const FlushMessage *m1 = dynamic_cast<const FlushMessage *>(message);
1528 if ( m1 != NULL ) {
1529 return true;
1530 }
1531 const CalibrateMessage *m2 = dynamic_cast<const CalibrateMessage *>(message);
1532 if ( m2 != NULL ) {
1533 return true;
1534 }
1535 const ParkMessage *m3 = dynamic_cast<const ParkMessage *>(message);
1536 if ( m3 != NULL ) {
1537 return true;
1538 }
1539 const GotoMessage *m4 = dynamic_cast<const GotoMessage *>(message);
1540 if ( m4 != NULL ) {
1541 return true;
1542 }
1543 const TimedGotoMessage *m5 = dynamic_cast<const TimedGotoMessage *>(message);
1544 if ( m5 != NULL ) {
1545 return true;
1546 }
1547 const SetEnabledMessage *m6 = dynamic_cast<const SetEnabledMessage *>(message);
1548 if ( m6 != NULL ) {
1549 return true;
1550 }
1551 const SetVelocityMessage *m7 = dynamic_cast<const SetVelocityMessage *>(message);
1552 if ( m7 != NULL ) {
1553 return true;
1554 }
1555 const SetMarginMessage *m8 = dynamic_cast<const SetMarginMessage *>(message);
1556 if ( m8 != NULL ) {
1557 return true;
1558 }
1559 return false;
1560}
1561
1562/// @cond INTERNALS
1563EXPORT_INTERFACE(PanTiltInterface)
1564/// @endcond
1565
1566
1567} // end namespace fawkes
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
const char * type() const
Get type of interface.
Definition: interface.cpp:652
void * data_ptr
Pointer to local memory storage.
Definition: interface.h:244
void set_field(FieldT &field, DataT &data)
Set a field, set data_changed to true and update data_changed accordingly.
Definition: interface.h:304
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0, const interface_enum_map_t *enum_map=0)
Add an entry to the info list.
Definition: message.cpp:435
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:146
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:156
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:147
CalibrateMessage Fawkes BlackBoard Interface Message.
virtual Message * clone() const
Clone this message.
FlushMessage Fawkes BlackBoard Interface Message.
virtual Message * clone() const
Clone this message.
GotoMessage Fawkes BlackBoard Interface Message.
void set_tilt(const float new_tilt)
Set tilt value.
void set_pan(const float new_pan)
Set pan value.
size_t maxlenof_tilt() const
Get maximum length of tilt value.
virtual Message * clone() const
Clone this message.
float tilt() const
Get tilt value.
size_t maxlenof_pan() const
Get maximum length of pan value.
ParkMessage Fawkes BlackBoard Interface Message.
virtual Message * clone() const
Clone this message.
SetEnabledMessage Fawkes BlackBoard Interface Message.
virtual Message * clone() const
Clone this message.
void set_enabled(const bool new_enabled)
Set enabled value.
size_t maxlenof_enabled() const
Get maximum length of enabled value.
SetMarginMessage Fawkes BlackBoard Interface Message.
void set_pan_margin(const float new_pan_margin)
Set pan_margin value.
virtual Message * clone() const
Clone this message.
void set_tilt_margin(const float new_tilt_margin)
Set tilt_margin value.
size_t maxlenof_pan_margin() const
Get maximum length of pan_margin value.
size_t maxlenof_tilt_margin() const
Get maximum length of tilt_margin value.
float tilt_margin() const
Get tilt_margin value.
float pan_margin() const
Get pan_margin value.
SetVelocityMessage Fawkes BlackBoard Interface Message.
size_t maxlenof_pan_velocity() const
Get maximum length of pan_velocity value.
void set_pan_velocity(const float new_pan_velocity)
Set pan_velocity value.
virtual Message * clone() const
Clone this message.
float tilt_velocity() const
Get tilt_velocity value.
void set_tilt_velocity(const float new_tilt_velocity)
Set tilt_velocity value.
size_t maxlenof_tilt_velocity() const
Get maximum length of tilt_velocity value.
float pan_velocity() const
Get pan_velocity value.
StopMessage Fawkes BlackBoard Interface Message.
virtual Message * clone() const
Clone this message.
TimedGotoMessage Fawkes BlackBoard Interface Message.
float time_sec() const
Get time_sec value.
size_t maxlenof_time_sec() const
Get maximum length of time_sec value.
virtual Message * clone() const
Clone this message.
void set_tilt(const float new_tilt)
Set tilt value.
void set_time_sec(const float new_time_sec)
Set time_sec value.
size_t maxlenof_tilt() const
Get maximum length of tilt value.
size_t maxlenof_pan() const
Get maximum length of pan value.
void set_pan(const float new_pan)
Set pan value.
PanTiltInterface Fawkes BlackBoard Interface.
static const uint32_t ERROR_NONE
ERROR_NONE constant.
static const uint32_t ERROR_UNSPECIFIC
ERROR_UNSPECIFIC constant.
static const uint32_t FLAG_SUPPORTS_PAN
FLAG_SUPPORTS_PAN constant.
static const uint32_t FLAG_SUPPORTS_TILT
FLAG_SUPPORTS_TILT constant.
static const uint32_t ERROR_TILT_OUTOFRANGE
ERROR_TILT_OUTOFRANGE constant.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
static const uint32_t ERROR_COMMUNICATION
ERROR_COMMUNICATION constant.
static const uint32_t ERROR_PAN_OUTOFRANGE
ERROR_PAN_OUTOFRANGE constant.
Fawkes library namespace.
@ IFT_FLOAT
float field
Definition: types.h:46
@ IFT_BOOL
boolean field
Definition: types.h:37
Timestamp data, must be present and first entries for each interface data structs!...
Definition: message.h:152