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.

  • 2
    Out of curiosity, what language are you using? RobotC, LabVIEW, NXT-G?
    – nhinkle
    May 7 '12 at 3:45
  • 2
    @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? 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: http://en.wikipedia.org/wiki/PID_controller

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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