HI,
nach ein bisschen durchforsten des Forums habe ich den Beitrag
https://www.roboternetz.de/phpBB2/ze...ight=tv+remote
gefunden.
Jetzt habe ich das Programm verkleinert.
So jetzt zum Problem:Code:// Includes: #include "RP6RobotBaseLib.h" // The RP6 Robot Base Library. // Always needs to be included! /*****************************************************************************/ // Defines: // RP6 Base Servo Connection: #define SERVO_OUT ADC0 // PINC0 XBUS Pin 10 #define SERVO_OUT2 ADC1 // PINC0 XBUS Pin 10 // Servo movement limits (depending on servo type): #define LEFT_TOUCH 800 // Left servo touch #define RIGHT_TOUCH 254 // Right servo touch [max. 255] #define PULSE_ADJUST 4 #define PULSE_REPETITION 19 // Pulse repetition frequency #define RC5_KEY_LEFT 4 #define RC5_KEY_RIGHT 6 #define DIR_LEFT -1 #define DIR_RIGHT 1 #define DIR_NONE 0 int8_t direction = DIR_NONE; /*****************************************************************************/ // Functions: /** * INIT SERVO * * Call this once before using the servo task. * */ void initSERVO(void) { DDRA |= SERVO_OUT; // SERVO_OUT -> OUTPUT PORTA &= ~SERVO_OUT; // SERVO_OUT -> LO DDRA |= SERVO_OUT2; // SERVO_OUT -> OUTPUT PORTA &= ~SERVO_OUT2; // SERVO_OUT -> LO startStopwatch1(); // Needed for 20ms pulse repetition } /** * PULSE SERVO * * This is the servo pulse generation. This function * must be called every 20ms (pulse repetition). * * position = 0 : Left touch * position = RIGHT_TOUCH : Right touch * * ATTENTION: ! This function is BLOCKING all other activities for about 1 ! * ! to 2ms (depending on the value of position)!!! ! * ! If you generate a pulse every 20ms 5-10% of the processor's ! * ! calculating time is wasted by this kind of pulse generation. ! * ! If this is a problem for the rest of your program, you ! * ! cannot use this method. ! * ! You will need an interrupt-based solution instead. ! * */ void pulseSERVO(uint8_t position) { cli(); PORTA |= SERVO_OUT; // SERVO_OUT -> HI (pulse start) PORTA |= SERVO_OUT2; // SERVO_OUT -> HI (pulse start) delayCycles(LEFT_TOUCH); while (position--) { delayCycles(PULSE_ADJUST); } PORTA &= ~SERVO_OUT; // SERVO_OUT -> LO (pulse end) PORTA &= ~SERVO_OUT2; // SERVO_OUT -> LO (pulse end) sei(); } void receiveRC5Data(RC5data_t rc5data) { // Output the received data: writeString_P("Toggle Bit:"); writeChar(rc5data.toggle_bit + '0'); writeString_P(" | Device Address:"); writeInteger(rc5data.device, DEC); writeString_P(" | Key Code:"); writeInteger(rc5data.key_code, DEC); writeChar('\n'); if (rc5data.key_code == RC5_KEY_LEFT) { direction = DIR_LEFT; } else if (rc5data.key_code == RC5_KEY_RIGHT) { direction = DIR_RIGHT; } else { direction = DIR_NONE; } } /** * SERVO TASK * * This is the servo demo task. * The positioning demo shows the servo lever rapidly * moving to the left touch, then slowly moving to * the right touch and so on ... * */ void task_SERVO(void) {static uint8_t pos; if (getStopwatch1() > PULSE_REPETITION) { // Pulse every ~20ms pulseSERVO(pos); // Servo pulse [1..2ms] // --------------------------------------------------------------------- // Your test code for positioning the servo here: if (direction == DIR_LEFT){ setLEDs(0b111000); pos+=5; } else if (direction == DIR_RIGHT){ setLEDs(0b000111); pos-=5; } else{ pos = pos; } // --------------------------------------------------------------------- setStopwatch1(0); } } /*****************************************************************************/ // Main function - The program starts here: int main(void) { initRobotBase(); // Always call this first! The Processor will not work // correctly otherwise. // --------------------------------------- // Write messages to the Serial Interface: writeString_P("\n\n _______________________\n"); writeString_P(" \\| RP6 ROBOT SYSTEM |/\n"); writeString_P(" \\_-_-_-_-_-_-_-_-_-_/\n\n"); writeString_P("################\n"); writeString_P("<<RP6 Base>>\n"); writeString_P(" Servo - Test 1 \n"); writeString_P(" Version 1.00 \n"); writeString_P("################\n\n"); mSleep(2500); setLEDs(0b111111); // Turn all LEDs on mSleep(500); // delay 500ms setLEDs(0b000000); // All LEDs off powerON(); // Set the RC5 Receive Handler: IRCOMM_setRC5DataReadyHandler(receiveRC5Data); initSERVO(); startStopwatch2(); // Used for the demo task while(true) { task_SERVO(); task_RP6System(); } return 0; }
Meines wissens sollte im Terminal doch wenigstens angezeigt werden welche Taste gedrückt worden ist.... tut es aber nicht...
Liegt es vll. daran, dass das task_Servo den Ablauf zu lange blockiert und somit keine Signale ausgewertet werden können??
Gruß Biohazard







Zitieren

Lesezeichen