Revision 0c8d22a5 src/server/motion_generator.cpp
src/server/motion_generator.cpp | ||
---|---|---|
25 | 25 |
* Excellence Initiative. |
26 | 26 |
*/ |
27 | 27 |
|
28 |
#include "server/motion_generator.h"
|
|
29 |
#include "boost/date_time/posix_time/posix_time.hpp"
|
|
28 |
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
29 |
#include "humotion/server/motion_generator.h"
|
|
30 | 30 |
|
31 |
using namespace std; |
|
32 |
using namespace humotion; |
|
33 |
using namespace humotion::server; |
|
34 |
using namespace boost; |
|
31 |
using humotion::server::MotionGenerator; |
|
35 | 32 |
|
36 | 33 |
//! constructor |
37 |
MotionGenerator::MotionGenerator(JointInterface *j){ |
|
34 |
MotionGenerator::MotionGenerator(JointInterface *j) {
|
|
38 | 35 |
joint_interface = j; |
39 |
last_mouth_target_update = posix_time::ptime(posix_time::min_date_time);
|
|
40 |
last_gaze_target_update = posix_time::ptime(posix_time::min_date_time);
|
|
36 |
last_mouth_target_update = boost::posix_time::ptime(boost::posix_time::min_date_time);
|
|
37 |
last_gaze_target_update = boost::posix_time::ptime(boost::posix_time::min_date_time);
|
|
41 | 38 |
} |
42 | 39 |
|
43 | 40 |
|
44 | 41 |
//! destructor |
45 |
MotionGenerator::~MotionGenerator(){ |
|
42 |
MotionGenerator::~MotionGenerator() {
|
|
46 | 43 |
} |
47 | 44 |
|
48 | 45 |
//! fetch the latest position and velocity and return the timestamp of that dataset |
... | ... | |
61 | 58 |
//! fetch the latest (=current) speed of a joint |
62 | 59 |
//! \param joint_id |
63 | 60 |
//! \return float value of joint speed |
64 |
float MotionGenerator::get_current_speed(int joint_id){ |
|
61 |
float MotionGenerator::get_current_speed(int joint_id) {
|
|
65 | 62 |
return joint_interface->get_ts_speed(joint_id).get_newest_value(); |
66 | 63 |
} |
67 | 64 |
|
68 | 65 |
//! fetch the latest (=current) position of a joint |
69 | 66 |
//! \param joint_id |
70 | 67 |
//! \return float value of joint position |
71 |
float MotionGenerator::get_current_position(int joint_id){ |
|
68 |
float MotionGenerator::get_current_position(int joint_id) {
|
|
72 | 69 |
/*Timestamp tsl = joint_interface->get_ts_position(joint_id).get_last_timestamp(); |
73 | 70 |
Timestamp now = Timestamp::now(); |
74 | 71 |
Timestamp diff=now-tsl; |
... | ... | |
79 | 76 |
|
80 | 77 |
//! update gaze target: |
81 | 78 |
//! \param GazeState with target values for the overall gaze |
82 |
void MotionGenerator::set_gaze_target(GazeState new_gaze_target){ |
|
83 |
//store value for next iteration |
|
79 |
void MotionGenerator::set_gaze_target(GazeState new_gaze_target) {
|
|
80 |
// store value for next iteration
|
|
84 | 81 |
requested_gaze_state = new_gaze_target; |
85 | 82 |
|
86 |
//keep track if the gaze targets are comming in regulary |
|
87 |
last_gaze_target_update = get_system_time(); |
|
83 |
// keep track if the gaze targets are comming in regulary
|
|
84 |
last_gaze_target_update = boost::get_system_time();
|
|
88 | 85 |
} |
89 | 86 |
|
90 | 87 |
//! update mouth state: |
91 | 88 |
//! \param MouthState with target values for the mouth joints |
92 |
void MotionGenerator::set_mouth_target(MouthState s){ |
|
93 |
//store value |
|
89 |
void MotionGenerator::set_mouth_target(MouthState s) {
|
|
90 |
// store value
|
|
94 | 91 |
requested_mouth_target = s; |
95 | 92 |
|
96 |
//keep track if the mouth targets are comming in regulary |
|
97 |
last_mouth_target_update = get_system_time(); |
|
93 |
// keep track if the mouth targets are comming in regulary
|
|
94 |
last_mouth_target_update = boost::get_system_time();
|
|
98 | 95 |
} |
99 | 96 |
|
100 | 97 |
|
101 | 98 |
//! was there incoming gaze data the last second? |
102 | 99 |
//! \return true if there was data incoming in the last second, false otherwise |
103 |
bool MotionGenerator::gaze_target_input_active(){ |
|
104 |
if (last_gaze_target_update + posix_time::milliseconds(1000) > get_system_time() ){ |
|
105 |
//incoming data -> if gaze is disabled, enable it! |
|
100 |
bool MotionGenerator::gaze_target_input_active() { |
|
101 |
if (last_gaze_target_update + boost::posix_time::milliseconds(1000) |
|
102 |
> boost::get_system_time() ) { |
|
103 |
// incoming data -> if gaze is disabled, enable it! |
|
106 | 104 |
joint_interface->enable_gaze_joints(); |
107 | 105 |
return true; |
108 |
}else{ |
|
109 |
//no incoming data, disable! |
|
110 |
joint_interface->disable_gaze_joints(); |
|
111 |
return false; |
|
112 | 106 |
} |
107 |
|
|
108 |
// else: no incoming data, disable! |
|
109 |
joint_interface->disable_gaze_joints(); |
|
110 |
return false; |
|
113 | 111 |
} |
114 | 112 |
|
115 | 113 |
//! was there incoming mouth data the last second? |
116 | 114 |
//! \return true if there was data incoming in the last second, false otherwise |
117 |
bool MotionGenerator::mouth_target_input_active(){ |
|
118 |
if (last_mouth_target_update + posix_time::milliseconds(1000) > get_system_time() ){ |
|
119 |
//incoming data -> if mouth is disabled, enable it! |
|
115 |
bool MotionGenerator::mouth_target_input_active() { |
|
116 |
if (last_mouth_target_update + boost::posix_time::milliseconds(1000) |
|
117 |
> boost::get_system_time() ) { |
|
118 |
// incoming data -> if mouth is disabled, enable it! |
|
120 | 119 |
joint_interface->enable_mouth_joints(); |
121 | 120 |
return true; |
122 |
}else{ |
|
123 |
//no incoming data, disable! |
|
124 |
joint_interface->disable_mouth_joints(); |
|
125 |
return false; |
|
126 | 121 |
} |
122 |
|
|
123 |
// else: no incoming data, disable! |
|
124 |
joint_interface->disable_mouth_joints(); |
|
125 |
return false; |
|
127 | 126 |
} |
128 | 127 |
|
129 | 128 |
//! limit target to min/max bounds: |
130 |
float MotionGenerator::limit_target(int joint_id, float val){ |
|
129 |
float MotionGenerator::limit_target(int joint_id, float val) {
|
|
131 | 130 |
assert(joint_id < JointInterface::JOINT_ID_ENUM_SIZE); |
132 | 131 |
|
133 |
//fetch min/max for joint: |
|
132 |
// fetch min/max for joint:
|
|
134 | 133 |
float min = joint_interface->get_joint_min(joint_id); |
135 | 134 |
float max = joint_interface->get_joint_max(joint_id); |
136 | 135 |
|
137 |
if (max < min){ |
|
138 |
printf("> ERROR: how can min (%4.2f) be bigger than max (%4.2f)?? FIX THIS! EXITING NOW\n",min,max); |
|
136 |
if (max < min) { |
|
137 |
printf("> ERROR: how can min (%4.2f) be bigger than max (%4.2f)?? EXITING NOW\n", min, max); |
|
138 |
printf("> HINT : did you initialize the joints' min/max positions properly?\n"); |
|
139 | 139 |
exit(0); |
140 | 140 |
} |
141 | 141 |
|
Also available in: Unified diff