30 std::scoped_lock lock(dataMutex);
33 if (!(reportedSensorValues && initialOrientation && reportedJointAnglesBool))
38 if (velocityBased && !(reportedJointVelocitiesBool))
46 NameValueMap reportedJointAngles = this->reportedJointAngles;
47 NameValueMap reportedJointVelocities = this->reportedJointVelocities;
49 reportedJointAnglesBool =
false;
50 reportedJointVelocitiesBool =
false;
54 std::map<std::string, float> headJoints;
58 std::vector<float> error = std::vector<float>(3);
95 headJoints[eye_pitch_left] = -1 * rotationVelocity[1] + kp * (rpy[1] - reportedJointAngles[eye_pitch_left]) ;
96 headJoints[eye_pitch_left] = 0.;
98 headJoints[eye_yaw_left] = rotationVelocity[2] + kp * (rpy[2] - reportedJointAngles[eye_yaw_left]);
99 headJoints[eye_yaw_right] = rotationVelocity[2] + kp * (rpy[2] - reportedJointAngles[eye_yaw_right]);
106 headJoints[eye_pitch_left] = -1.0 * rpy[1];
109 headJoints[eye_pitch_right] = rpy[1];
112 headJoints[eye_yaw_left] = 1 * rpy[2];
113 headJoints[eye_yaw_right] = 1 * rpy[2];
117 std::scoped_lock lock2(
mutex);
124 std::scoped_lock lock(dataMutex);
126 std::vector<float>
q =
values.orientationQuaternion;
130 rotationVelocity.clear();
132 rotationVelocity =
values.gyroscopeRotation;
134 reportedSensorValues =
true;
136 if (!initialOrientation)
138 initialOrientation =
true;
145 void VOR::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)
147 std::scoped_lock lock(
mutex);
149 this->eye_pitch_left = eye_pitch_left;
150 this->eye_pitch_right = eye_pitch_right;
151 this->eye_yaw_left = eye_yaw_left;
152 this->eye_yaw_right = eye_yaw_right;
153 this->neck_roll = neck_roll;
158 std::scoped_lock lock(
mutex);
167 std::scoped_lock lock(
mutex);
169 this->armar4 = armar4;
170 this->velocityBased = velocityBased;
175 std::vector<float> VOR::pid(std::vector<float> error, std::vector<float> kp, std::vector<float> ki, std::vector<float> kd)
177 if (error.size() != kp.size() || kp.size() != ki.size() || ki.size() != kd.size())
180 return {0.0, 0.0, 0.0};
184 std::vector<float> y;
186 for (
size_t i = 0; i < error.size(); i++)
188 err_sum[i] += error[i];
190 y.push_back(kp[i] * error[i] + (ki[i] * err_sum[i]) + (kd[i] * (error[i] - err_old[i])));
192 err_old[i] = error[i];
199 void armarx::VOR::onStop()
201 std::scoped_lock lock(dataMutex);
203 reportedSensorValues =
false;
204 initialOrientation =
false;
206 reportedJointVelocitiesBool =
false;
207 reportedJointAnglesBool =
false;
210 std::vector<float> err_old(3, 0.0);
211 err_old.swap(this->err_old);
212 std::vector<float> err_sum(3, 0.0);
213 err_sum.swap(this->err_sum);
219 std::scoped_lock lock(dataMutex);
221 reportedJointAnglesBool =
true;
222 this->reportedJointAngles =
values;
228 std::scoped_lock lock(dataMutex);
230 reportedJointVelocitiesBool =
true;
231 this->reportedJointVelocities =
values;