int main(void) { initRobotBase(); // Always call this first! // The Processor will not work correctly otherwise. // Write a text message to the UART: writeString_P("\nCounting and Receiving\n"); // Define a counting variable: uint16_t counter = 0; // clear the UART buffer once at the start of the program clearReceptionBuffer(); while(true) { // example of sending some data over UART counter++; SendDataOverUART(counter); //example of receiving some data over UART ShowDataReceivedOverUART(); mSleep(100); // delay 100ms = 0.1s } return 0; }
int main(void) { int i = 0; int timer; //Init Robotarm initRobotBase(); //Init Display vInitDisplay(); //Set Robotarm powerLED on green PowerLEDorange(); while(1){ //Write value 'i' to display ucShowPositiveDecimalValueInDisplay(i); //Wait 10 times 10 ms = 1 sec for(timer=0; timer<10; timer++){ mSleep(100); } //increment value 'i' with 1 i++; } }
int main(void) { initRobotBase(); setLEDs(0b111111); mSleep(1500); setLEDs(0b000000); // Set Bumpers state changed event handler: BUMPERS_setStateChangedHandler(bumpersStateChanged); powerON(); // Turn Encoders, Motor Current Sensors // ATTENTION: Automatic Motor control will not work without this! /* RP6 SAGAN GENERATED COMMANDS START */ /*{SAGAN1_COMMANDS_HERE}*/ /* RP6 SAGAN GENERATED COMMANDS STOP */ stop(); moveAtSpeed(0, 0); BUMPERS_setStateChangedHandler(BUMPERS_stateChanged_empty); setLEDs(0b000000); while (true) { statusLEDs.LED2 = !statusLEDs.LED2; // Toggle LED bit in LED shadow register... statusLEDs.LED5 = !statusLEDs.LED5; updateStatusLEDs(); mSleep(500); task_RP6System(); } return 0; }
int16_t main(void) { initRobotBase(); powerON(); setLEDs(0b111111); mSleep(1000); setLEDs(0b000000); mSleep(500); uint8_t runningLight = 1; for (uint8_t i = 0; i < 6; i++){ for (uint8_t j = 0; j< 3;j++) destination[j] = destinationarray[i][j]; //mainloopOpen(); mainloopClosed(); fancyled(&runningLight); /*for (uint8_t j = 0; j< 3;j++) source[j] = destination[j];*/ mSleep(2000); } task_RP6System(); while(true) { fancyled(&runningLight); if (motioncomplete == 0) moveAtSpeed(0,0); mSleep(200); task_RP6System(); } return 0; }
int main(void) { initRobotBase(); // Always call this first! The Processor will not work // correctly otherwise. mSleep(1000); // delay 1s speed = 0; //Speed for servo from '0'(fast) - '10'(slow) writeString_P("\n Key Board Control \n\n"); Start_position(); //Use this function to set the servomotor in the centre. //This function must be called before using Power_Servos(); Power_Servos(); //Use this function to power the servo motors on //When you want to power off the servos, you need to call function Power_Off_Servos(); // --------------------------------------- // Main loop: while(true) { Event(scan_keyboard()); // End of main loop! // --------------------------------------- } return 0; }
int main(void) { initRobotBase(); // Always call this first! The Processor will not work // correctly otherwise. writeString_P("\nRP6 Stopwatch Demo Program\n"); writeString_P("__________________________\n\n"); // Start all used Stopwatches: startStopwatch1(); startStopwatch2(); startStopwatch3(); startStopwatch4(); // Set a stopwatch to a specific initial value: setStopwatch2(1600); // Main loop while(true) { // Here we call the four "tasks" we have. // You should poll each stopwatch // in it's own function like it is done here, this keeps the sourcecode // a bit more tidy. (In the RP6 Manual you can find an example // which has this within the main method) task_LEDs(); task_counter1(); task_counter2(); task_counter3(); } return 0; }
int main(void) { initRobotBase(); setLEDs(0b111111); mSleep(500); setLEDs(0b000000); writeString_P("\nJust a simple counter program\n\n"); uint16_t counter = 0; while(true) { timer = 0; if(counter < 100) { writeString_P("Counter: "); writeInteger(counter, BIN); writeString_P("(BIN) | "); writeInteger(counter, OCT); writeString_P("(OCT) | "); writeInteger(counter, DEC); writeString_P("(DEC) | "); writeInteger(counter, HEX); writeString_P("(HEX) "); } else { writeString_P("Counter L: "); writeIntegerLength(counter, BIN, 16); writeString_P("(BIN) | "); writeIntegerLength(counter, OCT, 6); writeString_P("(OCT) | "); writeIntegerLength(counter, DEC, 6); writeString_P("(DEC) | "); writeIntegerLength(counter, HEX, 4); writeString_P("(HEX) "); } writeChar(' '); writeInteger(timer,DEC); writeString(" *100us"); writeChar('\n'); counter++; mSleep(100); } return 0; }
int main(void) { initRobotBase(); setLEDs(0b111111); mSleep(2500); setLEDs(0b100100); BUMPERS_setStateChangedHandler(bumpersStateChanged); powerON(); while(true) { behaviourController(); task_RP6System(); } return 0; }
int main(void) { question = 0; initRobotBase(); // Always call this first! The Processor will not work // correctly otherwise. Leds_Beeper(); writeString_P("\nHello! My name is RobotArmy\n"); while(true) { if(question != -1) askAQuestion(); } return 0; }
int main(void) { initRobotBase(); setLEDs(0b111111); mSleep(2500); powerON(); // Turn on Encoders, Current sensing, ACS and Power LED. /* In the following code segment we use the functions void move(uint8_t desired_speed, uint8_t dir, uint16_t distance, uint8_t blocking) and void rotate(uint8_t desired_speed, uint8_t dir, uint16_t angle, uint8_t blocking) The parameters have the following purposes: move: uint8_t desired_speed: The Speed the robot should try to maintain all the time during the movement. (but it will slow down a bit before it reaches the desired distance) uint8_t dir: The Direction the robot should move - this can be FWD for Forwards or BWD for Backwards. You can also use LEFT or RIGHT here, but this function is not optimized for rotation - you should use rotate instead! uint16_t distance: The distance we want to move. The distance needs to be given in encoder counts. You can use the macro DIST_MM() to convert the distance from mm to encoder counts if you have calibrated your Encoder sensors resoultion. Maximum distance is 65000 encoder counts! (not 65535 like you might have thought. There needs to be a bit space to the top value... anyways - who wants to move about 15m? ;) ) uint8_t blocking: This parameter sets if the function shall block the normal program flow during the movement. If the parameter is "true", the function will NOT quit until the robot has moved the given distance! ACS, Bumper, RC5 and other events are still processed and not affected, but the main program will be blocked (s. below). You can use "BLOCKING" instead of "true" and "NON_BLOCKING" instead of false to make the code more readable! rotate: uint8_t desired_speed: Same as above. uint8_t dir: Nearly the same as above, but here you should only use LEFT or RIGHT as parameters even if you can pass BWD or FWD to this function. uint16_t angle The angle to turn. Attention: This rotation function is not optimal for very small angles - it is optimized to turn angles over 25°! If you want smaller angles, you need to write your own function! And even for large angles this function is far away from beeing perfect as the encoder errors for rotation are rather big. You need to do some experiments to optimize this for the surfaces you want to use the Robot on. The encoders are mainly intended for very good speed regulation and don't work too well for tracked vehicles' dead reckoning. Not only for RP6 but for EVERY tracked vehicle out there - even for those with $10.000 price tag. Measuring distances when moving straight forward works OK - but not when rotating as there is a lot of tracks slippery and you always don't move as far as you measured. Solution: Use external sensors for rotation! Like electronic compass, gyroscopes, optical mouse sensor or similar. Also s. comments in next example! To block or not to block: If you set the "blocking" parameter to false, then the function will only set all necessary parameters and quit - it will not wait until the movement has finished. This code: move(60, FWD, DIST_MM(300), false); // <-- non blocking rotate(50, LEFT, 180, false); // <-- blocking mSleep(5000); would NOT work as intended! The Robot would NOT move 300mm and then turn 180°, instead it would only turn 180°! And, if you remove the mSleep(5000) at the end, it would maybe not even do this. You always need to check if the movement has finished and if you can initiate the next movement if you set the blocking parameter to false! This: move(60, FWD, DIST_MM(300), true); // <-- blocking movement rotate(50, LEFT, 180, true); // <-- blocking rotation would work like intended and the robot would move 300mm, turn 180° and stop. This is equivalent to this: move(60, FWD, DIST_MM(300), false); // <-- non-blocking movement while(!isMovementComplete()) // Now we need to wait until the movement task_RP6System(); // is finished before we go on. // If you set blocking to true, the function // does exactly this automatically. rotate(50, LEFT, 180, false); // <-- non-blocking rotation while(!isMovementComplete()) // Again, we need to wait for the task_RP6System(); // movement (rotation) to be finished... Of course, you do not need to wait for the movement to finish in a while-loop - you can also check this in several different ways and you can do other things while the movement is in progress. You will see some other ways in the next examples. You can use the "isMovementComplete()" function for checking if the last movement is complete. There is also a function "stop()" that can be used to abort a movement, e.g. if one of the sensors has detected an obstacle. But you do not need to use stop, you can also initiate the next movement without performing "stop" before. */ // Ok, now back to the example program. If you want this to work accurate, you // need to calibrate the encoders (s. RP6 manual)! // Main loop while(true) { setLEDs(0b100100); /* move(60, FWD, DIST_MM(300), true); // Move 300mm forwards // at Speed 60*5 ~= 300 counts/second // = 7.5cm/s with 0.25mm resolution // (6.9cm/s with 0.23mm resolution...) setLEDs(0b100000); rotate(50, LEFT, 180, true); // rotate 180° left setLEDs(0b100100); move(60, FWD, DIST_MM(300), true); // move 30cm forwards setLEDs(0b000100); rotate(50, RIGHT, 180, true); // rotate 180° right */ moveAtSpeed(0,0); //Bremsen move(70, BWD, DIST_MM(150), BLOCKING); //zurückfahren rotate(40, RIGHT, 30, BLOCKING); //Drehen move(70, FWD, DIST_MM(200), BLOCKING);//Vorwärts (am Hindernis vorbei) fahren rotate(40, LEFT, 30, BLOCKING); //zurückdrehen //dann geradeaus weiter } return 0; }
int main(void) { initRobotBase(); // Always call this first! The Processor will not work // correctly otherwise. // --------------------------------------- // Write messages to the Serial Interface // (here it is a RP6 text logo): writeString_P("\n\n _______________________\n"); writeString_P(" \\| RP6 ROBOT SYSTEM |/\n"); writeString_P(" \\_-_-_-_-_-_-_-_-_-_/\n\n"); // Explanation of special chars: // '\n' = new line // '\\' = '\' // These are "escape sequences" for characters you can not // use directly within strings. // Write "Hello World" to the Serial Interface: writeString_P("Hello World! My name is Robby!\n"); writeString_P("Let's go! :)\n"); // --------------------------------------- // LEDs: setLEDs(0b111111); // Turn all LEDs on! // 0b111111 is a binary value and is the same as // 63 in the decimal system. // For this routine, the binary value is better to read, because each bit // represents one of the LEDs. // e.g. this: // setLEDs(0b000001); would set only LED1 // setLEDs(0b000010); LED2 // setLEDs(0b000100); LED3 // setLEDs(0b101001); LED6, LED4, LED1 - and so on! mSleep(1000); // delay 1000ms = 1s setLEDs(0b000000); // All LEDs off! mSleep(500); // delay 500ms = 0.5s // --------------------------------------- uint8_t runningLight = 1; // This defines the local unsigned 8 bit variable "runningLight". // It can be accessed everywhere _below_ in this function. // And ONLY within this function! // --------------------------------------- // Main loop - the program will loop here forever! // In this program, it only runs a small LED chaselight. while(true) { // Here we do a small LED test: // --------------------------------------- setLEDs(runningLight); // Set status LEDs to the value of the variable // testLEDs. // In the first loop iteration it has the value 1, // and thus the StatusLED1 will be switched on. runningLight <<= 1; // shift the bits of "runningLight" one step to the left. // As there is only one bit set in this variable, // only one LED is on at the same time. // This results is a moving light dot like this: // 1: 0b000001 // 2: 0b000010 // 3: 0b000100 // 4: 0b001000 // 5: 0b010000 // 6: 0b100000 // // In decimal format that would be the numbers: // 1, 2, 4, 8, 16, 32 // When we have reached a value > 32 (32 means Status LED6 is on), // we need to reset the value of runningLight to 1 to start again // from the beginning... // Instead of "32" we could also write "0b100000". if(runningLight > 32) runningLight = 1; // reset runningLight to 1 (StatusLED1) // If we want to see the running Light, we need to // add a delay here - otherwise our human eyes would not see // the moving light dot: mSleep(100); // delay 100ms = 0.1s // --------------------------------------- } // End of main loop // --------------------------------------- // --------------------------------------- // The Program will NEVER get here! // (at least if you don't perform a "break" in the main loop, which // you should not do usually!) return 0; }
int main(void) { initRobotBase(); // Always call this first! The Processor will not work // correctly otherwise. setLEDs(0b111111); // Turn all LEDs on mSleep(500); // delay 500ms setLEDs(0b000000); // All LEDs off // Write a text message to the UART: writeString_P("\nJust a simple counter program\n\n"); // Define a counting variable: uint16_t counter = 0; // --------------------------------------- // Main loop: while(true) { timer = 0; // initialize universal timer variable for measuring how much // time the output required! (this is not directly related to this // example - it was added as a small example for the new System // timer added in Version 1.3 of the RP6Lib) // The timer has a resolution of 100µs and runs all the time. // Now we check what value the counter has, ... if(counter < 100) // ... is it smaller than 100? { // Yes --> output the Counter value with the "writeInteger" // function: writeString_P("Counter: "); writeInteger(counter, BIN); writeString_P("(BIN) | "); writeInteger(counter, OCT); writeString_P("(OCT) | "); writeInteger(counter, DEC); writeString_P("(DEC) | "); writeInteger(counter, HEX); writeString_P("(HEX) "); } else // ... or is it greater than or equal to 100? { // No, the counter >= 100 --> use "writeIntegerLength" instead. writeString_P("Counter L: "); writeIntegerLength(counter, BIN, 16); writeString_P("(BIN) | "); writeIntegerLength(counter, OCT, 6); writeString_P("(OCT) | "); writeIntegerLength(counter, DEC, 6); writeString_P("(DEC) | "); writeIntegerLength(counter, HEX, 4); writeString_P("(HEX) "); } writeChar(' '); writeInteger(timer,DEC); // display time (in 100µs) we needed for this output! // You will directly see that the time increases when // the output gets longer. writeString(" *100us"); writeChar('\n'); // New Line counter++; // Increment counter mSleep(100); // delay 200ms = 0.2s } // End of main loop! // --------------------------------------- return 0; }