31 std::scoped_lock lock(dataMutex);
42 else if (!velocityBased && !reportedJointAnglesBool)
69 NameControlModeMap jointModes;
73 reportedJointVelocitiesBool =
false;
75 removeSelfInducedOpticalFlow();
81 headJoints[eye_pitch_left] = 0.0;
82 headJoints[eye_yaw_right] = -0.8 * (flowX);
84 headJoints[eye_yaw_left] = headJoints[eye_yaw_right];
91 reportedJointAnglesBool =
false;
93 headJoints[eye_pitch_left] = (reportedJointAngles[eye_pitch_left] + flowY);
94 jointModes[eye_pitch_left] = ePositionControl;
98 headJoints[eye_pitch_right] = (reportedJointAngles[eye_pitch_left] + flowY);
99 jointModes[eye_pitch_right] = ePositionControl;
102 headJoints[eye_yaw_left] = (reportedJointAngles[eye_yaw_left] - flowX);
103 jointModes[eye_yaw_left] = ePositionControl;
105 headJoints[eye_yaw_right] = (reportedJointAngles[eye_yaw_left] - flowX);
106 jointModes[eye_yaw_right] = ePositionControl;
111 std::scoped_lock lock2(
mutex);
117 OKR::removeSelfInducedOpticalFlow()
121 if (jointVelocities.size() == 0)
128 for (
auto& kv : jointVelocities)
135 velocities = kv.second;
141 velocities = kv.second;
146 if (velocities.find(eye_yaw_right) == velocities.end())
152 flowY = flowY + velocities[eye_pitch_left];
153 flowX = flowX - velocities[eye_yaw_right];
158 std::string eye_pitch_right,
159 std::string eye_yaw_left,
160 std::string eye_yaw_right,
161 std::string neck_roll)
163 std::scoped_lock lock(
mutex);
164 this->eye_pitch_left = eye_pitch_left;
165 this->eye_pitch_right = eye_pitch_right;
166 this->eye_yaw_left = eye_yaw_left;
167 this->eye_yaw_right = eye_yaw_right;
168 this->neck_roll = neck_roll;
174 std::scoped_lock lock(
mutex);
184 std::scoped_lock lock(
mutex);
186 this->armar4 = armar4;
187 this->velocityBased = velocityBased;
191 OKR::pid(std::vector<float> error,
192 std::vector<float> kp,
193 std::vector<float> ki,
194 std::vector<float> kd)
196 if (error.size() != kp.size() || kp.size() != ki.size() || ki.size() != kd.size())
199 return {0.0, 0.0, 0.0};
202 std::vector<float> y;
204 for (
size_t i = 0; i < error.size(); i++)
206 err_sum[i] += error[i];
208 y.push_back(kp[i] * error[i] + (ki[i] * err_sum[i]) + (kd[i] * (error[i] - err_old[i])));
210 err_old[i] = error[i];
219 std::scoped_lock lock(dataMutex);
221 reportedJointAnglesBool =
true;
222 this->reportedJointAngles =
values;
229 const Ice::Current&
c)
231 std::scoped_lock lock(dataMutex);
233 reportedJointVelocitiesBool =
true;
234 this->reportedJointVelocities =
values;
243 std::scoped_lock lock(dataMutex);
248 this->flowT = deltaT;
259 std::scoped_lock lock(dataMutex);
261 this->errorX = angleX;
262 this->errorY = angleY;
268 std::scoped_lock lock(dataMutex);
271 reportedJointVelocitiesBool =
false;
272 reportedJointAnglesBool =
false;