Help with Gyro Accelerometers!

Hi everyone!
I’ve been able to retrieve a library for reading PSMove and succesfully integrated it in Unity

I can read accelerometers and Gyroscope data, and i would like to integrate both and implement a tracking system… Something like that

It would be FU***NG AWESOME!

I read a LOT of questions about pitch, roll and yaw, i broke my head against Quaternions and Euler rotations for something like a month now, but i still don’t have a satisfying result… I could really use some help…

Here’s my whole code… I was planning to use Kalmann filtering, but i still don’t have a good estimation for the accelerometer output… Any help? Suggestions?

With this code I have a fine tracking on the “front” semisphere, but it still lacks of the third axis (z), and I can’t rotate it backwards… I could rotate the accelerometer reading to match the gyroscope orientation or use the integrated magnetometer (yeah there’s a magnetometer too) but it’s far too slow… I’m starting to think i should track the whole joystick with a camera!

P.S.
I was planning on creating a library for movements tracking and publish it as good as done, but… I’m sorry i’m too ignorant for this :frowning:
My code is

Here’s my code btw

void Update(){
		int res = psmove_poll(PSMove);
		if (res>0) {
        	int[] x,y,z;
        	x = new int[1];
        	y = new int[1];
        	z = new int[1];
        	
        	//Calculating estimated position based on previous + gyroscope readings
		
		//These are c functions, needing (int*) as a parameter, since this is C# I came up with this array trick ;)
			
		psmove_get_gyroscope(PSMove,x,y,z);
		Vector3 RGyro = new Vector3(x[0],y[0],z[0]);
			
		//720.0f is just a "sensitivity" number (should be calibrated more accurately, but this looks fine >.< )
		RGyro = (RGyro-GyroFixedError)/720.0f;
		//GyroFixedError is a first reading done in the "start" method
		
		Quaternion GyroReadRotation = Quaternion.Euler(-RGyro.x,-RGyro.y,RGyro.z);
		
		//EstPos is an instance variable
		GyroSword.transform.rotation = EstPos*GyroReadRotation;
			
			
		//Reading Accelerometers and estimating actual position
		psmove_get_accelerometer(PSMove,x,y,z);

		Vector3 RAcc = new Vector3(x[0],y[0],z[0]);
		RAcc = RAcc/RAcc.magnitude;
		//These should be something like pitch and roll
		float pitch = Mathf.Acos(RAcc.y);
		float roll = Mathf.Atan2(RAcc.x,RAcc.z);
		
		float angle = 0;
		Vector3 axis = Vector3.zero;
		EstPos.ToAngleAxis(out angle, out axis);
		
		GameObject helper = new GameObject();
		//Nothing much, applying pitch and roll i found..
		helper.transform.rotation = Quaternion.identity;
		helper.transform.RotateAround(Vector3.right,pitch);
		helper.transform.RotateAround(helper.transform.TransformDirection(Vector3.up),roll);
		
		Quaternion AccRead = helper.transform.rotation;
			
		float w = Quaternion.Angle(AccRead,EstPos);
		
		EstPos = Quaternion.Slerp(EstPos,AccRead,w/90.0f);
			
		AccSword.transform.rotation = AccRead;
		GameObject.Destroy(helper);
        }

Up!

Can’t help you with your problem. But dear I ask what library you used to make the ps move speak?

Just wondering if you had any progress on getting this to work. I’d also be interested in any potential solution.