25 #include <Base/Common/BIASpragma.hh>
26 #include <PanTilt/DPPanTiltControl.hh>
28 #include "PanTiltSoftMotion.hh"
33 PanTiltSoftMotion::PanTiltSoftMotion() {
40 max_pan_speed = DPPTU_MAXSPEED / 8;
42 max_tilt_speed = DPPTU_MAXSPEED / 16;
44 PanTiltSoftMotion::~PanTiltSoftMotion() {}
46 void PanTiltSoftMotion::setLimits(
int _min_pan,
int _max_pan,
int _min_pan_speed,
int _max_pan_speed,
int _min_tilt_speed,
int _max_tilt_speed) {
49 min_pan_speed = _min_pan_speed;
50 max_pan_speed = _max_pan_speed;
51 min_tilt_speed = _min_tilt_speed;
52 max_tilt_speed = _max_tilt_speed;
55 void PanTiltSoftMotion::assert_pan(
int &pan) {
56 pan = max(min_pan, pan);
57 pan = min(max_pan, pan);
60 void PanTiltSoftMotion::assert_tilt(
int &tilt) {
61 tilt = max(min_tilt, tilt);
62 tilt = min(max_tilt, tilt);
65 int PanTiltSoftMotion::calcSpeed(
int start_val,
int end_val,
int cur_val,
int damp) {
66 float diff_val = (float)(end_val - start_val);
68 float val = (DPPTU_MAXSPEED / damp) * cos ( ((2*((
float)cur_val-(
float)start_val)) / diff_val) -1 );
72 int PanTiltSoftMotion::getPanSpeed(
int start_pan,
int end_pan,
int cur_pan,
int damp) {
76 if (end_pan < start_pan) {
78 if (cur_pan < end_pan)
81 if (cur_pan > end_pan)
84 int val = calcSpeed(start_pan, end_pan, cur_pan, damp);
85 val = max(min_pan_speed,val);
86 val = min(max_pan_speed,val);
91 int PanTiltSoftMotion::getTiltSpeed(
int start_pan,
int end_pan,
int start_tilt,
int end_tilt,
int cur_pan,
int cur_tilt,
int damp) {
96 if (end_tilt < start_tilt) {
98 if (cur_tilt < end_tilt)
101 if (cur_tilt > end_tilt)
105 if (start_pan == 0 && end_pan == 0) {
106 val = calcSpeed(start_tilt, end_tilt, cur_tilt, damp);
107 val = max(min_tilt_speed,val);
108 val = min(max_tilt_speed,val);
113 if (abs(cur_pan) > abs(start_pan) && abs(cur_pan) < abs(end_pan)) {
114 if ((start_tilt < end_tilt && cur_tilt >= end_tilt) || (start_tilt > end_tilt && cur_tilt <= end_tilt)) {
118 val = calcSpeed(start_tilt, end_tilt, cur_tilt, damp);
122 val = calcSpeed(start_tilt, end_tilt, cur_tilt, damp);
126 val = max(min_tilt_speed,val);
127 val = min(max_tilt_speed,val);