10

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.

HaydenStudios
  • 2,840
  • 5
  • 27
  • 45
Antonvh
  • 331
  • 1
  • 5
  • 2
    Out of curiosity, what language are you using? RobotC, LabVIEW, NXT-G? – nhinkle May 07 '12 at 03: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 04 '12 at 17:30
  • @ACarter whoops... totally missed that somehow. I guess my mind translated it to nxt somehow. – nhinkle Jun 04 '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 09 '12 at 02: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 08 '14 at 08:35

1 Answers1

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

kpt
  • 21
  • 1