25 #include <Base/Common/BIASpragma.hh>
26 #include <PanTilt/DPPanTiltControl.hh>
29 #include "PanTiltAutoControl.hh"
30 #include "PanTiltSoftMotion.hh"
35 bool PanTiltAutoControl::waiting_;
36 bool PanTiltAutoControl::exiting_;
37 bool PanTiltAutoControl::started_;
38 bool PanTiltAutoControl::bSpeedMode_;
39 long int PanTiltAutoControl::des_pan;
40 long int PanTiltAutoControl::des_tilt;
41 pthread_mutex_t PanTiltAutoControl::condition_mutex = PTHREAD_MUTEX_INITIALIZER;
42 pthread_cond_t PanTiltAutoControl::condition_cond = PTHREAD_COND_INITIALIZER;
45 PanTiltAutoControl::PanTiltAutoControl(std::string device,
bool heavyDutyMode):
58 pthread_cond_wait( &condition_cond, &condition_mutex );
78 pthread_create(&control_thread, NULL, this->threadFunc_pan_tilt, &
ptControl);
82 pthread_mutex_lock( &condition_mutex );
85 pthread_mutex_unlock( &condition_mutex );
89 pthread_mutex_lock( &condition_mutex );
91 pthread_cond_signal( &condition_cond );
92 pthread_mutex_unlock( &condition_mutex );
104 if (started_ )
return;
108 pthread_create(&control_thread, NULL, this->threadFunc_move_to, &
ptControl);
112 pthread_mutex_lock( &condition_mutex );
116 pthread_cond_wait( &condition_cond, &condition_mutex );
118 pthread_mutex_unlock( &condition_mutex );
121 void* PanTiltAutoControl::threadFunc_pan_tilt(
void *ptr)
125 float speed_damp = 32.0f;
130 int start_pan=0, start_tilt=0, end_pan=0, end_tilt=0, tilt_in_start=0, tilt_in_end=0;
134 pthread_mutex_lock( &condition_mutex );
135 while (waiting_ && !exiting_)
136 pthread_cond_wait( &condition_cond, &condition_mutex );
137 pthread_mutex_unlock( &condition_mutex );
144 pthread_cond_signal( &condition_cond );
149 tilt_in_start = -600; tilt_in_end = -1000;
152 tilt_in_start = 600; tilt_in_end = 1000;
154 start_pan = -1*pmod*1000; end_pan = pmod*1000;
157 start_pan = 0; end_pan = -1000;
158 start_tilt = 0; end_tilt = -400;
159 tilt_in_start = 0; tilt_in_end = -1000;
162 start_tilt = -400; end_tilt = -200;
165 start_tilt = -200; end_tilt = 0;
168 start_tilt = 0; end_tilt = 200;
171 start_tilt = 200; end_tilt = 400;
174 start_tilt = 400; end_tilt = 600;
177 start_tilt = 600; end_tilt = 800;
191 pthread_mutex_lock( &condition_mutex );
195 pthread_mutex_unlock( &condition_mutex );
196 if ( (pmod < 0 &&
cur_pan <= end_pan) ||( pmod > 0 &&
cur_pan >= end_pan)) {
204 void* PanTiltAutoControl::threadFunc_pan_only(
void *ptr) {
212 pthread_mutex_lock( &condition_mutex );
213 while (waiting_ && !exiting_)
214 pthread_cond_wait( &condition_cond, &condition_mutex );
215 pthread_mutex_unlock( &condition_mutex );
228 float speedmod = (1+cos((
float)
cur_pan*M_PI / 2000.0f)) / 2.0f;
229 pspeed = abs(DPPTU_MAXSPEED*speedmod) / 4;
230 pspeed = max(100,pspeed);
231 pspeed = min(DPPTU_MAXSPEED/2,pspeed);
234 pthread_mutex_lock( &condition_mutex );
237 pthread_mutex_unlock( &condition_mutex );
244 void* PanTiltAutoControl::threadFunc_move_to(
void *ptr) {
249 long int start_pan, start_tilt;
250 int pspeed = 0, tspeed = 0;
260 pthread_cond_signal( &condition_cond );
265 pthread_mutex_lock( &condition_mutex );
268 pthread_mutex_unlock( &condition_mutex );
269 if (pspeed == 0 && tspeed == 0)
276 int PanTiltAutoControl::abs(
int val) {
277 return (val < 0) ? -val : val;
280 int PanTiltAutoControl::min(
int val1,
int val2) {
281 return (val1 < val2) ? val1 : val2;
284 int PanTiltAutoControl::max(
int val1,
int val2) {
285 return (val1 < val2) ? val2 : val1;
void ResumeControl()
resume moving around
char SetSpeed(int nPanSpeed, int nTiltSpeed)
Set speed for movement.
void StopMoveTo()
stop move to desired position
abstract control class for control of Directed Perception Pan Tilt Unit.
Basic controller interface for Directed Perception Pan Tilt Unit.
~PanTiltAutoControl()
destructor moves to (0,0), then calls super-destructor to release ttyS0
BIAS::DPPanTiltControl ptControl
void StartControl()
start moving around
void GetCurrentPosition(long &lPanPos, long &lTiltPos)
int getTiltSpeed(int start_pan, int end_pan, int start_tilt, int end_tilt, int cur_pan, int cur_tilt, int damp)
void StartMoveTo(const long int pan, const long int tilt)
move to desired position
int SetMode(int nMode)
Set the mode in which the camera is to operate.
void StopControl()
stop/pause moving around
void ClosePanTiltUnit()
closes the comport stream connected to PTU
int getPanSpeed(int start_pan, int end_pan, int cur_pan, int damp)