AIY_Gadget

Google AIY Voice Kitを利用した音声制御おもちゃ (ForkLift?)

Google AIY Voice Kit

作りかた... The Voice Controlled ForkLift? の場合

  1. Google AIY Voice Kit とRaspberry Pi 3とmicro-SD(16GB以上)を買ってきます。
  2. Kitに添付された英文のThe MagPi? AIY Projects にしたがって、Google Speaker をそのまま最後まで作ります。
    1. 箱を組み立てる必要はないのですが、動作確認のため、MagPi?に記載された通りに最後まで作ってPythonのプログラムの動作確認を行うことをお勧めします。
    2. 注意
      1. マニュアル P. 38, STEP 06, "the LED inside the arched button should both indicate the device is running." ... ボタンのLEDは点灯しません. ... https://www.raspberrypi.org/magpi/issues/essentials-aiy-v1/
    3. 参考: https://kureuetan.com/web/raspberrypi/4346/
  3. AIY Voice Kit で作った Google Speakerで、MagPi? の chapter six の step 01 から step 07 まで、および、chapter seven の step 01 の backup first, step 02 の expect phrase, step 03 の handle phrase を一つずつ理解しながら実行し、p. 55 の cloudspeech_demo.py を作成し動作確認します。部品が手に入れば、step 04, step 05, step 06を実行して、led_demo.py を作成し, 実行します。p.59 のshutdown_demo.py を作成し動作確認します.
    1. MagPi? P.65の server_demo.py は servo_demo.py の間違いです。servoモータがあれば、これもテストしておくと良いです。
  4. Arduino Nano と タミヤ3チャンネルリモコン フォークリフト工作セット とブレッドボードとモータードライバ(Hブリッジ)を3個とジャンプワイヤの束を買ってきます。
    1. https://store.arduino.cc/usa/arduino-nano
      1. Arduino Nanoのバージョンに注意. 3.0だとダメです。Whats Next Purple だとちゃんと動きました。
      2. http://bizright-blog.tumblr.com/post/120520808729/arduino-nano30の落とし穴にはまったお話戸嶋
    2. https://www.tamiya.com/japan/products/70115/index.html
    3. http://akizukidenshi.com/catalog/g/gK-06375/
  5. AIY Voice Kit のRaspberry Pi (以後 Pi)に, Arduino のIDEをインストールします。
    1. https://make.kosakalab.com/make/electronic-work/inst_arduino-ide_raspi/
      1. sudo apt-get install arduino では動かないので、注意。
  6. PiのUSBコネクタの一つとArduino Nano をUSBケーブルで接続します。
  7. PiのArduino IDEの[Tool]の[Borad]でArduino Nano を選び、[Tool]の[Port]で /dev/ttyUSB0 を選びます。
  8. Arduino Nano で IDEのsketch の例の中のBasicのBlink(Lチカ)が動作することを確認します。ここで使うLEDはNano に最初から付いているLEDです。
  9. Adafruit のNeoPixels? のページを参考にして、Arduino Nano と NeoPixels? Strip を接続し, サンプルプログラムを動かして動作確認します。
    1. https://learn.adafruit.com/adafruit-neopixel-uberguide/the-magic-of-neopixels
  10. 以下の arduino の sketch を、Raspberry Pi の arduino のIDEで作成し、arduino nano に書き込みます。
    ٤Ƴ٤Ĥ
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
    
    -
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    !
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    
    #!/usr/bin/env python3
    # Copyright 2017 Google Inc.
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    # http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
     
    """A demo of the Google CloudSpeech recognizer."""
     
    import aiy.audio
    import aiy.cloudspeech
    import aiy.voicehat
    import serial
    import time
    import subprocess
     
    def main():
      recognizer = aiy.cloudspeech.get_recognizer()
      recognizer.expect_phrase('turn on the light')
      recognizer.expect_phrase('turn off the light')
      recognizer.expect_phrase('blink')
      recognizer.expect_phrase('go')
      recognizer.expect_phrase('forward')
      recognizer.expect_phrase('back')
      recognizer.expect_phrase('left')
      recognizer.expect_phrase('right')
      recognizer.expect_phrase('up')
      recognizer.expect_phrase('down')
      recognizer.expect_phrase('stop')
      recognizer.expect_phrase('goodbye')
      recognizer.expect_phrase('shutdown')
     
      button = aiy.voicehat.get_button()
      led = aiy.voicehat.get_led()
      aiy.audio.get_recorder().start()
      ser=serial.Serial('/dev/ttyUSB0',9600)
      time.sleep(2)
      aiy.audio.say('Hello, I\'m listening.')
     
      while True:
        # print('Press the button and speak')
        # button.wait_for_press()
        print('Listening...')
        text = recognizer.recognize()
        if not text:
          print('Sorry, I did not hear you.')
          aiy.audio.say('Sorry, I did not hear you.')
        else:
          print('You said "', text, '"')
          aiy.audio.say('you said '+text+'.')
          if 'turn on the light' in text:
            led.set_state(aiy.voicehat.LED.ON)
          elif 'turn off the light' in text:
            led.set_state(aiy.voicehat.LED.OFF)
          elif 'blink' in text:
            led.set_state(aiy.voicehat.LED.BLINK)
          elif 'stop' in text:
            ser.write(b"stop;")
          elif 'goodbye' in text:
            os._exit(0)
          elif 'shutdown' in text:
            subprocess.call(["sudo","shutdown","-h","now"])
          elif 'forward' in text:
            ser.write(b"go;")
          elif 'go' in text:
            ser.write(b"go;")
          elif 'back' in text:
            ser.write(b"back;")
          elif 'left' in text:
            ser.write(b"left;")
          elif 'right' in text:
            ser.write(b"right;")
          elif 'up' in text:
            ser.write(b"up;")
          elif 'down' in text:
            ser.write(b"down;")
     
    if __name__ == '__main__':
        main()
    
