Using The Motor Characterization Paper, I’ve got this for computing motor acceleration/velocity:
def compute(self, motor_pct, tm_diff):
motor_pct = max(min(1, motor_pct), -1)
appliedVoltage = self.config.nominalVoltage * motor_pct
appliedVoltage = math.copysign(max(abs(appliedVoltage) - self._vintercept, 0), appliedVoltage)
self.acceleration = (appliedVoltage - (self._kv * self.velocity)) / self._ka
self.velocity += self.acceleration * tm_diff
self.torque = self.acceleration * self._mass
So far so good… the result looks and feels pretty ‘real’ now. However, it occurred to me that I need to deal with brake mode. What’s the best way to hack that into this?
One way that snobotsim uses is just detect a voltage of 0… and then set acceleration/velocity to 0 and calls it a day. I feel there’s probably a slightly more realistic way to compute this, right? However, I’m not quite sure of the best way to do it.
Thanks!