Пример #1
0
    def _move(self, angle):
        done = False
        speed = self.speed

        while not done:
            wishedToSet = self.angleToPotential(angle)
            currentVal = self.pot.readRawValue()
            currentAngle = self.potentialToAngle(currentVal)
            print(F"to set:{angle}* current: {currentAngle}*")
            # print(F"to set:{wishedToSet} current: {currentVal}")

            if abs(currentVal - wishedToSet) < 20:
                self.move360Servo('stop', 0)
                done = True
                return

            angleDifference = abs(currentAngle - angle)
            if angleDifference < 100:
                newSpeed = mapValueToIntRange(angleDifference, 0, 100, 1, 100)
                print('slowing down', newSpeed)
                speed = 0.1

            if currentVal > wishedToSet:
                self.move360Servo('forward', speed)

            elif currentVal < wishedToSet:
                self.move360Servo('backward', speed)

            else:
                self.move360Servo('stop', 0)
                done = True
            time.sleep(0.05)
Пример #2
0
def readPotentiometers(potentiometers, scr):
    i = 0
    for p in potentiometers:
        val = None
        if p['adc'] == 0:
            val = adc0.read_adc(p['pin'], GAIN)
        else:
            val = adc1.read_adc(p['pin'], GAIN)
        rawVal = val


        valInRange = mapValueToIntRange(val, 0, 26208, 0, 4096)

        if valInRange > p['max']:
            p['max'] = valInRange
        if valInRange < p['min']:
            p['min'] = valInRange

        scr.addstr(i, 0, F"{p['name']} min: {p['min']} max: {p['max']} val: {valInRange}")
        i += 1
Пример #3
0
 def readPercentValue(self, value):
     mapValueToIntRange(value, self.minVal, self.maxVal, 0, 100)
Пример #4
0
 def angleToPercent(self, angle):
     return mapValueToIntRange(angle, 0, self.max_angle, 0, 100)
Пример #5
0
 def potentialToAngle(self, potential):
     return mapValueToIntRange(potential, self.pot.minVal, self.pot.maxVal,
                               0, self.max_angle)
Пример #6
0
 def angleToPotential(self, angle):
     return mapValueToIntRange(angle, 0, self.max_angle, self.pot.minVal,
                               self.pot.maxVal)
Пример #7
0
 def getValueFromAngle(self, angle):
     return mapValueToIntRange(angle, 0, 360, 0, 4095)