Fygo Posted April 15, 2014 at 06:59 PM Share Posted April 15, 2014 at 06:59 PM Hi everybody, Could somebody guide me how to save/count the orientation of the IMU Brick? Similarly to how brickv does it. I am trying to reproduce the same example with the 3D model with JS/Away3D/Actionscript. Seems to work "alright" not counting that my 3D models have different initial orientation so basically everything works the other way around (moving the brick left turns the object right, etc). I am retrieving the quaternions periodically and then pass them to flash where I convert them to a transformation 3D matrix and apply it to the models. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
borg Posted April 15, 2014 at 08:10 PM Share Posted April 15, 2014 at 08:10 PM Have you seen the IMU plugin on http://www.brickv.com/? I think it might do what you want. https://github.com/Tinkerforge/brickv.com/blob/master/js/brickv/plugins/PluginBrickIMU.js Quote Link to comment Share on other sites More sharing options...
Fygo Posted April 16, 2014 at 02:56 PM Author Share Posted April 16, 2014 at 02:56 PM Oh nice, thanks for that! However, still no go. I can save the position but the rotation is just broken. I guess the problem lies with the coordinate system. You are using a positive Z towards the user, is that correct? While Away3D has the positive Z facing away from the user. Unfortunately I have very few knowledge about these things (shame on me!), but I assume this would completely break the rotation. Is that so? Any hint/advance how to fix it? Edit: Here is how I am solving it: private function saveOrientation():void { var quatString:String = ExternalInterface.call("getQuaternionString"); //from JS in format "x,y,z,w" var quatArray:Array = quatString.split(","); _relX = -quatArray[0]; _relY = -quatArray[1]; _relZ = quatArray[2]; _relW = quatArray[3]; } And then upon update I use: var quatString:String = ExternalInterface.call("getQuaternionString"); //from JS in format "x,y,z,w" var quatArray:Array = quatString.split(","); var x:Number = -quatArray[0]; var y:Number = -quatArray[1]; var z:Number = quatArray[2]; var w:Number = -quatArray[3]; //there is a minus here, why? I have absolutely NO idea whether this is correct but it seems to work with a test cube. Is this approach at least remotely correct? All the rest of the calculation is from the example you showed me I am just not inverting the final transformation matrix (AS3: Matrix3D objects can be initialized with a Vector of 16 Numbers, where every four elements is a column.) Quote Link to comment Share on other sites More sharing options...
borg Posted April 16, 2014 at 08:39 PM Share Posted April 16, 2014 at 08:39 PM I don't know Away3D, so i can't help you, sorry. But of course they can use a different coordinate system than we. If it works with the changes you did it probably only means that the positive facing direction of some of the axis is different, which shouldn't be a problem (i.e. you probably did the right thing). Quote Link to comment Share on other sites More sharing options...
Fygo Posted April 25, 2014 at 05:40 PM Author Share Posted April 25, 2014 at 05:40 PM Well, you are right, if it works, there is nothing to solve. Thanks for your assistance. One last question - any example/hint of how to smooth the quaternion values so I could eliminate the shakiness? Thanks a lot. Quote Link to comment Share on other sites More sharing options...
borg Posted April 25, 2014 at 06:03 PM Share Posted April 25, 2014 at 06:03 PM Did you try to play around with the convergence speed? http://www.tinkerforge.com/en/doc/Software/Bricks/IMU_Brick_JavaScript.html#BrickIMU.setConvergenceSpeed Quote Link to comment Share on other sites More sharing options...
Fygo Posted April 25, 2014 at 07:00 PM Author Share Posted April 25, 2014 at 07:00 PM Jeez, that's it. Very nice, thanks a lot! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.