٤Ƴ٤Ĥ
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 
 
 
 
 
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
 
-
|
-
|
|
|
!
-
|
|
|
|
|
|
!
-
-
|
!
|
-
|
!
|
!
-
|
-
|
!
|
-
|
!
!
-
-
|
!
|
!
-
-
|
!
|
!
-
-
|
!
|
!
-
|
-
|
!
!
|
-
|
|
|
|
|
|
|
|
!
|
!
int w=60;
int d=20;
int c;
String str;
 
void setup() {
 
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
  digitalWrite(2,LOW);
  digitalWrite(3,LOW);
  digitalWrite(4,LOW);
  digitalWrite(5,LOW);
  digitalWrite(7,LOW);
  digitalWrite(8,LOW);
  Serial.begin(9600);
  c=0;
  str="stop"; 
}
 
void loop() {
 
  if(Serial.available()>0){
    str = Serial.readStringUntil(';');
    Serial.print(str); //for debug, echo back
    c=0;
  }
  if(str.indexOf("stop")==0){
    digitalWrite(2,LOW);
    digitalWrite(3,LOW);
    digitalWrite(4,LOW);
    digitalWrite(5,LOW);
    digitalWrite(7,LOW);
    digitalWrite(8,LOW);
  }
  else if(str.indexOf("go")==0){
    // digitalWrite(2,HIGH);
    // analogWrite(2,level);
    if(c<d) digitalWrite(2,HIGH); else digitalWrite(2,LOW);
    digitalWrite(3,LOW);
    // digitalWrite(4,HIGH);
    // analogWrite(4,level);
    if(c<d) digitalWrite(4,HIGH); else digitalWrite(4,LOW);
    digitalWrite(5,LOW);
  }
  else if(str.indexOf("back")==0){
    digitalWrite(2,LOW);
    // digitalWrite(3,HIGH);
    // analogWrite(3,level);
    if(c<d) digitalWrite(3,HIGH); else digitalWrite(3,LOW);
    digitalWrite(4,LOW);
    // digitalWrite(5,HIGH);
    // analogWrite(5,level);
    if(c<d) digitalWrite(5,HIGH); else digitalWrite(5,LOW);
  }
  else if(str.indexOf("left")==0){
    // digitalWrite(2,HIGH);
    // analogWrite(2,level);
    if(c<d) digitalWrite(2,HIGH); else digitalWrite(2,LOW);
    digitalWrite(3,LOW);
  }
  else if(str.indexOf("right")==0){
    // digitalWrite(4,HIGH);
    // analogWrite(4,level);
    if(c<d) digitalWrite(4,HIGH); else digitalWrite(4,LOW);
    digitalWrite(5,LOW);
  }
  else if(str.indexOf("up")==0){
    // digitalWrite(7,HIGH);
    // analogWrite(7,level);
    if(c<d) digitalWrite(7,HIGH); else digitalWrite(7,LOW);
    digitalWrite(8,LOW);
  }
  else if(str.indexOf("down")==0){
    digitalWrite(7,LOW);
    // digitalWrite(8,HIGH);
    // analogWrite(8,level);
    if(c<d) digitalWrite(8,HIGH); else digitalWrite(8,LOW);
  }
  delay(50);
  if(c>d) {
    c=0; 
    str="stop";
    digitalWrite(2,LOW);
    digitalWrite(3,LOW);
    digitalWrite(4,LOW);
    digitalWrite(5,LOW);
    digitalWrite(7,LOW);
    digitalWrite(8,LOW); 
  }
  else c++; 
}

start-forklift.sh

٤Ƴ٤Ĥ
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
-
!
 
 
 
 
 
 
 
 
 
 
#!/bin/bash --rcfile
 
source /etc/bash.bashrc
source /home/pi/.bashrc
 
cat /etc/aiyprojects.info
 
cd /home/pi/AIY-projects-python
source /home/pi/AIY-projects-python/env/bin/activate
cd /home/pi/AIY-projects-python/src/aiy-forklift
python3 forklift-ex1.py
 

forklift.service

٤Ƴ٤Ĥ
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
[Unit]
Description=FORKLIFT
After=syslog.target
 
[Service]
Type=simple
WorkingDirectory=/home/pi/AIY-projects-python/src/aiy-forklift
ExecStart=/bin/bash /home/pi/AIY-projects-python/src/aiy-forklift/start-forklift.sh
Restart = always
User = pi
 
[Install]
WantedBy = multi-user.target
 

Counter: 771, today: 1, yesterday: 0

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS