Fawkes API Fawkes Development Version
dp_thread.h
1
2/***************************************************************************
3 * dp_thread.h - DirectedPerception pan/tilt unit act thread
4 *
5 * Created: Sun Jun 21 17:26:33 2009
6 * Copyright 2006-2009 Tim Niemueller [www.niemueller.de]
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.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * Read the full text in the LICENSE.GPL file in the doc directory.
21 */
22
23#ifndef _PLUGINS_PANTILT_DIRPERC_DP_THREAD_H_
24#define _PLUGINS_PANTILT_DIRPERC_DP_THREAD_H_
25
26#include "../act_thread.h"
27
28#include <blackboard/interface_listener.h>
29
30#ifdef USE_TIMETRACKER
31# include <utils/time/tracker.h>
32#endif
33#include <memory>
34#include <string>
35
36namespace fawkes {
37class PanTiltInterface;
38class JointInterface;
39} // namespace fawkes
40
42
45{
46public:
47 PanTiltDirectedPerceptionThread(std::string &pantilt_cfg_prefix,
48 std::string &ptu_cfg_prefix,
49 std::string &ptu_name);
50
51 virtual void init();
52 virtual void finalize();
53 virtual void loop();
54
55 // For BlackBoardInterfaceListener
57 fawkes::Message * message) noexcept;
58
60
61 /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
62protected:
63 virtual void
65 {
66 Thread::run();
67 }
68
69private:
70 fawkes::PanTiltInterface *pantilt_if_;
71 fawkes::JointInterface * panjoint_if_;
72 fawkes::JointInterface * tiltjoint_if_;
73
75
76 std::string pantilt_cfg_prefix_;
77 std::string ptu_cfg_prefix_;
78 std::string ptu_name_;
79 std::string cfg_device_;
80 unsigned int cfg_read_timeout_ms_;
81
82 class WorkerThread : public fawkes::Thread
83 {
84 public:
85 WorkerThread(std::string ptu_name,
88
89 ~WorkerThread();
90 void goto_pantilt(float pan, float tilt);
91 void get_pantilt(float &pan, float &tilt);
92 bool is_final();
93 void stop_motion();
94 bool has_fresh_data();
95 void reset();
96
97 virtual void loop();
98
99 private:
100 void exec_goto_pantilt(float pan, float tilt);
101
102 private:
104 fawkes::Logger * logger_;
105
106 float pan_min_;
107 float pan_max_;
108 float tilt_min_;
109 float tilt_max_;
110
111 fawkes::Mutex *move_mutex_;
112 bool move_pending_;
113 float target_pan_;
114 float target_tilt_;
115
116 float cur_pan_;
117 float cur_tilt_;
118
119 bool reset_pending_;
120 bool fresh_data_;
121 };
122
123 WorkerThread *wt_;
124};
125
126#endif
DirectedPerception PTU implementation.
Definition: dp_ptu.h:31
Pan/tilt act thread.
Definition: act_thread.h:41
PanTilt act thread for PTUs from DirectedPerception employing the ASCII protocol.
Definition: dp_thread.h:45
virtual void loop()
Code to execute in the thread.
Definition: dp_thread.cpp:165
PanTiltDirectedPerceptionThread(std::string &pantilt_cfg_prefix, std::string &ptu_cfg_prefix, std::string &ptu_name)
Constructor.
Definition: dp_thread.cpp:49
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: dp_thread.h:64
virtual void finalize()
Finalize the thread.
Definition: dp_thread.cpp:126
virtual void init()
Initialize the thread.
Definition: dp_thread.cpp:63
void update_sensor_values()
Update sensor values as necessary.
Definition: dp_thread.cpp:146
virtual bool bb_interface_message_received(fawkes::Interface *interface, fawkes::Message *message) noexcept
BlackBoard message received notification.
Definition: dp_thread.cpp:226
BlackBoard interface listener.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
JointInterface Fawkes BlackBoard Interface.
Interface for logging.
Definition: logger.h:42
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:41
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
Mutex mutual exclusion lock.
Definition: mutex.h:33
PanTiltInterface Fawkes BlackBoard Interface.
Thread class encapsulation of pthreads.
Definition: thread.h:46
Fawkes library namespace.