Components and supplies
SparkFun IMU Breakout - MPU-9250
SparkFun Logic Level Converter - Bi-Directional
Arduino UNO
Tools and machines
Computer that can run Unity
Soldering iron (generic)
Apps and platforms
Arduino IDE
Unity
Project description
Code
SampleScene.unity
csharp
This code will probably not work as it is straight from a Unity Scene file. If you need the scene you will have to contact me and get it. I can't upload it to github as it is too big. I also don't think hackster.io supports uploading Unity files. Sorry!
1%YAML 1.1 2%TAG !u! tag:unity3d.com,2011: 3--- !u!29 &1 4OcclusionCullingSettings: 5 m_ObjectHideFlags: 0 6 serializedVersion: 2 7 m_OcclusionBakeSettings: 8 smallestOccluder: 5 9 smallestHole: 0.25 10 backfaceThreshold: 100 11 m_SceneGUID: 00000000000000000000000000000000 12 m_OcclusionCullingData: {fileID: 0} 13--- !u!104 &2 14RenderSettings: 15 m_ObjectHideFlags: 0 16 serializedVersion: 9 17 m_Fog: 0 18 m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} 19 m_FogMode: 3 20 m_FogDensity: 0.01 21 m_LinearFogStart: 0 22 m_LinearFogEnd: 300 23 m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} 24 m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} 25 m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} 26 m_AmbientIntensity: 1 27 m_AmbientMode: 0 28 m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} 29 m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} 30 m_HaloStrength: 0.5 31 m_FlareStrength: 1 32 m_FlareFadeSpeed: 3 33 m_HaloTexture: {fileID: 0} 34 m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} 35 m_DefaultReflectionMode: 0 36 m_DefaultReflectionResolution: 128 37 m_ReflectionBounces: 1 38 m_ReflectionIntensity: 1 39 m_CustomReflection: {fileID: 0} 40 m_Sun: {fileID: 0} 41 m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} 42 m_UseRadianceAmbientProbe: 0 43--- !u!157 &3 44LightmapSettings: 45 m_ObjectHideFlags: 0 46 serializedVersion: 11 47 m_GIWorkflowMode: 0 48 m_GISettings: 49 serializedVersion: 2 50 m_BounceScale: 1 51 m_IndirectOutputScale: 1 52 m_AlbedoBoost: 1 53 m_TemporalCoherenceThreshold: 1 54 m_EnvironmentLightingMode: 0 55 m_EnableBakedLightmaps: 1 56 m_EnableRealtimeLightmaps: 0 57 m_LightmapEditorSettings: 58 serializedVersion: 10 59 m_Resolution: 2 60 m_BakeResolution: 10 61 m_AtlasSize: 512 62 m_AO: 0 63 m_AOMaxDistance: 1 64 m_CompAOExponent: 1 65 m_CompAOExponentDirect: 0 66 m_Padding: 2 67 m_LightmapParameters: {fileID: 0} 68 m_LightmapsBakeMode: 1 69 m_TextureCompression: 1 70 m_FinalGather: 0 71 m_FinalGatherFiltering: 1 72 m_FinalGatherRayCount: 256 73 m_ReflectionCompression: 2 74 m_MixedBakeMode: 2 75 m_BakeBackend: 1 76 m_PVRSampling: 1 77 m_PVRDirectSampleCount: 32 78 m_PVRSampleCount: 256 79 m_PVRBounces: 2 80 m_PVRFilterTypeDirect: 0 81 m_PVRFilterTypeIndirect: 0 82 m_PVRFilterTypeAO: 0 83 m_PVRFilteringMode: 1 84 m_PVRCulling: 1 85 m_PVRFilteringGaussRadiusDirect: 1 86 m_PVRFilteringGaussRadiusIndirect: 5 87 m_PVRFilteringGaussRadiusAO: 2 88 m_PVRFilteringAtrousPositionSigmaDirect: 0.5 89 m_PVRFilteringAtrousPositionSigmaIndirect: 2 90 m_PVRFilteringAtrousPositionSigmaAO: 1 91 m_ShowResolutionOverlay: 1 92 m_LightingDataAsset: {fileID: 0} 93 m_UseShadowmask: 1 94--- !u!196 &4 95NavMeshSettings: 96 serializedVersion: 2 97 m_ObjectHideFlags: 0 98 m_BuildSettings: 99 serializedVersion: 2 100 agentTypeID: 0 101 agentRadius: 0.5 102 agentHeight: 2 103 agentSlope: 45 104 agentClimb: 0.4 105 ledgeDropHeight: 0 106 maxJumpAcrossDistance: 0 107 minRegionArea: 2 108 manualCellSize: 0 109 cellSize: 0.16666667 110 manualTileSize: 0 111 tileSize: 256 112 accuratePlacement: 0 113 debug: 114 m_Flags: 0 115 m_NavMeshData: {fileID: 0} 116--- !u!1 &170076733 117GameObject: 118 m_ObjectHideFlags: 0 119 m_CorrespondingSourceObject: {fileID: 0} 120 m_PrefabInternal: {fileID: 0} 121 serializedVersion: 6 122 m_Component: 123 - component: {fileID: 170076735} 124 - component: {fileID: 170076734} 125 m_Layer: 0 126 m_Name: Directional Light 127 m_TagString: Untagged 128 m_Icon: {fileID: 0} 129 m_NavMeshLayer: 0 130 m_StaticEditorFlags: 0 131 m_IsActive: 1 132--- !u!108 &170076734 133Light: 134 m_ObjectHideFlags: 0 135 m_CorrespondingSourceObject: {fileID: 0} 136 m_PrefabInternal: {fileID: 0} 137 m_GameObject: {fileID: 170076733} 138 m_Enabled: 1 139 serializedVersion: 8 140 m_Type: 1 141 m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} 142 m_Intensity: 1 143 m_Range: 10 144 m_SpotAngle: 30 145 m_CookieSize: 10 146 m_Shadows: 147 m_Type: 2 148 m_Resolution: -1 149 m_CustomResolution: -1 150 m_Strength: 1 151 m_Bias: 0.05 152 m_NormalBias: 0.4 153 m_NearPlane: 0.2 154 m_Cookie: {fileID: 0} 155 m_DrawHalo: 0 156 m_Flare: {fileID: 0} 157 m_RenderMode: 0 158 m_CullingMask: 159 serializedVersion: 2 160 m_Bits: 4294967295 161 m_Lightmapping: 1 162 m_LightShadowCasterMode: 0 163 m_AreaSize: {x: 1, y: 1} 164 m_BounceIntensity: 1 165 m_ColorTemperature: 6570 166 m_UseColorTemperature: 0 167 m_ShadowRadius: 0 168 m_ShadowAngle: 0 169--- !u!4 &170076735 170Transform: 171 m_ObjectHideFlags: 0 172 m_CorrespondingSourceObject: {fileID: 0} 173 m_PrefabInternal: {fileID: 0} 174 m_GameObject: {fileID: 170076733} 175 m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} 176 m_LocalPosition: {x: 0, y: 3, z: 0} 177 m_LocalScale: {x: 1, y: 1, z: 1} 178 m_Children: [] 179 m_Father: {fileID: 0} 180 m_RootOrder: 1 181 m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} 182--- !u!1 &282840810 183GameObject: 184 m_ObjectHideFlags: 0 185 m_CorrespondingSourceObject: {fileID: 0} 186 m_PrefabInternal: {fileID: 0} 187 serializedVersion: 6 188 m_Component: 189 - component: {fileID: 282840814} 190 - component: {fileID: 282840813} 191 - component: {fileID: 282840811} 192 m_Layer: 0 193 m_Name: Main Camera 194 m_TagString: MainCamera 195 m_Icon: {fileID: 0} 196 m_NavMeshLayer: 0 197 m_StaticEditorFlags: 0 198 m_IsActive: 1 199--- !u!81 &282840811 200AudioListener: 201 m_ObjectHideFlags: 0 202 m_CorrespondingSourceObject: {fileID: 0} 203 m_PrefabInternal: {fileID: 0} 204 m_GameObject: {fileID: 282840810} 205 m_Enabled: 1 206--- !u!20 &282840813 207Camera: 208 m_ObjectHideFlags: 0 209 m_CorrespondingSourceObject: {fileID: 0} 210 m_PrefabInternal: {fileID: 0} 211 m_GameObject: {fileID: 282840810} 212 m_Enabled: 1 213 serializedVersion: 2 214 m_ClearFlags: 1 215 m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} 216 m_projectionMatrixMode: 1 217 m_SensorSize: {x: 36, y: 24} 218 m_LensShift: {x: 0, y: 0} 219 m_FocalLength: 50 220 m_NormalizedViewPortRect: 221 serializedVersion: 2 222 x: 0 223 y: 0 224 width: 1 225 height: 1 226 near clip plane: 0.3 227 far clip plane: 1000 228 field of view: 60 229 orthographic: 0 230 orthographic size: 5 231 m_Depth: -1 232 m_CullingMask: 233 serializedVersion: 2 234 m_Bits: 4294967295 235 m_RenderingPath: -1 236 m_TargetTexture: {fileID: 0} 237 m_TargetDisplay: 0 238 m_TargetEye: 3 239 m_HDR: 1 240 m_AllowMSAA: 1 241 m_AllowDynamicResolution: 0 242 m_ForceIntoRT: 1 243 m_OcclusionCulling: 1 244 m_StereoConvergence: 10 245 m_StereoSeparation: 0.022 246--- !u!4 &282840814 247Transform: 248 m_ObjectHideFlags: 0 249 m_CorrespondingSourceObject: {fileID: 0} 250 m_PrefabInternal: {fileID: 0} 251 m_GameObject: {fileID: 282840810} 252 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 253 m_LocalPosition: {x: 0, y: 1, z: -10} 254 m_LocalScale: {x: 1, y: 1, z: 1} 255 m_Children: [] 256 m_Father: {fileID: 0} 257 m_RootOrder: 0 258 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 259--- !u!1 &359781717 260GameObject: 261 m_ObjectHideFlags: 0 262 m_CorrespondingSourceObject: {fileID: 0} 263 m_PrefabInternal: {fileID: 0} 264 serializedVersion: 6 265 m_Component: 266 - component: {fileID: 359781721} 267 - component: {fileID: 359781720} 268 - component: {fileID: 359781719} 269 - component: {fileID: 359781718} 270 m_Layer: 0 271 m_Name: Cube 272 m_TagString: Untagged 273 m_Icon: {fileID: 0} 274 m_NavMeshLayer: 0 275 m_StaticEditorFlags: 0 276 m_IsActive: 1 277--- !u!65 &359781718 278BoxCollider: 279 m_ObjectHideFlags: 0 280 m_CorrespondingSourceObject: {fileID: 0} 281 m_PrefabInternal: {fileID: 0} 282 m_GameObject: {fileID: 359781717} 283 m_Material: {fileID: 0} 284 m_IsTrigger: 0 285 m_Enabled: 1 286 serializedVersion: 2 287 m_Size: {x: 1, y: 1, z: 1} 288 m_Center: {x: 0, y: 0, z: 0} 289--- !u!23 &359781719 290MeshRenderer: 291 m_ObjectHideFlags: 0 292 m_CorrespondingSourceObject: {fileID: 0} 293 m_PrefabInternal: {fileID: 0} 294 m_GameObject: {fileID: 359781717} 295 m_Enabled: 1 296 m_CastShadows: 1 297 m_ReceiveShadows: 1 298 m_DynamicOccludee: 1 299 m_MotionVectors: 1 300 m_LightProbeUsage: 1 301 m_ReflectionProbeUsage: 1 302 m_RenderingLayerMask: 4294967295 303 m_Materials: 304 - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} 305 m_StaticBatchInfo: 306 firstSubMesh: 0 307 subMeshCount: 0 308 m_StaticBatchRoot: {fileID: 0} 309 m_ProbeAnchor: {fileID: 0} 310 m_LightProbeVolumeOverride: {fileID: 0} 311 m_ScaleInLightmap: 1 312 m_PreserveUVs: 0 313 m_IgnoreNormalsForChartDetection: 0 314 m_ImportantGI: 0 315 m_StitchLightmapSeams: 0 316 m_SelectedEditorRenderState: 3 317 m_MinimumChartSize: 4 318 m_AutoUVMaxDistance: 0.5 319 m_AutoUVMaxAngle: 89 320 m_LightmapParameters: {fileID: 0} 321 m_SortingLayerID: 0 322 m_SortingLayer: 0 323 m_SortingOrder: 0 324--- !u!33 &359781720 325MeshFilter: 326 m_ObjectHideFlags: 0 327 m_CorrespondingSourceObject: {fileID: 0} 328 m_PrefabInternal: {fileID: 0} 329 m_GameObject: {fileID: 359781717} 330 m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} 331--- !u!4 &359781721 332Transform: 333 m_ObjectHideFlags: 0 334 m_CorrespondingSourceObject: {fileID: 0} 335 m_PrefabInternal: {fileID: 0} 336 m_GameObject: {fileID: 359781717} 337 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 338 m_LocalPosition: {x: 0, y: 0, z: 0} 339 m_LocalScale: {x: 1, y: 0.2260268, z: 2.0065644} 340 m_Children: [] 341 m_Father: {fileID: 0} 342 m_RootOrder: 3 343 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 344--- !u!1 &618750917 345GameObject: 346 m_ObjectHideFlags: 0 347 m_CorrespondingSourceObject: {fileID: 0} 348 m_PrefabInternal: {fileID: 0} 349 serializedVersion: 6 350 m_Component: 351 - component: {fileID: 618750918} 352 - component: {fileID: 618750919} 353 m_Layer: 0 354 m_Name: Right Hand 355 m_TagString: Untagged 356 m_Icon: {fileID: 0} 357 m_NavMeshLayer: 0 358 m_StaticEditorFlags: 0 359 m_IsActive: 1 360--- !u!4 &618750918 361Transform: 362 m_ObjectHideFlags: 0 363 m_CorrespondingSourceObject: {fileID: 0} 364 m_PrefabInternal: {fileID: 0} 365 m_GameObject: {fileID: 618750917} 366 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 367 m_LocalPosition: {x: 0, y: 0, z: 0} 368 m_LocalScale: {x: 1, y: 1, z: 1} 369 m_Children: 370 - {fileID: 638365778} 371 - {fileID: 1834950146} 372 - {fileID: 1342024134} 373 - {fileID: 1156108526} 374 - {fileID: 2126949329} 375 - {fileID: 649102870} 376 m_Father: {fileID: 1634297806} 377 m_RootOrder: 1 378 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 379--- !u!114 &618750919 380MonoBehaviour: 381 m_ObjectHideFlags: 0 382 m_CorrespondingSourceObject: {fileID: 0} 383 m_PrefabInternal: {fileID: 0} 384 m_GameObject: {fileID: 618750917} 385 m_Enabled: 1 386 m_EditorHideFlags: 0 387 m_Script: {fileID: 11500000, guid: 97d3efc7a87236943b45c903b94f56f1, type: 3} 388 m_Name: 389 m_EditorClassIdentifier: 390 jointType: 1 391 wrist: {fileID: 638365779} 392 thumb: {fileID: 1834950147} 393 index: {fileID: 1342024135} 394 middle: {fileID: 1156108527} 395 ring: {fileID: 2126949330} 396 pinky: {fileID: 649102871} 397--- !u!1 &638365777 398GameObject: 399 m_ObjectHideFlags: 0 400 m_CorrespondingSourceObject: {fileID: 0} 401 m_PrefabInternal: {fileID: 0} 402 serializedVersion: 6 403 m_Component: 404 - component: {fileID: 638365778} 405 - component: {fileID: 638365779} 406 m_Layer: 0 407 m_Name: Wrist 408 m_TagString: Untagged 409 m_Icon: {fileID: 0} 410 m_NavMeshLayer: 0 411 m_StaticEditorFlags: 0 412 m_IsActive: 1 413--- !u!4 &638365778 414Transform: 415 m_ObjectHideFlags: 0 416 m_CorrespondingSourceObject: {fileID: 0} 417 m_PrefabInternal: {fileID: 0} 418 m_GameObject: {fileID: 638365777} 419 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 420 m_LocalPosition: {x: 0, y: 0, z: 0} 421 m_LocalScale: {x: 1, y: 1, z: 1} 422 m_Children: [] 423 m_Father: {fileID: 618750918} 424 m_RootOrder: 0 425 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 426--- !u!114 &638365779 427MonoBehaviour: 428 m_ObjectHideFlags: 0 429 m_CorrespondingSourceObject: {fileID: 0} 430 m_PrefabInternal: {fileID: 0} 431 m_GameObject: {fileID: 638365777} 432 m_Enabled: 1 433 m_EditorHideFlags: 0 434 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 435 m_Name: 436 m_EditorClassIdentifier: 437 jointType: 7 438 rotationValues: {x: 0, y: 0, z: 0} 439--- !u!1 &649102869 440GameObject: 441 m_ObjectHideFlags: 0 442 m_CorrespondingSourceObject: {fileID: 0} 443 m_PrefabInternal: {fileID: 0} 444 serializedVersion: 6 445 m_Component: 446 - component: {fileID: 649102870} 447 - component: {fileID: 649102871} 448 m_Layer: 0 449 m_Name: Pinky 450 m_TagString: Untagged 451 m_Icon: {fileID: 0} 452 m_NavMeshLayer: 0 453 m_StaticEditorFlags: 0 454 m_IsActive: 1 455--- !u!4 &649102870 456Transform: 457 m_ObjectHideFlags: 0 458 m_CorrespondingSourceObject: {fileID: 0} 459 m_PrefabInternal: {fileID: 0} 460 m_GameObject: {fileID: 649102869} 461 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 462 m_LocalPosition: {x: 0, y: 0, z: 0} 463 m_LocalScale: {x: 1, y: 1, z: 1} 464 m_Children: [] 465 m_Father: {fileID: 618750918} 466 m_RootOrder: 5 467 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 468--- !u!114 &649102871 469MonoBehaviour: 470 m_ObjectHideFlags: 0 471 m_CorrespondingSourceObject: {fileID: 0} 472 m_PrefabInternal: {fileID: 0} 473 m_GameObject: {fileID: 649102869} 474 m_Enabled: 1 475 m_EditorHideFlags: 0 476 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 477 m_Name: 478 m_EditorClassIdentifier: 479 jointType: 6 480 rotationValues: {x: 0, y: 0, z: 0} 481--- !u!1 &715455438 482GameObject: 483 m_ObjectHideFlags: 0 484 m_CorrespondingSourceObject: {fileID: 0} 485 m_PrefabInternal: {fileID: 0} 486 serializedVersion: 6 487 m_Component: 488 - component: {fileID: 715455439} 489 - component: {fileID: 715455440} 490 m_Layer: 0 491 m_Name: Ring 492 m_TagString: Untagged 493 m_Icon: {fileID: 0} 494 m_NavMeshLayer: 0 495 m_StaticEditorFlags: 0 496 m_IsActive: 1 497--- !u!4 &715455439 498Transform: 499 m_ObjectHideFlags: 0 500 m_CorrespondingSourceObject: {fileID: 0} 501 m_PrefabInternal: {fileID: 0} 502 m_GameObject: {fileID: 715455438} 503 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 504 m_LocalPosition: {x: 0, y: 0, z: 0} 505 m_LocalScale: {x: 1, y: 1, z: 1} 506 m_Children: [] 507 m_Father: {fileID: 1375661944} 508 m_RootOrder: 4 509 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 510--- !u!114 &715455440 511MonoBehaviour: 512 m_ObjectHideFlags: 0 513 m_CorrespondingSourceObject: {fileID: 0} 514 m_PrefabInternal: {fileID: 0} 515 m_GameObject: {fileID: 715455438} 516 m_Enabled: 1 517 m_EditorHideFlags: 0 518 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 519 m_Name: 520 m_EditorClassIdentifier: 521 jointType: 5 522 rotationValues: {x: 0, y: 0, z: 0} 523--- !u!1 &1156108525 524GameObject: 525 m_ObjectHideFlags: 0 526 m_CorrespondingSourceObject: {fileID: 0} 527 m_PrefabInternal: {fileID: 0} 528 serializedVersion: 6 529 m_Component: 530 - component: {fileID: 1156108526} 531 - component: {fileID: 1156108527} 532 m_Layer: 0 533 m_Name: Middle 534 m_TagString: Untagged 535 m_Icon: {fileID: 0} 536 m_NavMeshLayer: 0 537 m_StaticEditorFlags: 0 538 m_IsActive: 1 539--- !u!4 &1156108526 540Transform: 541 m_ObjectHideFlags: 0 542 m_CorrespondingSourceObject: {fileID: 0} 543 m_PrefabInternal: {fileID: 0} 544 m_GameObject: {fileID: 1156108525} 545 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 546 m_LocalPosition: {x: 0, y: 0, z: 0} 547 m_LocalScale: {x: 1, y: 1, z: 1} 548 m_Children: [] 549 m_Father: {fileID: 618750918} 550 m_RootOrder: 3 551 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 552--- !u!114 &1156108527 553MonoBehaviour: 554 m_ObjectHideFlags: 0 555 m_CorrespondingSourceObject: {fileID: 0} 556 m_PrefabInternal: {fileID: 0} 557 m_GameObject: {fileID: 1156108525} 558 m_Enabled: 1 559 m_EditorHideFlags: 0 560 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 561 m_Name: 562 m_EditorClassIdentifier: 563 jointType: 4 564 rotationValues: {x: 0, y: 0, z: 0} 565--- !u!1 &1182598610 566GameObject: 567 m_ObjectHideFlags: 0 568 m_CorrespondingSourceObject: {fileID: 0} 569 m_PrefabInternal: {fileID: 0} 570 serializedVersion: 6 571 m_Component: 572 - component: {fileID: 1182598611} 573 - component: {fileID: 1182598612} 574 m_Layer: 0 575 m_Name: Middle 576 m_TagString: Untagged 577 m_Icon: {fileID: 0} 578 m_NavMeshLayer: 0 579 m_StaticEditorFlags: 0 580 m_IsActive: 1 581--- !u!4 &1182598611 582Transform: 583 m_ObjectHideFlags: 0 584 m_CorrespondingSourceObject: {fileID: 0} 585 m_PrefabInternal: {fileID: 0} 586 m_GameObject: {fileID: 1182598610} 587 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 588 m_LocalPosition: {x: 0, y: 0, z: 0} 589 m_LocalScale: {x: 1, y: 1, z: 1} 590 m_Children: [] 591 m_Father: {fileID: 1375661944} 592 m_RootOrder: 3 593 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 594--- !u!114 &1182598612 595MonoBehaviour: 596 m_ObjectHideFlags: 0 597 m_CorrespondingSourceObject: {fileID: 0} 598 m_PrefabInternal: {fileID: 0} 599 m_GameObject: {fileID: 1182598610} 600 m_Enabled: 1 601 m_EditorHideFlags: 0 602 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 603 m_Name: 604 m_EditorClassIdentifier: 605 jointType: 4 606 rotationValues: {x: 0, y: 0, z: 0} 607--- !u!1 &1342024133 608GameObject: 609 m_ObjectHideFlags: 0 610 m_CorrespondingSourceObject: {fileID: 0} 611 m_PrefabInternal: {fileID: 0} 612 serializedVersion: 6 613 m_Component: 614 - component: {fileID: 1342024134} 615 - component: {fileID: 1342024135} 616 m_Layer: 0 617 m_Name: Index 618 m_TagString: Untagged 619 m_Icon: {fileID: 0} 620 m_NavMeshLayer: 0 621 m_StaticEditorFlags: 0 622 m_IsActive: 1 623--- !u!4 &1342024134 624Transform: 625 m_ObjectHideFlags: 0 626 m_CorrespondingSourceObject: {fileID: 0} 627 m_PrefabInternal: {fileID: 0} 628 m_GameObject: {fileID: 1342024133} 629 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 630 m_LocalPosition: {x: 0, y: 0, z: 0} 631 m_LocalScale: {x: 1, y: 1, z: 1} 632 m_Children: [] 633 m_Father: {fileID: 618750918} 634 m_RootOrder: 2 635 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 636--- !u!114 &1342024135 637MonoBehaviour: 638 m_ObjectHideFlags: 0 639 m_CorrespondingSourceObject: {fileID: 0} 640 m_PrefabInternal: {fileID: 0} 641 m_GameObject: {fileID: 1342024133} 642 m_Enabled: 1 643 m_EditorHideFlags: 0 644 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 645 m_Name: 646 m_EditorClassIdentifier: 647 jointType: 3 648 rotationValues: {x: 0, y: 0, z: 0} 649--- !u!1 &1375661943 650GameObject: 651 m_ObjectHideFlags: 0 652 m_CorrespondingSourceObject: {fileID: 0} 653 m_PrefabInternal: {fileID: 0} 654 serializedVersion: 6 655 m_Component: 656 - component: {fileID: 1375661944} 657 - component: {fileID: 1375661945} 658 m_Layer: 0 659 m_Name: Left Hand 660 m_TagString: Untagged 661 m_Icon: {fileID: 0} 662 m_NavMeshLayer: 0 663 m_StaticEditorFlags: 0 664 m_IsActive: 1 665--- !u!4 &1375661944 666Transform: 667 m_ObjectHideFlags: 0 668 m_CorrespondingSourceObject: {fileID: 0} 669 m_PrefabInternal: {fileID: 0} 670 m_GameObject: {fileID: 1375661943} 671 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 672 m_LocalPosition: {x: 0, y: 0, z: 0} 673 m_LocalScale: {x: 1, y: 1, z: 1} 674 m_Children: 675 - {fileID: 2139301569} 676 - {fileID: 1920256460} 677 - {fileID: 1734569599} 678 - {fileID: 1182598611} 679 - {fileID: 715455439} 680 - {fileID: 1489611121} 681 m_Father: {fileID: 1634297806} 682 m_RootOrder: 0 683 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 684--- !u!114 &1375661945 685MonoBehaviour: 686 m_ObjectHideFlags: 0 687 m_CorrespondingSourceObject: {fileID: 0} 688 m_PrefabInternal: {fileID: 0} 689 m_GameObject: {fileID: 1375661943} 690 m_Enabled: 1 691 m_EditorHideFlags: 0 692 m_Script: {fileID: 11500000, guid: 97d3efc7a87236943b45c903b94f56f1, type: 3} 693 m_Name: 694 m_EditorClassIdentifier: 695 jointType: 0 696 wrist: {fileID: 2139301570} 697 thumb: {fileID: 1920256461} 698 index: {fileID: 1734569600} 699 middle: {fileID: 1182598612} 700 ring: {fileID: 715455440} 701 pinky: {fileID: 1489611122} 702--- !u!1 &1489611120 703GameObject: 704 m_ObjectHideFlags: 0 705 m_CorrespondingSourceObject: {fileID: 0} 706 m_PrefabInternal: {fileID: 0} 707 serializedVersion: 6 708 m_Component: 709 - component: {fileID: 1489611121} 710 - component: {fileID: 1489611122} 711 m_Layer: 0 712 m_Name: Pinky 713 m_TagString: Untagged 714 m_Icon: {fileID: 0} 715 m_NavMeshLayer: 0 716 m_StaticEditorFlags: 0 717 m_IsActive: 1 718--- !u!4 &1489611121 719Transform: 720 m_ObjectHideFlags: 0 721 m_CorrespondingSourceObject: {fileID: 0} 722 m_PrefabInternal: {fileID: 0} 723 m_GameObject: {fileID: 1489611120} 724 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 725 m_LocalPosition: {x: 0, y: 0, z: 0} 726 m_LocalScale: {x: 1, y: 1, z: 1} 727 m_Children: [] 728 m_Father: {fileID: 1375661944} 729 m_RootOrder: 5 730 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 731--- !u!114 &1489611122 732MonoBehaviour: 733 m_ObjectHideFlags: 0 734 m_CorrespondingSourceObject: {fileID: 0} 735 m_PrefabInternal: {fileID: 0} 736 m_GameObject: {fileID: 1489611120} 737 m_Enabled: 1 738 m_EditorHideFlags: 0 739 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 740 m_Name: 741 m_EditorClassIdentifier: 742 jointType: 6 743 rotationValues: {x: 0, y: 0, z: 0} 744--- !u!1 &1634297804 745GameObject: 746 m_ObjectHideFlags: 0 747 m_CorrespondingSourceObject: {fileID: 0} 748 m_PrefabInternal: {fileID: 0} 749 serializedVersion: 6 750 m_Component: 751 - component: {fileID: 1634297806} 752 - component: {fileID: 1634297805} 753 - component: {fileID: 1634297807} 754 - component: {fileID: 1634297809} 755 - component: {fileID: 1634297808} 756 m_Layer: 0 757 m_Name: Manager 758 m_TagString: Untagged 759 m_Icon: {fileID: 0} 760 m_NavMeshLayer: 0 761 m_StaticEditorFlags: 0 762 m_IsActive: 1 763--- !u!114 &1634297805 764MonoBehaviour: 765 m_ObjectHideFlags: 0 766 m_CorrespondingSourceObject: {fileID: 0} 767 m_PrefabInternal: {fileID: 0} 768 m_GameObject: {fileID: 1634297804} 769 m_Enabled: 0 770 m_EditorHideFlags: 0 771 m_Script: {fileID: 11500000, guid: 69efc1ee053c2584bb05fc39be1dc2fa, type: 3} 772 m_Name: 773 m_EditorClassIdentifier: 774 debugInput: 0 775 rawInput: "<leftHand> \ <wrist>12,12,12</wrist> \ <thumb>12,12,12</thumb> \ <index>12,12,12</index> 776 \ <middle>12,12,12</middle> \ <ring>12,12,12</ring> \ <pinky>12,12,12</pinky> 777 </leftHand> <rightHand> \ <wrist>12,12,12</wrist> \ <thumb>12,12,12</thumb> \ <index>12,12,12</index> 778 \ <middle>12,12,12</middle> \ <ring>12,12,12</ring> \ <pinky>12,12,12</pinky> 779 </rightHand>" 780 separators: 781 - ',' 782 leftHand: {fileID: 1375661945} 783 rightHand: {fileID: 618750919} 784--- !u!4 &1634297806 785Transform: 786 m_ObjectHideFlags: 0 787 m_CorrespondingSourceObject: {fileID: 0} 788 m_PrefabInternal: {fileID: 0} 789 m_GameObject: {fileID: 1634297804} 790 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 791 m_LocalPosition: {x: 0, y: 0, z: 0} 792 m_LocalScale: {x: 1, y: 1, z: 1} 793 m_Children: 794 - {fileID: 1375661944} 795 - {fileID: 618750918} 796 m_Father: {fileID: 0} 797 m_RootOrder: 2 798 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 799--- !u!114 &1634297807 800MonoBehaviour: 801 m_ObjectHideFlags: 0 802 m_CorrespondingSourceObject: {fileID: 0} 803 m_PrefabInternal: {fileID: 0} 804 m_GameObject: {fileID: 1634297804} 805 m_Enabled: 1 806 m_EditorHideFlags: 0 807 m_Script: {fileID: 11500000, guid: f95131f0b00481045aecb0720acf8392, type: 3} 808 m_Name: 809 m_EditorClassIdentifier: 810 SamplePeriod: 512 811 Beta: 20 812 quat: 813 - 1 814 - 0 815 - 0 816 - 0 817--- !u!114 &1634297808 818MonoBehaviour: 819 m_ObjectHideFlags: 0 820 m_CorrespondingSourceObject: {fileID: 0} 821 m_PrefabInternal: {fileID: 0} 822 m_GameObject: {fileID: 1634297804} 823 m_Enabled: 0 824 m_EditorHideFlags: 0 825 m_Script: {fileID: 11500000, guid: 423e01db97df98b4e9eb0352ebc16864, type: 3} 826 m_Name: 827 m_EditorClassIdentifier: 828 rawInput: 829 accelerometerSensitivity: 16384 830 gyroscopeSensitivity: 131 831 magnetometerSensitivity: 0.6 832 truncateFactor: 1000 833 debug: 0 834 axDebug: 0 835 ayDebug: 0 836 azDebug: 0 837 gxDebug: 0 838 gyDebug: 0 839 gzDebug: 0 840 mxDebug: 0 841 myDebug: 0 842 mzDebug: 0 843 dataSet: {fileID: 4900000, guid: ff342d1bba19e9c48a249264ed593c82, type: 3} 844 parseIndex: 3 845 axIndex: 1 846 ayIndex: 2 847 azIndex: 3 848 gxIndex: 7 849 gyIndex: 8 850 gzIndex: 9 851 mxIndex: 10 852 myIndex: 11 853 mzIndex: 12 854 ax: 0 855 ay: 0 856 az: 0 857 gx: 0 858 gy: 0 859 gz: 0 860 mx: 0 861 my: 0 862 mz: 0 863 cube: {fileID: 359781721} 864--- !u!114 &1634297809 865MonoBehaviour: 866 m_ObjectHideFlags: 0 867 m_CorrespondingSourceObject: {fileID: 0} 868 m_PrefabInternal: {fileID: 0} 869 m_GameObject: {fileID: 1634297804} 870 m_Enabled: 1 871 m_EditorHideFlags: 0 872 m_Script: {fileID: 11500000, guid: 5301478171ed98d4c957c7fe59f725ff, type: 3} 873 m_Name: 874 m_EditorClassIdentifier: 875 rawInput: 876 accelerometerSensitivity: 16384 877 gyroscopeSensitivity: 131 878 magnetometerSensitivity: 0.6 879 truncateFactor: 100 880 debug: 0 881 axDebug: 1 882 ayDebug: 0 883 azDebug: 0 884 gxDebug: 0 885 gyDebug: 0 886 gzDebug: 0 887 mxDebug: 1 888 myDebug: 0 889 mzDebug: 0 890 dataSet: {fileID: 4900000, guid: ff342d1bba19e9c48a249264ed593c82, type: 3} 891 parseIndex: 2500 892 axIndex: 1 893 ayIndex: 2 894 azIndex: 3 895 gxIndex: 7 896 gyIndex: 8 897 gzIndex: 9 898 mxIndex: 10 899 myIndex: 11 900 mzIndex: 12 901 ax: 0 902 ay: 0 903 az: 0 904 gx: 0 905 gy: 0 906 gz: 0 907 mx: 0 908 my: 0 909 mz: 0 910 cube: {fileID: 359781721} 911--- !u!1 &1734569598 912GameObject: 913 m_ObjectHideFlags: 0 914 m_CorrespondingSourceObject: {fileID: 0} 915 m_PrefabInternal: {fileID: 0} 916 serializedVersion: 6 917 m_Component: 918 - component: {fileID: 1734569599} 919 - component: {fileID: 1734569600} 920 m_Layer: 0 921 m_Name: Index 922 m_TagString: Untagged 923 m_Icon: {fileID: 0} 924 m_NavMeshLayer: 0 925 m_StaticEditorFlags: 0 926 m_IsActive: 1 927--- !u!4 &1734569599 928Transform: 929 m_ObjectHideFlags: 0 930 m_CorrespondingSourceObject: {fileID: 0} 931 m_PrefabInternal: {fileID: 0} 932 m_GameObject: {fileID: 1734569598} 933 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 934 m_LocalPosition: {x: 0, y: 0, z: 0} 935 m_LocalScale: {x: 1, y: 1, z: 1} 936 m_Children: [] 937 m_Father: {fileID: 1375661944} 938 m_RootOrder: 2 939 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 940--- !u!114 &1734569600 941MonoBehaviour: 942 m_ObjectHideFlags: 0 943 m_CorrespondingSourceObject: {fileID: 0} 944 m_PrefabInternal: {fileID: 0} 945 m_GameObject: {fileID: 1734569598} 946 m_Enabled: 1 947 m_EditorHideFlags: 0 948 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 949 m_Name: 950 m_EditorClassIdentifier: 951 jointType: 3 952 rotationValues: {x: 0, y: 0, z: 0} 953--- !u!1 &1834950145 954GameObject: 955 m_ObjectHideFlags: 0 956 m_CorrespondingSourceObject: {fileID: 0} 957 m_PrefabInternal: {fileID: 0} 958 serializedVersion: 6 959 m_Component: 960 - component: {fileID: 1834950146} 961 - component: {fileID: 1834950147} 962 m_Layer: 0 963 m_Name: Thumb 964 m_TagString: Untagged 965 m_Icon: {fileID: 0} 966 m_NavMeshLayer: 0 967 m_StaticEditorFlags: 0 968 m_IsActive: 1 969--- !u!4 &1834950146 970Transform: 971 m_ObjectHideFlags: 0 972 m_CorrespondingSourceObject: {fileID: 0} 973 m_PrefabInternal: {fileID: 0} 974 m_GameObject: {fileID: 1834950145} 975 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 976 m_LocalPosition: {x: 0, y: 0, z: 0} 977 m_LocalScale: {x: 1, y: 1, z: 1} 978 m_Children: [] 979 m_Father: {fileID: 618750918} 980 m_RootOrder: 1 981 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 982--- !u!114 &1834950147 983MonoBehaviour: 984 m_ObjectHideFlags: 0 985 m_CorrespondingSourceObject: {fileID: 0} 986 m_PrefabInternal: {fileID: 0} 987 m_GameObject: {fileID: 1834950145} 988 m_Enabled: 1 989 m_EditorHideFlags: 0 990 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 991 m_Name: 992 m_EditorClassIdentifier: 993 jointType: 2 994 rotationValues: {x: 0, y: 0, z: 0} 995--- !u!1 &1920256459 996GameObject: 997 m_ObjectHideFlags: 0 998 m_CorrespondingSourceObject: {fileID: 0} 999 m_PrefabInternal: {fileID: 0} 1000 serializedVersion: 6 1001 m_Component: 1002 - component: {fileID: 1920256460} 1003 - component: {fileID: 1920256461} 1004 m_Layer: 0 1005 m_Name: Thumb 1006 m_TagString: Untagged 1007 m_Icon: {fileID: 0} 1008 m_NavMeshLayer: 0 1009 m_StaticEditorFlags: 0 1010 m_IsActive: 1 1011--- !u!4 &1920256460 1012Transform: 1013 m_ObjectHideFlags: 0 1014 m_CorrespondingSourceObject: {fileID: 0} 1015 m_PrefabInternal: {fileID: 0} 1016 m_GameObject: {fileID: 1920256459} 1017 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 1018 m_LocalPosition: {x: 0, y: 0, z: 0} 1019 m_LocalScale: {x: 1, y: 1, z: 1} 1020 m_Children: [] 1021 m_Father: {fileID: 1375661944} 1022 m_RootOrder: 1 1023 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 1024--- !u!114 &1920256461 1025MonoBehaviour: 1026 m_ObjectHideFlags: 0 1027 m_CorrespondingSourceObject: {fileID: 0} 1028 m_PrefabInternal: {fileID: 0} 1029 m_GameObject: {fileID: 1920256459} 1030 m_Enabled: 1 1031 m_EditorHideFlags: 0 1032 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 1033 m_Name: 1034 m_EditorClassIdentifier: 1035 jointType: 2 1036 rotationValues: {x: 0, y: 0, z: 0} 1037--- !u!1 &2126949328 1038GameObject: 1039 m_ObjectHideFlags: 0 1040 m_CorrespondingSourceObject: {fileID: 0} 1041 m_PrefabInternal: {fileID: 0} 1042 serializedVersion: 6 1043 m_Component: 1044 - component: {fileID: 2126949329} 1045 - component: {fileID: 2126949330} 1046 m_Layer: 0 1047 m_Name: Ring 1048 m_TagString: Untagged 1049 m_Icon: {fileID: 0} 1050 m_NavMeshLayer: 0 1051 m_StaticEditorFlags: 0 1052 m_IsActive: 1 1053--- !u!4 &2126949329 1054Transform: 1055 m_ObjectHideFlags: 0 1056 m_CorrespondingSourceObject: {fileID: 0} 1057 m_PrefabInternal: {fileID: 0} 1058 m_GameObject: {fileID: 2126949328} 1059 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 1060 m_LocalPosition: {x: 0, y: 0, z: 0} 1061 m_LocalScale: {x: 1, y: 1, z: 1} 1062 m_Children: [] 1063 m_Father: {fileID: 618750918} 1064 m_RootOrder: 4 1065 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 1066--- !u!114 &2126949330 1067MonoBehaviour: 1068 m_ObjectHideFlags: 0 1069 m_CorrespondingSourceObject: {fileID: 0} 1070 m_PrefabInternal: {fileID: 0} 1071 m_GameObject: {fileID: 2126949328} 1072 m_Enabled: 1 1073 m_EditorHideFlags: 0 1074 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 1075 m_Name: 1076 m_EditorClassIdentifier: 1077 jointType: 5 1078 rotationValues: {x: 0, y: 0, z: 0} 1079--- !u!1 &2139301568 1080GameObject: 1081 m_ObjectHideFlags: 0 1082 m_CorrespondingSourceObject: {fileID: 0} 1083 m_PrefabInternal: {fileID: 0} 1084 serializedVersion: 6 1085 m_Component: 1086 - component: {fileID: 2139301569} 1087 - component: {fileID: 2139301570} 1088 m_Layer: 0 1089 m_Name: Wrist 1090 m_TagString: Untagged 1091 m_Icon: {fileID: 0} 1092 m_NavMeshLayer: 0 1093 m_StaticEditorFlags: 0 1094 m_IsActive: 1 1095--- !u!4 &2139301569 1096Transform: 1097 m_ObjectHideFlags: 0 1098 m_CorrespondingSourceObject: {fileID: 0} 1099 m_PrefabInternal: {fileID: 0} 1100 m_GameObject: {fileID: 2139301568} 1101 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 1102 m_LocalPosition: {x: 0, y: 0, z: 0} 1103 m_LocalScale: {x: 1, y: 1, z: 1} 1104 m_Children: [] 1105 m_Father: {fileID: 1375661944} 1106 m_RootOrder: 0 1107 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 1108--- !u!114 &2139301570 1109MonoBehaviour: 1110 m_ObjectHideFlags: 0 1111 m_CorrespondingSourceObject: {fileID: 0} 1112 m_PrefabInternal: {fileID: 0} 1113 m_GameObject: {fileID: 2139301568} 1114 m_Enabled: 1 1115 m_EditorHideFlags: 0 1116 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 1117 m_Name: 1118 m_EditorClassIdentifier: 1119 jointType: 7 1120 rotationValues: {x: 0, y: 0, z: 0} 1121
Unity Quaternion Filter
csharp
quaternion method
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Cleaner : MonoBehaviour { 6 7 private static Cleaner inst; 8 public static Cleaner instance { get { return inst; } } 9 10 private void Awake() 11 { 12 if (inst != null && inst != this) 13 Destroy(this.gameObject); 14 else 15 inst = this; 16 } 17 18 19 20 21 /// <summary> 22 /// Gets or sets the sample period. 23 /// </summary> 24 [SerializeField] public float SamplePeriod = 501;//501; //delta t. used to be 512 25 26 /// <summary> 27 /// Gets or sets the algorithm gain beta. 28 /// </summary> 29 [SerializeField] public float Beta = 0.1f; 30 31 /// <summary> 32 /// Gets or sets the Quaternion output. 33 /// </summary> 34 [SerializeField] public float[] quat; 35 36 public Quaternion GetQuaternionData(float gz, float gx, float gy, float az, float ax, float ay, float mz, float mx, float my) 37 { 38 //float.Parse(stateInfo[0]) 39 MadgwickQuaternionUpdate(gz, gx, gy, az, ax, ay, mz, mx, my); 40 Quaternion retQuat = new Quaternion(quat[0], quat[1], quat[2], quat[3]); 41 return retQuat; 42 } 43 44 /// <summary> 45 /// Algorithm AHRS update method. Requires only gyroscope and accelerometer data. 46 /// </summary> 47 /// <param name="gx"> 48 /// Gyroscope x axis measurement in radians/s. 49 /// </param> 50 /// <param name="gy"> 51 /// Gyroscope y axis measurement in radians/s. 52 /// </param> 53 /// <param name="gz"> 54 /// Gyroscope z axis measurement in radians/s. 55 /// </param> 56 /// <param name="ax"> 57 /// Accelerometer x axis measurement in any calibrated units. 58 /// </param> 59 /// <param name="ay"> 60 /// Accelerometer y axis measurement in any calibrated units. 61 /// </param> 62 /// <param name="az"> 63 /// Accelerometer z axis measurement in any calibrated units. 64 /// </param> 65 /// <param name="mx"> 66 /// Magnetometer x axis measurement in any calibrated units. 67 /// </param> 68 /// <param name="my"> 69 /// Magnetometer y axis measurement in any calibrated units. 70 /// </param> 71 /// <param name="mz"> 72 /// Magnetometer z axis measurement in any calibrated units. 73 /// </param> 74 /// <remarks> 75 /// Optimised for minimal arithmetic. 76 /// Total : 160 77 /// Total *: 172 78 /// Total /: 5 79 /// Total sqrt: 5 80 /// </remarks> 81 public void MadgwickQuaternionUpdate(float gz, float gx, float gy, float az, float ax, float ay, float mz, float mx, float my) 82 { 83 float q1 = quat[0], q2 = quat[1], q3 = quat[2], q4 = quat[3]; // short name local variable for readability 84 float norm; 85 float hx, hy, _2bx, _2bz; 86 float s1, s2, s3, s4; 87 float qDot1, qDot2, qDot3, qDot4; 88 89 // Auxiliary variables to avoid repeated arithmetic 90 float _2q1mx; 91 float _2q1my; 92 float _2q1mz; 93 float _2q2mx; 94 float _4bx; 95 float _4bz; 96 float _2q1 = 2f * q1; 97 float _2q2 = 2f * q2; 98 float _2q3 = 2f * q3; 99 float _2q4 = 2f * q4; 100 float _2q1q3 = 2f * q1 * q3; 101 float _2q3q4 = 2f * q3 * q4; 102 float q1q1 = q1 * q1; 103 float q1q2 = q1 * q2; 104 float q1q3 = q1 * q3; 105 float q1q4 = q1 * q4; 106 float q2q2 = q2 * q2; 107 float q2q3 = q2 * q3; 108 float q2q4 = q2 * q4; 109 float q3q3 = q3 * q3; 110 float q3q4 = q3 * q4; 111 float q4q4 = q4 * q4; 112 113 // Normalise accelerometer measurement 114 norm = (float)Mathf.Sqrt(ax * ax + ay * ay + az * az); 115 if (norm == 0f) return; // handle NaN 116 norm = 1 / norm; // use reciprocal for division 117 ax *= norm; 118 ay *= norm; 119 az *= norm; 120 121 // Normalise magnetometer measurement 122 norm = (float)Mathf.Sqrt(mx * mx + my * my + mz * mz); 123 if (norm == 0f) return; // handle NaN 124 norm = 1 / norm; // use reciprocal for division 125 mx *= norm; 126 my *= norm; 127 mz *= norm; 128 129 // Reference direction of Earth's magnetic field 130 _2q1mx = 2f * q1 * mx; 131 _2q1my = 2f * q1 * my; 132 _2q1mz = 2f * q1 * mz; 133 _2q2mx = 2f * q2 * mx; 134 hx = mx * q1q1 - _2q1my * q4 + _2q1mz * q3 + mx * q2q2 + _2q2 * my * q3 + _2q2 * mz * q4 - mx * q3q3 - mx * q4q4; 135 hy = _2q1mx * q4 + my * q1q1 - _2q1mz * q2 + _2q2mx * q3 - my * q2q2 + my * q3q3 + _2q3 * mz * q4 - my * q4q4; 136 _2bx = (float)Mathf.Sqrt(hx * hx + hy * hy); 137 _2bz = -_2q1mx * q3 + _2q1my * q2 + mz * q1q1 + _2q2mx * q4 - mz * q2q2 + _2q3 * my * q4 - mz * q3q3 + mz * q4q4; 138 _4bx = 2f * _2bx; 139 _4bz = 2f * _2bz; 140 141 // Gradient decent algorithm corrective step 142 s1 = -_2q3 * (2f * q2q4 - _2q1q3 - ax) + _2q2 * (2f * q1q2 + _2q3q4 - ay) - _2bz * q3 * (_2bx * (0.5f - q3q3 - q4q4) + _2bz * (q2q4 - q1q3) - mx) + (-_2bx * q4 + _2bz * q2) * (_2bx * (q2q3 - q1q4) + _2bz * (q1q2 + q3q4) - my) + _2bx * q3 * (_2bx * (q1q3 + q2q4) + _2bz * (0.5f - q2q2 - q3q3) - mz); 143 s2 = _2q4 * (2f * q2q4 - _2q1q3 - ax) + _2q1 * (2f * q1q2 + _2q3q4 - ay) - 4f * q2 * (1 - 2f * q2q2 - 2f * q3q3 - az) + _2bz * q4 * (_2bx * (0.5f - q3q3 - q4q4) + _2bz * (q2q4 - q1q3) - mx) + (_2bx * q3 + _2bz * q1) * (_2bx * (q2q3 - q1q4) + _2bz * (q1q2 + q3q4) - my) + (_2bx * q4 - _4bz * q2) * (_2bx * (q1q3 + q2q4) + _2bz * (0.5f - q2q2 - q3q3) - mz); 144 s3 = -_2q1 * (2f * q2q4 - _2q1q3 - ax) + _2q4 * (2f * q1q2 + _2q3q4 - ay) - 4f * q3 * (1 - 2f * q2q2 - 2f * q3q3 - az) + (-_4bx * q3 - _2bz * q1) * (_2bx * (0.5f - q3q3 - q4q4) + _2bz * (q2q4 - q1q3) - mx) + (_2bx * q2 + _2bz * q4) * (_2bx * (q2q3 - q1q4) + _2bz * (q1q2 + q3q4) - my) + (_2bx * q1 - _4bz * q3) * (_2bx * (q1q3 + q2q4) + _2bz * (0.5f - q2q2 - q3q3) - mz); 145 s4 = _2q2 * (2f * q2q4 - _2q1q3 - ax) + _2q3 * (2f * q1q2 + _2q3q4 - ay) + (-_4bx * q4 + _2bz * q2) * (_2bx * (0.5f - q3q3 - q4q4) + _2bz * (q2q4 - q1q3) - mx) + (-_2bx * q1 + _2bz * q3) * (_2bx * (q2q3 - q1q4) + _2bz * (q1q2 + q3q4) - my) + _2bx * q2 * (_2bx * (q1q3 + q2q4) + _2bz * (0.5f - q2q2 - q3q3) - mz); 146 norm = 1f / (float)Mathf.Sqrt(s1 * s1 + s2 * s2 + s3 * s3 + s4 * s4); // normalise step magnitude 147 s1 *= norm; 148 s2 *= norm; 149 s3 *= norm; 150 s4 *= norm; 151 152 // Compute rate of change of quaternion 153 qDot1 = 0.5f * (-q2 * gx - q3 * gy - q4 * gz) - Beta * s1; 154 qDot2 = 0.5f * (q1 * gx + q3 * gz - q4 * gy) - Beta * s2; 155 qDot3 = 0.5f * (q1 * gy - q2 * gz + q4 * gx) - Beta * s3; 156 qDot4 = 0.5f * (q1 * gz + q2 * gy - q3 * gx) - Beta * s4; 157 158 // Integrate to yield quaternion 159 q1 += qDot1 * SamplePeriod; 160 q2 += qDot2 * SamplePeriod; 161 q3 += qDot3 * SamplePeriod; 162 q4 += qDot4 * SamplePeriod; 163 norm = 1f / (float)Mathf.Sqrt(q1 * q1 + q2 * q2 + q3 * q3 + q4 * q4); // normalise quaternion 164 quat[0] = q1 * norm; 165 quat[1] = q2 * norm; 166 quat[2] = q3 * norm; 167 quat[3] = q4 * norm; 168 } 169 170 // NOT DONE YET 171 public void MahonyQuaternionUpdate(float gz, float gx, float gy, float az, float ax, float ay, float mz, float mx, float my) 172 { 173 float q1 = quat[0], q2 = quat[1], q3 = quat[2], q4 = quat[3]; // short name local variable for readability 174 float norm; 175 float hx, hy, bx, bz; 176 float vx, vy, vz, wx, wy, wz; 177 float ex, ey, ez; 178 float pa, pb, pc; 179 180 // Auxiliary variables to avoid repeated arithmetic 181 float q1q1 = q1 * q2; 182 float q1q2 = q1 * q2; 183 float q1q3 = q1 * q3; 184 float q1q4 = q1 * q4; 185 float q2q2 = q2 * q2; 186 float q2q3 = q2 * q3; 187 float q2q4 = q2 * q4; 188 float q3q3 = q3 * q3; 189 float q3q4 = q3 * q4; 190 float q4q4 = q4 * q4; 191 192 // Normalise accelerometer measurement 193 norm = (float)Mathf.Sqrt(ax * ax + ay * ay + az * az); 194 if (norm == 0f) return; 195 norm = 1.0f / norm; 196 mx *= norm; 197 my *= norm; 198 mz *= norm; 199 200 // Reference direction of Earth's magnetic field 201 hx = 2.0f * mx * (0.5f - q3q3 - q4q4) + 2.0f * my * (q2q3 - q1q4) + 2.0f * mz * (q2q4 + q1q3); 202 hy = 2.0f * mx * (q2q3 + q1q4) + 2.0f * my * (0.5f - q2q2 + q4q4) + 2.0f * mz * (q3q4 - q1q2); 203 bx = (float)Mathf.Sqrt((hx * hx) + (hy * hy)); 204 bz = 2.0f * mx * (q2q4 - q1q3) + 2.0f * my * (q3q4 + q1q2) + 2.0f * mz * (0.5f - q2q2 - q3q3); 205 206 207 // Estimated direction of gravity and magnetic field 208 vx = 2.0f * (q2q4 - q1q3); 209 vy = 2.0f * (q1q2 + q3q4); 210 vz = q1q1 - q2q2 - q3q3 + q4q4; 211 wx = 2.0f * bx * (0.5f - q3q3 - q4q4) + 2.0f * bz * (q2q4 - q1q3); 212 wy = 2.0f * bx * (q2q3 - q1q4) + 2.0f * bz * (q1q2 + q3q4); 213 wz = 2.0f * bx * (q1q3 + q2q4) + 2.0f * bz * (0.5f - q2q2 - q3q3); 214 215 // Error is cross product between estimated direction and measured direction of gravity 216 ex = (ay * vz - az * vy) + (my * wz - mz * wy); 217 ey = (az * vx - ax * vz) + (mz * wx - mx * wz); 218 ez = (ax * vy - ay * vx) + (mx * wy - my * wx); 219 220 /* 221 * 222 * unfinished business 223 * need to keep working 224 * the below is still just copied from above for reference, 225 * so therefore the below code has no significance and once reach 226 * near the same point delete 227 * 228 * also have no idea what Ki is above so need to check it out. 229 * otherwise the code will bork itself 230 * 231 * end 232 * 233 * */ 234 235 /* 236 if (Ki > 0.0f) 237 { 238 eInt[0] += ex; 239 240 241 242 243 // Gradient decent algorithm corrective step 244 s1 = -_2q3 * (2f * q2q4 - _2q1q3 - ax) + _2q2 * (2f * q1q2 + _2q3q4 - ay) - _2bz * q3 * (_2bx * (0.5f - q3q3 - q4q4) + _2bz * (q2q4 - q1q3) - mx) + (-_2bx * q4 + _2bz * q2) * (_2bx * (q2q3 - q1q4) + _2bz * (q1q2 + q3q4) - my) + _2bx * q3 * (_2bx * (q1q3 + q2q4) + _2bz * (0.5f - q2q2 - q3q3) - mz); 245 s2 = _2q4 * (2f * q2q4 - _2q1q3 - ax) + _2q1 * (2f * q1q2 + _2q3q4 - ay) - 4f * q2 * (1 - 2f * q2q2 - 2f * q3q3 - az) + _2bz * q4 * (_2bx * (0.5f - q3q3 - q4q4) + _2bz * (q2q4 - q1q3) - mx) + (_2bx * q3 + _2bz * q1) * (_2bx * (q2q3 - q1q4) + _2bz * (q1q2 + q3q4) - my) + (_2bx * q4 - _4bz * q2) * (_2bx * (q1q3 + q2q4) + _2bz * (0.5f - q2q2 - q3q3) - mz); 246 s3 = -_2q1 * (2f * q2q4 - _2q1q3 - ax) + _2q4 * (2f * q1q2 + _2q3q4 - ay) - 4f * q3 * (1 - 2f * q2q2 - 2f * q3q3 - az) + (-_4bx * q3 - _2bz * q1) * (_2bx * (0.5f - q3q3 - q4q4) + _2bz * (q2q4 - q1q3) - mx) + (_2bx * q2 + _2bz * q4) * (_2bx * (q2q3 - q1q4) + _2bz * (q1q2 + q3q4) - my) + (_2bx * q1 - _4bz * q3) * (_2bx * (q1q3 + q2q4) + _2bz * (0.5f - q2q2 - q3q3) - mz); 247 s4 = _2q2 * (2f * q2q4 - _2q1q3 - ax) + _2q3 * (2f * q1q2 + _2q3q4 - ay) + (-_4bx * q4 + _2bz * q2) * (_2bx * (0.5f - q3q3 - q4q4) + _2bz * (q2q4 - q1q3) - mx) + (-_2bx * q1 + _2bz * q3) * (_2bx * (q2q3 - q1q4) + _2bz * (q1q2 + q3q4) - my) + _2bx * q2 * (_2bx * (q1q3 + q2q4) + _2bz * (0.5f - q2q2 - q3q3) - mz); 248 norm = 1f / (float)Mathf.Sqrt(s1 * s1 + s2 * s2 + s3 * s3 + s4 * s4); // normalise step magnitude 249 s1 *= norm; 250 s2 *= norm; 251 s3 *= norm; 252 s4 *= norm; 253 254 // Compute rate of change of quaternion 255 qDot1 = 0.5f * (-q2 * gx - q3 * gy - q4 * gz) - Beta * s1; 256 qDot2 = 0.5f * (q1 * gx + q3 * gz - q4 * gy) - Beta * s2; 257 qDot3 = 0.5f * (q1 * gy - q2 * gz + q4 * gx) - Beta * s3; 258 qDot4 = 0.5f * (q1 * gz + q2 * gy - q3 * gx) - Beta * s4; 259 260 // Integrate to yield quaternion 261 q1 += qDot1 * SamplePeriod; 262 q2 += qDot2 * SamplePeriod; 263 q3 += qDot3 * SamplePeriod; 264 q4 += qDot4 * SamplePeriod; 265 norm = 1f / (float)Mathf.Sqrt(q1 * q1 + q2 * q2 + q3 * q3 + q4 * q4); // normalise quaternion 266 quat[0] = q1 * norm; 267 quat[1] = q2 * norm; 268 quat[2] = q3 * norm; 269 quat[3] = q4 * norm; 270 */ 271 } 272 273 274} 275
Arduino Script
c_cpp
Arduino script. Courtesy of Kris Winer. Some of it is changed.
1/* MPU9250 Basic Example Code 2 by: Kris Winer 3 date: April 1, 2014 4 license: Beerware - Use this code however you'd like. If you 5 find it useful you can buy me a beer some time. 6 Modified by Brent Wilkins July 19, 2016 7 8 Demonstrate basic MPU-9250 functionality including parameterizing the register 9 addresses, initializing the sensor, getting properly scaled accelerometer, 10 gyroscope, and magnetometer data out. Added display functions to allow display 11 to on breadboard monitor. Addition of 9 DoF sensor fusion using open source 12 Madgwick and Mahony filter algorithms. Sketch runs on the 3.3 V 8 MHz Pro Mini 13 and the Teensy 3.1. 14 15 SDA and SCL should have external pull-up resistors (to 3.3V). 16 10k resistors are on the EMSENSR-9250 breakout board. 17 18 Hardware setup: 19 MPU9250 Breakout --------- Arduino 20 VDD ---------------------- 3.3V 21 VDDI --------------------- 3.3V 22 SDA ----------------------- A4 23 SCL ----------------------- A5 24 GND ---------------------- GND 25 */ 26 27#include "quaternionFilters.h" 28#include "MPU9250.h" 29 30 31#define AHRS true // Set to false for basic data read 32#define SerialDebug true // Set to true to get Serial output for debugging 33#define Information false // Set to true to get imu info 34 35// Pin definitions 36int intPin = 12; // These can be changed, 2 and 3 are the Arduinos ext int pins 37int myLed = 13; // Set up pin 13 led for toggling 38 39MPU9250 myIMU; 40 41void setup() 42{ 43 Wire.begin(); 44 // TWBR = 12; // 400 kbit/sec I2C speed 45 Serial.begin(115200); 46 47 // Set up the interrupt pin, its set as active high, push-pull 48 pinMode(intPin, INPUT); 49 digitalWrite(intPin, LOW); 50 pinMode(myLed, OUTPUT); 51 digitalWrite(myLed, HIGH); 52 53 54 // Read the WHO_AM_I register, this is a good test of communication 55 byte c = myIMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); 56 Serial.print("MPU9250 "); Serial.print("I AM "); Serial.print(c, HEX); 57 Serial.print(" I should be "); Serial.println(0x71, HEX); 58 59 60 if (c == 0x71) // WHO_AM_I should always be 0x68 61 { 62 Serial.println("MPU9250 is online..."); 63 64 // Start by performing self test and reporting values 65 myIMU.MPU9250SelfTest(myIMU.SelfTest); 66 if(Information) 67 { 68 Serial.print("x-axis self test: acceleration trim within : "); 69 Serial.print(myIMU.SelfTest[0],1); Serial.println("% of factory value"); 70 Serial.print("y-axis self test: acceleration trim within : "); 71 Serial.print(myIMU.SelfTest[1],1); Serial.println("% of factory value"); 72 Serial.print("z-axis self test: acceleration trim within : "); 73 Serial.print(myIMU.SelfTest[2],1); Serial.println("% of factory value"); 74 Serial.print("x-axis self test: gyration trim within : "); 75 Serial.print(myIMU.SelfTest[3],1); Serial.println("% of factory value"); 76 Serial.print("y-axis self test: gyration trim within : "); 77 Serial.print(myIMU.SelfTest[4],1); Serial.println("% of factory value"); 78 Serial.print("z-axis self test: gyration trim within : "); 79 Serial.print(myIMU.SelfTest[5],1); Serial.println("% of factory value"); 80 } 81 82 // Calibrate gyro and accelerometers, load biases in bias registers 83 myIMU.calibrateMPU9250(myIMU.gyroBias, myIMU.accelBias); 84 85 86 87 88 myIMU.initMPU9250(); 89 // Initialize device for active mode read of acclerometer, gyroscope, and 90 // temperature 91 Serial.println("MPU9250 initialized for active data mode...."); 92 93 // Read the WHO_AM_I register of the magnetometer, this is a good test of 94 // communication 95 byte d = myIMU.readByte(AK8963_ADDRESS, WHO_AM_I_AK8963); 96 if(Information){ 97 Serial.print("AK8963 "); Serial.print("I AM "); Serial.print(d, HEX); 98 Serial.print(" I should be "); Serial.println(0x48, HEX); 99 } 100 101 102 103 // Get magnetometer calibration from AK8963 ROM 104 myIMU.initAK8963(myIMU.magCalibration); 105 // Initialize device for active mode read of magnetometer 106 Serial.println("AK8963 initialized for active data mode...."); 107 if (SerialDebug && Information) 108 { 109 Serial.println("Calibration values: "); 110 Serial.print("X-Axis sensitivity adjustment value "); 111 Serial.println(myIMU.magCalibration[0], 2); 112 Serial.print("Y-Axis sensitivity adjustment value "); 113 Serial.println(myIMU.magCalibration[1], 2); 114 Serial.print("Z-Axis sensitivity adjustment value "); 115 Serial.println(myIMU.magCalibration[2], 2); 116 } 117 118 119 120 } // if (c == 0x71) 121 else 122 { 123 Serial.print("Could not connect to MPU9250: 0x"); 124 Serial.println(c, HEX); 125 while(1) ; // Loop forever if communication doesn't happen 126 } 127} 128 129void loop() 130{ 131 // If intPin goes high, all data registers have new data 132 // On interrupt, check if data ready interrupt 133 if (myIMU.readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01) 134 { 135 myIMU.readAccelData(myIMU.accelCount); // Read the x/y/z adc values 136 myIMU.getAres(); 137 138 // Now we'll calculate the accleration value into actual g's 139 // This depends on scale being set 140 myIMU.ax = (float)myIMU.accelCount[0]*myIMU.aRes; // - accelBias[0]; 141 myIMU.ay = (float)myIMU.accelCount[1]*myIMU.aRes; // - accelBias[1]; 142 myIMU.az = (float)myIMU.accelCount[2]*myIMU.aRes; // - accelBias[2]; 143 144 myIMU.readGyroData(myIMU.gyroCount); // Read the x/y/z adc values 145 myIMU.getGres(); 146 147 // Calculate the gyro value into actual degrees per second 148 // This depends on scale being set 149 myIMU.gx = (float)myIMU.gyroCount[0]*myIMU.gRes; 150 myIMU.gy = (float)myIMU.gyroCount[1]*myIMU.gRes; 151 myIMU.gz = (float)myIMU.gyroCount[2]*myIMU.gRes; 152 153 myIMU.readMagData(myIMU.magCount); // Read the x/y/z adc values 154 myIMU.getMres(); 155 // User environmental x-axis correction in milliGauss, should be 156 // automatically calculated 157 myIMU.magbias[0] = +470.; 158 // User environmental x-axis correction in milliGauss TODO axis?? 159 myIMU.magbias[1] = +120.; 160 // User environmental x-axis correction in milliGauss 161 myIMU.magbias[2] = +125.; 162 163 // Calculate the magnetometer values in milliGauss 164 // Include factory calibration per data sheet and user environmental 165 // corrections 166 // Get actual magnetometer value, this depends on scale being set 167 myIMU.mx = (float)myIMU.magCount[0]*myIMU.mRes*myIMU.magCalibration[0] - 168 myIMU.magbias[0]; 169 myIMU.my = (float)myIMU.magCount[1]*myIMU.mRes*myIMU.magCalibration[1] - 170 myIMU.magbias[1]; 171 myIMU.mz = (float)myIMU.magCount[2]*myIMU.mRes*myIMU.magCalibration[2] - 172 myIMU.magbias[2]; 173 } // if (readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01) 174 175 // Must be called before updating quaternions! 176 myIMU.updateTime(); 177 178 // Sensors x (y)-axis of the accelerometer is aligned with the y (x)-axis of 179 // the magnetometer; the magnetometer z-axis (+ down) is opposite to z-axis 180 // (+ up) of accelerometer and gyro! We have to make some allowance for this 181 // orientationmismatch in feeding the output to the quaternion filter. For the 182 // MPU-9250, we have chosen a magnetic rotation that keeps the sensor forward 183 // along the x-axis just like in the LSM9DS0 sensor. This rotation can be 184 // modified to allow any convenient orientation convention. This is ok by 185 // aircraft orientation standards! Pass gyro rate as rad/s 186// MadgwickQuaternionUpdate(ax, ay, az, gx*PI/180.0f, gy*PI/180.0f, gz*PI/180.0f, my, mx, mz); 187 MahonyQuaternionUpdate(myIMU.ax, myIMU.ay, myIMU.az, myIMU.gx*DEG_TO_RAD, 188 myIMU.gy*DEG_TO_RAD, myIMU.gz*DEG_TO_RAD, myIMU.my, 189 myIMU.mx, myIMU.mz, myIMU.deltat); 190 191 if (!AHRS) 192 { 193 myIMU.delt_t = millis() - myIMU.count; 194 if (myIMU.delt_t > 500) 195 { 196 if(SerialDebug) 197 { 198 // Print acceleration values in milligs! 199 Serial.print("X-acceleration: "); Serial.print(1000*myIMU.ax); 200 Serial.print(" mg "); 201 Serial.print("Y-acceleration: "); Serial.print(1000*myIMU.ay); 202 Serial.print(" mg "); 203 Serial.print("Z-acceleration: "); Serial.print(1000*myIMU.az); 204 Serial.println(" mg "); 205 206 // Print gyro values in degree/sec 207 Serial.print("X-gyro rate: "); Serial.print(myIMU.gx, 3); 208 Serial.print(" degrees/sec "); 209 Serial.print("Y-gyro rate: "); Serial.print(myIMU.gy, 3); 210 Serial.print(" degrees/sec "); 211 Serial.print("Z-gyro rate: "); Serial.print(myIMU.gz, 3); 212 Serial.println(" degrees/sec"); 213 214 // Print mag values in degree/sec 215 Serial.print("X-mag field: "); Serial.print(myIMU.mx); 216 Serial.print(" mG "); 217 Serial.print("Y-mag field: "); Serial.print(myIMU.my); 218 Serial.print(" mG "); 219 Serial.print("Z-mag field: "); Serial.print(myIMU.mz); 220 Serial.println(" mG"); 221 222 myIMU.tempCount = myIMU.readTempData(); // Read the adc values 223 // Temperature in degrees Centigrade 224 myIMU.temperature = ((float) myIMU.tempCount) / 333.87 + 21.0; 225 // Print temperature in degrees Centigrade 226 Serial.print("Temperature is "); Serial.print(myIMU.temperature, 1); 227 Serial.println(" degrees C"); 228 229 } 230 231 232 myIMU.count = millis(); 233 digitalWrite(myLed, !digitalRead(myLed)); // toggle led 234 } // if (myIMU.delt_t > 500) 235 } // if (!AHRS) 236 else 237 { 238 // Serial print and/or display at 0.5 s rate independent of data rates 239 myIMU.delt_t = millis() - myIMU.count; 240 241 // update LCD once per half-second independent of read rate 242 if (myIMU.delt_t > 500) 243 { 244 if(SerialDebug) 245 { 246 247 // time 248 Serial.print (myIMU.delt_t); 249 250 251 252 Serial.print("\ "); 253 //Serial.print("ax = "); 254 Serial.print(round((int)1000*myIMU.ax)); 255 Serial.print ("\ "); 256 //Serial.print(" ay = "); 257 Serial.print(round((int)1000*myIMU.ay )); 258 Serial.print ("\ "); 259 //Serial.print(" az = "); 260 Serial.print(round((int)1000*myIMU.az)); 261 Serial.print ("\ "); 262 //Serial.println(" mg"); 263 264 //Serial.print("gx = "); 265 Serial.print( round(myIMU.gx)); //leaves in degrees per sec 266 //* 3.14159/180)); 267 //, 2); 268 Serial.print ("\ "); 269 //Serial.print(" gy = "); 270 Serial.print(round( myIMU.gy)); 271 //* 3.14159/180)); 272 //, 2); 273 Serial.print ("\ "); 274 //Serial.print(" gz = "); 275 Serial.print( round(myIMU.gz)); 276 //* 3.14159/180)); 277 //, 2); 278 Serial.print ("\ "); 279 //Serial.println(" deg/s"); 280 281 //Serial.print("mx = "); 282 Serial.print( round((int)myIMU.mx) ); 283 Serial.print ("\ "); 284 //Serial.print(" my = "); 285 Serial.print( round((int)myIMU.my) ); 286 Serial.print ("\ "); 287 //Serial.print(" mz = "); 288 Serial.print( round((int)myIMU.mz) ); 289 //Serial.print("/t"); 290 291 /** Quarternions */ 292 /* 293 Serial.print(*getQ()); 294 Serial.print("\ "); 295 Serial.print(*(getQ() + 1)); 296 Serial.print("\ "); 297 Serial.print(*(getQ() + 2)); 298 Serial.print("\ "); 299 Serial.println(*(getQ() + 3)); 300 Serial.println(""); 301 //Serial.println(" mG"); 302*/ 303 Serial.println(""); 304 305 /* 306 Serial.print("q0 = "); Serial.print(*getQ()); 307 Serial.print(" qx = "); Serial.print(*(getQ() + 1)); 308 Serial.print(" qy = "); Serial.print(*(getQ() + 2)); 309 Serial.print(" qz = "); Serial.println(*(getQ() + 3)); 310 */ 311 312 } 313 314 315 316// Define output variables from updated quaternion---these are Tait-Bryan 317// angles, commonly used in aircraft orientation. In this coordinate system, 318// the positive z-axis is down toward Earth. Yaw is the angle between Sensor 319// x-axis and Earth magnetic North (or true North if corrected for local 320// declination, looking down on the sensor positive yaw is counterclockwise. 321// Pitch is angle between sensor x-axis and Earth ground plane, toward the 322// Earth is positive, up toward the sky is negative. Roll is angle between 323// sensor y-axis and Earth ground plane, y-axis up is positive roll. These 324// arise from the definition of the homogeneous rotation matrix constructed 325// from quaternions. Tait-Bryan angles as well as Euler angles are 326// non-commutative; that is, the get the correct orientation the rotations 327// must be applied in the correct order which for this configuration is yaw, 328// pitch, and then roll. 329// For more see 330// http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles 331// which has additional links. 332 myIMU.yaw = atan2(2.0f * (*(getQ()+1) * *(getQ()+2) + *getQ() * 333 *(getQ()+3)), *getQ() * *getQ() + *(getQ()+1) * *(getQ()+1) 334 - *(getQ()+2) * *(getQ()+2) - *(getQ()+3) * *(getQ()+3)); 335 myIMU.pitch = -asin(2.0f * (*(getQ()+1) * *(getQ()+3) - *getQ() * 336 *(getQ()+2))); 337 myIMU.roll = atan2(2.0f * (*getQ() * *(getQ()+1) + *(getQ()+2) * 338 *(getQ()+3)), *getQ() * *getQ() - *(getQ()+1) * *(getQ()+1) 339 - *(getQ()+2) * *(getQ()+2) + *(getQ()+3) * *(getQ()+3)); 340 myIMU.pitch *= RAD_TO_DEG; 341 myIMU.yaw *= RAD_TO_DEG; 342 // Declination of SparkFun Electronics (4005'26.6"N 10511'05.9"W) is 343 // 8 30' E 0 21' (or 8.5) on 2016-07-19 344 // - http://www.ngdc.noaa.gov/geomag-web/#declination 345 // Declination of XYZ place (3739'45.9"N 12150'33.3"W) 346 //(Pleasanton, California) 13.32 E 0.34 on 2018-08-29, changing by 0.10W per year 347 //myIMU.yaw -= 8.5; 348 myIMU.yaw -= 13.32; 349 myIMU.roll *= RAD_TO_DEG; 350 351 if(SerialDebug) 352 { 353 /* 354 Serial.print("Yaw, Pitch, Roll: "); 355 Serial.print(myIMU.yaw, 2); 356 Serial.print(", "); 357 Serial.print(myIMU.pitch, 2); 358 Serial.print(", "); 359 Serial.println(myIMU.roll, 2); 360*/ 361/* 362 Serial.print("rate = "); 363 Serial.print((float)myIMU.sumCount/myIMU.sum, 2); 364 Serial.println(" Hz"); 365*/ 366 367 } 368 369 myIMU.count = millis(); 370 myIMU.sumCount = 0; 371 myIMU.sum = 0; 372 } // if (myIMU.delt_t > 500) 373 } // if (AHRS) 374} 375 376
Arduino Script
c_cpp
Arduino script. Courtesy of Kris Winer. Some of it is changed.
1/* MPU9250 Basic Example Code 2 by: Kris Winer 3 date: April 1, 2014 4 5 license: Beerware - Use this code however you'd like. If you 6 find it useful 7 you can buy me a beer some time. 8 Modified by Brent Wilkins July 19, 2016 9 10 11 Demonstrate basic MPU-9250 functionality including parameterizing the register 12 13 addresses, initializing the sensor, getting properly scaled accelerometer, 14 gyroscope, 15 and magnetometer data out. Added display functions to allow display 16 to on breadboard 17 monitor. Addition of 9 DoF sensor fusion using open source 18 Madgwick and Mahony 19 filter algorithms. Sketch runs on the 3.3 V 8 MHz Pro Mini 20 and the Teensy 3.1. 21 22 23 SDA and SCL should have external pull-up resistors (to 3.3V). 24 10k resistors 25 are on the EMSENSR-9250 breakout board. 26 27 Hardware setup: 28 MPU9250 Breakout 29 --------- Arduino 30 VDD ---------------------- 3.3V 31 VDDI --------------------- 32 3.3V 33 SDA ----------------------- A4 34 SCL ----------------------- A5 35 GND 36 ---------------------- GND 37 */ 38 39#include "quaternionFilters.h" 40#include 41 "MPU9250.h" 42 43 44#define AHRS true // Set to false for basic 45 data read 46#define SerialDebug true // Set to true to get Serial output 47 for debugging 48#define Information false // Set to true to get imu info 49 50// 51 Pin definitions 52int intPin = 12; // These can be changed, 2 and 3 are the Arduinos 53 ext int pins 54int myLed = 13; // Set up pin 13 led for toggling 55 56MPU9250 57 myIMU; 58 59void setup() 60{ 61 Wire.begin(); 62 // TWBR = 12; // 400 kbit/sec 63 I2C speed 64 Serial.begin(115200); 65 66 // Set up the interrupt pin, its set 67 as active high, push-pull 68 pinMode(intPin, INPUT); 69 digitalWrite(intPin, 70 LOW); 71 pinMode(myLed, OUTPUT); 72 digitalWrite(myLed, HIGH); 73 74 75 // 76 Read the WHO_AM_I register, this is a good test of communication 77 byte c = myIMU.readByte(MPU9250_ADDRESS, 78 WHO_AM_I_MPU9250); 79 Serial.print("MPU9250 "); Serial.print("I AM "); Serial.print(c, 80 HEX); 81 Serial.print(" I should be "); Serial.println(0x71, HEX); 82 83 84 85 if (c == 0x71) // WHO_AM_I should always be 0x68 86 { 87 Serial.println("MPU9250 88 is online..."); 89 90 // Start by performing self test and reporting values 91 92 myIMU.MPU9250SelfTest(myIMU.SelfTest); 93 if(Information) 94 { 95 Serial.print("x-axis 96 self test: acceleration trim within : "); 97 Serial.print(myIMU.SelfTest[0],1); 98 Serial.println("% of factory value"); 99 Serial.print("y-axis self test: 100 acceleration trim within : "); 101 Serial.print(myIMU.SelfTest[1],1); Serial.println("% 102 of factory value"); 103 Serial.print("z-axis self test: acceleration trim within 104 : "); 105 Serial.print(myIMU.SelfTest[2],1); Serial.println("% of factory value"); 106 107 Serial.print("x-axis self test: gyration trim within : "); 108 Serial.print(myIMU.SelfTest[3],1); 109 Serial.println("% of factory value"); 110 Serial.print("y-axis self test: 111 gyration trim within : "); 112 Serial.print(myIMU.SelfTest[4],1); Serial.println("% 113 of factory value"); 114 Serial.print("z-axis self test: gyration trim within 115 : "); 116 Serial.print(myIMU.SelfTest[5],1); Serial.println("% of factory value"); 117 118 } 119 120 // Calibrate gyro and accelerometers, load biases in bias registers 121 122 myIMU.calibrateMPU9250(myIMU.gyroBias, myIMU.accelBias); 123 124 125 126 127 128 myIMU.initMPU9250(); 129 // Initialize device for active mode read of acclerometer, 130 gyroscope, and 131 // temperature 132 Serial.println("MPU9250 initialized 133 for active data mode...."); 134 135 // Read the WHO_AM_I register of the magnetometer, 136 this is a good test of 137 // communication 138 byte d = myIMU.readByte(AK8963_ADDRESS, 139 WHO_AM_I_AK8963); 140 if(Information){ 141 Serial.print("AK8963 "); Serial.print("I 142 AM "); Serial.print(d, HEX); 143 Serial.print(" I should be "); Serial.println(0x48, 144 HEX); 145 } 146 147 148 149 // Get magnetometer calibration from AK8963 ROM 150 151 myIMU.initAK8963(myIMU.magCalibration); 152 // Initialize device for active 153 mode read of magnetometer 154 Serial.println("AK8963 initialized for active 155 data mode...."); 156 if (SerialDebug && Information) 157 { 158 Serial.println("Calibration 159 values: "); 160 Serial.print("X-Axis sensitivity adjustment value "); 161 162 Serial.println(myIMU.magCalibration[0], 2); 163 Serial.print("Y-Axis 164 sensitivity adjustment value "); 165 Serial.println(myIMU.magCalibration[1], 166 2); 167 Serial.print("Z-Axis sensitivity adjustment value "); 168 Serial.println(myIMU.magCalibration[2], 169 2); 170 } 171 172 173 174 } // if (c == 0x71) 175 else 176 { 177 Serial.print("Could 178 not connect to MPU9250: 0x"); 179 Serial.println(c, HEX); 180 while(1) ; 181 // Loop forever if communication doesn't happen 182 } 183} 184 185void loop() 186{ 187 188 // If intPin goes high, all data registers have new data 189 // On interrupt, 190 check if data ready interrupt 191 if (myIMU.readByte(MPU9250_ADDRESS, INT_STATUS) 192 & 0x01) 193 { 194 myIMU.readAccelData(myIMU.accelCount); // Read the x/y/z 195 adc values 196 myIMU.getAres(); 197 198 // Now we'll calculate the accleration 199 value into actual g's 200 // This depends on scale being set 201 myIMU.ax 202 = (float)myIMU.accelCount[0]*myIMU.aRes; // - accelBias[0]; 203 myIMU.ay = (float)myIMU.accelCount[1]*myIMU.aRes; 204 // - accelBias[1]; 205 myIMU.az = (float)myIMU.accelCount[2]*myIMU.aRes; // - 206 accelBias[2]; 207 208 myIMU.readGyroData(myIMU.gyroCount); // Read the x/y/z 209 adc values 210 myIMU.getGres(); 211 212 // Calculate the gyro value into actual 213 degrees per second 214 // This depends on scale being set 215 myIMU.gx = (float)myIMU.gyroCount[0]*myIMU.gRes; 216 217 myIMU.gy = (float)myIMU.gyroCount[1]*myIMU.gRes; 218 myIMU.gz = (float)myIMU.gyroCount[2]*myIMU.gRes; 219 220 221 myIMU.readMagData(myIMU.magCount); // Read the x/y/z adc values 222 myIMU.getMres(); 223 224 // User environmental x-axis correction in milliGauss, should be 225 // automatically 226 calculated 227 myIMU.magbias[0] = +470.; 228 // User environmental x-axis 229 correction in milliGauss TODO axis?? 230 myIMU.magbias[1] = +120.; 231 // 232 User environmental x-axis correction in milliGauss 233 myIMU.magbias[2] = +125.; 234 235 236 // Calculate the magnetometer values in milliGauss 237 // Include factory 238 calibration per data sheet and user environmental 239 // corrections 240 // 241 Get actual magnetometer value, this depends on scale being set 242 myIMU.mx = 243 (float)myIMU.magCount[0]*myIMU.mRes*myIMU.magCalibration[0] - 244 myIMU.magbias[0]; 245 246 myIMU.my = (float)myIMU.magCount[1]*myIMU.mRes*myIMU.magCalibration[1] - 247 248 myIMU.magbias[1]; 249 myIMU.mz = (float)myIMU.magCount[2]*myIMU.mRes*myIMU.magCalibration[2] 250 - 251 myIMU.magbias[2]; 252 } // if (readByte(MPU9250_ADDRESS, INT_STATUS) 253 & 0x01) 254 255 // Must be called before updating quaternions! 256 myIMU.updateTime(); 257 258 259 // Sensors x (y)-axis of the accelerometer is aligned with the y (x)-axis of 260 261 // the magnetometer; the magnetometer z-axis (+ down) is opposite to z-axis 262 263 // (+ up) of accelerometer and gyro! We have to make some allowance for this 264 265 // orientationmismatch in feeding the output to the quaternion filter. For the 266 267 // MPU-9250, we have chosen a magnetic rotation that keeps the sensor forward 268 269 // along the x-axis just like in the LSM9DS0 sensor. This rotation can be 270 271 // modified to allow any convenient orientation convention. This is ok by 272 273 // aircraft orientation standards! Pass gyro rate as rad/s 274// MadgwickQuaternionUpdate(ax, 275 ay, az, gx*PI/180.0f, gy*PI/180.0f, gz*PI/180.0f, my, mx, mz); 276 MahonyQuaternionUpdate(myIMU.ax, 277 myIMU.ay, myIMU.az, myIMU.gx*DEG_TO_RAD, 278 myIMU.gy*DEG_TO_RAD, 279 myIMU.gz*DEG_TO_RAD, myIMU.my, 280 myIMU.mx, myIMU.mz, myIMU.deltat); 281 282 283 if (!AHRS) 284 { 285 myIMU.delt_t = millis() - myIMU.count; 286 if (myIMU.delt_t 287 > 500) 288 { 289 if(SerialDebug) 290 { 291 // Print acceleration 292 values in milligs! 293 Serial.print("X-acceleration: "); Serial.print(1000*myIMU.ax); 294 295 Serial.print(" mg "); 296 Serial.print("Y-acceleration: "); Serial.print(1000*myIMU.ay); 297 298 Serial.print(" mg "); 299 Serial.print("Z-acceleration: "); Serial.print(1000*myIMU.az); 300 301 Serial.println(" mg "); 302 303 // Print gyro values in degree/sec 304 305 Serial.print("X-gyro rate: "); Serial.print(myIMU.gx, 3); 306 Serial.print(" 307 degrees/sec "); 308 Serial.print("Y-gyro rate: "); Serial.print(myIMU.gy, 309 3); 310 Serial.print(" degrees/sec "); 311 Serial.print("Z-gyro 312 rate: "); Serial.print(myIMU.gz, 3); 313 Serial.println(" degrees/sec"); 314 315 316 // Print mag values in degree/sec 317 Serial.print("X-mag field: 318 "); Serial.print(myIMU.mx); 319 Serial.print(" mG "); 320 Serial.print("Y-mag 321 field: "); Serial.print(myIMU.my); 322 Serial.print(" mG "); 323 Serial.print("Z-mag 324 field: "); Serial.print(myIMU.mz); 325 Serial.println(" mG"); 326 327 328 myIMU.tempCount = myIMU.readTempData(); // Read the adc values 329 // 330 Temperature in degrees Centigrade 331 myIMU.temperature = ((float) myIMU.tempCount) 332 / 333.87 + 21.0; 333 // Print temperature in degrees Centigrade 334 Serial.print("Temperature 335 is "); Serial.print(myIMU.temperature, 1); 336 Serial.println(" degrees 337 C"); 338 339 } 340 341 342 myIMU.count = millis(); 343 digitalWrite(myLed, 344 !digitalRead(myLed)); // toggle led 345 } // if (myIMU.delt_t > 500) 346 } 347 // if (!AHRS) 348 else 349 { 350 // Serial print and/or display at 0.5 s rate 351 independent of data rates 352 myIMU.delt_t = millis() - myIMU.count; 353 354 355 // update LCD once per half-second independent of read rate 356 if (myIMU.delt_t 357 > 500) 358 { 359 if(SerialDebug) 360 { 361 362 // time 363 364 Serial.print (myIMU.delt_t); 365 366 367 368 Serial.print("\ "); 369 370 //Serial.print("ax = "); 371 Serial.print(round((int)1000*myIMU.ax)); 372 373 Serial.print ("\ "); 374 //Serial.print(" ay = "); 375 Serial.print(round((int)1000*myIMU.ay 376 )); 377 Serial.print ("\ "); 378 //Serial.print(" az = "); 379 380 Serial.print(round((int)1000*myIMU.az)); 381 Serial.print ("\ "); 382 383 //Serial.println(" mg"); 384 385 //Serial.print("gx = "); 386 387 Serial.print( round(myIMU.gx)); //leaves in degrees per sec 388 //* 389 3.14159/180)); 390 //, 2); 391 Serial.print ("\ "); 392 //Serial.print(" 393 gy = "); 394 Serial.print(round( myIMU.gy)); 395 //* 3.14159/180)); 396 397 //, 2); 398 Serial.print ("\ "); 399 //Serial.print(" 400 gz = "); 401 Serial.print( round(myIMU.gz)); 402 //* 3.14159/180)); 403 404 //, 2); 405 Serial.print ("\ "); 406 //Serial.println(" 407 deg/s"); 408 409 //Serial.print("mx = "); 410 Serial.print( round((int)myIMU.mx) 411 ); 412 Serial.print ("\ "); 413 //Serial.print(" my = "); 414 415 Serial.print( round((int)myIMU.my) ); 416 Serial.print ("\ "); 417 418 //Serial.print(" mz = "); 419 Serial.print( round((int)myIMU.mz) 420 ); 421 //Serial.print("/t"); 422 423 /** Quarternions */ 424 /* 425 426 Serial.print(*getQ()); 427 Serial.print("\ "); 428 Serial.print(*(getQ() 429 + 1)); 430 Serial.print("\ "); 431 Serial.print(*(getQ() + 2)); 432 433 Serial.print("\ "); 434 Serial.println(*(getQ() + 3)); 435 Serial.println(""); 436 437 //Serial.println(" mG"); 438*/ 439 Serial.println(""); 440 441 442 /* 443 Serial.print("q0 = "); Serial.print(*getQ()); 444 Serial.print(" 445 qx = "); Serial.print(*(getQ() + 1)); 446 Serial.print(" qy = "); Serial.print(*(getQ() 447 + 2)); 448 Serial.print(" qz = "); Serial.println(*(getQ() + 3)); 449 */ 450 451 452 } 453 454 455 456// Define output variables from updated quaternion---these 457 are Tait-Bryan 458// angles, commonly used in aircraft orientation. In this coordinate 459 system, 460// the positive z-axis is down toward Earth. Yaw is the angle between 461 Sensor 462// x-axis and Earth magnetic North (or true North if corrected for local 463// 464 declination, looking down on the sensor positive yaw is counterclockwise. 465// 466 Pitch is angle between sensor x-axis and Earth ground plane, toward the 467// Earth 468 is positive, up toward the sky is negative. Roll is angle between 469// sensor y-axis 470 and Earth ground plane, y-axis up is positive roll. These 471// arise from the definition 472 of the homogeneous rotation matrix constructed 473// from quaternions. Tait-Bryan 474 angles as well as Euler angles are 475// non-commutative; that is, the get the correct 476 orientation the rotations 477// must be applied in the correct order which for this 478 configuration is yaw, 479// pitch, and then roll. 480// For more see 481// http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles 482// 483 which has additional links. 484 myIMU.yaw = atan2(2.0f * (*(getQ()+1) * *(getQ()+2) 485 + *getQ() * 486 *(getQ()+3)), *getQ() * *getQ() + *(getQ()+1) 487 * *(getQ()+1) 488 - *(getQ()+2) * *(getQ()+2) - *(getQ()+3) * 489 *(getQ()+3)); 490 myIMU.pitch = -asin(2.0f * (*(getQ()+1) * *(getQ()+3) - *getQ() 491 * 492 *(getQ()+2))); 493 myIMU.roll = atan2(2.0f * (*getQ() 494 * *(getQ()+1) + *(getQ()+2) * 495 *(getQ()+3)), *getQ() * *getQ() 496 - *(getQ()+1) * *(getQ()+1) 497 - *(getQ()+2) * *(getQ()+2) + 498 *(getQ()+3) * *(getQ()+3)); 499 myIMU.pitch *= RAD_TO_DEG; 500 myIMU.yaw 501 *= RAD_TO_DEG; 502 // Declination of SparkFun Electronics (4005'26.6"N 503 10511'05.9"W) is 504 // 8 30' E 0 21' (or 8.5) on 2016-07-19 505 // 506 - http://www.ngdc.noaa.gov/geomag-web/#declination 507 // Declination of XYZ 508 place (3739'45.9"N 12150'33.3"W) 509 //(Pleasanton, California) 13.32 E 0.34 510 on 2018-08-29, changing by 0.10W per year 511 //myIMU.yaw -= 8.5; 512 myIMU.yaw 513 -= 13.32; 514 myIMU.roll *= RAD_TO_DEG; 515 516 if(SerialDebug) 517 { 518 519 /* 520 Serial.print("Yaw, Pitch, Roll: "); 521 Serial.print(myIMU.yaw, 522 2); 523 Serial.print(", "); 524 Serial.print(myIMU.pitch, 2); 525 526 Serial.print(", "); 527 Serial.println(myIMU.roll, 2); 528*/ 529/* 530 531 Serial.print("rate = "); 532 Serial.print((float)myIMU.sumCount/myIMU.sum, 533 2); 534 Serial.println(" Hz"); 535*/ 536 537 } 538 539 myIMU.count 540 = millis(); 541 myIMU.sumCount = 0; 542 myIMU.sum = 0; 543 } // if 544 (myIMU.delt_t > 500) 545 } // if (AHRS) 546} 547 548
Unity Run Script
csharp
actual methods that are ran and used. includes void start/void update
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using System.IO; 5using System.IO.Ports; 6 7public class DatasetParser : MonoBehaviour { 8 [Header("Serial Connect")] 9 public SerialPort sp = new SerialPort("COM3", 115200); // Change Port 10 public string rawInput = ""; 11 12 [Header("Sensitivity")] 13 public float accelerometerSensitivity = 16384f; 14 public float gyroscopeSensitivity = 131f; 15 public float magnetometerSensitivity = 0.6f; 16 public float truncateFactor = 1000; 17 18 19 [Header("Debug Mode")] 20 public bool debug; 21 [SerializeField] float axDebug = 0f; 22 [SerializeField] float ayDebug = 0f; 23 [SerializeField] float azDebug = 0f; 24 [SerializeField] float gxDebug = 0f; 25 [SerializeField] float gyDebug = 0f; 26 [SerializeField] float gzDebug = 0f; 27 [SerializeField] float mxDebug = 0f; 28 [SerializeField] float myDebug = 0f; 29 [SerializeField] float mzDebug = 0f; 30 31 // Parse parameters 32 [Header("Parsing")] 33 public TextAsset dataSet; 34 private char lineSeparator = '\n'; 35 private char fieldSeparator = '\ '; 36 37 // Info 38 private string[] rawStates; 39 public int parseIndex = 3; 40 string[] stateInfo; //used to be no public 41 float deltat; //added to read deltat from arduino code 42 43 // IMU Dataset Consts 44 [Header("IMU Processing")] 45 [SerializeField] int axIndex = 1; 46 [SerializeField] int ayIndex = 2; 47 [SerializeField] int azIndex = 3; 48 [SerializeField] int gxIndex = 7; 49 [SerializeField] int gyIndex = 8; 50 [SerializeField] int gzIndex = 9; 51 [SerializeField] int mxIndex = 10; 52 [SerializeField] int myIndex = 11; 53 [SerializeField] int mzIndex = 12; 54 55 [SerializeField] float ax = 0f; 56 [SerializeField] float ay = 0f; 57 [SerializeField] float az = 0f; 58 [SerializeField] float gx = 0f; 59 [SerializeField] float gy = 0f; 60 [SerializeField] float gz = 0f; 61 [SerializeField] float mx = 0f; 62 [SerializeField] float my = 0f; 63 [SerializeField] float mz = 0f; 64 65 [Header("Tranformation")] 66 Quaternion currRotation; 67 public Transform cube; 68 69 void Start () { 70 if (!debug) 71 { 72 sp.Open(); 73 sp.ReadTimeout = 1; 74 } 75 ParseData(); 76 //deltat = float.Parse(stateInfo[0]); 77 InvokeRepeating("HandleImu", 2f, 0.5f); //last number default 0.1f, should tecnnically be the same as delta t (0.5f seconds), now 0.25f 78 } 79 80 /*void FixedUpdate () { 81 if (debug) 82 DebugState(); 83 else 84 ReadState(); 85 UpdateCube(); 86 }*/ 87 88 void HandleImu() 89 { 90 if (debug) 91 { 92 DebugState(); 93 } 94 else 95 { 96 //ReadState(); 97 ReadFromConector(); 98 } 99 UpdateCube(); 100 } 101 102 void UpdateCube() 103 { 104 // Unity Compensation 105 currRotation = Cleaner.instance.GetQuaternionData(gz, gx, gy, az, ax, ay, mz, mx, my); 106 107 // General 108 //currRotation = Cleaner.instance.GetQuaternionData(gx, gy, gz, ax, ay, az, mx, my, mz); 109 cube.rotation = currRotation; 110 } 111 112 void DebugState() 113 { 114 ax = axDebug/* / accelerometerSensitivity*/; 115 ay = ayDebug /*/ accelerometerSensitivity*/; 116 az = azDebug/* / accelerometerSensitivity*/; 117 gx = gxDebug/* / gyroscopeSensitivity * Mathf.PI / 180*/; 118 gy = gyDebug/* / gyroscopeSensitivity * Mathf.PI / 180*/; 119 gz = gzDebug /*/ gyroscopeSensitivity * Mathf.PI / 180*/; 120 mx = mxDebug /*/ magnetometerSensitivity*/; 121 my = myDebug /*/ magnetometerSensitivity*/; 122 mz = mzDebug /*/ magnetometerSensitivity*/; 123 } 124 125 void ReadFromConector() 126 { 127 rawInput = sp.ReadLine(); 128 stateInfo = rawInput.Split('\ '); 129 print((float.Parse(stateInfo[4]) / gyroscopeSensitivity) + " " 130 + (float.Parse(stateInfo[5]) / gyroscopeSensitivity) + " " 131 + (float.Parse(stateInfo[6]) / gyroscopeSensitivity)); 132 ax = float.Parse(stateInfo[1]) / accelerometerSensitivity; 133 ay = float.Parse(stateInfo[2]) / accelerometerSensitivity; 134 az = float.Parse(stateInfo[3]) / accelerometerSensitivity; 135 gx = float.Parse(stateInfo[4]) / gyroscopeSensitivity * Mathf.PI/180; 136 gy = float.Parse(stateInfo[5]) / gyroscopeSensitivity * Mathf.PI / 180; 137 gz = float.Parse(stateInfo[6]) / gyroscopeSensitivity * Mathf.PI / 180; 138 mx = float.Parse(stateInfo[7]) / magnetometerSensitivity; 139 my = float.Parse(stateInfo[8]) / magnetometerSensitivity; 140 mz = float.Parse(stateInfo[9]) / magnetometerSensitivity; 141 142 // Truncate (sig figs?) 143 ax = Mathf.Round(ax * truncateFactor) / truncateFactor; 144 ay = Mathf.Round(ay * truncateFactor) / truncateFactor; 145 az = Mathf.Round(az * truncateFactor) / truncateFactor; 146 gx = Mathf.Round(gx * truncateFactor) / truncateFactor; 147 gy = Mathf.Round(gy * truncateFactor) / truncateFactor; 148 gz = Mathf.Round(gz * truncateFactor) / truncateFactor; 149 mx = Mathf.Round(mx * truncateFactor) / truncateFactor; 150 my = Mathf.Round(my * truncateFactor) / truncateFactor; 151 mz = Mathf.Round(mz * truncateFactor) / truncateFactor; 152 } 153 154 void ReadState() 155 { 156 if (parseIndex >= rawStates.Length) return; 157 stateInfo = rawStates[parseIndex].Split(fieldSeparator); 158 //print(stateInfo[1]); 159 ax = float.Parse(stateInfo[axIndex]) / accelerometerSensitivity; 160 ay = float.Parse(stateInfo[ayIndex]) / accelerometerSensitivity; 161 az = float.Parse(stateInfo[azIndex]) / accelerometerSensitivity; 162 gx = float.Parse(stateInfo[gxIndex]) / gyroscopeSensitivity * Mathf.PI / 180; 163 gy = float.Parse(stateInfo[gyIndex]) / gyroscopeSensitivity * Mathf.PI / 180; 164 gz = float.Parse(stateInfo[gzIndex]) / gyroscopeSensitivity * Mathf.PI / 180; 165 mx = float.Parse(stateInfo[mxIndex]) / magnetometerSensitivity; 166 my = float.Parse(stateInfo[myIndex]) / magnetometerSensitivity; 167 mz = float.Parse(stateInfo[mzIndex]) / magnetometerSensitivity; 168 //print(ax + " " + ay + " " + az + " " + gx + " " + gy + " " + gz + " " + mx + " " + my + " " + mz); 169 170 // Truncate 171 ax = Mathf.Round(ax * truncateFactor) / truncateFactor; 172 ay = Mathf.Round(ay * truncateFactor) / truncateFactor; 173 az = Mathf.Round(az * truncateFactor) / truncateFactor; 174 gx = Mathf.Round(gx * truncateFactor) / truncateFactor; 175 gy = Mathf.Round(gy * truncateFactor) / truncateFactor; 176 gz = Mathf.Round(gz * truncateFactor) / truncateFactor; 177 mx = Mathf.Round(mx * truncateFactor) / truncateFactor; 178 my = Mathf.Round(my * truncateFactor) / truncateFactor; 179 mz = Mathf.Round(mz * truncateFactor) / truncateFactor; 180 181 parseIndex++; 182 } 183 184 void ParseData() 185 { 186 rawStates = dataSet.text.Split(lineSeparator); 187 } 188} 189
SampleScene.unity
csharp
This code will probably not work as it is straight from a Unity Scene file. If you need the scene you will have to contact me and get it. I can't upload it to github as it is too big. I also don't think hackster.io supports uploading Unity files. Sorry!
1%YAML 1.1 2%TAG !u! tag:unity3d.com,2011: 3--- !u!29 &1 4OcclusionCullingSettings: 5 m_ObjectHideFlags: 0 6 serializedVersion: 2 7 m_OcclusionBakeSettings: 8 smallestOccluder: 5 9 smallestHole: 0.25 10 backfaceThreshold: 100 11 m_SceneGUID: 00000000000000000000000000000000 12 m_OcclusionCullingData: {fileID: 0} 13--- !u!104 &2 14RenderSettings: 15 m_ObjectHideFlags: 0 16 serializedVersion: 9 17 m_Fog: 0 18 m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} 19 m_FogMode: 3 20 m_FogDensity: 0.01 21 m_LinearFogStart: 0 22 m_LinearFogEnd: 300 23 m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} 24 m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} 25 m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} 26 m_AmbientIntensity: 1 27 m_AmbientMode: 0 28 m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} 29 m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} 30 m_HaloStrength: 0.5 31 m_FlareStrength: 1 32 m_FlareFadeSpeed: 3 33 m_HaloTexture: {fileID: 0} 34 m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} 35 m_DefaultReflectionMode: 0 36 m_DefaultReflectionResolution: 128 37 m_ReflectionBounces: 1 38 m_ReflectionIntensity: 1 39 m_CustomReflection: {fileID: 0} 40 m_Sun: {fileID: 0} 41 m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} 42 m_UseRadianceAmbientProbe: 0 43--- !u!157 &3 44LightmapSettings: 45 m_ObjectHideFlags: 0 46 serializedVersion: 11 47 m_GIWorkflowMode: 0 48 m_GISettings: 49 serializedVersion: 2 50 m_BounceScale: 1 51 m_IndirectOutputScale: 1 52 m_AlbedoBoost: 1 53 m_TemporalCoherenceThreshold: 1 54 m_EnvironmentLightingMode: 0 55 m_EnableBakedLightmaps: 1 56 m_EnableRealtimeLightmaps: 0 57 m_LightmapEditorSettings: 58 serializedVersion: 10 59 m_Resolution: 2 60 m_BakeResolution: 10 61 m_AtlasSize: 512 62 m_AO: 0 63 m_AOMaxDistance: 1 64 m_CompAOExponent: 1 65 m_CompAOExponentDirect: 0 66 m_Padding: 2 67 m_LightmapParameters: {fileID: 0} 68 m_LightmapsBakeMode: 1 69 m_TextureCompression: 1 70 m_FinalGather: 0 71 m_FinalGatherFiltering: 1 72 m_FinalGatherRayCount: 256 73 m_ReflectionCompression: 2 74 m_MixedBakeMode: 2 75 m_BakeBackend: 1 76 m_PVRSampling: 1 77 m_PVRDirectSampleCount: 32 78 m_PVRSampleCount: 256 79 m_PVRBounces: 2 80 m_PVRFilterTypeDirect: 0 81 m_PVRFilterTypeIndirect: 0 82 m_PVRFilterTypeAO: 0 83 m_PVRFilteringMode: 1 84 m_PVRCulling: 1 85 m_PVRFilteringGaussRadiusDirect: 1 86 m_PVRFilteringGaussRadiusIndirect: 5 87 m_PVRFilteringGaussRadiusAO: 2 88 m_PVRFilteringAtrousPositionSigmaDirect: 0.5 89 m_PVRFilteringAtrousPositionSigmaIndirect: 2 90 m_PVRFilteringAtrousPositionSigmaAO: 1 91 m_ShowResolutionOverlay: 1 92 m_LightingDataAsset: {fileID: 0} 93 m_UseShadowmask: 1 94--- !u!196 &4 95NavMeshSettings: 96 serializedVersion: 2 97 m_ObjectHideFlags: 0 98 m_BuildSettings: 99 serializedVersion: 2 100 agentTypeID: 0 101 agentRadius: 0.5 102 agentHeight: 2 103 agentSlope: 45 104 agentClimb: 0.4 105 ledgeDropHeight: 0 106 maxJumpAcrossDistance: 0 107 minRegionArea: 2 108 manualCellSize: 0 109 cellSize: 0.16666667 110 manualTileSize: 0 111 tileSize: 256 112 accuratePlacement: 0 113 debug: 114 m_Flags: 0 115 m_NavMeshData: {fileID: 0} 116--- !u!1 &170076733 117GameObject: 118 m_ObjectHideFlags: 0 119 m_CorrespondingSourceObject: {fileID: 0} 120 m_PrefabInternal: {fileID: 0} 121 serializedVersion: 6 122 m_Component: 123 - component: {fileID: 170076735} 124 - component: {fileID: 170076734} 125 m_Layer: 0 126 m_Name: Directional Light 127 m_TagString: Untagged 128 m_Icon: {fileID: 0} 129 m_NavMeshLayer: 0 130 m_StaticEditorFlags: 0 131 m_IsActive: 1 132--- !u!108 &170076734 133Light: 134 m_ObjectHideFlags: 0 135 m_CorrespondingSourceObject: {fileID: 0} 136 m_PrefabInternal: {fileID: 0} 137 m_GameObject: {fileID: 170076733} 138 m_Enabled: 1 139 serializedVersion: 8 140 m_Type: 1 141 m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} 142 m_Intensity: 1 143 m_Range: 10 144 m_SpotAngle: 30 145 m_CookieSize: 10 146 m_Shadows: 147 m_Type: 2 148 m_Resolution: -1 149 m_CustomResolution: -1 150 m_Strength: 1 151 m_Bias: 0.05 152 m_NormalBias: 0.4 153 m_NearPlane: 0.2 154 m_Cookie: {fileID: 0} 155 m_DrawHalo: 0 156 m_Flare: {fileID: 0} 157 m_RenderMode: 0 158 m_CullingMask: 159 serializedVersion: 2 160 m_Bits: 4294967295 161 m_Lightmapping: 1 162 m_LightShadowCasterMode: 0 163 m_AreaSize: {x: 1, y: 1} 164 m_BounceIntensity: 1 165 m_ColorTemperature: 6570 166 m_UseColorTemperature: 0 167 m_ShadowRadius: 0 168 m_ShadowAngle: 0 169--- !u!4 &170076735 170Transform: 171 m_ObjectHideFlags: 0 172 m_CorrespondingSourceObject: {fileID: 0} 173 m_PrefabInternal: {fileID: 0} 174 m_GameObject: {fileID: 170076733} 175 m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} 176 m_LocalPosition: {x: 0, y: 3, z: 0} 177 m_LocalScale: {x: 1, y: 1, z: 1} 178 m_Children: [] 179 m_Father: {fileID: 0} 180 m_RootOrder: 1 181 m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} 182--- !u!1 &282840810 183GameObject: 184 m_ObjectHideFlags: 0 185 m_CorrespondingSourceObject: {fileID: 0} 186 m_PrefabInternal: {fileID: 0} 187 serializedVersion: 6 188 m_Component: 189 - component: {fileID: 282840814} 190 - component: {fileID: 282840813} 191 - component: {fileID: 282840811} 192 m_Layer: 0 193 m_Name: Main Camera 194 m_TagString: MainCamera 195 m_Icon: {fileID: 0} 196 m_NavMeshLayer: 0 197 m_StaticEditorFlags: 0 198 m_IsActive: 1 199--- !u!81 &282840811 200AudioListener: 201 m_ObjectHideFlags: 0 202 m_CorrespondingSourceObject: {fileID: 0} 203 m_PrefabInternal: {fileID: 0} 204 m_GameObject: {fileID: 282840810} 205 m_Enabled: 1 206--- !u!20 &282840813 207Camera: 208 m_ObjectHideFlags: 0 209 m_CorrespondingSourceObject: {fileID: 0} 210 m_PrefabInternal: {fileID: 0} 211 m_GameObject: {fileID: 282840810} 212 m_Enabled: 1 213 serializedVersion: 2 214 m_ClearFlags: 1 215 m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} 216 m_projectionMatrixMode: 1 217 m_SensorSize: {x: 36, y: 24} 218 m_LensShift: {x: 0, y: 0} 219 m_FocalLength: 50 220 m_NormalizedViewPortRect: 221 serializedVersion: 2 222 x: 0 223 y: 0 224 width: 1 225 height: 1 226 near clip plane: 0.3 227 far clip plane: 1000 228 field of view: 60 229 orthographic: 0 230 orthographic size: 5 231 m_Depth: -1 232 m_CullingMask: 233 serializedVersion: 2 234 m_Bits: 4294967295 235 m_RenderingPath: -1 236 m_TargetTexture: {fileID: 0} 237 m_TargetDisplay: 0 238 m_TargetEye: 3 239 m_HDR: 1 240 m_AllowMSAA: 1 241 m_AllowDynamicResolution: 0 242 m_ForceIntoRT: 1 243 m_OcclusionCulling: 1 244 m_StereoConvergence: 10 245 m_StereoSeparation: 0.022 246--- !u!4 &282840814 247Transform: 248 m_ObjectHideFlags: 0 249 m_CorrespondingSourceObject: {fileID: 0} 250 m_PrefabInternal: {fileID: 0} 251 m_GameObject: {fileID: 282840810} 252 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 253 m_LocalPosition: {x: 0, y: 1, z: -10} 254 m_LocalScale: {x: 1, y: 1, z: 1} 255 m_Children: [] 256 m_Father: {fileID: 0} 257 m_RootOrder: 0 258 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 259--- !u!1 &359781717 260GameObject: 261 m_ObjectHideFlags: 0 262 m_CorrespondingSourceObject: {fileID: 0} 263 m_PrefabInternal: {fileID: 0} 264 serializedVersion: 6 265 m_Component: 266 - component: {fileID: 359781721} 267 - component: {fileID: 359781720} 268 - component: {fileID: 359781719} 269 - component: {fileID: 359781718} 270 m_Layer: 0 271 m_Name: Cube 272 m_TagString: Untagged 273 m_Icon: {fileID: 0} 274 m_NavMeshLayer: 0 275 m_StaticEditorFlags: 0 276 m_IsActive: 1 277--- !u!65 &359781718 278BoxCollider: 279 m_ObjectHideFlags: 0 280 m_CorrespondingSourceObject: {fileID: 0} 281 m_PrefabInternal: {fileID: 0} 282 m_GameObject: {fileID: 359781717} 283 m_Material: {fileID: 0} 284 m_IsTrigger: 0 285 m_Enabled: 1 286 serializedVersion: 2 287 m_Size: {x: 1, y: 1, z: 1} 288 m_Center: {x: 0, y: 0, z: 0} 289--- !u!23 &359781719 290MeshRenderer: 291 m_ObjectHideFlags: 0 292 m_CorrespondingSourceObject: {fileID: 0} 293 m_PrefabInternal: {fileID: 0} 294 m_GameObject: {fileID: 359781717} 295 m_Enabled: 1 296 m_CastShadows: 1 297 m_ReceiveShadows: 1 298 m_DynamicOccludee: 1 299 m_MotionVectors: 1 300 m_LightProbeUsage: 1 301 m_ReflectionProbeUsage: 1 302 m_RenderingLayerMask: 4294967295 303 m_Materials: 304 - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} 305 m_StaticBatchInfo: 306 firstSubMesh: 0 307 subMeshCount: 0 308 m_StaticBatchRoot: {fileID: 0} 309 m_ProbeAnchor: {fileID: 0} 310 m_LightProbeVolumeOverride: {fileID: 0} 311 m_ScaleInLightmap: 1 312 m_PreserveUVs: 0 313 m_IgnoreNormalsForChartDetection: 0 314 m_ImportantGI: 0 315 m_StitchLightmapSeams: 0 316 m_SelectedEditorRenderState: 3 317 m_MinimumChartSize: 4 318 m_AutoUVMaxDistance: 0.5 319 m_AutoUVMaxAngle: 89 320 m_LightmapParameters: {fileID: 0} 321 m_SortingLayerID: 0 322 m_SortingLayer: 0 323 m_SortingOrder: 0 324--- !u!33 &359781720 325MeshFilter: 326 m_ObjectHideFlags: 0 327 m_CorrespondingSourceObject: {fileID: 0} 328 m_PrefabInternal: {fileID: 0} 329 m_GameObject: {fileID: 359781717} 330 m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} 331--- !u!4 &359781721 332Transform: 333 m_ObjectHideFlags: 0 334 m_CorrespondingSourceObject: {fileID: 0} 335 m_PrefabInternal: {fileID: 0} 336 m_GameObject: {fileID: 359781717} 337 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 338 m_LocalPosition: {x: 0, y: 0, z: 0} 339 m_LocalScale: {x: 1, y: 0.2260268, z: 2.0065644} 340 m_Children: [] 341 m_Father: {fileID: 0} 342 m_RootOrder: 3 343 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 344--- !u!1 &618750917 345GameObject: 346 m_ObjectHideFlags: 0 347 m_CorrespondingSourceObject: {fileID: 0} 348 m_PrefabInternal: {fileID: 0} 349 serializedVersion: 6 350 m_Component: 351 - component: {fileID: 618750918} 352 - component: {fileID: 618750919} 353 m_Layer: 0 354 m_Name: Right Hand 355 m_TagString: Untagged 356 m_Icon: {fileID: 0} 357 m_NavMeshLayer: 0 358 m_StaticEditorFlags: 0 359 m_IsActive: 1 360--- !u!4 &618750918 361Transform: 362 m_ObjectHideFlags: 0 363 m_CorrespondingSourceObject: {fileID: 0} 364 m_PrefabInternal: {fileID: 0} 365 m_GameObject: {fileID: 618750917} 366 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 367 m_LocalPosition: {x: 0, y: 0, z: 0} 368 m_LocalScale: {x: 1, y: 1, z: 1} 369 m_Children: 370 - {fileID: 638365778} 371 - {fileID: 1834950146} 372 - {fileID: 1342024134} 373 - {fileID: 1156108526} 374 - {fileID: 2126949329} 375 - {fileID: 649102870} 376 m_Father: {fileID: 1634297806} 377 m_RootOrder: 1 378 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 379--- !u!114 &618750919 380MonoBehaviour: 381 m_ObjectHideFlags: 0 382 m_CorrespondingSourceObject: {fileID: 0} 383 m_PrefabInternal: {fileID: 0} 384 m_GameObject: {fileID: 618750917} 385 m_Enabled: 1 386 m_EditorHideFlags: 0 387 m_Script: {fileID: 11500000, guid: 97d3efc7a87236943b45c903b94f56f1, type: 3} 388 m_Name: 389 m_EditorClassIdentifier: 390 jointType: 1 391 wrist: {fileID: 638365779} 392 thumb: {fileID: 1834950147} 393 index: {fileID: 1342024135} 394 middle: {fileID: 1156108527} 395 ring: {fileID: 2126949330} 396 pinky: {fileID: 649102871} 397--- !u!1 &638365777 398GameObject: 399 m_ObjectHideFlags: 0 400 m_CorrespondingSourceObject: {fileID: 0} 401 m_PrefabInternal: {fileID: 0} 402 serializedVersion: 6 403 m_Component: 404 - component: {fileID: 638365778} 405 - component: {fileID: 638365779} 406 m_Layer: 0 407 m_Name: Wrist 408 m_TagString: Untagged 409 m_Icon: {fileID: 0} 410 m_NavMeshLayer: 0 411 m_StaticEditorFlags: 0 412 m_IsActive: 1 413--- !u!4 &638365778 414Transform: 415 m_ObjectHideFlags: 0 416 m_CorrespondingSourceObject: {fileID: 0} 417 m_PrefabInternal: {fileID: 0} 418 m_GameObject: {fileID: 638365777} 419 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 420 m_LocalPosition: {x: 0, y: 0, z: 0} 421 m_LocalScale: {x: 1, y: 1, z: 1} 422 m_Children: [] 423 m_Father: {fileID: 618750918} 424 m_RootOrder: 0 425 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 426--- !u!114 &638365779 427MonoBehaviour: 428 m_ObjectHideFlags: 0 429 m_CorrespondingSourceObject: {fileID: 0} 430 m_PrefabInternal: {fileID: 0} 431 m_GameObject: {fileID: 638365777} 432 m_Enabled: 1 433 m_EditorHideFlags: 0 434 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 435 m_Name: 436 m_EditorClassIdentifier: 437 jointType: 7 438 rotationValues: {x: 0, y: 0, z: 0} 439--- !u!1 &649102869 440GameObject: 441 m_ObjectHideFlags: 0 442 m_CorrespondingSourceObject: {fileID: 0} 443 m_PrefabInternal: {fileID: 0} 444 serializedVersion: 6 445 m_Component: 446 - component: {fileID: 649102870} 447 - component: {fileID: 649102871} 448 m_Layer: 0 449 m_Name: Pinky 450 m_TagString: Untagged 451 m_Icon: {fileID: 0} 452 m_NavMeshLayer: 0 453 m_StaticEditorFlags: 0 454 m_IsActive: 1 455--- !u!4 &649102870 456Transform: 457 m_ObjectHideFlags: 0 458 m_CorrespondingSourceObject: {fileID: 0} 459 m_PrefabInternal: {fileID: 0} 460 m_GameObject: {fileID: 649102869} 461 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 462 m_LocalPosition: {x: 0, y: 0, z: 0} 463 m_LocalScale: {x: 1, y: 1, z: 1} 464 m_Children: [] 465 m_Father: {fileID: 618750918} 466 m_RootOrder: 5 467 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 468--- !u!114 &649102871 469MonoBehaviour: 470 m_ObjectHideFlags: 0 471 m_CorrespondingSourceObject: {fileID: 0} 472 m_PrefabInternal: {fileID: 0} 473 m_GameObject: {fileID: 649102869} 474 m_Enabled: 1 475 m_EditorHideFlags: 0 476 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 477 m_Name: 478 m_EditorClassIdentifier: 479 jointType: 6 480 rotationValues: {x: 0, y: 0, z: 0} 481--- !u!1 &715455438 482GameObject: 483 m_ObjectHideFlags: 0 484 m_CorrespondingSourceObject: {fileID: 0} 485 m_PrefabInternal: {fileID: 0} 486 serializedVersion: 6 487 m_Component: 488 - component: {fileID: 715455439} 489 - component: {fileID: 715455440} 490 m_Layer: 0 491 m_Name: Ring 492 m_TagString: Untagged 493 m_Icon: {fileID: 0} 494 m_NavMeshLayer: 0 495 m_StaticEditorFlags: 0 496 m_IsActive: 1 497--- !u!4 &715455439 498Transform: 499 m_ObjectHideFlags: 0 500 m_CorrespondingSourceObject: {fileID: 0} 501 m_PrefabInternal: {fileID: 0} 502 m_GameObject: {fileID: 715455438} 503 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 504 m_LocalPosition: {x: 0, y: 0, z: 0} 505 m_LocalScale: {x: 1, y: 1, z: 1} 506 m_Children: [] 507 m_Father: {fileID: 1375661944} 508 m_RootOrder: 4 509 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 510--- !u!114 &715455440 511MonoBehaviour: 512 m_ObjectHideFlags: 0 513 m_CorrespondingSourceObject: {fileID: 0} 514 m_PrefabInternal: {fileID: 0} 515 m_GameObject: {fileID: 715455438} 516 m_Enabled: 1 517 m_EditorHideFlags: 0 518 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 519 m_Name: 520 m_EditorClassIdentifier: 521 jointType: 5 522 rotationValues: {x: 0, y: 0, z: 0} 523--- !u!1 &1156108525 524GameObject: 525 m_ObjectHideFlags: 0 526 m_CorrespondingSourceObject: {fileID: 0} 527 m_PrefabInternal: {fileID: 0} 528 serializedVersion: 6 529 m_Component: 530 - component: {fileID: 1156108526} 531 - component: {fileID: 1156108527} 532 m_Layer: 0 533 m_Name: Middle 534 m_TagString: Untagged 535 m_Icon: {fileID: 0} 536 m_NavMeshLayer: 0 537 m_StaticEditorFlags: 0 538 m_IsActive: 1 539--- !u!4 &1156108526 540Transform: 541 m_ObjectHideFlags: 0 542 m_CorrespondingSourceObject: {fileID: 0} 543 m_PrefabInternal: {fileID: 0} 544 m_GameObject: {fileID: 1156108525} 545 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 546 m_LocalPosition: {x: 0, y: 0, z: 0} 547 m_LocalScale: {x: 1, y: 1, z: 1} 548 m_Children: [] 549 m_Father: {fileID: 618750918} 550 m_RootOrder: 3 551 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 552--- !u!114 &1156108527 553MonoBehaviour: 554 m_ObjectHideFlags: 0 555 m_CorrespondingSourceObject: {fileID: 0} 556 m_PrefabInternal: {fileID: 0} 557 m_GameObject: {fileID: 1156108525} 558 m_Enabled: 1 559 m_EditorHideFlags: 0 560 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 561 m_Name: 562 m_EditorClassIdentifier: 563 jointType: 4 564 rotationValues: {x: 0, y: 0, z: 0} 565--- !u!1 &1182598610 566GameObject: 567 m_ObjectHideFlags: 0 568 m_CorrespondingSourceObject: {fileID: 0} 569 m_PrefabInternal: {fileID: 0} 570 serializedVersion: 6 571 m_Component: 572 - component: {fileID: 1182598611} 573 - component: {fileID: 1182598612} 574 m_Layer: 0 575 m_Name: Middle 576 m_TagString: Untagged 577 m_Icon: {fileID: 0} 578 m_NavMeshLayer: 0 579 m_StaticEditorFlags: 0 580 m_IsActive: 1 581--- !u!4 &1182598611 582Transform: 583 m_ObjectHideFlags: 0 584 m_CorrespondingSourceObject: {fileID: 0} 585 m_PrefabInternal: {fileID: 0} 586 m_GameObject: {fileID: 1182598610} 587 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 588 m_LocalPosition: {x: 0, y: 0, z: 0} 589 m_LocalScale: {x: 1, y: 1, z: 1} 590 m_Children: [] 591 m_Father: {fileID: 1375661944} 592 m_RootOrder: 3 593 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 594--- !u!114 &1182598612 595MonoBehaviour: 596 m_ObjectHideFlags: 0 597 m_CorrespondingSourceObject: {fileID: 0} 598 m_PrefabInternal: {fileID: 0} 599 m_GameObject: {fileID: 1182598610} 600 m_Enabled: 1 601 m_EditorHideFlags: 0 602 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 603 m_Name: 604 m_EditorClassIdentifier: 605 jointType: 4 606 rotationValues: {x: 0, y: 0, z: 0} 607--- !u!1 &1342024133 608GameObject: 609 m_ObjectHideFlags: 0 610 m_CorrespondingSourceObject: {fileID: 0} 611 m_PrefabInternal: {fileID: 0} 612 serializedVersion: 6 613 m_Component: 614 - component: {fileID: 1342024134} 615 - component: {fileID: 1342024135} 616 m_Layer: 0 617 m_Name: Index 618 m_TagString: Untagged 619 m_Icon: {fileID: 0} 620 m_NavMeshLayer: 0 621 m_StaticEditorFlags: 0 622 m_IsActive: 1 623--- !u!4 &1342024134 624Transform: 625 m_ObjectHideFlags: 0 626 m_CorrespondingSourceObject: {fileID: 0} 627 m_PrefabInternal: {fileID: 0} 628 m_GameObject: {fileID: 1342024133} 629 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 630 m_LocalPosition: {x: 0, y: 0, z: 0} 631 m_LocalScale: {x: 1, y: 1, z: 1} 632 m_Children: [] 633 m_Father: {fileID: 618750918} 634 m_RootOrder: 2 635 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 636--- !u!114 &1342024135 637MonoBehaviour: 638 m_ObjectHideFlags: 0 639 m_CorrespondingSourceObject: {fileID: 0} 640 m_PrefabInternal: {fileID: 0} 641 m_GameObject: {fileID: 1342024133} 642 m_Enabled: 1 643 m_EditorHideFlags: 0 644 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 645 m_Name: 646 m_EditorClassIdentifier: 647 jointType: 3 648 rotationValues: {x: 0, y: 0, z: 0} 649--- !u!1 &1375661943 650GameObject: 651 m_ObjectHideFlags: 0 652 m_CorrespondingSourceObject: {fileID: 0} 653 m_PrefabInternal: {fileID: 0} 654 serializedVersion: 6 655 m_Component: 656 - component: {fileID: 1375661944} 657 - component: {fileID: 1375661945} 658 m_Layer: 0 659 m_Name: Left Hand 660 m_TagString: Untagged 661 m_Icon: {fileID: 0} 662 m_NavMeshLayer: 0 663 m_StaticEditorFlags: 0 664 m_IsActive: 1 665--- !u!4 &1375661944 666Transform: 667 m_ObjectHideFlags: 0 668 m_CorrespondingSourceObject: {fileID: 0} 669 m_PrefabInternal: {fileID: 0} 670 m_GameObject: {fileID: 1375661943} 671 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 672 m_LocalPosition: {x: 0, y: 0, z: 0} 673 m_LocalScale: {x: 1, y: 1, z: 1} 674 m_Children: 675 - {fileID: 2139301569} 676 - {fileID: 1920256460} 677 - {fileID: 1734569599} 678 - {fileID: 1182598611} 679 - {fileID: 715455439} 680 - {fileID: 1489611121} 681 m_Father: {fileID: 1634297806} 682 m_RootOrder: 0 683 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 684--- !u!114 &1375661945 685MonoBehaviour: 686 m_ObjectHideFlags: 0 687 m_CorrespondingSourceObject: {fileID: 0} 688 m_PrefabInternal: {fileID: 0} 689 m_GameObject: {fileID: 1375661943} 690 m_Enabled: 1 691 m_EditorHideFlags: 0 692 m_Script: {fileID: 11500000, guid: 97d3efc7a87236943b45c903b94f56f1, type: 3} 693 m_Name: 694 m_EditorClassIdentifier: 695 jointType: 0 696 wrist: {fileID: 2139301570} 697 thumb: {fileID: 1920256461} 698 index: {fileID: 1734569600} 699 middle: {fileID: 1182598612} 700 ring: {fileID: 715455440} 701 pinky: {fileID: 1489611122} 702--- !u!1 &1489611120 703GameObject: 704 m_ObjectHideFlags: 0 705 m_CorrespondingSourceObject: {fileID: 0} 706 m_PrefabInternal: {fileID: 0} 707 serializedVersion: 6 708 m_Component: 709 - component: {fileID: 1489611121} 710 - component: {fileID: 1489611122} 711 m_Layer: 0 712 m_Name: Pinky 713 m_TagString: Untagged 714 m_Icon: {fileID: 0} 715 m_NavMeshLayer: 0 716 m_StaticEditorFlags: 0 717 m_IsActive: 1 718--- !u!4 &1489611121 719Transform: 720 m_ObjectHideFlags: 0 721 m_CorrespondingSourceObject: {fileID: 0} 722 m_PrefabInternal: {fileID: 0} 723 m_GameObject: {fileID: 1489611120} 724 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 725 m_LocalPosition: {x: 0, y: 0, z: 0} 726 m_LocalScale: {x: 1, y: 1, z: 1} 727 m_Children: [] 728 m_Father: {fileID: 1375661944} 729 m_RootOrder: 5 730 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 731--- !u!114 &1489611122 732MonoBehaviour: 733 m_ObjectHideFlags: 0 734 m_CorrespondingSourceObject: {fileID: 0} 735 m_PrefabInternal: {fileID: 0} 736 m_GameObject: {fileID: 1489611120} 737 m_Enabled: 1 738 m_EditorHideFlags: 0 739 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 740 m_Name: 741 m_EditorClassIdentifier: 742 jointType: 6 743 rotationValues: {x: 0, y: 0, z: 0} 744--- !u!1 &1634297804 745GameObject: 746 m_ObjectHideFlags: 0 747 m_CorrespondingSourceObject: {fileID: 0} 748 m_PrefabInternal: {fileID: 0} 749 serializedVersion: 6 750 m_Component: 751 - component: {fileID: 1634297806} 752 - component: {fileID: 1634297805} 753 - component: {fileID: 1634297807} 754 - component: {fileID: 1634297809} 755 - component: {fileID: 1634297808} 756 m_Layer: 0 757 m_Name: Manager 758 m_TagString: Untagged 759 m_Icon: {fileID: 0} 760 m_NavMeshLayer: 0 761 m_StaticEditorFlags: 0 762 m_IsActive: 1 763--- !u!114 &1634297805 764MonoBehaviour: 765 m_ObjectHideFlags: 0 766 m_CorrespondingSourceObject: {fileID: 0} 767 m_PrefabInternal: {fileID: 0} 768 m_GameObject: {fileID: 1634297804} 769 m_Enabled: 0 770 m_EditorHideFlags: 0 771 m_Script: {fileID: 11500000, guid: 69efc1ee053c2584bb05fc39be1dc2fa, type: 3} 772 m_Name: 773 m_EditorClassIdentifier: 774 debugInput: 0 775 rawInput: "<leftHand> \ <wrist>12,12,12</wrist> \ <thumb>12,12,12</thumb> \ <index>12,12,12</index> 776 \ <middle>12,12,12</middle> \ <ring>12,12,12</ring> \ <pinky>12,12,12</pinky> 777 </leftHand> <rightHand> \ <wrist>12,12,12</wrist> \ <thumb>12,12,12</thumb> \ <index>12,12,12</index> 778 \ <middle>12,12,12</middle> \ <ring>12,12,12</ring> \ <pinky>12,12,12</pinky> 779 </rightHand>" 780 separators: 781 - ',' 782 leftHand: {fileID: 1375661945} 783 rightHand: {fileID: 618750919} 784--- !u!4 &1634297806 785Transform: 786 m_ObjectHideFlags: 0 787 m_CorrespondingSourceObject: {fileID: 0} 788 m_PrefabInternal: {fileID: 0} 789 m_GameObject: {fileID: 1634297804} 790 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 791 m_LocalPosition: {x: 0, y: 0, z: 0} 792 m_LocalScale: {x: 1, y: 1, z: 1} 793 m_Children: 794 - {fileID: 1375661944} 795 - {fileID: 618750918} 796 m_Father: {fileID: 0} 797 m_RootOrder: 2 798 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 799--- !u!114 &1634297807 800MonoBehaviour: 801 m_ObjectHideFlags: 0 802 m_CorrespondingSourceObject: {fileID: 0} 803 m_PrefabInternal: {fileID: 0} 804 m_GameObject: {fileID: 1634297804} 805 m_Enabled: 1 806 m_EditorHideFlags: 0 807 m_Script: {fileID: 11500000, guid: f95131f0b00481045aecb0720acf8392, type: 3} 808 m_Name: 809 m_EditorClassIdentifier: 810 SamplePeriod: 512 811 Beta: 20 812 quat: 813 - 1 814 - 0 815 - 0 816 - 0 817--- !u!114 &1634297808 818MonoBehaviour: 819 m_ObjectHideFlags: 0 820 m_CorrespondingSourceObject: {fileID: 0} 821 m_PrefabInternal: {fileID: 0} 822 m_GameObject: {fileID: 1634297804} 823 m_Enabled: 0 824 m_EditorHideFlags: 0 825 m_Script: {fileID: 11500000, guid: 423e01db97df98b4e9eb0352ebc16864, type: 3} 826 m_Name: 827 m_EditorClassIdentifier: 828 rawInput: 829 accelerometerSensitivity: 16384 830 gyroscopeSensitivity: 131 831 magnetometerSensitivity: 0.6 832 truncateFactor: 1000 833 debug: 0 834 axDebug: 0 835 ayDebug: 0 836 azDebug: 0 837 gxDebug: 0 838 gyDebug: 0 839 gzDebug: 0 840 mxDebug: 0 841 myDebug: 0 842 mzDebug: 0 843 dataSet: {fileID: 4900000, guid: ff342d1bba19e9c48a249264ed593c82, type: 3} 844 parseIndex: 3 845 axIndex: 1 846 ayIndex: 2 847 azIndex: 3 848 gxIndex: 7 849 gyIndex: 8 850 gzIndex: 9 851 mxIndex: 10 852 myIndex: 11 853 mzIndex: 12 854 ax: 0 855 ay: 0 856 az: 0 857 gx: 0 858 gy: 0 859 gz: 0 860 mx: 0 861 my: 0 862 mz: 0 863 cube: {fileID: 359781721} 864--- !u!114 &1634297809 865MonoBehaviour: 866 m_ObjectHideFlags: 0 867 m_CorrespondingSourceObject: {fileID: 0} 868 m_PrefabInternal: {fileID: 0} 869 m_GameObject: {fileID: 1634297804} 870 m_Enabled: 1 871 m_EditorHideFlags: 0 872 m_Script: {fileID: 11500000, guid: 5301478171ed98d4c957c7fe59f725ff, type: 3} 873 m_Name: 874 m_EditorClassIdentifier: 875 rawInput: 876 accelerometerSensitivity: 16384 877 gyroscopeSensitivity: 131 878 magnetometerSensitivity: 0.6 879 truncateFactor: 100 880 debug: 0 881 axDebug: 1 882 ayDebug: 0 883 azDebug: 0 884 gxDebug: 0 885 gyDebug: 0 886 gzDebug: 0 887 mxDebug: 1 888 myDebug: 0 889 mzDebug: 0 890 dataSet: {fileID: 4900000, guid: ff342d1bba19e9c48a249264ed593c82, type: 3} 891 parseIndex: 2500 892 axIndex: 1 893 ayIndex: 2 894 azIndex: 3 895 gxIndex: 7 896 gyIndex: 8 897 gzIndex: 9 898 mxIndex: 10 899 myIndex: 11 900 mzIndex: 12 901 ax: 0 902 ay: 0 903 az: 0 904 gx: 0 905 gy: 0 906 gz: 0 907 mx: 0 908 my: 0 909 mz: 0 910 cube: {fileID: 359781721} 911--- !u!1 &1734569598 912GameObject: 913 m_ObjectHideFlags: 0 914 m_CorrespondingSourceObject: {fileID: 0} 915 m_PrefabInternal: {fileID: 0} 916 serializedVersion: 6 917 m_Component: 918 - component: {fileID: 1734569599} 919 - component: {fileID: 1734569600} 920 m_Layer: 0 921 m_Name: Index 922 m_TagString: Untagged 923 m_Icon: {fileID: 0} 924 m_NavMeshLayer: 0 925 m_StaticEditorFlags: 0 926 m_IsActive: 1 927--- !u!4 &1734569599 928Transform: 929 m_ObjectHideFlags: 0 930 m_CorrespondingSourceObject: {fileID: 0} 931 m_PrefabInternal: {fileID: 0} 932 m_GameObject: {fileID: 1734569598} 933 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 934 m_LocalPosition: {x: 0, y: 0, z: 0} 935 m_LocalScale: {x: 1, y: 1, z: 1} 936 m_Children: [] 937 m_Father: {fileID: 1375661944} 938 m_RootOrder: 2 939 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 940--- !u!114 &1734569600 941MonoBehaviour: 942 m_ObjectHideFlags: 0 943 m_CorrespondingSourceObject: {fileID: 0} 944 m_PrefabInternal: {fileID: 0} 945 m_GameObject: {fileID: 1734569598} 946 m_Enabled: 1 947 m_EditorHideFlags: 0 948 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 949 m_Name: 950 m_EditorClassIdentifier: 951 jointType: 3 952 rotationValues: {x: 0, y: 0, z: 0} 953--- !u!1 &1834950145 954GameObject: 955 m_ObjectHideFlags: 0 956 m_CorrespondingSourceObject: {fileID: 0} 957 m_PrefabInternal: {fileID: 0} 958 serializedVersion: 6 959 m_Component: 960 - component: {fileID: 1834950146} 961 - component: {fileID: 1834950147} 962 m_Layer: 0 963 m_Name: Thumb 964 m_TagString: Untagged 965 m_Icon: {fileID: 0} 966 m_NavMeshLayer: 0 967 m_StaticEditorFlags: 0 968 m_IsActive: 1 969--- !u!4 &1834950146 970Transform: 971 m_ObjectHideFlags: 0 972 m_CorrespondingSourceObject: {fileID: 0} 973 m_PrefabInternal: {fileID: 0} 974 m_GameObject: {fileID: 1834950145} 975 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 976 m_LocalPosition: {x: 0, y: 0, z: 0} 977 m_LocalScale: {x: 1, y: 1, z: 1} 978 m_Children: [] 979 m_Father: {fileID: 618750918} 980 m_RootOrder: 1 981 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 982--- !u!114 &1834950147 983MonoBehaviour: 984 m_ObjectHideFlags: 0 985 m_CorrespondingSourceObject: {fileID: 0} 986 m_PrefabInternal: {fileID: 0} 987 m_GameObject: {fileID: 1834950145} 988 m_Enabled: 1 989 m_EditorHideFlags: 0 990 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 991 m_Name: 992 m_EditorClassIdentifier: 993 jointType: 2 994 rotationValues: {x: 0, y: 0, z: 0} 995--- !u!1 &1920256459 996GameObject: 997 m_ObjectHideFlags: 0 998 m_CorrespondingSourceObject: {fileID: 0} 999 m_PrefabInternal: {fileID: 0} 1000 serializedVersion: 6 1001 m_Component: 1002 - component: {fileID: 1920256460} 1003 - component: {fileID: 1920256461} 1004 m_Layer: 0 1005 m_Name: Thumb 1006 m_TagString: Untagged 1007 m_Icon: {fileID: 0} 1008 m_NavMeshLayer: 0 1009 m_StaticEditorFlags: 0 1010 m_IsActive: 1 1011--- !u!4 &1920256460 1012Transform: 1013 m_ObjectHideFlags: 0 1014 m_CorrespondingSourceObject: {fileID: 0} 1015 m_PrefabInternal: {fileID: 0} 1016 m_GameObject: {fileID: 1920256459} 1017 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 1018 m_LocalPosition: {x: 0, y: 0, z: 0} 1019 m_LocalScale: {x: 1, y: 1, z: 1} 1020 m_Children: [] 1021 m_Father: {fileID: 1375661944} 1022 m_RootOrder: 1 1023 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 1024--- !u!114 &1920256461 1025MonoBehaviour: 1026 m_ObjectHideFlags: 0 1027 m_CorrespondingSourceObject: {fileID: 0} 1028 m_PrefabInternal: {fileID: 0} 1029 m_GameObject: {fileID: 1920256459} 1030 m_Enabled: 1 1031 m_EditorHideFlags: 0 1032 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 1033 m_Name: 1034 m_EditorClassIdentifier: 1035 jointType: 2 1036 rotationValues: {x: 0, y: 0, z: 0} 1037--- !u!1 &2126949328 1038GameObject: 1039 m_ObjectHideFlags: 0 1040 m_CorrespondingSourceObject: {fileID: 0} 1041 m_PrefabInternal: {fileID: 0} 1042 serializedVersion: 6 1043 m_Component: 1044 - component: {fileID: 2126949329} 1045 - component: {fileID: 2126949330} 1046 m_Layer: 0 1047 m_Name: Ring 1048 m_TagString: Untagged 1049 m_Icon: {fileID: 0} 1050 m_NavMeshLayer: 0 1051 m_StaticEditorFlags: 0 1052 m_IsActive: 1 1053--- !u!4 &2126949329 1054Transform: 1055 m_ObjectHideFlags: 0 1056 m_CorrespondingSourceObject: {fileID: 0} 1057 m_PrefabInternal: {fileID: 0} 1058 m_GameObject: {fileID: 2126949328} 1059 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 1060 m_LocalPosition: {x: 0, y: 0, z: 0} 1061 m_LocalScale: {x: 1, y: 1, z: 1} 1062 m_Children: [] 1063 m_Father: {fileID: 618750918} 1064 m_RootOrder: 4 1065 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 1066--- !u!114 &2126949330 1067MonoBehaviour: 1068 m_ObjectHideFlags: 0 1069 m_CorrespondingSourceObject: {fileID: 0} 1070 m_PrefabInternal: {fileID: 0} 1071 m_GameObject: {fileID: 2126949328} 1072 m_Enabled: 1 1073 m_EditorHideFlags: 0 1074 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 1075 m_Name: 1076 m_EditorClassIdentifier: 1077 jointType: 5 1078 rotationValues: {x: 0, y: 0, z: 0} 1079--- !u!1 &2139301568 1080GameObject: 1081 m_ObjectHideFlags: 0 1082 m_CorrespondingSourceObject: {fileID: 0} 1083 m_PrefabInternal: {fileID: 0} 1084 serializedVersion: 6 1085 m_Component: 1086 - component: {fileID: 2139301569} 1087 - component: {fileID: 2139301570} 1088 m_Layer: 0 1089 m_Name: Wrist 1090 m_TagString: Untagged 1091 m_Icon: {fileID: 0} 1092 m_NavMeshLayer: 0 1093 m_StaticEditorFlags: 0 1094 m_IsActive: 1 1095--- !u!4 &2139301569 1096Transform: 1097 m_ObjectHideFlags: 0 1098 m_CorrespondingSourceObject: {fileID: 0} 1099 m_PrefabInternal: {fileID: 0} 1100 m_GameObject: {fileID: 2139301568} 1101 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 1102 m_LocalPosition: {x: 0, y: 0, z: 0} 1103 m_LocalScale: {x: 1, y: 1, z: 1} 1104 m_Children: [] 1105 m_Father: {fileID: 1375661944} 1106 m_RootOrder: 0 1107 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 1108--- !u!114 &2139301570 1109MonoBehaviour: 1110 m_ObjectHideFlags: 0 1111 m_CorrespondingSourceObject: {fileID: 0} 1112 m_PrefabInternal: {fileID: 0} 1113 m_GameObject: {fileID: 2139301568} 1114 m_Enabled: 1 1115 m_EditorHideFlags: 0 1116 m_Script: {fileID: 11500000, guid: 7e9a3f3986544564fa640a3a2fa4835d, type: 3} 1117 m_Name: 1118 m_EditorClassIdentifier: 1119 jointType: 7 1120 rotationValues: {x: 0, y: 0, z: 0} 1121
Unity Quaternion Filter
csharp
quaternion method
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Cleaner : MonoBehaviour { 6 7 private static Cleaner inst; 8 public static Cleaner instance { get { return inst; } } 9 10 private void Awake() 11 { 12 if (inst != null && inst != this) 13 Destroy(this.gameObject); 14 else 15 inst = this; 16 } 17 18 19 20 21 /// <summary> 22 /// Gets or sets the sample period. 23 /// </summary> 24 [SerializeField] public float SamplePeriod = 501;//501; //delta t. used to be 512 25 26 /// <summary> 27 /// Gets or sets the algorithm gain beta. 28 /// </summary> 29 [SerializeField] public float Beta = 0.1f; 30 31 /// <summary> 32 /// Gets or sets the Quaternion output. 33 /// </summary> 34 [SerializeField] public float[] quat; 35 36 public Quaternion GetQuaternionData(float gz, float gx, float gy, float az, float ax, float ay, float mz, float mx, float my) 37 { 38 //float.Parse(stateInfo[0]) 39 MadgwickQuaternionUpdate(gz, gx, gy, az, ax, ay, mz, mx, my); 40 Quaternion retQuat = new Quaternion(quat[0], quat[1], quat[2], quat[3]); 41 return retQuat; 42 } 43 44 /// <summary> 45 /// Algorithm AHRS update method. Requires only gyroscope and accelerometer data. 46 /// </summary> 47 /// <param name="gx"> 48 /// Gyroscope x axis measurement in radians/s. 49 /// </param> 50 /// <param name="gy"> 51 /// Gyroscope y axis measurement in radians/s. 52 /// </param> 53 /// <param name="gz"> 54 /// Gyroscope z axis measurement in radians/s. 55 /// </param> 56 /// <param name="ax"> 57 /// Accelerometer x axis measurement in any calibrated units. 58 /// </param> 59 /// <param name="ay"> 60 /// Accelerometer y axis measurement in any calibrated units. 61 /// </param> 62 /// <param name="az"> 63 /// Accelerometer z axis measurement in any calibrated units. 64 /// </param> 65 /// <param name="mx"> 66 /// Magnetometer x axis measurement in any calibrated units. 67 /// </param> 68 /// <param name="my"> 69 /// Magnetometer y axis measurement in any calibrated units. 70 /// </param> 71 /// <param name="mz"> 72 /// Magnetometer z axis measurement in any calibrated units. 73 /// </param> 74 /// <remarks> 75 /// Optimised for minimal arithmetic. 76 /// Total : 160 77 /// Total *: 172 78 /// Total /: 5 79 /// Total sqrt: 5 80 /// </remarks> 81 public void MadgwickQuaternionUpdate(float gz, float gx, float gy, float az, float ax, float ay, float mz, float mx, float my) 82 { 83 float q1 = quat[0], q2 = quat[1], q3 = quat[2], q4 = quat[3]; // short name local variable for readability 84 float norm; 85 float hx, hy, _2bx, _2bz; 86 float s1, s2, s3, s4; 87 float qDot1, qDot2, qDot3, qDot4; 88 89 // Auxiliary variables to avoid repeated arithmetic 90 float _2q1mx; 91 float _2q1my; 92 float _2q1mz; 93 float _2q2mx; 94 float _4bx; 95 float _4bz; 96 float _2q1 = 2f * q1; 97 float _2q2 = 2f * q2; 98 float _2q3 = 2f * q3; 99 float _2q4 = 2f * q4; 100 float _2q1q3 = 2f * q1 * q3; 101 float _2q3q4 = 2f * q3 * q4; 102 float q1q1 = q1 * q1; 103 float q1q2 = q1 * q2; 104 float q1q3 = q1 * q3; 105 float q1q4 = q1 * q4; 106 float q2q2 = q2 * q2; 107 float q2q3 = q2 * q3; 108 float q2q4 = q2 * q4; 109 float q3q3 = q3 * q3; 110 float q3q4 = q3 * q4; 111 float q4q4 = q4 * q4; 112 113 // Normalise accelerometer measurement 114 norm = (float)Mathf.Sqrt(ax * ax + ay * ay + az * az); 115 if (norm == 0f) return; // handle NaN 116 norm = 1 / norm; // use reciprocal for division 117 ax *= norm; 118 ay *= norm; 119 az *= norm; 120 121 // Normalise magnetometer measurement 122 norm = (float)Mathf.Sqrt(mx * mx + my * my + mz * mz); 123 if (norm == 0f) return; // handle NaN 124 norm = 1 / norm; // use reciprocal for division 125 mx *= norm; 126 my *= norm; 127 mz *= norm; 128 129 // Reference direction of Earth's magnetic field 130 _2q1mx = 2f * q1 * mx; 131 _2q1my = 2f * q1 * my; 132 _2q1mz = 2f * q1 * mz; 133 _2q2mx = 2f * q2 * mx; 134 hx = mx * q1q1 - _2q1my * q4 + _2q1mz * q3 + mx * q2q2 + _2q2 * my * q3 + _2q2 * mz * q4 - mx * q3q3 - mx * q4q4; 135 hy = _2q1mx * q4 + my * q1q1 - _2q1mz * q2 + _2q2mx * q3 - my * q2q2 + my * q3q3 + _2q3 * mz * q4 - my * q4q4; 136 _2bx = (float)Mathf.Sqrt(hx * hx + hy * hy); 137 _2bz = -_2q1mx * q3 + _2q1my * q2 + mz * q1q1 + _2q2mx * q4 - mz * q2q2 + _2q3 * my * q4 - mz * q3q3 + mz * q4q4; 138 _4bx = 2f * _2bx; 139 _4bz = 2f * _2bz; 140 141 // Gradient decent algorithm corrective step 142 s1 = -_2q3 * (2f * q2q4 - _2q1q3 - ax) + _2q2 * (2f * q1q2 + _2q3q4 - ay) - _2bz * q3 * (_2bx * (0.5f - q3q3 - q4q4) + _2bz * (q2q4 - q1q3) - mx) + (-_2bx * q4 + _2bz * q2) * (_2bx * (q2q3 - q1q4) + _2bz * (q1q2 + q3q4) - my) + _2bx * q3 * (_2bx * (q1q3 + q2q4) + _2bz * (0.5f - q2q2 - q3q3) - mz); 143 s2 = _2q4 * (2f * q2q4 - _2q1q3 - ax) + _2q1 * (2f * q1q2 + _2q3q4 - ay) - 4f * q2 * (1 - 2f * q2q2 - 2f * q3q3 - az) + _2bz * q4 * (_2bx * (0.5f - q3q3 - q4q4) + _2bz * (q2q4 - q1q3) - mx) + (_2bx * q3 + _2bz * q1) * (_2bx * (q2q3 - q1q4) + _2bz * (q1q2 + q3q4) - my) + (_2bx * q4 - _4bz * q2) * (_2bx * (q1q3 + q2q4) + _2bz * (0.5f - q2q2 - q3q3) - mz); 144 s3 = -_2q1 * (2f * q2q4 - _2q1q3 - ax) + _2q4 * (2f * q1q2 + _2q3q4 - ay) - 4f * q3 * (1 - 2f * q2q2 - 2f * q3q3 - az) + (-_4bx * q3 - _2bz * q1) * (_2bx * (0.5f - q3q3 - q4q4) + _2bz * (q2q4 - q1q3) - mx) + (_2bx * q2 + _2bz * q4) * (_2bx * (q2q3 - q1q4) + _2bz * (q1q2 + q3q4) - my) + (_2bx * q1 - _4bz * q3) * (_2bx * (q1q3 + q2q4) + _2bz * (0.5f - q2q2 - q3q3) - mz); 145 s4 = _2q2 * (2f * q2q4 - _2q1q3 - ax) + _2q3 * (2f * q1q2 + _2q3q4 - ay) + (-_4bx * q4 + _2bz * q2) * (_2bx * (0.5f - q3q3 - q4q4) + _2bz * (q2q4 - q1q3) - mx) + (-_2bx * q1 + _2bz * q3) * (_2bx * (q2q3 - q1q4) + _2bz * (q1q2 + q3q4) - my) + _2bx * q2 * (_2bx * (q1q3 + q2q4) + _2bz * (0.5f - q2q2 - q3q3) - mz); 146 norm = 1f / (float)Mathf.Sqrt(s1 * s1 + s2 * s2 + s3 * s3 + s4 * s4); // normalise step magnitude 147 s1 *= norm; 148 s2 *= norm; 149 s3 *= norm; 150 s4 *= norm; 151 152 // Compute rate of change of quaternion 153 qDot1 = 0.5f * (-q2 * gx - q3 * gy - q4 * gz) - Beta * s1; 154 qDot2 = 0.5f * (q1 * gx + q3 * gz - q4 * gy) - Beta * s2; 155 qDot3 = 0.5f * (q1 * gy - q2 * gz + q4 * gx) - Beta * s3; 156 qDot4 = 0.5f * (q1 * gz + q2 * gy - q3 * gx) - Beta * s4; 157 158 // Integrate to yield quaternion 159 q1 += qDot1 * SamplePeriod; 160 q2 += qDot2 * SamplePeriod; 161 q3 += qDot3 * SamplePeriod; 162 q4 += qDot4 * SamplePeriod; 163 norm = 1f / (float)Mathf.Sqrt(q1 * q1 + q2 * q2 + q3 * q3 + q4 * q4); // normalise quaternion 164 quat[0] = q1 * norm; 165 quat[1] = q2 * norm; 166 quat[2] = q3 * norm; 167 quat[3] = q4 * norm; 168 } 169 170 // NOT DONE YET 171 public void MahonyQuaternionUpdate(float gz, float gx, float gy, float az, float ax, float ay, float mz, float mx, float my) 172 { 173 float q1 = quat[0], q2 = quat[1], q3 = quat[2], q4 = quat[3]; // short name local variable for readability 174 float norm; 175 float hx, hy, bx, bz; 176 float vx, vy, vz, wx, wy, wz; 177 float ex, ey, ez; 178 float pa, pb, pc; 179 180 // Auxiliary variables to avoid repeated arithmetic 181 float q1q1 = q1 * q2; 182 float q1q2 = q1 * q2; 183 float q1q3 = q1 * q3; 184 float q1q4 = q1 * q4; 185 float q2q2 = q2 * q2; 186 float q2q3 = q2 * q3; 187 float q2q4 = q2 * q4; 188 float q3q3 = q3 * q3; 189 float q3q4 = q3 * q4; 190 float q4q4 = q4 * q4; 191 192 // Normalise accelerometer measurement 193 norm = (float)Mathf.Sqrt(ax * ax + ay * ay + az * az); 194 if (norm == 0f) return; 195 norm = 1.0f / norm; 196 mx *= norm; 197 my *= norm; 198 mz *= norm; 199 200 // Reference direction of Earth's magnetic field 201 hx = 2.0f * mx * (0.5f - q3q3 - q4q4) + 2.0f * my * (q2q3 - q1q4) + 2.0f * mz * (q2q4 + q1q3); 202 hy = 2.0f * mx * (q2q3 + q1q4) + 2.0f * my * (0.5f - q2q2 + q4q4) + 2.0f * mz * (q3q4 - q1q2); 203 bx = (float)Mathf.Sqrt((hx * hx) + (hy * hy)); 204 bz = 2.0f * mx * (q2q4 - q1q3) + 2.0f * my * (q3q4 + q1q2) + 2.0f * mz * (0.5f - q2q2 - q3q3); 205 206 207 // Estimated direction of gravity and magnetic field 208 vx = 2.0f * (q2q4 - q1q3); 209 vy = 2.0f * (q1q2 + q3q4); 210 vz = q1q1 - q2q2 - q3q3 + q4q4; 211 wx = 2.0f * bx * (0.5f - q3q3 - q4q4) + 2.0f * bz * (q2q4 - q1q3); 212 wy = 2.0f * bx * (q2q3 - q1q4) + 2.0f * bz * (q1q2 + q3q4); 213 wz = 2.0f * bx * (q1q3 + q2q4) + 2.0f * bz * (0.5f - q2q2 - q3q3); 214 215 // Error is cross product between estimated direction and measured direction of gravity 216 ex = (ay * vz - az * vy) + (my * wz - mz * wy); 217 ey = (az * vx - ax * vz) + (mz * wx - mx * wz); 218 ez = (ax * vy - ay * vx) + (mx * wy - my * wx); 219 220 /* 221 * 222 * unfinished business 223 * need to keep working 224 * the below is still just copied from above for reference, 225 * so therefore the below code has no significance and once reach 226 * near the same point delete 227 * 228 * also have no idea what Ki is above so need to check it out. 229 * otherwise the code will bork itself 230 * 231 * end 232 * 233 * */ 234 235 /* 236 if (Ki > 0.0f) 237 { 238 eInt[0] += ex; 239 240 241 242 243 // Gradient decent algorithm corrective step 244 s1 = -_2q3 * (2f * q2q4 - _2q1q3 - ax) + _2q2 * (2f * q1q2 + _2q3q4 - ay) - _2bz * q3 * (_2bx * (0.5f - q3q3 - q4q4) + _2bz * (q2q4 - q1q3) - mx) + (-_2bx * q4 + _2bz * q2) * (_2bx * (q2q3 - q1q4) + _2bz * (q1q2 + q3q4) - my) + _2bx * q3 * (_2bx * (q1q3 + q2q4) + _2bz * (0.5f - q2q2 - q3q3) - mz); 245 s2 = _2q4 * (2f * q2q4 - _2q1q3 - ax) + _2q1 * (2f * q1q2 + _2q3q4 - ay) - 4f * q2 * (1 - 2f * q2q2 - 2f * q3q3 - az) + _2bz * q4 * (_2bx * (0.5f - q3q3 - q4q4) + _2bz * (q2q4 - q1q3) - mx) + (_2bx * q3 + _2bz * q1) * (_2bx * (q2q3 - q1q4) + _2bz * (q1q2 + q3q4) - my) + (_2bx * q4 - _4bz * q2) * (_2bx * (q1q3 + q2q4) + _2bz * (0.5f - q2q2 - q3q3) - mz); 246 s3 = -_2q1 * (2f * q2q4 - _2q1q3 - ax) + _2q4 * (2f * q1q2 + _2q3q4 - ay) - 4f * q3 * (1 - 2f * q2q2 - 2f * q3q3 - az) + (-_4bx * q3 - _2bz * q1) * (_2bx * (0.5f - q3q3 - q4q4) + _2bz * (q2q4 - q1q3) - mx) + (_2bx * q2 + _2bz * q4) * (_2bx * (q2q3 - q1q4) + _2bz * (q1q2 + q3q4) - my) + (_2bx * q1 - _4bz * q3) * (_2bx * (q1q3 + q2q4) + _2bz * (0.5f - q2q2 - q3q3) - mz); 247 s4 = _2q2 * (2f * q2q4 - _2q1q3 - ax) + _2q3 * (2f * q1q2 + _2q3q4 - ay) + (-_4bx * q4 + _2bz * q2) * (_2bx * (0.5f - q3q3 - q4q4) + _2bz * (q2q4 - q1q3) - mx) + (-_2bx * q1 + _2bz * q3) * (_2bx * (q2q3 - q1q4) + _2bz * (q1q2 + q3q4) - my) + _2bx * q2 * (_2bx * (q1q3 + q2q4) + _2bz * (0.5f - q2q2 - q3q3) - mz); 248 norm = 1f / (float)Mathf.Sqrt(s1 * s1 + s2 * s2 + s3 * s3 + s4 * s4); // normalise step magnitude 249 s1 *= norm; 250 s2 *= norm; 251 s3 *= norm; 252 s4 *= norm; 253 254 // Compute rate of change of quaternion 255 qDot1 = 0.5f * (-q2 * gx - q3 * gy - q4 * gz) - Beta * s1; 256 qDot2 = 0.5f * (q1 * gx + q3 * gz - q4 * gy) - Beta * s2; 257 qDot3 = 0.5f * (q1 * gy - q2 * gz + q4 * gx) - Beta * s3; 258 qDot4 = 0.5f * (q1 * gz + q2 * gy - q3 * gx) - Beta * s4; 259 260 // Integrate to yield quaternion 261 q1 += qDot1 * SamplePeriod; 262 q2 += qDot2 * SamplePeriod; 263 q3 += qDot3 * SamplePeriod; 264 q4 += qDot4 * SamplePeriod; 265 norm = 1f / (float)Mathf.Sqrt(q1 * q1 + q2 * q2 + q3 * q3 + q4 * q4); // normalise quaternion 266 quat[0] = q1 * norm; 267 quat[1] = q2 * norm; 268 quat[2] = q3 * norm; 269 quat[3] = q4 * norm; 270 */ 271 } 272 273 274} 275
Downloadable files
Wiring
Sparkfun IMU MPU-9250 to Arduino Uno board
Wiring

Wiring
Sparkfun IMU MPU-9250 to Arduino Uno board
Wiring

Comments
Only logged in users can leave comments