Revision ea068cf1 src/server/neck_motion_generator.cpp
src/server/neck_motion_generator.cpp | ||
---|---|---|
48 | 48 |
//! constructor |
49 | 49 |
NeckMotionGenerator::NeckMotionGenerator(JointInterface *j) : |
50 | 50 |
GazeMotionGenerator(j, 3, 1.0/Server::MOTION_UPDATERATE) { |
51 |
breath_time = 0.0; |
|
51 |
breath_time_ = 0.0;
|
|
52 | 52 |
} |
53 | 53 |
|
54 | 54 |
|
... | ... | |
63 | 63 |
// -> triangular wave as speeds -> (x<0.5)? 2*x*x: 1- 2*(1-x)**2 = 4x - 2x**2 - 1 |
64 | 64 |
float breath_offset = 0.0; |
65 | 65 |
// 0...1 -> move up, 1..2 -> return, 2..3 -> still |
66 |
float breath_time_normalized = (breath_time * 3)/CONST_BREATH_PERIOD; |
|
66 |
float breath_time_normalized = (breath_time_ * 3)/CONST_BREATH_PERIOD;
|
|
67 | 67 |
|
68 | 68 |
if (breath_time_normalized <= 0.5) { |
69 | 69 |
// accelerated motion |
... | ... | |
82 | 82 |
} |
83 | 83 |
|
84 | 84 |
// fetch next time |
85 |
breath_time += 1000.0/Server::MOTION_UPDATERATE; |
|
86 |
if (breath_time >= CONST_BREATH_PERIOD) { |
|
87 |
breath_time -= CONST_BREATH_PERIOD; |
|
85 |
breath_time_ += 1000.0/Server::MOTION_UPDATERATE;
|
|
86 |
if (breath_time_ >= CONST_BREATH_PERIOD) {
|
|
87 |
breath_time_ -= CONST_BREATH_PERIOD;
|
|
88 | 88 |
} |
89 | 89 |
|
90 | 90 |
return breath_offset; |
... | ... | |
110 | 110 |
&neck_roll_speed); |
111 | 111 |
|
112 | 112 |
// reached target? |
113 |
float goal_diff = fabs(get_current_gaze().distance_pt_abs(requested_gaze_state)); |
|
114 |
float target_diff = fabs(requested_gaze_state.distance_pt_abs(previous_neck_target));
|
|
113 |
float goal_diff = fabs(get_current_gaze().distance_pt_abs(requested_gaze_state_));
|
|
114 |
float target_diff = fabs(requested_gaze_state_.distance_pt_abs(previous_neck_target_));
|
|
115 | 115 |
|
116 | 116 |
// printf("GOAL DIFF = %f TARGET DIFF = %f\n",goal_diff,target_diff); |
117 | 117 |
// get_current_gaze().dump(); |
... | ... | |
119 | 119 |
|
120 | 120 |
// check if new target |
121 | 121 |
// close to goal? |
122 |
if ( (neck_saccade_active) && (goal_diff < 1.0) ) { |
|
123 |
neck_saccade_reached_goal = true; |
|
122 |
if ( (neck_saccade_active_) && (goal_diff < 1.0) ) {
|
|
123 |
neck_saccade_reached_goal_ = true;
|
|
124 | 124 |
} |
125 | 125 |
|
126 |
if (neck_saccade_active) { |
|
127 |
previous_neck_target = requested_gaze_state;
|
|
126 |
if (neck_saccade_active_) {
|
|
127 |
previous_neck_target_ = requested_gaze_state_;
|
|
128 | 128 |
} |
129 | 129 |
|
130 | 130 |
// if we get a new target now, we can stop the neck saccade |
131 | 131 |
if (target_diff > .1) { |
132 |
if (neck_saccade_reached_goal) { |
|
132 |
if (neck_saccade_reached_goal_) {
|
|
133 | 133 |
// joint_interface->neck_saccade_done(); |
134 |
neck_saccade_active = false; |
|
135 |
neck_saccade_reached_goal = false; |
|
134 |
neck_saccade_active_ = false;
|
|
135 |
neck_saccade_reached_goal_ = false;
|
|
136 | 136 |
} |
137 | 137 |
} |
138 | 138 |
|
139 | 139 |
if (neck_saccade_requested) { |
140 |
neck_saccade_active = true; |
|
140 |
neck_saccade_active_ = true;
|
|
141 | 141 |
} |
142 | 142 |
|
143 | 143 |
// check if this is a small or big saccade |
144 |
if (neck_saccade_active || neck_saccade_omr) { |
|
144 |
if (neck_saccade_active_ || neck_saccade_omr) {
|
|
145 | 145 |
// full saccade with neck motion -> update neck target |
146 |
requested_neck_state = requested_gaze_state;
|
|
146 |
requested_neck_state_ = requested_gaze_state_;
|
|
147 | 147 |
} |
148 | 148 |
|
149 | 149 |
// get targets: this is the sum of stored neck target and up-to-date offset: |
150 |
float neck_pan_target = requested_neck_state.pan + requested_gaze_state.pan_offset;
|
|
151 |
float neck_tilt_target = requested_neck_state.tilt + requested_gaze_state.tilt_offset;
|
|
150 |
float neck_pan_target = requested_neck_state_.pan + requested_gaze_state_.pan_offset;
|
|
151 |
float neck_tilt_target = requested_neck_state_.tilt + requested_gaze_state_.tilt_offset;
|
|
152 | 152 |
// roll is always equal to requested gaze (not neck) state |
153 |
float neck_roll_target = requested_gaze_state.roll + requested_gaze_state.roll_offset;
|
|
153 |
float neck_roll_target = requested_gaze_state_.roll + requested_gaze_state_.roll_offset;
|
|
154 | 154 |
|
155 | 155 |
// add breath wave to tilt |
156 | 156 |
neck_tilt_target += get_breath_offset(); |
... | ... | |
164 | 164 |
reflexxes_calculate_profile(); |
165 | 165 |
|
166 | 166 |
// tell the joint if about the new values |
167 |
joint_interface->set_target(JointInterface::ID_NECK_PAN, |
|
167 |
joint_interface_->set_target(JointInterface::ID_NECK_PAN,
|
|
168 | 168 |
reflexxes_position_output->NewPositionVector->VecData[0], |
169 | 169 |
reflexxes_position_output->NewVelocityVector->VecData[0]); |
170 | 170 |
|
171 |
joint_interface->set_target(JointInterface::ID_NECK_TILT, |
|
171 |
joint_interface_->set_target(JointInterface::ID_NECK_TILT,
|
|
172 | 172 |
reflexxes_position_output->NewPositionVector->VecData[1], |
173 | 173 |
reflexxes_position_output->NewVelocityVector->VecData[1]); |
174 | 174 |
|
175 |
joint_interface->set_target(JointInterface::ID_NECK_ROLL, |
|
175 |
joint_interface_->set_target(JointInterface::ID_NECK_ROLL,
|
|
176 | 176 |
reflexxes_position_output->NewPositionVector->VecData[2], |
177 | 177 |
reflexxes_position_output->NewVelocityVector->VecData[2]); |
178 | 178 |
|
... | ... | |
188 | 188 |
void NeckMotionGenerator::publish_targets() { |
189 | 189 |
// publish values if there is an active gaze input within the last timerange |
190 | 190 |
if (gaze_target_input_active()) { |
191 |
joint_interface->publish_target(JointInterface::ID_NECK_PAN); |
|
192 |
joint_interface->publish_target(JointInterface::ID_NECK_TILT); |
|
193 |
joint_interface->publish_target(JointInterface::ID_NECK_ROLL); |
|
191 |
joint_interface_->publish_target(JointInterface::ID_NECK_PAN);
|
|
192 |
joint_interface_->publish_target(JointInterface::ID_NECK_TILT);
|
|
193 |
joint_interface_->publish_target(JointInterface::ID_NECK_ROLL);
|
|
194 | 194 |
} |
195 | 195 |
} |
196 | 196 |
|
Also available in: Unified diff