Voice Hat Motorsteuerung
- __blackjack__
- User
- Beiträge: 13041
- Registriert: Samstag 2. Juni 2018, 10:21
- Wohnort: 127.0.0.1
- Kontaktdaten:
@janko84: Was hättest Du denn erwartet was da passiert und warum?
„All religions are the same: religion is basically guilt, with different holidays.” — Cathy Ladman
In dem Magpi Heft, wo die Motorensteuerung beschrieben wird, ist es so im code, nur leider geht es nicht. Aber wenn hier meine Fragestellung kritisiert wird, bin ich sehr wahrscheinlich auf mich allein gestellt.
Werde hier im Forum keine Fragen mehr stellen. Diese Kategorie kann geschlossen werden. Bye
Werde hier im Forum keine Fragen mehr stellen. Diese Kategorie kann geschlossen werden. Bye
- __blackjack__
- User
- Beiträge: 13041
- Registriert: Samstag 2. Juni 2018, 10:21
- Wohnort: 127.0.0.1
- Kontaktdaten:
@janko84: Entweder ist es da so im Code, dann steht es falsch im Heft, oder es steht dort anders. Überleg doch mal was die einzelnen Anweisungen machen und welchen Effekt das jeweils hat.
„All religions are the same: religion is basically guilt, with different holidays.” — Cathy Ladman
Ich habe verschiedenes versucht, wenn ich es so mache:
so funktioniert es, nach einer sekunde schaltet er ein und nach einer weiteren schaltet er wieder aus. und so weiter und so fort. ( Eine eigenständige datei, nicht in meinem Code )
Aber ich kreige es nicht hin, das es in meinem code funktioniert, bei links und rechts nach 5 sekunden ausschaltet.
Wenn ich links sage, muss der Motor anfangen zu drehen und nach 5 sekunden aufhöhren. genau das gleiche bei rechts.
Ich habe nur 2 Motoren (pwm4 und pwm17) .
Start pwm4.on() + pwm17.on()
Stop pwm4.off() + pwm17.off()
Left pwm4.on() + pwm17.off()
Right pwm4.off() + pwm17.on()
kann mir da bitte jemand helfen, bin schon seit tagen dran , immer wieder versuche ich es aufs neue.
Code: Alles auswählen
from gpiozero import PWMOutputDevive
from time import sleep
pwm4 = PWMOutputDevice(4)
while True:
pwm4.on()
sleep(1)
pwm4.off()
sleep(1)
Aber ich kreige es nicht hin, das es in meinem code funktioniert, bei links und rechts nach 5 sekunden ausschaltet.
Wenn ich links sage, muss der Motor anfangen zu drehen und nach 5 sekunden aufhöhren. genau das gleiche bei rechts.
Ich habe nur 2 Motoren (pwm4 und pwm17) .
Start pwm4.on() + pwm17.on()
Stop pwm4.off() + pwm17.off()
Left pwm4.on() + pwm17.off()
Right pwm4.off() + pwm17.on()
kann mir da bitte jemand helfen, bin schon seit tagen dran , immer wieder versuche ich es aufs neue.
wie sieht es hiermit aus?
Code: Alles auswählen
if 'Start' in text:
print('Motor fährt los')
pwm4.on()
pwm17.on()
sleep(5)
pwm4.off()
pwm17.off()
elif 'Stop' in text:
print('Motor haltet an')
pwm4.off()
pwm17.off()
elif 'right' in text:
print('Motor geht nach rechts')
pwm4.on()
pwm17.off()
sleep(5)
pwm4.off()
elif 'left' in text:
print('Motor geht nach links')
pwm4.off()
pwm17.on()
sleep(5)
pwm17.off()
Ich bin Pazifist und greife niemanden an, auch nicht mit Worten.
Für alle meine Code Beispiele gilt: "There is always a better way."
https://projecteuler.net/profile/Brotherluii.png
Für alle meine Code Beispiele gilt: "There is always a better way."
https://projecteuler.net/profile/Brotherluii.png
Geil. Es funktioniert, Danke viel mals.
Jetzt habe ich ein allerletztes problem an dem ich schon seit tagen paralell dran bin und es nicht lösen kann. das letzte problem:
Es funktioniert jetzt nur wenn ich auf den button drücke und dann den befehl sage, jedesmal wenn ich ein befehl sagen will muss ich also den knopf drücken.
Ich möchte das der google assistent immer zuhört und das ich nur das hotword sagen mussund dann den befehl anstatt den button zu drücken.
kann mir da jemand helfen? habe 2 files, eines ist aissistent_library und das andere asisstant_library_local , beide funktionieren wenn ich ok google sage und dan den befehl.
Bei local führt er glaube ich python befehle wie im terminal aus und beim anderen kann man fragen was man will = Google Assistent
mein code:
Aissistant_library Code:
Assistant_Library_Local Code:
Jetzt habe ich ein allerletztes problem an dem ich schon seit tagen paralell dran bin und es nicht lösen kann. das letzte problem:
Es funktioniert jetzt nur wenn ich auf den button drücke und dann den befehl sage, jedesmal wenn ich ein befehl sagen will muss ich also den knopf drücken.
Ich möchte das der google assistent immer zuhört und das ich nur das hotword sagen mussund dann den befehl anstatt den button zu drücken.
kann mir da jemand helfen? habe 2 files, eines ist aissistent_library und das andere asisstant_library_local , beide funktionieren wenn ich ok google sage und dan den befehl.
Bei local führt er glaube ich python befehle wie im terminal aus und beim anderen kann man fragen was man will = Google Assistent
mein code:
Code: Alles auswählen
import aiy.audio
import aiy.cloudspeech
import aiy.voicehat
from gpiozero import PWMOutputDevice
from time import sleep
import time
def main():
recognizer = aiy.cloudspeech.get_recognizer()
recognizer.expect_phrase('Start')
recognizer.expect_phrase('Stop')
recognizer.expect_phrase('stop')
recognizer.expect_phrase('left')
recognizer.expect_phrase('Right')
recognizer.expect_phrase('right')
recognizer.expect_phrase('Left')
button = aiy.voicehat.get_button()
led = aiy.voicehat.get_led()
aiy.audio.get_recorder().start()
pwm4 = PWMOutputDevice(4)
pwm17 = PWMOutputDevice(17)
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 'Stop' in text:
print('Motor haltet an')
pwm4.off()
pwm17.off()
elif 'stop' in text:
print('Motor haltet an')
pwm4.off()
pwm17.off()
elif 'right' in text:
print('Motor geht nach rechts')
pwm4.on()
pwm17.off()
sleep(2)
pwm4.off()
elif 'left' in text:
print('Motor geht nach links')
pwm4.off()
pwm17.on()
sleep(5)
pwm17.off()
elif 'Right' in text:
print('Motor geht nach rechts')
pwm4.on()
pwm17.off()
sleep(2)
pwm4.off()
elif 'Left' in text:
print('Motor geht nach links')
pwm4.off()
pwm17.on()
sleep(5)
pwm17.off()
if __name__ == '__main__':
main()
Code: Alles auswählen
import logging
import platform
import sys
import aiy.assistant.auth_helpers
from aiy.assistant.library import Assistant
import aiy.voicehat
from google.assistant.library.event import EventType
logging.basicConfig(
level=logging.INFO,
format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s"
)
def process_event(event):
status_ui = aiy.voicehat.get_status_ui()
if event.type == EventType.ON_START_FINISHED:
status_ui.status('ready')
if sys.stdout.isatty():
print('Say "OK, Google" then speak, or press Ctrl+C to quit...')
elif event.type == EventType.ON_CONVERSATION_TURN_STARTED:
status_ui.status('listening')
elif event.type == EventType.ON_END_OF_UTTERANCE:
status_ui.status('thinking')
elif (event.type == EventType.ON_CONVERSATION_TURN_FINISHED
or event.type == EventType.ON_CONVERSATION_TURN_TIMEOUT
or event.type == EventType.ON_NO_RESPONSE):
status_ui.status('ready')
elif event.type == EventType.ON_ASSISTANT_ERROR and event.args and event.args['is_fatal']:
sys.exit(1)
def main():
if platform.machine() == 'armv6l':
print('Cannot run hotword demo on Pi Zero!')
exit(-1)
credentials = aiy.assistant.auth_helpers.get_assistant_credentials()
with Assistant(credentials) as assistant:
for event in assistant.start():
process_event(event)
if __name__ == '__main__':
main()
Code: Alles auswählen
import logging
import platform
import subprocess
import sys
import aiy.assistant.auth_helpers
from aiy.assistant.library import Assistant
import aiy.audio
import aiy.voicehat
from google.assistant.library.event import EventType
logging.basicConfig(
level=logging.INFO,
format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s"
)
def power_off_pi():
aiy.audio.say('Good bye!')
subprocess.call('sudo shutdown now', shell=True)
def reboot_pi():
aiy.audio.say('See you in a bit!')
subprocess.call('sudo reboot', shell=True)
def say_ip():
ip_address = subprocess.check_output("hostname -I | cut -d' ' -f1", shell=True)
aiy.audio.say('My IP address is %s' % ip_address.decode('utf-8'))
def process_event(assistant, event):
status_ui = aiy.voicehat.get_status_ui()
if event.type == EventType.ON_START_FINISHED:
status_ui.status('ready')
if sys.stdout.isatty():
print('Say "OK, Google" then speak, or press Ctrl+C to quit...')
elif event.type == EventType.ON_CONVERSATION_TURN_STARTED:
status_ui.status('listening')
elif event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED and event.args:
print('You said:', event.args['text'])
text = event.args['text'].lower()
if text == 'power off':
assistant.stop_conversation()
power_off_pi()
elif text == 'reboot':
assistant.stop_conversation()
reboot_pi()
elif text == 'ip address':
assistant.stop_conversation()
say_ip()
elif event.type == EventType.ON_END_OF_UTTERANCE:
status_ui.status('thinking')
elif (event.type == EventType.ON_CONVERSATION_TURN_FINISHED
or event.type == EventType.ON_CONVERSATION_TURN_TIMEOUT
or event.type == EventType.ON_NO_RESPONSE):
status_ui.status('ready')
elif event.type == EventType.ON_ASSISTANT_ERROR and event.args and event.args['is_fatal']:
sys.exit(1)
def main():
if platform.machine() == 'armv6l':
print('Cannot run hotword demo on Pi Zero!')
exit(-1)
credentials = aiy.assistant.auth_helpers.get_assistant_credentials()
with Assistant(credentials) as assistant:
for event in assistant.start():
process_event(assistant, event)
if __name__ == '__main__':
main()