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()
Voice Hat Motorsteuerung
Bitte setzt deinen Code in Python-Tags. Sonst ist dein Code nicht zu entziffern, da die Einrueckungen verloren gehen. Und wenn du das Problem geloest hast, aber dann weitere Aenderungen wuenschst, muessen wir natuerlich auch den aktuellen Stand kennen.
- __blackjack__
- User
- Beiträge: 13099
- Registriert: Samstag 2. Juni 2018, 10:21
- Wohnort: 127.0.0.1
- Kontaktdaten:
@janko84: Im (vollständigen) Editor für Beiträge gibt es über dem Texteingabefeld eine Schaltfläche mit der Aufschrift „Python“. Damit fügt man die Tags ein. Zwischen die Tags kommt dann der Python-Quelltext.
Anmerkungen zum Code: `led`, `pwm27`, und `pwm22` werden definiert, aber nicht verwendet.
``'off' or 'Stop' in text`` macht nicht was Du denkst. Das ``or`` ist kein umgangssprachliches „oder“ sondern ein binärer Operator wie ``+`` oder ``*``. Der linke Operand ist ``'off'`` und der rechte Operand ist ``'Stop' in text``. Nichtleere Zeichenketten sind ”wahr”, also ist ``'off'`` ”wahr” und damit ist der Ausdruck *immer* wahr. Korrekt wäre ``'off' in text or 'Stop' in text``.
Anmerkungen zum Code: `led`, `pwm27`, und `pwm22` werden definiert, aber nicht verwendet.
``'off' or 'Stop' in text`` macht nicht was Du denkst. Das ``or`` ist kein umgangssprachliches „oder“ sondern ein binärer Operator wie ``+`` oder ``*``. Der linke Operand ist ``'off'`` und der rechte Operand ist ``'Stop' in text``. Nichtleere Zeichenketten sind ”wahr”, also ist ``'off'`` ”wahr” und damit ist der Ausdruck *immer* wahr. Korrekt wäre ``'off' in text or 'Stop' in text``.
„All religions are the same: religion is basically guilt, with different holidays.” — Cathy Ladman
Hier der Code der funktioniert:
Jetzt will ich , das right und left jeweils nur 5 sekunden lang gehen und danach abschalten
etwas mit from time import sleep, aber weis nicht wie
Code: Alles auswählen
#!/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' in text:
print('Motor geht nach rechts')
pwm4.on()
pwm17.off()
elif 'left' in text:
print('Motor geht nach links')
pwm4.off()
pwm17.on()
if __name__ == '__main__':
main()
etwas mit from time import sleep, aber weis nicht wie
- __blackjack__
- User
- Beiträge: 13099
- Registriert: Samstag 2. Juni 2018, 10:21
- Wohnort: 127.0.0.1
- Kontaktdaten:
@janko84: Nee, der Code funktioniert nicht, wegen dem ``or``. Du kommst da nie dazu „left“ oder „right“ zu sagen, bzw. wird das nie erkannt, weil davor immer die Bedingung beim ersten ``elif`` greift, weil die immer wahr ist, egal was für einen Wert `text` hat.
Was ist denn jetzt Dein konkretes Problem damit `sleep` aus dem `time`-Modul zu importieren und zu verwenden?
Das Du `pwm22` und `pwm27` nicht benutzt sieht man ja am Code, die Frage ist warum Du sie dann definierst. Gilt wie gesagt auch für `led`.
Was ist denn jetzt Dein konkretes Problem damit `sleep` aus dem `time`-Modul zu importieren und zu verwenden?
Das Du `pwm22` und `pwm27` nicht benutzt sieht man ja am Code, die Frage ist warum Du sie dann definierst. Gilt wie gesagt auch für `led`.
„All religions are the same: religion is basically guilt, with different holidays.” — Cathy Ladman
Ja sorry, hab den falschen code einkopiert, mein code hat keine or mehr, auch die pwm22 und pwm27 sind weg.
es geht mir jetzt nur noch um die zeitliche steuerung, sprich left und right jeweils nur 5 sekunden laufen lassen, danach stop. das ist alles.
es geht mir jetzt nur noch um die zeitliche steuerung, sprich left und right jeweils nur 5 sekunden laufen lassen, danach stop. das ist alles.
Hier mein code:
Habe ch schon versucht, ghet aber nicht. Oben habe ich :
Code: Alles auswählen
#!/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
from time import sleep
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)
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 'right' in text:
print('Motor geht nach rechts')
pwm4.on()
pwm17.off()
elif 'left' in text:
print('Motor geht nach links')
pwm4.off()
pwm17.on()
if __name__ == '__main__':
main()
Code: Alles auswählen
from time import sleep
Code: Alles auswählen
elif 'right' in text:
print('Motor geht nach rechts')
pwm4.on()
sleep(5)
pwm17.off()
elif 'left' in text:
print('Motor geht nach links')
pwm4.off()
pwm17.on()
sleep(5)
- pillmuncher
- User
- Beiträge: 1484
- Registriert: Samstag 21. März 2009, 22:59
- Wohnort: Pfaffenwinkel
Dass es nicht geht, liegt daran, dass etwas nicht funktioniert.
PS: Wenn dir diese Antwort nicht hilft, überleg einmal, ob deine Art der Fragestellung viel hilfreicher ist.
In specifications, Murphy's Law supersedes Ohm's.
- __blackjack__
- User
- Beiträge: 13099
- 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: 13099
- 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