Exemplo n.º 1
0
def findWall(speed):
    s = sensors[SENS_R]
    sClicks = s._sensorClicks
    robohat.forward(speed)
    # Sanity check (possibly report timeout)
    countDown = 1000

    while(not robohat.irAll() and countDown > 0):
        time.sleep(0.01)
        countDown -= 1

    robohat.stop()

    time.sleep(1)
    eClicks = s._sensorClicks
    print("final clicks: ", (sClicks - eClicks))
Exemplo n.º 2
0
def forward(revs, speed):
    robohat.forward(speed)

    clicks = int(revs*CLICKS_PER_REV)
    # doesn't matter which side's sensor we use
    s = sensors[SENS_L]
    s.start(clicks).wait(5)

    # TODO: figure out how many clicks for the motors to stop, and allow for that
    # in the above loop:
    # speed, extra clicks
    # 30, 7-8
    # 50, 11-12
    # 70, 13
    # 100, 13-14
    robohat.stop()

    time.sleep(1)
    print("final clicks: ", s._sensorClicks)
Exemplo n.º 3
0
def wallAvoid():
    print('Starting wall avoid')
    speed = 100
    time_end = time.time() + 4
    # main loop
    try:
       for i in range(2):
            time_end = time.time() + 6
            while time.time() < time_end:
                rightSensor = robohat.irRight()
                leftSensor = robohat.irLeft()
                if rightSensor and leftSensor:
                    robohat.spinLeft(speed)
                    time.sleep(1)
                elif rightSensor:
                    robohat.spinLeft(speed)
                    time.sleep(0.2)
                elif leftSensor == True:
                    robohat.spinRight(speed)
                    time.sleep(0.2)
                else:
                    robohat.forward(speed)
            robohat.forward(0)
            time.sleep(3)
            robohat.forward(speed)
            time.sleep(0.2)
            robohat.spinLeft(speed)
            time.sleep(4)

    except KeyboardInterrupt:
        robohat.stop()
        robohat.cleanup()
Exemplo n.º 4
0
def wallAvoid():
    print('Starting wall avoid')
    speed = 100
    time_end = time.time() + 4
    # main loop
    try:
        for i in range(2):
            time_end = time.time() + 6
            while time.time() < time_end:
                rightSensor = robohat.irRight()
                leftSensor = robohat.irLeft()
                if rightSensor and leftSensor:
                    robohat.spinLeft(speed)
                    time.sleep(1)
                elif rightSensor:
                    robohat.spinLeft(speed)
                    time.sleep(0.2)
                elif leftSensor == True:
                    robohat.spinRight(speed)
                    time.sleep(0.2)
                else:
                    robohat.forward(speed)
            robohat.forward(0)
            time.sleep(3)
            robohat.forward(speed)
            time.sleep(0.2)
            robohat.spinLeft(speed)
            time.sleep(4)

    except KeyboardInterrupt:
        robohat.stop()
        robohat.cleanup()
Exemplo n.º 5
0
import robohat, time

speed = 80

robohat.init()

# main loop
try:
    while True:
       rightSensor = robohat.irRight()
       leftSensor = robohat.irLeft()
       print "right:{0}, left:{1}".format(rightSensor, leftSensor)
       if rightSensor and leftSensor:
          robohat.spinLeft(speed)
          time.sleep(1)
       elif rightSensor:
          robohat.spinLeft(speed)
          time.sleep(0.2)
          print('Turn Left')
       elif leftSensor == True:
          robohat.spinRight(speed)
          time.sleep(0.2)
          print('Turn Right')
       else:
          robohat.forward(speed)

except KeyboardInterrupt:
    robohat.stop()
    robohat.cleanup()
    return chr(0x10 + ord(c3) - 65)  # 16=Up, 17=Down, 18=Right, 19=Left arrows

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

speed = 60


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:
            robohat.spinLeft(speed)
            print ('Spin Left', speed)
        elif keyp == '.' or keyp == '>':
            speed = min(100, speed+10)
            print ('Speed+', speed)
        elif keyp == ',' or keyp == '<':
            speed = max (0, speed-10)
Exemplo n.º 7
0
    else:
        return "Right"


if __name__ == "__main__":
    init()

    try:
        while True:
            dist = int(robohat.getDistance())
            print("Distance: ", dist)
            left_ir = robohat.irLeft()
            right_ir = robohat.irRight()
            if not (left_ir or right_ir):
                if dist > 50:
                    robohat.forward(settings["speed"])
                    print("No obstacles in range to worry about")
                    time.sleep(0.5)
                elif dist > 10:
                    print("Getting close, speed is: ",
                          int((settings["speed"]) * float(dist / 50)))
                    robohat.forward(int(
                        (settings["speed"]) * float(dist / 50)))
                    time.sleep(0.5)
                elif dist < 10:
                    print("I'm getting close, taking evasive action!")
                    if side_distances() == "Left":
                        print("Evading left!")
                        robohat.spinLeft(settings["speed"])
                    else:
                        print("Evading right!")