/*! \brief The "main" function of the avoider demo */ void run_breitenberg_shocker(void) { e_init_port(); e_init_motors(); e_init_ad_scan(ALL_ADC); e_calibrate_ir(); e_activate_agenda(flow_led, 900); e_activate_agenda(shock_neuron, 650); e_start_agendas_processing(); while(1); }
/*! \brief The "main" function of the follower demo */ void run_breitenberg_follower(void) { e_init_port(); e_init_motors(); e_init_ad_scan(ALL_ADC); e_calibrate_ir(); e_activate_agenda(k2000_led, 2500); e_activate_agenda(follow_neuron, 650); e_start_agendas_processing(); while(1); }
void robot_off(void) { e_init_port(); e_init_motors(); e_init_ad_scan(ALL_ADC); e_calibrate_ir(); e_start_agendas_processing(); while (1) { e_led_clear(); wait(10000); } }
int main(void) { e_init_port(); e_init_motors(); e_init_ad_scan(ALL_ADC); e_calibrate_ir(); int selector=getselector(); switch (selector) { case 0:robot_off();break; case 1:aggressive();break; case 2:fear();break; case 3:curious();break; case 4:love();break; case 5:robot_off();break; default:/*own high level behaviour*/break; } }
int main() { // init robot e_init_port(); e_init_ad_scan(); e_init_uart1(); e_led_clear(); e_init_motors(); e_start_agendas_processing(); // wait for s to start btcomWaitForCommand('s'); btcomSendString("==== READY - IR TESTING ====\n\n"); e_calibrate_ir(); // initialize ircom and start reading ircomStart(); ircomEnableContinuousListening(); ircomListen(); // rely on selector to define the role int selector = getselector(); // show selector choosen int i; long int j; for (i = 0; i < selector; i++) { e_led_clear(); for(j = 0; j < 200000; j++) asm("nop"); e_set_led(i%8, 1); for(j = 0; j < 300000; j++) asm("nop"); e_led_clear(); for(j = 0; j < 300000; j++) asm("nop"); } // activate obstacle avoidance e_activate_agenda(obstacleAvoidance, 10000); // acting as sender if (selector == 1) { btcomSendString("==== EMITTER ====\n\n"); int i; for (i = 0; i < 10000; i++) { // takes ~15knops for a 32window, avoid putting messages too close... for(j = 0; j < 200000; j++) asm("nop"); ircomSend(i % 256); while (ircomSendDone() == 0); btcomSendString("."); } } // acting as receiver else if (selector == 2) { btcomSendString("==== RECEIVER ====\n\n"); int i = 0; while (i < 200) { // ircomListen(); IrcomMessage imsg; ircomPopMessage(&imsg); if (imsg.error == 0) { int val = (int) imsg.value; /* Send Value*/ char tmp[128]; sprintf(tmp, "Receive successful : %d - distance=%f \t direction=%f \n", val, (double)imsg.distance, (double)imsg.direction); btcomSendString(tmp); } else if (imsg.error > 0) { btcomSendString("Receive failed \n"); } // else imsg.error == -1 -> no message available in the queue if (imsg.error != -1) i++; } } // no proper role defined... else { int i = 0; long int j; while(1) { e_led_clear(); for(j = 0; j < 200000; j++) asm("nop"); e_set_led(i, 1); for(j = 0; j < 300000; j++) asm("nop"); i++; i = i%8; } } ircomStop(); return 0; }
int main(void) { int cam_mode,cam_x1,cam_y1,cam_width,cam_heigth,cam_zx,cam_zy; if(getSelector() == 0) return; char c; int i;//buff_length; //int wait_cam; //defining the position of the several inputs and outputs (motors are outputs) in the respective SFR //the SFR are programed as structures, so accessing to an input/output implies only acessing to the field of the structure corresponding to the SFR that was //assigned to that input/output (see epuck_ports.h and p30f6014.h to understand the SFR assignment) e_init_port(); e_init_motors(); //important to enable uart interface e_init_uart1(); e_init_ad_scan(ALL_ADC); e_calibrate_ir(); //initial configuration of the camera cam_x1=(ARRAY_WIDTH/Z_WIDTH-WIDTH)/2; cam_y1=(ARRAY_HEIGHT/Z_HEIGHT-HEIGHT)/2; cam_width=WIDTH; cam_heigth=HEIGHT; cam_zx=Z_WIDTH; cam_zy=Z_HEIGHT; cam_mode=MODE; if(cam_mode==GREY_SCALE_MODE) cam_size=cam_width*cam_heigth; else cam_size=cam_width*cam_heigth*2; //not waiting for camera wait_cam=0; e_activate_agenda(updateFlag, 500);//500//1000 e_activate_agenda(readValues, 10); e_start_agendas_processing(); keepFinding = 0; e_set_led(4,1); keepFinding = 1; int s = getSelector(); while(s==getSelector()); /*while(1){ sprintf(b1,"%i\n",e_get_calibrated_prox(S_FRONT_LEFT)); e_send_uart1_char(b1,10); while(e_uart1_sending()); }*/ while(1){ while(keepFinding) { if(!cameraOn) { startCamera(); correctRobot(); } while(!captura()); //e_send_uart1_char(buffer,buff_length); //while(e_uart1_sending()); if(cameraOn > 5) processaImagem(); cameraOn++; } if(cameraOn) stopCamera(); while(!flag); flag = 0; sendInputs(); readOrder(); readOrder(); e_set_speed_left(speedLeft); e_set_speed_right(speedRight); e_set_led(4,0); } return 0; }
/*! \brief The "main" function of the program */ void run_wallfollow() { int leftwheel, rightwheel; // motor speed left and right int distances[NB_SENSORS]; // array keeping the distance sensor readings int i; // FOR-loop counters int gostraight; int loopcount; unsigned char selector_change; e_init_port(); e_init_ad_scan(ALL_ADC); e_init_motors(); e_start_agendas_processing(); //follow_sensor_calibrate(); e_activate_agenda(left_led, 2500); e_activate_agenda(right_led, 2500); e_pause_agenda(left_led); e_pause_agenda(right_led); e_calibrate_ir(); loopcount=0; int selectionValue; // selector_change = !(followgetSelectorValue() & 0x0001); e_set_steps_right(0); selectionValue = followgetSelectorValue(); while (doesWallExist(selectionValue)) { followGetSensorValues(distances); // read sensor values gostraight=0; if (selectionValue == 1) { //// if(selector_change == LEFT_FOLLOW) { // selector_change = RIGHT_FOLLOW; e_led_clear(); e_pause_agenda(left_led); e_restart_agenda(right_led); // } for (i=0; i<8; i++) { if (distances[i]>50) {break;} } if (i==8) { gostraight=1; } else { follow_weightleft[0]=-10; follow_weightleft[7]=-10; follow_weightright[0]=10; follow_weightright[7]=10; if (distances[2]>300) { distances[1]-=200; distances[2]-=600; distances[3]-=100; } } } else { // if(selector_change == RIGHT_FOLLOW) { // selector_change = LEFT_FOLLOW; e_led_clear(); e_pause_agenda(right_led); e_restart_agenda(left_led); // } for (i=0; i<8; i++) { if (distances[i]>50) {break;} } if (i==8) { gostraight=1; } else { follow_weightleft[0]=10; follow_weightleft[7]=10; follow_weightright[0]=-10; follow_weightright[7]=-10; if (distances[5]>300) { distances[4]-=100; distances[5]-=600; distances[6]-=200; } } } leftwheel=BIAS_SPEED; rightwheel=BIAS_SPEED; if (gostraight==0) { for (i=0; i<8; i++) { leftwheel+=follow_weightleft[i]*(distances[i]>>4); rightwheel+=follow_weightright[i]*(distances[i]>>4); } } // set robot speed followsetSpeed(leftwheel, rightwheel); wait(15000); //doesWallExist(selectionValue); } }
int main() { // init robot e_init_port(); e_init_ad_scan(); e_init_uart1(); e_led_clear(); e_init_motors(); e_start_agendas_processing(); // initialise buffer int k; for (k = 0; k < NB_NEIGHBOURS; k++) neighbours[k].id = -1; // wait for s to start /* btcomWaitForCommand('s'); */ btcomSendString("-OK-\n"); e_calibrate_ir(); // initialize ircom, then rng and start listening ircomStart(); //ircomEnableContinuousListening(); //ircomEnableProximity(); initRandomNumberGenerator(); // after rng init we can disable prox sensors //ircomDisableProximity(); ircomEnableContinuousListening(); ircomListen(); id = getselector(); ircomResetTime(); lastClock = ircomGetTime(); // activate movement //e_activate_agenda(move, 2500); organiseInit(); // advertise current direction e_led_clear(); e_set_led(0,1); e_set_led(4,1); while(1) { int messageReceived = 0; while(((ircomGetTime() - lastClock < COM_CYCLE_SPEED) || (ircomIsReceiving() == 1))) { IrcomMessage msg; ircomPopMessage(&msg); if (msg.error == 0) { processNewMessage(&msg); messageReceived = 1; SetRobotSeen(msg); } } e_set_body_led(messageReceived); SendData(); //sendId(); //sendAngleToNeighbours(); lastClock = ircomGetTime(); e_set_body_led(0); } ircomStop(); return 0; }