• 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 BrentShanahan1 · Apr 10, 2015 at 07:06 PM · javascriptnan

Getting NAN for simple equation

I currently have 7 different PID controllers controlling a simulation, all with different tuning values. They are all coded the exact same aside from variable names and tuning values. The strangest thing is that the latest one I added is giving me NAN despite the simple equation outputting what I would think is a usable value.

Here is my code:

 //Input Values in fixedUpdate
 var dist : float = Vector3.Distance(pathpoint, uavPos);
 var zVel : float = UAV.transform.InverseTransformDirection(GetComponent.<Rigidbody>().velocity).z;

 //Runs through 2 PIDs in fixedUpdate
 var distErr : float= locZError(0, dist);
 var velErr : float = velZError(zVel, distErr);

 //PID with NAN Error
 private var errSumVelZ : float;
 private var lastTimeVelZ : float;
 private var lastErrVelZ : float;
 function velZError(input : float, setPoint : float){
    //input=0.0001448985 setPoint= 181.3836
    var now : float = Time.time;
    var timeChange : float = (now - lastTimeVelZ);
    
    var error : float = setPoint - input;

    Debug.Log(error); // outputs 181.3835
    Debug.Log(timeChange); // outputs 0.01999998
    Debug.Log(error * timeChange); // outputs 3.627666
    errSumVelZ += (error * timeChange);
    Debug.Log(errSumVelZ); //outputs NAN

    var dErr : float = (error - lastErrVelZ) / timeChange;
    
    var Output : float = (.3 * error) + (0 * errSumVelZ) + (2 * dErr);
     
    lastErrVelZ = error;
    lastTimeVelZ = now;
    
    return Output;
 }

What would cause 'errSumVelZ += 3.627666' to create NAN?

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 UNZoOM · Apr 10, 2015 at 07:34 PM

Initialize errSumVelZ like

private var errSumVelZ : float =0.0;

Comment
Add comment · Show 2 · 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 BrentShanahan1 · Apr 10, 2015 at 07:39 PM 0
Share

Still getting NAN...

avatar image Eric5h5 · Apr 10, 2015 at 07:45 PM 0
Share

It's pointless because the default value for floats is 0.0 anyway.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

Setting Scroll View Width GUILayout 1 Answer

InputPositionWithLocalOffset Issue o.0 0 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Randomly generated corridor? 2 Answers

Error BCE0044 JavaScript 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