Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
#include "hardware.h"// Initialise the hardwarevoid appInitHardware(void) { initHardware();// Set UART1 to 115200 baud uartInit(UART1, 115200); // Tell rprintf to output to UART1 rprintfInit(&uart1SendByte);}// Initialise the softwareTICK_COUNT appInitSoftware(TICK_COUNT loopStart){ return 0;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) { // -------- Start Switch/Button------- // Switch/Button - see switch.h // To test if it is pressed then if(SWITCH_pressed(&button)){ // pressed } // To test if it is released then if(SWITCH_released(&button)){ // released } // -------- End Switch/Button------- // -------- Start Marquee------- // Marquee - see 'segled.h' // Before using the Marquee you need to redirect rprintf to write to it // This can be done using Writer old = rprintfInit(marqueeGetWriter(&marquee)); // All rprintf output will then be sent to the marquee but will not // display until an end-of-line eg "\n" has been sent. Example:- // rprintf("Hello World\n"); // If the endDelay is non-zero then the marquee will scroll // forever or until you call: marqueeStop(&marquee); // If the endDelay is zero then the marquee will stop once // the entire line has been shown ('one-shot' mode) // In 'one-shot' mode then you may want to make sure that // a previous line has finished before you display a second line. // This can be done as follows:- marqueeSetEndDelay(&marquee,0); // Make sure we are in one-shot mode if(marqueeIsActive(&marquee)==FALSE){ if(loopCount==1){ rprintf("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"); }else{ rprintf("Loop=%u\n",(unsigned)loopCount); // Put the loop count } } // Restore rprintf back to its previous location rprintfInit(old); // -------- End Marquee------- // -------- Start Sharp GP2------- // Read the Sharp GP2 and store the result in ADC_ir_sensor.distance.cm distanceRead(ADC_ir_sensor); // The value can be printed using %u eg rprintf("Distance=%u",ADC_ir_sensor.distance.cm); // or dumped using: rprintf("ADC_ir_sensor: "); distanceDump(ADC_ir_sensor); rprintfCRLF(); // -------- End Sharp GP2------- // -------- Start Actuators ------- // To control your.motors/servos then see actuators.h in the manual // To retrieve the required speed of Left_wheel use: // DRIVE_SPEED speed=act_getSpeed(Left_wheel); // To set the required speed of Left_wheel use: // act_setSpeed(Left_wheel,speed); // This example will move the motors back and forth using the loopStart time: TICK_COUNT ms = loopStart / 1000; // Get current time in ms int16_t now = ms % (TICK_COUNT)10000; // 10 sec for a full swing if(now >= (int16_t)5000){ // Goes from 0ms...5000ms now = (int16_t)10000 - now; // then 5000ms...0ms } // Map it into DRIVE_SPEED range DRIVE_SPEED speed = interpolate(now, 0, 5000, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX); // Set speed for all motors/servos act_setSpeed(&Left_wheel,speed); act_setSpeed(&Right_wheel,speed); act_setSpeed(&IR_servo,speed); // -------- End Actuators ------- return 0;}
#include "hardware.h"//global variablesint sharp_IR_reading=0;int scan_thresh=0;//threshold value of scanning sensorint scan_angle=30;//position of scanner, in units of servo commandint max_scan_angle=56;//maximum position scanner can rotate to (57)// Initialise the hardwarevoid appInitHardware(void) { initHardware();// Set UART1 to 115200 baud uartInit(UART1, 115200); // Tell rprintf to output to UART1 rprintfInit(&uart1SendByte);}// Initialise the softwareTICK_COUNT appInitSoftware(TICK_COUNT loopStart){ return 0;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) { // -------- Start Switch/Button------- // Switch/Button - see switch.h // To test if it is pressed then if(SWITCH_pressed(&button)){ // pressed } // To test if it is released then if(SWITCH_released(&button)){ // released } // -------- End Switch/Button------- // -------- Start Marquee------- // Marquee - see 'segled.h' // Before using the Marquee you need to redirect rprintf to write to it // This can be done using Writer old = rprintfInit(marqueeGetWriter(&marquee)); // All rprintf output will then be sent to the marquee but will not // display until an end-of-line eg "\n" has been sent. Example:- // rprintf("Hello World\n"); // If the endDelay is non-zero then the marquee will scroll // forever or until you call: marqueeStop(&marquee); // If the endDelay is zero then the marquee will stop once // the entire line has been shown ('one-shot' mode) // In 'one-shot' mode then you may want to make sure that // a previous line has finished before you display a second line. // This can be done as follows:- marqueeSetEndDelay(&marquee,0); // Make sure we are in one-shot mode if(marqueeIsActive(&marquee)==FALSE){ if(loopCount==1){ rprintf("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"); }else{ rprintf("Loop=%u\n",(unsigned)loopCount); // Put the loop count } } // Restore rprintf back to its previous location rprintfInit(old); // -------- End Marquee------- // -------- Start Sharp GP2------- // Read the Sharp GP2 and store the result in ADC_ir_sensor.distance.cm distanceRead(ADC_ir_sensor); // The value can be printed using %u eg rprintf("Distance=%u",ADC_ir_sensor.distance.cm); // or dumped using: rprintf("ADC_ir_sensor: "); distanceDump(ADC_ir_sensor); rprintfCRLF(); // -------- End Sharp GP2------- // -------- Start Actuators ------- // To control your.motors/servos then see actuators.h in the manual // To retrieve the required speed of Left_wheel use: // DRIVE_SPEED speed=act_getSpeed(Left_wheel); // To set the required speed of Left_wheel use: // act_setSpeed(Left_wheel,speed); // This example will move the motors back and forth using the loopStart time://this function causes scanning servo to center on edge of objectvoid scan(void) { //lower (-) goes right //higher (+) goes left //30 far right, 50 straight, 56 far left (until it jams) sharp_IR_reading=a2dConvert8bit(3); if (sharp_IR_reading > scan_thresh)//object detected { if (scan_angle>41) //overflow protection scan_angle-=2;//scan right } else //object not detected { if (scan_angle<=max_scan_angle) //maximum servo angle scan_angle+=2; //scan left else //if scanned all the way, this forces it to start over scan_angle=30; } //servo scan code servo_scan(scan_angle); }//automatically calculates threshold value before runvoid autocalibrate(void) { scan_thresh=a2dConvert8bit(3);//sensor reading }int main(void) { //LED_on(); initialize(); delay_cycles(42000);//two second wait delay//find thresholds autocalibrate(); //LED_off(); while(1) { scan(); //object on left if(scan_angle > 57) robot_turn_left(); //object on right else if(scan_angle < 41) robot_turn_right(); //object is centered else robot_go_straight(); delay_cycles(400);//a small delay to prevent crazy oscillations } /*********ADD YOUR CODE ABOVE THIS LINE **********/ return 0; }
Build started 20.4.2011 at 22:07:21avr-gcc -g -Wall -DF_CPU=16000000 -mmcu=atmega640 -gdwarf-2 -std=gnu99 -fpack-struct -fshort-enums -funsigned-char -funsigned-bitfields -I"../../WebbotLib" -MD -MP -MT irtest.o -MF irtest.d -O0 -c -o irtest.o irtest.cirtest.c: In function 'scan':irtest.c:118: warning: implicit declaration of function 'servo_scan'irtest.c: In function 'appControl':irtest.c:128: warning: 'main' is normally a non-static functionirtest.c: In function 'main':irtest.c:132: warning: implicit declaration of function 'initialize'irtest.c:149: warning: implicit declaration of function 'robot_turn_left'irtest.c:153: warning: implicit declaration of function 'robot_turn_right'irtest.c:157: warning: implicit declaration of function 'robot_go_straight'irtest.c: In function 'appControl':irtest.c:164: error: expected declaration or statement at end of inputirtest.c:164: warning: control reaches end of non-void functionmake: *** [irtest.o] Error 1Build failed with 1 errors and 7 warnings...
'initialize''robot_turn_left''robot_turn_right''robot_go_straight'servo_scan'
Ok i get it, nobody wants to do this for me and i under stand. I just wanted to compare "good " code with what i believe to be the not so good code i am using. I have continued to try to get this to work with but with no luck. this is the code i have been trying to compile maybe someone can look at this and let me know where i am going wrong ..i hope.. I get 1 error and 7 warnings they are :QuoteBuild started 20.4.2011 at 22:07:21avr-gcc -g -Wall -DF_CPU=16000000 -mmcu=atmega640 -gdwarf-2 -std=gnu99 -fpack-struct -fshort-enums -funsigned-char -funsigned-bitfields -I"../../WebbotLib" -MD -MP -MT irtest.o -MF irtest.d -O0 -c -o irtest.o irtest.cirtest.c: In function 'scan':irtest.c:118: warning: implicit declaration of function 'servo_scan'irtest.c: In function 'appControl':irtest.c:128: warning: 'main' is normally a non-static functionirtest.c: In function 'main':irtest.c:132: warning: implicit declaration of function 'initialize'irtest.c:149: warning: implicit declaration of function 'robot_turn_left'irtest.c:153: warning: implicit declaration of function 'robot_turn_right'irtest.c:157: warning: implicit declaration of function 'robot_go_straight'irtest.c: In function 'appControl':irtest.c:164: error: expected declaration or statement at end of inputirtest.c:164: warning: control reaches end of non-void functionmake: *** [irtest.o] Error 1Build failed with 1 errors and 7 warnings...thanks in advance for any help