Skocz do zawartości

Problem z zaprogramowaniem linefollowera w Bascomie


Pomocna odpowiedź

Tłumaczenie na polski

Jeżeli pinb.6 = 1 i Pinb.5 = 0 to Prawo

Prawo jest komendą nie znaną bo te suby są źle zrobione. Możesz je usunąć. Zobacz kod z artykułu o programowalnym lf'ie.

Aby uruchomić silnik dajesz stan wysoki na tranzystor a aby zatrzymać niski.

PORTB.0 = 1

Uruchamia silnik

PORTB.0 = 0

Gasi go

Aby sterować drugim zmieniasz PORTB.0 na PORTB.1

Teraz nie wiedziałem za bardzo jak napisać gdy na skręcać w prawo to żeby lewy silnik się kręcił i wyszło mi takie coś;

'***** konfiguracja portów *****
$regfile = "attiny13.dat"


Sensor1 Alias Pinb.7 Czujnik Lewy
Sensor2 Alias Pinb.3 Czujnik Srodkowy
Sensor3 Alias Pinb.2 Czunik Prawy


Config Pinb.5 = Output
Config Pinb.6 = Output

Do
If Pinb.7 = 1 And Pinb.3 = 0 And Pinb.2 = 0 Then Pinb.6 = 0 And Pinb.5 = 1
If Pinb.7 = 1 And Pinb.3 = 1 And Pinb.2 = 0 Then Pinb.6 = 0 And Pinb.5 = 1
If Pinb.7 = 0 And Pinb.3 = 1 And Pinb.2 = 1 Then Pinb.6 = 1 And Pinb.5 = 0
If Pinb.7 = 0 And Pinb.3 = 0 And Pinb.2 = 1 Then Pinb.6 = 1 And Pinb.5 = 0
If Pinb.7 = 1 And Pinb.3 = 0 And Pinb.2 = 1 Then Pinb.6 = 1 And Pinb.5 = 1
If Pinb.7 = 1 And Pinb.3 = 1 And Pinb.2 = 1 Then Pinb.6 = 1 And Pinb.5 = 1




Loop

End If

End                                                         'end pro

Tak ? :

'***** konfiguracja portów *****
$regfile = "attiny13.dat"

Config Pinb.7 = Input
Config Pinb.3 = Input
Config Pinb.2 = Input


Config Pinb.5 = Output
Config Pinb.6 = Output

Do
If Pinb.7 = 1 And Pinb.3 = 0 And Pinb.2 = 0 Then Pinb.6 = 0 And Pinb.5 = 1
If Pinb.7 = 1 And Pinb.3 = 1 And Pinb.2 = 0 Then Pinb.6 = 0 And Pinb.5 = 1
If Pinb.7 = 0 And Pinb.3 = 1 And Pinb.2 = 1 Then Pinb.6 = 1 And Pinb.5 = 0
If Pinb.7 = 0 And Pinb.3 = 0 And Pinb.2 = 1 Then Pinb.6 = 1 And Pinb.5 = 0
If Pinb.7 = 1 And Pinb.3 = 0 And Pinb.2 = 1 Then Pinb.6 = 1 And Pinb.5 = 1
If Pinb.7 = 1 And Pinb.3 = 1 And Pinb.2 = 1 Then Pinb.6 = 1 And Pinb.5 = 1




Loop

End If

End                                                         'end

Kod powinien działać. Można tylko zoptymalizować te ify. Możesz usunąć warunki w których są wymagane zera bo są nie potrzebne. Nie całe ify tylko kawałek np Pinb.3 = 0. Jeżeli zostanie to w programie to będzie przeszkadzać.

Usuń ten end if. Ułomnością bascoma jest ilość parametrów w lini. Musisz rozpisać te ify na rozbudowane. W tutku bascoma jest.

Wydzieliłem posty z tematu o robocie forumowicza grabo. Proszę prowadzić dyskusję dotyczącą problemów modelarza w tym temacie. Autora proszę o więcej samodzielności, bo forum to nie miejsce na robienie gotowców.

Chodziło mi o taki zapis

if pinb.1 = 1 then 
 zmienna = 1 
 kobieta = 3 
 portb.3 = 2 
end if

Wyżej nie potrzebnie masz tyle and. And po angielsku znaczy i. Usuń tam gdzie nie pasuje.

Bądź aktywny - zaloguj się lub utwórz konto!

Tylko zarejestrowani użytkownicy mogą komentować zawartość tej strony

Utwórz konto w ~20 sekund!

Zarejestruj nowe konto, to proste!

Zarejestruj się »

Zaloguj się

Posiadasz własne konto? Użyj go!

Zaloguj się »
×
×
  • Utwórz nowe...