30 std::scoped_lock lock(dataMutex);
41 else if (!velocityBased && !reportedJointAnglesBool)
68 NameControlModeMap jointModes;
72 reportedJointVelocitiesBool =
false;
74 removeSelfInducedOpticalFlow();
80 headJoints[eye_pitch_left] = 0.0;
81 headJoints[eye_yaw_right] = -0.8 * (flowX);
83 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;
112 std::scoped_lock lock2(
mutex);
117 void OKR::removeSelfInducedOpticalFlow()
121 if (jointVelocities.size() == 0)
128 for (
auto& kv : jointVelocities)
131 long timestamp = kv.first;
133 if (timestamp <= flow_time + flowT)
135 velocities = kv.second;
140 velocities = kv.second;
145 if (velocities.find(eye_yaw_right) == velocities.end())
151 flowY = flowY + velocities[eye_pitch_left] ;
152 flowX = flowX - velocities[eye_yaw_right] ;
156 void OKR::setJointNames(std::string eye_pitch_left, std::string eye_pitch_right, std::string eye_yaw_left, std::string eye_yaw_right, std::string neck_roll)
158 std::scoped_lock lock(
mutex);
159 this->eye_pitch_left = eye_pitch_left;
160 this->eye_pitch_right = eye_pitch_right;
161 this->eye_yaw_left = eye_yaw_left;
162 this->eye_yaw_right = eye_yaw_right;
163 this->neck_roll = neck_roll;
168 std::scoped_lock lock(
mutex);
177 std::scoped_lock lock(
mutex);
179 this->armar4 = armar4;
180 this->velocityBased = velocityBased;
183 std::vector<float> OKR::pid(std::vector<float> error, std::vector<float> kp, std::vector<float> ki, std::vector<float> kd)
185 if (error.size() != kp.size() || kp.size() != ki.size() || ki.size() != kd.size())
188 return {0.0, 0.0, 0.0};
191 std::vector<float> y;
193 for (
size_t i = 0; i < error.size(); i++)
195 err_sum[i] += error[i];
197 y.push_back(kp[i] * error[i] + (ki[i] * err_sum[i]) + (kd[i] * (error[i] - err_old[i])));
199 err_old[i] = error[i];
207 std::scoped_lock lock(dataMutex);
209 reportedJointAnglesBool =
true;
210 this->reportedJointAngles =
values;
216 std::scoped_lock lock(dataMutex);
218 reportedJointVelocitiesBool =
true;
219 this->reportedJointVelocities =
values;
222 jointVelocities[timestamp] = test;
229 std::scoped_lock lock(dataMutex);
234 this->flowT = deltaT;
236 flow_time = timestamp;
241 std::scoped_lock lock(dataMutex);
243 this->errorX = angleX;
244 this->errorY = angleY;
250 std::scoped_lock lock(dataMutex);
253 reportedJointVelocitiesBool =
false;
254 reportedJointAnglesBool =
false;