コード例 #1
0
    def close(self):
        # Run this when ending the main python script
        print("Robot| Closing Robot Thread")

        # Safely close main threads
        # self.stopped = True
        # self.mainThread.join(2)

        # In case the thread didn't close, use the lock when closing up
        with self.actionLock:
            self.LWheel.close()
            self.RWheel.close()
            self.camera.close()

            RoboHat.cleanup()
コード例 #2
0
    def __init__(self):
        RoboHat.init()

        self.actionLock = RLock()

        # Hardware
        self.LWheel = Wheel(Const.leftWheelPinA, Const.leftWheelPinB,
                            Const.leftEncoderPinA, Const.leftEncoderPinB)

        self.RWheel = Wheel(Const.rightWheelPinA, Const.rightWheelPinB,
                            Const.rightEncoderPinA, Const.rightEncoderPinB)

        self.camera = PanTiltPiCamera(Const.cameraPanPin, Const.cameraTiltPin)

        # Behaviors
        self.behavior = FollowLine(self)

        # Threading
        self.stopped = False
コード例 #3
0
import time

from HardwareLibs import RoboHat

RoboHat.init()

try:
    while True:
        dist = RoboHat.getDistance()
        print "Distance: ", int(dist)
        time.sleep(1)

except KeyboardInterrupt:
    print
    pass

finally:
    RoboHat.cleanup()
コード例 #4
0
ファイル: motorTest2.py プロジェクト: shuoyueqishi/RoverBot
    return chr(0x10 + ord(c3) - 65)  # 16=Up, 17=Down, 18=Right, 19=Left arrows


# End of single character reading
#======================================================================

speed = 60

print "Tests the motors by using the arrow keys to control"
print "Use , or < to slow down"
print "Use . or > to speed up"
print "Speed changes take effect when the next arrow key is pressed"
print "Press Ctrl-C to end"
print

RoboHat.init()

# main loop
try:
    while True:
        keyp = readkey()
        if keyp == 'w' or ord(keyp) == 16:
            RoboHat.forward(speed)
            print 'Forward', speed
        elif keyp == 'z' or ord(keyp) == 17:
            RoboHat.reverse(speed)
            print 'Reverse', speed
        elif keyp == 's' or ord(keyp) == 18:
            RoboHat.spinRight(speed)
            print 'Spin Right', speed
        elif keyp == 'a' or ord(keyp) == 19:
コード例 #5
0
def doServos():
    RoboHat.setServo(pan, pVal)
    RoboHat.setServo(tilt, tVal)
コード例 #6
0
def readkey(getchar_fn=None):
    getchar = getchar_fn or readchar
    c1 = getchar()
    if ord(c1) != 0x1b:
        return c1
    c2 = getchar()
    if ord(c2) != 0x5b:
        return c1
    c3 = getchar()
    return chr(0x10 + ord(c3) - 65)  # 16=Up, 17=Down, 18=Right, 19=Left arrows


# End of single character reading
#======================================================================

RoboHat.init()
#print "Robohat version: ", robohat.version()


def doServos():
    RoboHat.setServo(pan, pVal)
    RoboHat.setServo(tilt, tVal)


print "Use Arrows or W-Up, Z-Down, A-Left, S-Right Space=Centre, ^C=Exit:"

try:
    while True:
        key = readkey()
        if key == ' ':
            tVal = 0
コード例 #7
0
import time

from HardwareLibs import RoboHat

RoboHat.init()

try:
    lastL = RoboHat.irLeft()
    lastR = RoboHat.irRight()
    lastLineL = RoboHat.irLeftLine()
    lastLineR = RoboHat.irRightLine()
    print 'Left, Right, LeftLine, RightLine:', lastL, lastR, lastLineL, lastLineR
    print
    while True:
        newL = RoboHat.irLeft()
        newR = RoboHat.irRight()
        newLineL = RoboHat.irLeftLine()
        newLineR = RoboHat.irRightLine()
        if (newL != lastL) or (newR != lastR) or (newLineL != lastLineL) or (
                newLineR != lastLineR):
            print 'Left, Right, LeftLine, RightLine:', newL, newR, newLineL, newLineR
            print
            lastL = newL
            lastR = newR
            lastLineL = newLineL
            lastLineR = newLineR
        time.sleep(0.1)

except KeyboardInterrupt:
    print