Gordon Sulc
/
Bee
bees.cpp
- Committer:
- gsulc
- Date:
- 2011-12-16
- Revision:
- 0:178a07cd3e39
File content as of revision 0:178a07cd3e39:
#include "bees.h" int find_pollen() { return 1; } int return_home() { return 1; } int send_directions() { //while(!xbee.readable()) {} //read header //read contents int i = 0; while(1){ xbee.putc(directions[i] + 2); if(DEBUG) pc.printf("Sending %d\n\r", directions[i]); if(directions[i] == TERMINATE_CHAR) { if (DEBUG) pc.printf("Successfully transfered directions.\n\r"); return 1; } i++; } if (DEBUG) pc.printf("Error writing directions.\n\r"); return 0; } /********************************************************* Name: get_directions inputs: void outputs: int: 1 = completed sucessfully; 0 = unsuccessful Purpose: gets directions on where to move *********************************************************/ int get_directions() { //int buff[DIRECTIONS]; int i; // wait until the xbee can be read //while(!xbee.readable()) {} //read header //read contents i = 0; while(1){ directions[i] = xbee.getc() - 2; if (DEBUG) pc.printf("dir %d\n\r", directions[i]); if(directions[i] == TERMINATE_CHAR) return 1; //successfully transfered directions i++; } if (DEBUG) pc.printf("Error reading directions.\n\r"); return 0; } int gather() { return 1; } int goto_pollen() { return 1; } void blaze() { int i; for (i = 0; i < (2*DIRECTIONS); i++) { directions[i] = rand() % 3 - 1; directions[++i] = rand() % 20 + 51; if(DEBUG){ pc.printf("Directions: %d, %d\n\r", directions[i-1], directions[i]); } } directions[i] = TERMINATE_CHAR; if(DEBUG) pc.printf("Temrinate\n\r"); } int copy() { static int direct = 0; static int state = 0; /*if(dotype == GetMove) { current_move = directions[direct]; }*/ //else if (dotype == DoMove) { static int current_move; if(state == 0) { current_move = directions[direct]; if(DEBUG) pc.printf("Oh! got the Move! %d\n\r", current_move); state = 1; } else if (state == 2) { if(move_state == Stopped) state = 0; if(DEBUG) pc.printf("Waiting for Next Move\n\r"); } else if (state == 1) { if (current_move == TERMINATE_CHAR) { l_motor.speed(NEUTRAL); r_motor.speed(NEUTRAL); move_state = Stopped; return 1; } else if (current_move <= 1) { if(DEBUG) pc.printf("I like to rotate! \n\r"); rotate(current_move); //if((r_tics >= r_goal) || (l_tics >= l_goal)) direct++; } else if (current_move >= 20) { if(DEBUG) pc.printf("I like to move it move it! \n\r"); move(0.5, current_move); //if((r_tics >= r_goal) || (l_tics >= l_goal)) direct++; } state = 2; } return 0; }