Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by nincs · Aug 27, 2017 at 09:54 PM · unity 5updategyroscopebluetoothsensor

IMU data in void Update()

Hi,

I would like to receive data from Bluetooth IMU module, and rotate a gameObject with it! I successfully connect and get first data from the sensor with void Start () method;

 using UnityEngine;
 using System.Collections;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Runtime.InteropServices;
 using System.Text;
 using System.IO;
 using LpmsCSharpWrapper;
 
 public class ImuReader_BB : MonoBehaviour 
 {
     public string sensor1;
     public float rotationX;
     public float rotationY;
     public float rotationZ;
 
     void Start ()
     {
         string sensor1 = "00:04:3E:9F:E0:DA";
 
         // Initalize sensor manager
         LpSensorManager.initSensorManager ();
 
         // Connect to sensor 1 
         LpSensorManager.connectToLpms (LpSensorManager.DEVICE_LPMS_B2, sensor1);
         //wait for estabilishment of sensor 1 connection
         Debug.Log ("Sensor connected");
 
     }
     void Update()
     {
         SensorData sd1;
         unsafe
         {
             sd1 = *((SensorData*)LpSensorManager.getSensorData(sensor1));
         }
         Debug.Log(String.Format("{0:0.000} {1:0.000} {2:0.000} {3:0.000} ", 
             sd1.timeStamp, sd1.ax, sd1.ay, sd1.az));
         System.Threading.Thread.Sleep(100);
     }
 }

To move the gameObject I would like to call per frame in void Update() but in this way, every data from the sensor is 0.

What I’m doing wrong?

Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tobi_s · Sep 11, 2017 at 12:53 PM

Hi @nincs,

it seems like your code displays the acceleration data of your IMU, as you print the ax, ay, and az data fields. In order to have them filled in you may have to change the configuration of your LPMS-B2 IMU in LpmsControl. Also, in order to obtain the rotation data you will have to look at the quaternion data instead of the acceleration data. Make sure that the IMU is configured to transfer the quaternion data and look at that data instead, i.e., the qw, qx, qy, qz fields. There are a few conventions that are different: Unity uses a left-handed coordinate system while the LPMS sensor uses a right-handed system; the convention for world-to-object or object-to-world may be different (I can never remember); the LP library uses z for the vertical, Unity uses y. Therefore you will have to modify the quaternion before passing it to Unity, I think unity x = sd1.qx, unity y = sd1.qz, unity z = sd1.qy, unity w = sd.qw should do the trick.

Finally, getNextData actually returns the front of the data queue. In order to retrieve the latest data sample, you will have to loop over getNextData until you are at the latest sample. Untested example code follows:

 double lastTimeStamp = -1;
 bool found;
 do {
    sd1 = *((SensorData *)LpSensorManager.getSensorData(sensor1));
    found = sd1.timeStamp == lastTimeStamp;  // stop if we found the same timestamp twice, i.e. the same sample
    lastTimeStamp = sd1.timeStamp;
 } while (!found);
 // example use of sd1 ... conventions may be different.
 this.transform.localRotation = new Quaternion(sd1.qx, sd1.qz, sd1.qy, sd1.qw);

Hope this helps, please let me know here or follow up at support@lp-research.com.

ps I just learned that an example Unity project can be found here: https://bitbucket.org/lpresearch/openmat/downloads/LpSensorCSharpExample.zip

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

184 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Move character until true 0 Answers

Update function not updating like it should be.? 1 Answer

list update in custom inspector 0 Answers

SyncVars not updating on client 1 Answer

Android game updater (autopatch) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges