PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Warum läuft mein Prog nicht?



Elmar.Rieke
23.01.2006, 22:20
Tach zusammen
Ich verzweifle noch:
Mein ASURO soll bei einem druck auf die rechten Taster rechts blinken, bei einm Druck auf die linken Taster links blinken, das klappt auch.
Jetzt soll er auch noch in die jeweilige Richtung fahren, doch jedesmal wenn ich die Motorsteuerung auch nur anfasse, egal an welcher Programmstelle, führt er immer das Programm für "rechts" aus, egal welchen Schalter ich drücke.... ich blaube ich ](*,) ](*,)
Das Programm unten zeigt den Blinker, sobald man die Kommentare an der Motorsteuerungentfernt spinnt dat Ding.
Thx for help


#include "asuro.h"

int main(void)
{
unsigned int x;
unsigned int y;
unsigned int Sw;
Sw = 0;
Init();
StatusLED(GREEN);
while(1)
{ Sw = PollSwitch(); //Taster prüfen

if(Sw>0){ //Wenn Taster, schaun wir mal
StatusLED(YELLOW);
if(Sw<8){ //rechte Seite
for(y = 0;y < 3;y++){ // drei mal blinken
BackLED(OFF,ON);
for(x = 0;x < 180;x++){Sleep(255);}
BackLED(OFF,OFF);
for(x = 0;x < 180;x++){Sleep(255);}
}
/*
// Hier ein wenig nach rechts
MotorDir(FWD,BREAK);
MotorSpeed(190,0);
for(x = 0;x < 180;x++){Sleep(255);}
// Beide Motoren marsch
MotorDir(FWD,FWD);
MotorSpeed(190,190);
*/
StatusLED(GREEN);
BackLED(OFF,OFF);
}
else if(Sw>4){ // linke seite
for(y = 0;y < 3;y++){ // drei mal blinken
BackLED(ON,OFF);
for(x = 0;x < 180;x++){Sleep(255);}
BackLED(OFF,OFF);
for(x = 0;x < 180;x++){Sleep(255);}
}
/*
// und ein wenig nach links
MotorDir(BREAK,FWD);
MotorSpeed(0,190);
for(x = 0;x < 180;x++){Sleep(255);}
// und geradeaus
MotorDir(FWD,FWD);
MotorSpeed(190,190);
*/
// Blinker aus
StatusLED(GREEN);
BackLED(OFF,OFF);
}
}
else{
}
StatusLED(GREEN);
BackLED(OFF,OFF);
Sw = 0;
}
return 0;
//return 0;
}

djselbeck
24.01.2006, 10:30
Hallo,

hatte dieses Problem auch erst. Das liegt daran, dass der Motor scheinbar Störimpulse sendet, so dass das Schaltersignal beeinflusst wird. es lässt sich lösen in dem du:



unsigned int Sw[5] = {0,0,0,0,0};

Init();
StatusLED(GREEN);
while(1)
{
int i=0;
for(i=0;i<5;i++)
{
Sw[i]=PollSwitch();
}
if((Sw[1]>0)&&(Sw[2]>0)&&(Sw[3]>0)&&(Sw[0]>0)&&(Sw[4]>0)){ //Wenn Taster, schaun wir mal
StatusLED(YELLOW);
if((Sw[1]<8)&&(Sw[2]<8)&&(Sw[3]<8)&&(Sw[0]<8)&&(Sw[4]<8)){ //rechte Seite
for(y = 0;y < 3;y++){ // drei mal blinken
BackLED(OFF,ON);
for(x = 0;x < 180;x++){Sleep(255);}
BackLED(OFF,OFF);
for(x = 0;x < 180;x++){Sleep(255);}
}
/*
// Hier ein wenig nach rechts
MotorDir(FWD,BREAK);
MotorSpeed(190,0);
for(x = 0;x < 180;x++){Sleep(255);}
// Beide Motoren marsch
MotorDir(FWD,FWD);
MotorSpeed(190,190);
*/
StatusLED(GREEN);
BackLED(OFF,OFF);
}
else if((Sw[1]>4)&&(Sw[2]>4)&&(Sw[3]>4)&&(Sw[0]>4)&&(Sw[4]>4)){ // linke seite
for(y = 0;y < 3;y++){ // drei mal blinken
BackLED(ON,OFF);
for(x = 0;x < 180;x++){Sleep(255);}
BackLED(OFF,OFF);
for(x = 0;x < 180;x++){Sleep(255);}
}
/*
// und ein wenig nach links
MotorDir(BREAK,FWD);
MotorSpeed(0,190);
for(x = 0;x < 180;x++){Sleep(255);}
// und geradeaus
MotorDir(FWD,FWD);
MotorSpeed(190,190);
*/
// Blinker aus
StatusLED(GREEN);
BackLED(OFF,OFF);
}
}
else{
}
StatusLED(GREEN);
BackLED(OFF,OFF);
Sw = 0;
}
return 0;
//return 0;
}

Elmar.Rieke
24.01.2006, 20:33
Super, klappt!
Sieht nach einem timing-Problem aus? Du liest einfach die PollSwitches 5mal hintereinander aus und hoffst das einer im Array das Signal mitbekommen hat, richtig?

Na, jedenfalls besten Dank
Elmar =D>

m.a.r.v.i.n
25.01.2006, 08:07
Normalerweise sollte auch 2x PollSwitch aufrufen mit anschließendem Vergleich auch ausreichen:



unsigned char Sw1, Sw2;

Sw1 = PollSwitch();
Sw2 = PollSwitch();

if (Sw1 && Sw2 && Sw == Sw2) // Schalter gedrückt und gleiches Ergebnis
{
if (Sw1 < 8) // rechte Seite
...


Gruß Peter