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 /
avatar image
0
Question by Grix · Apr 03, 2018 at 07:19 PM · transformpositionaccelerometeracceleration

How do I get the acceleration of an object accurately?

I am making a simulated Inertial Measurement Unit (IMU) which is a device that detects acceleration (linear and angular but lets focus on linear first).

I found this script and based mine on it but converted to c#: http://wiki.unity3d.com/index.php/IMU_Inertial_Measurement_Unit

Basically it just records the position for each step and uses the difference divided by deltatime to get speed, and then records the speed and uses the difference divided by deltatime to get acceleration.

Problem is that some frames seem produce inaccurate numbers. For example if I let an object fall freely, the script doesn't report a smoothly increasing Y value which would give a smoothly increasing speed and a constant acceleration. Instead, the Y value is slightly off every time it records, so sometimes the velocity increases twice as much as it did the last step, and sometimes it even goes backwards for one step. This of course completely messes up the acceleration calculation. So basically, the position is slightly inaccurate, which causes a much bigger inaccuracy in its derivation, which causes and even bigger inaccuracy in that derivation.

So what's a way to get more accurate position values for the exact time? What am I doing wrong?

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
Best Answer

Answer by Grix · Apr 03, 2018 at 07:29 PM

Actually I think I fixed it myself, I just had to move the code from Update() to FixedUpdate(), that massively improved the results

Comment
Add comment · Show 4 · 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
avatar image toddisarockstar · Apr 03, 2018 at 10:55 PM 0
Share

the code you are looking at seems a bit much to simply get acceleration. you should be able to simply subtract the distance moved and the last frames distance moved to get your result.

     public float acceleration;
     public float distancemoved=0;
     public float lastdistancemoved=0;
     public Vector3 last = transform.position;
 void Update(){   
         distancemoved = Vector3.Distance (last, transform.position);
         distancemoved *= Time.deltaTime;
         acceleration = distancemoved - lastdistancemoved;
         lastdistancemoved = distancemoved;
         last = transform.position;
     }

avatar image Grix toddisarockstar · Apr 03, 2018 at 11:02 PM 0
Share

That's basically what it does, but most of the code is for also calculating angular acceleration, not just linear. And also I needed acceleration as a vector with direction, not just a float. But I have compressed the script by subtracting whole vectors directly ins$$anonymous$$d of component by component.

avatar image toddisarockstar Grix · Apr 03, 2018 at 11:14 PM 0
Share

if you need to separate the vectors it would be even easier

     public Vector3 acceleration;
     public Vector3 distancemoved=Vector3.zero;
     public Vector3 lastdistancemoved=Vector3.zero;
     public Vector3 last = transform.position;
 void Update(){   
         distancemoved = (transform.position - last) * Time.deltaTime ;
         acceleration = distancemoved - lastdistancemoved;
         lastdistancemoved = distancemoved;
         last = transform.position;
     }

avatar image seul_kk131 · Nov 08, 2021 at 02:27 PM 0
Share

hello. it's been a while about your question. if you sccussed making your virtual IMU sensor , i want to know about your idea.

I think that i can get position data according to time, and then differential the position data i can get acceleromter.

give me some hint... i want to make virtual sensor as you.

@Grix

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

110 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

Related Questions

Change position of camera on scene load? 1 Answer

Create a straight gradient equation with a grid of 3d objects 1 Answer

Following another object's position/rotation like parent/child relationship? 4 Answers

How do you set the initial value of a variable to an objects current position in unity? 1 Answer

Create an animation with variables? 1 Answer


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