Esempio n. 1
0
    def setPID(self, kp, kd, ki):
        # Do not execute if any constant is negative
        if (kp < 0) or (kd < 0) or (ki < 0):
            return False

        # Convert all constants to bytes
        data = list()
        data.extend(su.FloatToBytes(kp))
        data.extend(su.FloatToBytes(kd))
        data.extend(su.FloatToBytes(ki))

        # Assemble packet and write to USB, return true for success
        packet = pu.getPacket(0x05, self.cid, data)
        self.ser.write(packet)
        return True
Esempio n. 2
0
    def setPPR(self, ppr):
        # Do not execute if PPR is out of range
        if ppr < 0:
            return False

        # Update internally
        self.ppr = ppr

        # Assemble packet and write to USB, return true for success
        packet = pu.getPacket(0x15, self.cid, su.FloatToBytes(ppr))
        self.ser.write(packet)
        return True
Esempio n. 3
0
    def rotateSpeed(self, rots, rpm):
        # Do not execute if RPM is out of range, rotations < 0, or if not in PID mode
        if (rpm < -65000) or (rpm > 65000) or (rots < 0) or not self.isPID:
            return False

        # Update internal memory of direction
        if rpm < 0:
            self.cw = False
        elif rpm > 0:
            self.cw = True

        rpm = abs(rpm)

        # Assemble payload -- pwm, then direction, then # rotations
        data = list()
        data.extend(su.ShortToBytes(rpm))
        data.append(int(self.cw))
        data.extend(su.FloatToBytes(rots))

        # Assemble packet and write to USB, return true for success
        packet = pu.getPacket(0x0A, self.cid, data)
        self.ser.write(packet)
        return True
Esempio n. 4
0
    def rotatePWM(self, rots, pwm):
        # Do not execute if PWM is out of range, rotations < 0, or if in PID mode
        if (pwm < -255) or (pwm > 255) or (rots < 0) or self.isPID:
            return False

        # Update internal memory of direction
        if pwm < 0:
            self.cw = False
        elif pwm > 0:
            self.cw = True

        pwm = abs(pwm)

        # Assemble payload -- pwm, then direction, then # rotations
        data = list()
        data.append(pwm)
        data.append(int(self.cw))
        data.extend(su.FloatToBytes(rots))

        # Assemble packet and write to USB, return true for success
        packet = pu.getPacket(0x09, self.cid, data)
        self.ser.write(packet)
        return True