humotion / src / server / motion_generator.cpp @ 8c6c1163
History | View | Annotate | Download (3.719 KB)
1 |
/*
|
---|---|
2 |
* This file is part of humotion
|
3 |
*
|
4 |
* Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
|
5 |
* http://opensource.cit-ec.de/projects/humotion
|
6 |
*
|
7 |
* This file may be licensed under the terms of the
|
8 |
* GNU Lesser General Public License Version 3 (the ``LGPL''),
|
9 |
* or (at your option) any later version.
|
10 |
*
|
11 |
* Software distributed under the License is distributed
|
12 |
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
|
13 |
* express or implied. See the LGPL for the specific language
|
14 |
* governing rights and limitations.
|
15 |
*
|
16 |
* You should have received a copy of the LGPL along with this
|
17 |
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
|
18 |
* or write to the Free Software Foundation, Inc.,
|
19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
20 |
*
|
21 |
* The development of this software was supported by the
|
22 |
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
|
23 |
* The Excellence Cluster EXC 277 is a grant of the Deutsche
|
24 |
* Forschungsgemeinschaft (DFG) in the context of the German
|
25 |
* Excellence Initiative.
|
26 |
*/
|
27 |
|
28 |
#include "server/motion_generator.h" |
29 |
|
30 |
using namespace std; |
31 |
using namespace humotion; |
32 |
using namespace humotion::server; |
33 |
using namespace boost; |
34 |
|
35 |
//! constructor
|
36 |
MotionGenerator::MotionGenerator(JointInterface *j){ |
37 |
joint_interface = j; |
38 |
} |
39 |
|
40 |
|
41 |
//! destructor
|
42 |
MotionGenerator::~MotionGenerator(){ |
43 |
} |
44 |
|
45 |
//! fetch thr latest (=current) position of a joint
|
46 |
//! \param joint_id
|
47 |
//! \return float value of joint position
|
48 |
float MotionGenerator::get_current_position(int joint_id){ |
49 |
return joint_interface->get_ts_position(joint_id).get_newest_value();
|
50 |
} |
51 |
|
52 |
//! update gaze target:
|
53 |
//! \param GazeState with target values for the overall gaze
|
54 |
void MotionGenerator::set_gaze_target(GazeState new_gaze_target){
|
55 |
//store value for next iteration
|
56 |
requested_gaze_state = new_gaze_target; |
57 |
|
58 |
//keep track if the gaze targets are comming in regulary
|
59 |
last_gaze_target_update = get_system_time(); |
60 |
} |
61 |
|
62 |
//! update mouth state:
|
63 |
//! \param MouthState with target values for the mouth joints
|
64 |
void MotionGenerator::set_mouth_target(MouthState s){
|
65 |
//store value
|
66 |
requested_mouth_target = s; |
67 |
|
68 |
//keep track if the mouth targets are comming in regulary
|
69 |
last_mouth_target_update = get_system_time(); |
70 |
} |
71 |
|
72 |
|
73 |
//! was there incoming gaze data the last second?
|
74 |
//! \return true if there was data incoming in the last second, false otherwise
|
75 |
bool MotionGenerator::gaze_target_input_active(){
|
76 |
if (last_gaze_target_update + posix_time::milliseconds(1000) > get_system_time() ){ |
77 |
//incoming data -> if gaze is disabled, enable it!
|
78 |
joint_interface->enable_gaze_joints(); |
79 |
return true; |
80 |
}else{
|
81 |
//no incoming data, disable!
|
82 |
joint_interface->disable_gaze_joints(); |
83 |
return false; |
84 |
} |
85 |
} |
86 |
|
87 |
//! was there incoming mouth data the last second?
|
88 |
//! \return true if there was data incoming in the last second, false otherwise
|
89 |
bool MotionGenerator::mouth_target_input_active(){
|
90 |
if (last_mouth_target_update + posix_time::milliseconds(1000) > get_system_time() ){ |
91 |
//incoming data -> if mouth is disabled, enable it!
|
92 |
joint_interface->enable_mouth_joints(); |
93 |
return true; |
94 |
}else{
|
95 |
//no incoming data, disable!
|
96 |
joint_interface->disable_mouth_joints(); |
97 |
return false; |
98 |
} |
99 |
} |
100 |
|
101 |
//! limit target to min/max bounds:
|
102 |
float MotionGenerator::limit_target(int joint_id, float val){ |
103 |
assert(joint_id < JointInterface::JOINT_ID_ENUM_SIZE); |
104 |
|
105 |
//fetch min/max for joint:
|
106 |
float min = joint_interface->get_joint_min(joint_id);
|
107 |
float max = joint_interface->get_joint_max(joint_id);
|
108 |
|
109 |
if (max < min){
|
110 |
printf("> ERROR: how can min (%4.2f) be bigger than max (%4.2f)?? FIX THIS! EXITING NOW\n",min,max);
|
111 |
exit(0);
|
112 |
} |
113 |
|
114 |
val = fmin(val, max); |
115 |
val = fmax(val, min); |
116 |
|
117 |
return val;
|
118 |
} |
119 |
|