Voice Hat Motorsteuerung
Verfasst: Mittwoch 27. Juni 2018, 11:27
Hallo
Ich brauche dringend Hilfe, bin schon seit Tagen dran und weis nicht weiter.
Ich habe ein Raspberry pi mit einer Voice HAT Platine drauf, (AIY Voice Kit) .
Ich will 2 Motoren ansteuern, einmal beide laufen lassen, einmal Stop beide, einmal nur einen und einmal nur den anderen.
Wenn ich Start sage, laufen beide Motoren
Wenn ich stop sage , halten beide motoren an ( Wobei egal was ich sage, sie halten immer an)
dasist mal das eine Probelme, das andere , ich bings nicht fertig die einzeln anzusteuern.( Verkabelung ist ok, nur Programcode ist nicht gut)
Kann mir da jemand bitte helfen????
Hier der Code:
#!/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
from gpiozero import PWMOutputDevice
def main():
recognizer = aiy.cloudspeech.get_recognizer()
recognizer.expect_phrase('Start')
recognizer.expect_phrase('Stop')
recognizer.expect_phrase('left')
recognizer.expect_phrase('right')
button = aiy.voicehat.get_button()
led = aiy.voicehat.get_led()
aiy.audio.get_recorder().start()
pwm4 = PWMOutputDevice(4)
pwm17 = PWMOutputDevice(17)
pwm27 = PWMOutputDevice(27)
pwm22 = PWMOutputDevice(22)
while True:
print('Drücke den Knopf und Spreche')
button.wait_for_press()
print('Höre zu...')
text = recognizer.recognize()
if text is None:
print('Sorry, Ich habe dich nicht gehöhrt')
else:
print('You said "', text, '"')
if 'Start' in text:
print('Motor fährt los')
pwm4.on()
pwm17.on()
elif 'off' or 'Stop' in text:
print('Motor haltet an')
pwm4.off()
pwm17.off()
elif 'right' or 'rechts' in text:
print('Motor geht nach rechts')
pwm4.on()
pwm17.off()
elif 'left' or 'links' in text:
print('Motor geht nach links')
pwm4.off()
pwm17.on()
if __name__ == '__main__':
main()
Ich brauche dringend Hilfe, bin schon seit Tagen dran und weis nicht weiter.
Ich habe ein Raspberry pi mit einer Voice HAT Platine drauf, (AIY Voice Kit) .
Ich will 2 Motoren ansteuern, einmal beide laufen lassen, einmal Stop beide, einmal nur einen und einmal nur den anderen.
Wenn ich Start sage, laufen beide Motoren
Wenn ich stop sage , halten beide motoren an ( Wobei egal was ich sage, sie halten immer an)
dasist mal das eine Probelme, das andere , ich bings nicht fertig die einzeln anzusteuern.( Verkabelung ist ok, nur Programcode ist nicht gut)
Kann mir da jemand bitte helfen????
Hier der Code:
#!/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
from gpiozero import PWMOutputDevice
def main():
recognizer = aiy.cloudspeech.get_recognizer()
recognizer.expect_phrase('Start')
recognizer.expect_phrase('Stop')
recognizer.expect_phrase('left')
recognizer.expect_phrase('right')
button = aiy.voicehat.get_button()
led = aiy.voicehat.get_led()
aiy.audio.get_recorder().start()
pwm4 = PWMOutputDevice(4)
pwm17 = PWMOutputDevice(17)
pwm27 = PWMOutputDevice(27)
pwm22 = PWMOutputDevice(22)
while True:
print('Drücke den Knopf und Spreche')
button.wait_for_press()
print('Höre zu...')
text = recognizer.recognize()
if text is None:
print('Sorry, Ich habe dich nicht gehöhrt')
else:
print('You said "', text, '"')
if 'Start' in text:
print('Motor fährt los')
pwm4.on()
pwm17.on()
elif 'off' or 'Stop' in text:
print('Motor haltet an')
pwm4.off()
pwm17.off()
elif 'right' or 'rechts' in text:
print('Motor geht nach rechts')
pwm4.on()
pwm17.off()
elif 'left' or 'links' in text:
print('Motor geht nach links')
pwm4.off()
pwm17.on()
if __name__ == '__main__':
main()