Ich gebe dem RP6 über die Kommunikationsschnittstelle einen Rotate-Befehl und möchte diesen unterbrechen können, wenn ich ihm den nächsten Befehl "stop" sende. Ist das möglich?
Zur Zeit bekommt er den "stop"-Befehl erst, wenn der Rotate-Befehl komplett abgearbeitet ist. Kann man irgendwie einen neuen Eventhandler einbauen oder gibt es einen anderen Weg zur Lösung?
Hier ist der Code:
Wenn ich bei dem Rotate-Befehl das "BLOCKING" auf "NON_BLOCKING" setze, dreht er sich nicht und fährt auch nicht. Woran könnte das liegen?Code:#define MOVE_SPEED 100 #define TURN_SPEED 40 uint16_t tENCL_min_l_time = 0; uint16_t tENCL_min_h_time = 0; uint16_t tENCL_max_l_time = 0; uint16_t tENCL_max_h_time = 0; uint16_t tENCR_min_l_time = 0; uint16_t tENCR_min_h_time = 0; uint16_t tENCR_max_l_time = 0; uint16_t tENCR_max_h_time = 0; void runRobot(void) { uint16_t pwm_tmp = 0; uint16_t pwm = 0; uint8_t turn_direction = LEFT; uint8_t move_direction = FWD; uint8_t move_or_rotate = 0; powerON(); setMotorDir(FWD,FWD); moveAtSpeed(0,0); startStopwatch1(); startStopwatch2(); setMotorPower(pwm,pwm); mSleep(500); writeString("runRobot\n"); clearReceptionBuffer(); while(true) { if(getInputLine()) { if(strcmp(receiveBuffer,"end")==0 || strcmp(receiveBuffer,"x")==0) { writeString_P("\nEND\n"); break; } else if(strcmp(receiveBuffer,"fwd")==0) { writeString_P("\nACK\n"); writeString_P("\nChange direction: FWD\n"); setMotorDir(FWD,FWD); move_direction = FWD; move_or_rotate = 1; } else if(strcmp(receiveBuffer,"bwd")==0) { writeString_P("\nACK\n"); writeString_P("\nChange direction: BWD\n"); setMotorDir(BWD,BWD); move_direction = BWD; move_or_rotate = 1; } else if(strcmp(receiveBuffer,"l")==0) { writeString_P("\nACK\n"); writeString_P("\nChange direction: Left\n"); setMotorDir(BWD,FWD); turn_direction=LEFT; move_or_rotate = 2; } else if(strcmp(receiveBuffer,"r")==0) { writeString_P("\nACK\n"); writeString_P("\nChange direction: Right\n"); setMotorDir(FWD,BWD); turn_direction=RIGHT; move_or_rotate = 2; } //******************************************************// //**********hier kommt stop und sollte rotate beenden*********// else if(strcmp(receiveBuffer,"stop")==0) { writeString_P("\nStop all wheels\n"); move(0, FWD, DIST_MM(0), BLOCKING); move_or_rotate = 0; } else if(strcmp(receiveBuffer,"bat")==0) { writeString_P("\nBat:"); printUBat(adcBat); writeChar('\n'); } else { if(move_or_rotate == 0) { writeString_P("\nSelect a direction first\n"); } else { pwm_tmp = atoi(receiveBuffer); if(pwm_tmp == 0) { uint8_t not_a_number = 0; int8_t i; for(i = strlen(receiveBuffer)-1; i >= 0 ; i--) if((receiveBuffer[i] < '0') || (receiveBuffer[i] > '9')) { not_a_number = 1; writeString_P("\n### NOT A NUMBER! ###\n"); break; } if(not_a_number) pwm_tmp = pwm; } else if(pwm_tmp < 0) {pwm_tmp = 0;} pwm = pwm_tmp; if(move_or_rotate == 1) { writeString_P("\nDrive now "); writeInteger(pwm_tmp,DEC); writeChar('\n'); //******************************************************// //**********BLOCKING oder NON_BLOCKING?*********// move(MOVE_SPEED, move_direction, DIST_MM(pwm), BLOCKING); writeString_P("\nACK\n"); pwm = 0; } else if(move_or_rotate == 2) { writeString_P("\nrotate now "); writeInteger(pwm_tmp,DEC); writeChar('\n'); //******************************************************// //**********BLOCKING oder NON_BLOCKING?*********// rotate(TURN_SPEED, turn_direction, pwm, BLOCKING); writeString_P("\nACK\n"); pwm = 0; } else { writeString_P("\nundefined error please send again\n"); } } } } task_ADC(); } stopStopwatch1(); stopStopwatch2(); mSleep(500); setMotorPower(0,0); setMotorDir(FWD,FWD); powerOFF(); }
Außerdem weiß ich nicht, wie man einen neuen Eventhandler implementiert in C, kann mir da jemand helfen?
Vielen Dank.







Zitieren

Lesezeichen