Ejemplo n.º 1
0
 def __init__(self, in1=13, in2=12, ena=6, in3=21, in4=20, enb=26):
     self.motorL = motor.Motor(in1, in2, ena)  #motor LEFT
     self.motorR = motor.Motor(in3, in4, enb)  #motor RIGHT
     self.servoLR = servos.Servo()  #servo LEFT RIGHT
     self.servoUD = servos.Servo(chan=1, centerVal=1800)
     self.servoUD.stop()
     self.stop()  #servo UP DOWN
Ejemplo n.º 2
0
import servos

s = servos.Servo('rudder', 1)

s.set_position(77)
Ejemplo n.º 3
0
from threading import Thread

import logging
import cv2
import vision
import gestures
import servos
import os

app = Flask(__name__)
ask = Ask(app, '/')

logging.getLogger("flask_ask").setLevel(logging.DEBUG)
threads = []
feed = cv2.VideoCapture(0)
servo0 = servos.Servo(250, 600, 0)
servo1 = servos.Servo(527, 225, 1)
servo2 = servos.Servo(154, 382, 2)
servo3 = servos.Servo(105, 620, 3)
light_flag = False 

gestures.home([servo0, servo1, servo2, servo3])

gestures.wake_up([servo1, servo2, servo3])

@ask.intent('LightOnOff', mapping={'OnOff': 'state'})
def turn_on_off(state):
    global light_flag
    if state == 'on': 
        if light_flag:
            return statement('Are you blind?')
Ejemplo n.º 4
0
    # unserialized graph_def
    with tf.gfile.GFile(frozen_graph_filename, "rb") as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())

    with tf.Graph().as_default() as graph:
        # The name var will prefix every op/nodes in your graph
        # Since we load everything in a new graph, this is not needed
        tf.import_graph_def(graph_def)

    return graph


graph = load_graph('./Imitation_better.pb')
pwm = Adafruit_PCA9685.PCA9685()
servo0 = servos.Servo(250, 600, 0)
servo1 = servos.Servo(120, 538, 1)
servo2 = servos.Servo(154, 382, 2)
servo3 = servos.Servo(105, 620, 3)
pwm.set_pwm_freq(60)
servo0.set_pos(0)
servo1.set_pos(0)
servo2.set_pos(0)
servo3.set_pos(0)


def set_servos(positions, coords):

    # Set default variables to load
    x = graph.get_tensor_by_name('import/vector_observation:0')
    y = graph.get_tensor_by_name('import/action:0')
Ejemplo n.º 5
0
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawTextHelpFormatter)
    parser.add_argument('--device-model-id', '--device_model_id', type=str,
                        metavar='DEVICE_MODEL_ID', required=False,
                        help='the device model ID registered with Google')
    parser.add_argument('--project-id', '--project_id', type=str,
                        metavar='PROJECT_ID', required=False,
                        help='the project ID used to register this device')
    parser.add_argument('--device-config', type=str,
                        metavar='DEVICE_CONFIG_FILE',
                        default=os.path.join(
                            os.path.expanduser('~/.config'),
                            'googlesamples-assistant',
                            'device_config_library.json'
                        ),
                        help='path to store and read device configuration')
    parser.add_argument('--credentials', type=existing_file,
                        metavar='OAUTH2_CREDENTIALS_FILE',
                        default=os.path.join(
                            os.path.expanduser('/home/pi/.config'),
                            'google-oauthlib-tool',
                            'credentials.json'
                        ),
                        help='path to store and read OAuth2 credentials')
    parser.add_argument('-v', '--version', action='version',
                        version='%(prog)s ' + Assistant.__version_str__())

    args = parser.parse_args()
    with open(args.credentials, 'r') as f:
        credentials = google.oauth2.credentials.Credentials(token=None,
                                                            **json.load(f))

    device_model_id = None
    last_device_id = None
    try:
        with open(args.device_config) as f:
            device_config = json.load(f)
            device_model_id = device_config['model_id']
            last_device_id = device_config.get('last_device_id', None)
    except FileNotFoundError:
        pass

    if not args.device_model_id and not device_model_id:
        raise Exception('Missing --device-model-id option')

    # Re-register if "device_model_id" is given by the user and it differs
    # from what we previously registered with.
    should_register = (
        args.device_model_id and args.device_model_id != device_model_id)

    device_model_id = args.device_model_id or device_model_id

    servo0 = servos.Servo(250, 600, 0)
    servo1 = servos.Servo(120, 538, 1)
    servo2 = servos.Servo(154, 382, 2)
    servo3 = servos.Servo(105, 620, 3)

    servo0.set_pos(0)
    servo1.set_pos(0)
    servo2.set_pos(0)
    servo3.set_pos(0)

    servo3.set_pos(0.5)
    time.sleep(0.1)
    servo3.set_pos(-0.5)
    time.sleep(0.1)
    servo3.set_pos(0.25)
    time.sleep(0.1)
    servo3.set_pos(-0.25)
    time.sleep(0.1)
    servo3.set_pos(0)


    with Assistant(credentials, device_model_id) as assistant:
        events = assistant.start()

        device_id = assistant.device_id
        print('device_model_id:', device_model_id)
        print('device_id:', device_id + '\n')

        # Re-register if "device_id" is different from the last "device_id":
        if should_register or (device_id != last_device_id):
            if args.project_id:
                register_device(args.project_id, credentials,
                                device_model_id, device_id)
                pathlib.Path(os.path.dirname(args.device_config)).mkdir(
                    exist_ok=True)
                with open(args.device_config, 'w') as f:
                    json.dump({
                        'last_device_id': device_id,
                        'model_id': device_model_id,
                    }, f)
            else:
                print(WARNING_NOT_REGISTERED)

        for event in events:
            process_event(event)