def setPitchRollFromInput(self, pitch, roll): # both elevons have equal limits to pitch and roll input # pitch and roll input have seperate limits pitch = n.arduino_map(n.clamp(pitch, self.pitchDownLimit, self.pitchUpLimit), self.pitchDownLimit, self.pitchUpLimit, -45, 45) roll = n.arduino_map(n.clamp(roll, self.rollDownLimit, self.rollUpLimit), self.rollDownLimit, self.rollUpLimit, -45, 45) self.setPitchRoll(pitch, roll)
def setPitchRollFromInput(self, pitch, roll): # both elevons have equal limits to pitch and roll input # pitch and roll input have seperate limits pitch = n.arduino_map( n.clamp(pitch, self.pitchDownLimit, self.pitchUpLimit), self.pitchDownLimit, self.pitchUpLimit, -45, 45) roll = n.arduino_map( n.clamp(roll, self.rollDownLimit, self.rollUpLimit), self.rollDownLimit, self.rollUpLimit, -45, 45) self.setPitchRoll(pitch, roll)
def setUpDownLimit(self, up, down): # save history for live servo update - to know which value to update - top/left or bottom/right a, b = self.oldRange u, d = False, False if (up != a): u = True self.oldRange[0] = up if (down != b): d = True self.oldRange[1] = down """ Sets up and down servo limitations in percentage values: range - 0 to 100, useful for flap of airbrake definition, control surface offsets for airplane neutral point correction Correct upDirection values must be set to work properly up=0, down=100 -> full range """ if (self.upAdd == -1): self.up = n.arduino_map(up, 0, 100, MIN, MAX) self.down = n.arduino_map(down, 0, 100, MIN, MAX) if (u): self.setPosition(self.up) print("Servo position: %d" % (self.up)) u = False elif (d): self.setPosition(self.down) print("Servo position: %d" % (self.down)) d = False elif (self.upAdd == 1): self.up = n.arduino_map(up, 0, 100, MAX, MIN) self.down = n.arduino_map(down, 0, 100, MAX, MIN) if (u): self.setPosition(self.up) print("Servo position: %d" % (self.up)) u = False elif (d): self.setPosition(self.down) print("Servo position: %d" % (self.down)) d = False
def setPositionPercent(self, position): position = n.arduino_map(position, 0, 100, MIN, MAX) self.setPosition(position)
def setThrottle(self, throttle): self.throttle = throttle self.setServoValue( self.channel, n.arduino_map(throttle, MIN, MAX, servoMin, servoMax))
def setThrottleFromInput(self, throttle): throttle = n.arduino_map(n.clamp(throttle, MIN, MAX), MIN, MAX, self.minThrottle, self.maxThrottle) self.setThrottle(throttle) print("throttle: %d" % (self.throttle))
def setServoValue(self, channel, value): t = time.time() if (t - self.timer > delays.SERVO_COMMAND_REFRESH_DELAY): self.timer = t value = n.arduino_map(value, 0, 180, servoMin, servoMax) pwm.set_pwm(channel, on, int(value))
def tiltToPositionWithLimits(self, tilt, upTilt, downTilt): return n.arduino_map(tilt, downTilt, upTilt, self.down, self.up)
def setRollFromInput(self, roll): roll = n.arduino_map( n.clamp(roll, self.rollDownLimit, self.rollUpLimit), self.rollDownLimit, self.rollUpLimit, -45, 45) self.setRoll(roll)
def setPitchFromInput(self, pitch): pitch = n.arduino_map( n.clamp(pitch, self.pitchDownLimit, self.pitchUpLimit), self.pitchDownLimit, self.pitchUpLimit, -45, 45) self.setPitch(pitch)
def positionToTilt(self, position): return n.arduino_map(position, self.down, self.up, self.downTilt, self.upTilt)
def tiltToPosition(self, tilt): return n.arduino_map(tilt, self.downTilt, self.upTilt, self.down, self.up)
def setPitchFromInput(self, pitch): pitch = n.arduino_map(n.clamp(pitch, self.pitchDownLimit, self.pitchUpLimit), self.pitchDownLimit, self.pitchUpLimit, -45, 45) self.setPitch(pitch)
def setRollFromInput(self, roll): roll = n.arduino_map(n.clamp(roll, self.rollDownLimit, self.rollUpLimit), self.rollDownLimit, self.rollUpLimit, -45, 45) self.setRoll(roll)