LEGO® Answers is a question and answer site for LEGO® and building block enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Out of curiosity, what language are you using? RobotC, LabVIEW, NXT-G? – nhinkle May 7 '12 at 3:45
@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'll do) – ACarter Jun 4 '12 at 17:30
@ACarter whoops... totally missed that somehow. I guess my mind translated it to nxt somehow. – nhinkle Jun 4 '12 at 20:31
what do you mean by "smoother limit"? do you mean what kpt said, that the motor slows down before reaching the angle limit? – Nate Koppenhaver Jun 9 '12 at 2:41
Yes, I mean the motor slows down. The line of code I suggested would be to slow because of inertia of the model. – Antonvh Aug 8 '14 at 8:35

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:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.