Answers.Body: <p>By "smoother limit", if you mean "when it gets closer to the limit, it will softly land there by slowing down" then:
  I recommend using PID control where the response (how fast the motor is moving to the limit) is controlled proportional to the error (how far away from the limit you are).</p>
  
  <p>Wikipedia has a good intro to PID control: <a href="http://en.wikipedia.org/wiki/PID_controller" rel="nofollow">http://en.wikipedia.org/wiki/PID_controller</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-05-17T23:52:26.973Z
Answers.LastActivityDate: 2012-05-17T23:52:26.973Z
Answers.UserDisplayName: kpt
Body: <p>What is a good algorithm in NXC for control saturation? I want to make sure my motors don't turn past a certain angle, or they will break the model. 
  I could do something like:</p>
  
  <pre><code>if (angle &gt; 45) {angle = 45;)
  </code></pre>
  
  <p>But that would be a hard limit. I'm looking for a smoother limit.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2012-05-07T03:45:10.033Z
Comments.Text: Out of curiosity, what language are you using? RobotC, LabVIEW, NXT-G?
Comments.UserDisplayName: nhinkle
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2012-06-04T17:30:14.573Z
Comments.Text: @nhinkle, I don't mean to be patronising, but it does say NXC in the title. (**N** ot e **X** actly **C**) (not a very helpful site, but [this](http://bricxcc.sourceforge.net/nbc/nxcdoc/index.html)'ll do)
Comments.UserDisplayName: ACarter
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2012-06-04T20:31:53.217Z
Comments.Text: @ACarter whoops... totally missed that somehow. I guess my mind translated it to `nxt` somehow.
Comments.UserDisplayName: nhinkle
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2012-06-09T02:41:08.597Z
Comments.Text: what do you mean by "smoother limit"? do you mean what kpt said, that the motor slows down before reaching the angle limit?
Comments.UserDisplayName: Nate Koppenhaver
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-08T08:35:28.243Z
Comments.Text: Yes, I mean the motor slows down. The line of code I suggested would be to slow because of inertia of the model.
Comments.UserDisplayName: Antonvh
Tags: <nxt><mindstorms><programming><nxc>
Title: NXC Saturation algorithm for limiting motors?
UserDisplayName: Antonvh
ThreadText: # NXC Saturation algorithm for limiting motors?
  
  (Asked by: username_0 on 2012-04-19)
  
  What is a good algorithm in NXC for control saturation? I want to make sure my motors don't turn past a certain angle, or they will break the model.
  I could do something like:
  
  ```
  if (angle > 45) {angle = 45;)
  
  ```
  
  But that would be a hard limit. I'm looking for a smoother limit.
  
  **Tags:** nxt, mindstorms, programming, nxc
  
  > **Comments:**
  > **username_1**: Out of curiosity, what language are you using? RobotC, LabVIEW, NXT-G?  
  > **username_2**: @username_1, I don't mean to be patronising, but it does say NXC in the title. (**N** ot e **X** actly **C**) (not a very helpful site, but [this](http://bricxcc.sourceforge.net/nbc/nxcdoc/index.html)'ll do)  
  > **username_1**: @username_2 whoops... totally missed that somehow. I guess my mind translated it to `nxt` somehow.  
  > **username_3**: what do you mean by "smoother limit"? do you mean what kpt said, that the motor slows down before reaching the angle limit?  
  > **username_0**: Yes, I mean the motor slows down. The line of code I suggested would be to slow because of inertia of the model.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_4 on 2012-05-17. Score: 2
  
  By "smoother limit", if you mean "when it gets closer to the limit, it will softly land there by slowing down" then:
  I recommend using PID control where the response (how fast the motor is moving to the limit) is controlled proportional to the error (how far away from the limit you are).
  
  Wikipedia has a good intro to PID control: <http://en.wikipedia.org/wiki/PID_controller>
  
  
  ---
  
  