void onGyroscopeData (myo::Myo * myo, uint64_t timestamp, const myo::Vector3< float > & gyro) { gyroX = gyro.x(); gyroY = gyro.y(); gyroZ = gyro.z(); }
void onAccelerometerData (myo::Myo* myo, uint64_t timestamp, const myo::Vector3< float > & accel) { accelX = accel.x(); accelY = accel.y(); accelZ = accel.z(); count+=1; }
jobject getJavaVector3(JNIEnv * env, myo::Vector3<float> vector3) { jclass vector3Class = env->FindClass("net/johnluetke/myojni/jni/Vector3"); jmethodID vector3Constructor = env->GetMethodID(vector3Class, "<init>", "(DDD)V"); jobject javaVector3 = env->NewObject(vector3Class, vector3Constructor, vector3.x(), vector3.y(), vector3.z()); return javaVector3; }
// units of deg/s void onGyroscopeData(myo::Myo* myo, uint64_t timestamp, const myo::Vector3<float>& gyro) { g_x = gyro.x(); g_y = gyro.y(); g_z = gyro.z(); osc::OutboundPacketStream p(buffer, OUTPUT_BUFFER_SIZE); p << osc::BeginMessage("/myo/gyro") << MAC << g_x << g_y << g_z << osc::EndMessage; transmitSocket->Send(p.Data(), p.Size()); }
// units of g void onAccelerometerData(myo::Myo* myo, uint64_t timestamp, const myo::Vector3<float>& accel) { a_x = accel.x(); a_y = accel.y(); a_z = accel.z(); osc::OutboundPacketStream p(buffer, OUTPUT_BUFFER_SIZE); p << osc::BeginMessage("/myo/accel") << MAC << a_x << a_y << a_z << osc::EndMessage; transmitSocket->Send(p.Data(), p.Size()); }
// onOrientationData() is called whenever the Myo device provides its current orientation, which is represented // as a unit quaternion. void onOrientationData(myo::Myo* myo, uint64_t timestamp, const myo::Quaternion<float>& quat) { // wait flag tells us we must wait for user if (wait) { if (timestamp > t) { wait = false; } } else if (setup_stage == 4){ // initialization complete myo::Vector3<float> vec(1, 0, 0); vec = myo::rotate(quat, vec); float x = v.dot(v.proj(vec, vec_left), vec_left); float y = v.dot(v.proj(vec, vec_up), vec_up); maybeDragMouse(x, y); } else if (setup_stage == 3){ // create coordinate system printf("vec_center = (%f,%f,%f)\n", vec_center.x(), vec_center.y(), vec_center.z()); printf("rough vec_up = (%f,%f,%f)\n", vec_up.x(), vec_up.y(), vec_up.z()); // make vec_up orthogonal to vec_center //vec_up = vecNormalize(closestOrthogonalVector(vec_up, vec_center)); //printf("clean vec_up = (%f,%f,%f)\n", vec_up.x(), vec_up.y(), vec_up.z()); // left side of person wearing the Myo vec_left = v.cross(vec_center, vec_up); printf("vec_left = (%f,%f,%f)\n", vec_left.x(), vec_left.y(), vec_left.z()); printf("vec_up . vec_center = %f\n", v.dot(vec_up, vec_center)); printf("vec_up . vec_left = %f\n", v.dot(vec_up, vec_left)); printf("vec_left . vec_center = %f\n", v.dot(vec_left, vec_center)); setup_stage++; } else if (setup_stage == 2) { // measure vec_up myo::Vector3<float> vec(1, 0, 0); vec_center = myo::rotate(quat, vec); printf("Measured.\n"); setup_stage++; } else if (setup_stage == 1) { // measure vec_center myo::Vector3<float> vec(1, 0, 0); vec_up = myo::rotate(quat, vec); printf("Measured.\n"); printf("Point at center of screen. Measuring in 3 seconds.\n"); wait = true; t = timestamp + 3000000; setup_stage++; } else if (setup_stage == 0) { // waiting for user to be ready printf("Point straight up. Measuring in 3 seconds.\n"); wait = true; t = timestamp + 3000000; setup_stage++; } }
void Filter::onAccelerometerData(myo::Myo *myo, uint64_t timestamp, const myo::Vector3< float > &accel){ accelX_old = accelX; accelY_old = accelY; accelZ_old = accelZ; using std::atan2; using std::asin; using std::sqrt; using std::cos; using std::sin; using std::max; using std::min; //shift the coordinate system in order to cancel out gravity in the right axis //roll = roll - roll_i; //pitch = pitch - pitch_i; //yaw = yaw - yaw_i; //accelX = -1 * accel.y(); //accelY = -1 * accel.z(); //accelZ = accel.x(); // pitch = alpha // yaw = beta // roll = gamma //accelX *= cos(yaw) * cos(roll) + cos(yaw) * sin(roll) - sin(yaw); //accelY *= cos(roll) * sin(pitch) * sin(yaw) - cos(pitch) * sin(roll) + cos(pitch) * cos(roll) + sin(pitch) * sin(yaw) * sin(roll) + cos(yaw) * sin(pitch); //accelZ *= cos(pitch) * cos(roll) * sin(yaw) + sin(pitch) * sin(roll) - cos(roll) * sin(pitch) + cos(pitch) * sin(yaw) * sin(roll) + cos(pitch) * cos(yaw); if (fabs(accel.x() - accelX_old) > 0.01) accelX = accel.x(); if (fabs(accel.y() - accelY_old) > 0.01) accelY = accel.y(); if (fabs(accel.z() - accelZ_old) > 0.01) accelZ = accel.z() - 1; }
void DataCollector::onAccelerometerData(myo::Myo* myo, uint64_t timestamp, const myo::Vector3<float>& accel) { xAccel = accel.x(); yAccel = accel.y(); zAccel = accel.z(); }
double DataCollector::angle_between(myo::Vector3<float> v1, myo::Vector3<float> v2){ return v1.angleTo(v2)*180.0/3.14159265; //Return angle between v1 and v2 in degrees }
void onAccelerometerData(myo::Myo* myo, uint64_t timestamp, const myo::Vector3<float> &accel) { accx = accel.x() * 40; accy = accel.y() * 40; accz = accel.z() * 40; }
void onAccelerometerData(myo::Myo*, uint64_t timestamp, const myo::Vector3<float> & accel) { accelVal = (int)accel.magnitude(); }
void onGyroscopeData(myo::Myo* myo, uint64_t timestamp, const myo::Vector3<float>& vec) { const int count = 3; float values[count] = { values[0] = vec.x(), values[1] = vec.y(), values[2] = vec.z() }; this->addEventData(myo, timestamp, "gyroscope", new VectorEventData(values, count)); }
void sendData(myo::Vector3<double> curPos) { fprintf(hFile, "%d\t%d\t%d\t%f\t%f\t%f\t%c\t%s\n", yaw_w, pitch_w, roll_w, curPos.x(), curPos.y(), curPos.z(), (whichArm == myo::armLeft ? 'L' : 'R'), currentPose.toString().c_str()); fflush(hFile); }