Ejemplo n.º 1
0
    def __init__(self, left=(2, 3), right=(4, 5), pwm=(6, 9)):
        # GPIO pin setup
        if does_module_exists(MODULE_NAME):
            self.left_backward = mraa.Gpio(left[0])
            self.left_forward = mraa.Gpio(left[1])

            self.right_forward = mraa.Gpio(right[0])
            self.right_backward = mraa.Gpio(right[1])

            self.left_forward.dir(mraa.DIR_OUT)
            self.left_backward.dir(mraa.DIR_OUT)
            self.right_backward.dir(mraa.DIR_OUT)
            self.right_forward.dir(mraa.DIR_OUT)

            self.en_A = mraa.Pwm(pwm[1])
            self.en_B = mraa.Pwm(pwm[0])

            self.en_A.enable(True)
            self.en_B.enable(True)

            self.halt()
            self.en_A.write(.5)
            self.en_B.write(.5)
Ejemplo n.º 2
0
import socket

from .common import UDP_IP_PORT, Keys
import utility

if utility.does_module_exists('mraa'):
    import mraa
    import rover

    car = rover.RoverClient()
    car_move = True
else:
    car_move = False

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(UDP_IP_PORT)


def receive_loop():
    while True:
        data, addr = sock.recvfrom(1024)
        print("processing ", data)
        if car_move:
            if data == Keys.KEY_UP.value:
                car.forward()
            elif data == Keys.KEY_DOWN.value:
                car.backward()
            elif data == Keys.KEY_LEFT.value:
                car.forward_left()
            elif data == Keys.KEY_RIGHT.value:
                car.forward_right()
Ejemplo n.º 3
0
 def forward_left(self, seconds=DEFAULT_RUN_LENGTH):
     if does_module_exists(MODULE_NAME):
         self.on(self.right_forward, self.left_backward)
         self.nap(seconds)
         self.off(self.right_forward, self.left_backward)
Ejemplo n.º 4
0
 def halt(self):
     if does_module_exists(MODULE_NAME):
         self.left_forward.write(0)
         self.left_backward.write(0)
         self.right_forward.write(0)
         self.right_backward.write(0)
Ejemplo n.º 5
0
"""
Execute in Intel Edison
"""

from utility import does_module_exists
import time

MODULE_NAME = "mraa"
DEFAULT_RUN_LENGTH = 0.5
DEFAULT_TURN_SLEEP = 0.3

if does_module_exists(MODULE_NAME):
    import mraa


class RoverClient(object):
    def __init__(self, left=(2, 3), right=(4, 5), pwm=(6, 9)):
        # GPIO pin setup
        if does_module_exists(MODULE_NAME):
            self.left_backward = mraa.Gpio(left[0])
            self.left_forward = mraa.Gpio(left[1])

            self.right_forward = mraa.Gpio(right[0])
            self.right_backward = mraa.Gpio(right[1])

            self.left_forward.dir(mraa.DIR_OUT)
            self.left_backward.dir(mraa.DIR_OUT)
            self.right_backward.dir(mraa.DIR_OUT)
            self.right_forward.dir(mraa.DIR_OUT)

            self.en_A = mraa.Pwm(pwm[1])