Пример #1
0
        cmd, duration = text.split()
    except ValueError:
        duration = '0'

    if cmd[0] == 'f':
        print('Forward', end=' ')
        robot.forward(0.4)
        if duration == 'd':
            inch_forward()

    elif cmd[0] == 'b':
        print('Backward', end=' ')
        robot.backward(0.4)
    elif cmd[0] == 'l':
        print('Left', end=' ')
        robot.left(0.4)
    elif cmd[0] == 'r':
        print('Right', end=' ')
        robot.right(0.4)
    elif cmd[0] == 'd':
        print("Distance")
        distance()

    try:
        duration = float(duration)
    except ValueError:
        duration = 0

    if duration > 0:
        print(duration)
Пример #2
0
            speed =1.0
            robot.forward(speed)
        
        key = getchar()
        if key == "w":
            robot.stop()
            time.sleep(0.01)
            robot.forward(speed)
        elif key == "z":
            robot.stop()
            time.sleep(0.01)
            robot.backward(speed)
        elif key == "a":
            robot.stop()
            time.sleep(0.01)
            robot.left(speed)
        elif key == "d":
            robot.stop()
            time.sleep(0.01)
            robot.right(speed)
        elif key == " ": # space bar
            robot.stop()
        elif key == "q": # q key for quit  
            break
        else:
            print(key)
            
    
finally:
    # Reset GPIO settings
    GPIO.cleanup()
time.sleep(0.5)
wii.rumble = 0

wii.rpt_mode = cwiid.RPT_BTN

while True:
    last_direction = current_direction
    # Convert speed from percentage to float (0 to 1)
    float_speed = speed / 100
    if (current_direction == "forward") :
        robot.forward(float_speed)
    # rev
    elif (current_direction == "backward") :
        robot.backward(float_speed)
    elif (current_direction == "left") :
        robot.left(float_speed)
    elif (current_direction == "right") :
        robot.right(float_speed)
    # stop
    else :
        robot.stop()

    time.sleep(delay)

    # Get next key pressed      
    buttons = wii.state["buttons"]
    
    # set button to stop so that if no buttons pressed we stop
    current_direction = "stop"

    # + and - = quit
Пример #4
0
from gpiozero import Robot
from time import sleep

robot = Robot(left=(4, 14), right=(17, 18))

robot.forward()  # full speed forwards
robot.forward(0.5)  # half speed forwards

robot.backward()  # full speed backwards
robot.backward(0.5)  # half speed backwards

robot.stop()  # stop the motor

robot.value = 0.5  # half speed forwards
robot.value = -0.5  # half speed backwards
robot.value = 0  # stop

robot.reverse()  # reverse direction at same speed, e.g...

robot.forward(0.5)  # going forward at half speed
robot.reverse()  # now going backwards at half speed

robot.right()

robot.left()
Пример #5
0
robot1 = Robot(left=(16, 20), right=(6, 5))

PwmRight = PWMOutputDevice(19)
PwmLeft = PWMOutputDevice(13)

PwmRight.frequency = 1000
PwmRight.value = 0.25

PwmLeft.frequency = 1000
PwmLeft.value = 0.25

led1.on()
robot1.forward()
sleep(1)
led1.off()
robot1.left()
sleep(1)
#robot1.right()
sleep(1)
#robot1.backward()
led1.on()
sleep(1)
robot1.stop()
led1.off()

#const int kMotorA_IN1 = 16;
#const int kMotorA_IN2 = 20;
#const int kMotorA_PWM = 19;
#const int kMotorB_IN3 =  6;
#const int kMotorB_IN4 =  5;
#const int kMotorB_PWM = 13;
Пример #6
0
import I2C_LCD_driver
from time import sleep
from gpiozero import Robot

mylcd = I2C_LCD_driver.lcd()

robot = Robot(left=(7, 8), right=(9, 10))

tiempo = 10

speed = 0.3

while True:
    mylcd.lcd_display_string("forw ", 1)
    robot.forward(speed)
    sleep(tiempo)
    robot.stop()
    mylcd.lcd_display_string("right", 1)
    robot.right(speed)
    sleep(tiempo)
    robot.stop()
    mylcd.lcd_display_string("left ", 1)
    robot.left(speed)
    sleep(tiempo)
    robot.stop()
    mylcd.lcd_display_string("Back ", 1)
    robot.backward(speed)
    sleep(tiempo)
    robot.stop()
# start speed is 50% which is fairly slow on a flat surface
speed = 50

print("Robot control - use number keys to control direction")
print("Speed " + str(speed) + "% - use +/- to change speed")

while True:
    # Convert speed from percentage to float (0 to 1)
    float_speed = speed / 100
    if (current_direction == "forward"):
        robot.forward(float_speed)
    # rev
    elif (current_direction == "backward"):
        robot.backward(float_speed)
    elif (current_direction == "left"):
        robot.left(float_speed)
    elif (current_direction == "right"):
        robot.right(float_speed)
    # stop
    else:
        robot.stop()

    # Get next key pressed
    ch = getch()

    # q = quit
    if (ch == 'q'):
        break
    elif (ch == '+'):
        speed += 10
        if speed > 100: