int main(){
  //servo_angle(16,1800);
  //pause(500);
  print("This is Receiver!\n");
  xbee = fdserial_open(9,8,0,9600); //access these port with the xbee
  while(1){
    command = fdserial_rxChar(xbee); //recieve one bit of data from transmitter
    if(command == 0) {
      high(0);
      low(1);
      low(2);
    }      
    else if(command == 1) {
      low(0);
      high(1);
      low(2);
    } 
    else if(command == 2) {
      low(0);
      low(1);
      high(2);
    } 
    else {
      low(0);
      low(1);
      low(2);
    } 
  }  
}
int main()                                    // Main function
{
  xbee = fdserial_open( 9, 8, 0, 9600 ); //Initialize communication

  char c; //Create char

  while ( 1 )
  {
    c = fdserial_rxChar( xbee ); //get all values sent to the ActivityBot
 
    if ( c == 'f' ) //if the robot was told to go forward, go forward
    {
      drive_speed( 64, 64 );
    } else if ( c == 'b' ) //if the robot was told to go backward, go backward
    {
      drive_speed( -64, -64 );
    } else if ( c == 'l' ) //if the robot was told to go left, go left
    {
      drive_speed( 0, 64 );
    } else if ( c == 'r' ) //if the robot was told to go right, go right
    {
      drive_speed( 64, 0 );
    } else if ( c == 's' ) //if the robot is told to stop, stop
    {
      drive_speed( 0, 0 );
    }
  }
}
Beispiel #3
0
static int nextchar(State *state)
{
    int ch;
    if ((ch = state->savedChar) != EOF)
        state->savedChar = EOF;
    else
        ch = fdserial_rxChar(wifi);
    return ch;
}
Beispiel #4
0
void gps_run(void *par)
{
  gps_byte_t tempBuff[16];
  gps_byte_t ch;
  int idx;

  gps_ser = fdserial_open(_gps_rx_pin, _gps_tx_pin, 0, _gps_baud);
  for(;;)
  {
    if(gps_stopping)
    {

      fdserial_close(gps_ser);
      gps_stopping = 0;
    }
    ch = fdserial_rxChar(gps_ser);
    
    //search for the start of an NMEA sentence
    if(ch != '$')
      continue;


    //read in characters from the GPS
    idx = 0;
    do
    {
      ch = fdserial_rxChar(gps_ser);
      inBuff[idx++] = ch;      
    }while(ch != 13);
    inBuff[idx] = 0;      //null terminate

    //got the full sentence, do a little prep work to get ready for parsing.
    //modifies inBuff!
    PrepBuff();

    if(strncmp(inBuff, "GPRMC", 5) == 0)
      ParseRMC();
    if(strncmp(inBuff, "GPGGA", 5) == 0)
      ParseGGA();
  }
}
int main()
{
  //simpleterm_close(); //close default terminal, I want to use those pins
                      //if the default uart pins are not b nused, this isn't needed
                      
  fdserial *d = fdserial_open(RX_PIN, TX_PIN,0, BAUD);
  
  while(1)                                    
  {
     fdserial_txChar(d, fdserial_rxChar(d));
  }
}
void pollPingSensors(void *par) {
  // The last IR sensor will be retagged with this position number,
  // in case there are more PINGs than IRs.
  const int lastIRposition = 7;
  propterm = fdserial_open(QUICKSTART_RX_PIN, QUICKSTART_TX_PIN, 0, 115200);
  //term = fdserial_open(31, 30, 0, 115200); // for Debugging
  // Initialize variables outside of loop
  // This may or may not improve performance.
  int ping = 0, ir = 0;
  char receivedChar;
 while(1) // Repeat indefinitely
  {
    /* We wait for input from the other side,
       Which lets us not activate the sensors
       if the other end is not working,
       and also lets the other end rate limit the input. */
    receivedChar = fdserial_rxChar(propterm);
    //char receivedChar = 'i'; // for Debugging - Cause it to always run instead of waiting for a signal
    // Only send data when we get the expected "init" character, avoiding running on random garbage from an open connection
    if (receivedChar == 'i') {
      high(16); // LEDs for debugging
      isActive = 1;
      for(int i=0; i < NUMBER_OF_PING_SENSORS; i++ ) {
        ping = ping_cm(FIRST_PING_SENSOR_PIN + i);
        dprint(propterm, "p,%d,%d.", i, ping);
        receivedChar = fdserial_rxChar(propterm); // Should get a character after each output for rate limiting
        //dprint(term, "p,%d,%d\n", i, ping); // For Debugging
        if(i < NUMBER_OF_IR_SENSORS) { // If there is also an IR sensor at this number check it too
          ir = mcp3208_IR_cm(i);
          dprint(propterm, "i,%d,%d.", i, ir);
          receivedChar = fdserial_rxChar(propterm); // Should get a character after each output for rate limiting
        }
      }
     //dprint(term, "\n"); // For Debugging - add a line break here and pull the above two
    }
    low(16); // LEDs for debugging
  }
/* TODO: Be sure to test that the data coming in is REAL TIME! */
}
Beispiel #7
0
int main()
{
  //access the simpleIDE terminal
  simpleterm_close();
  //set full-duplex serialization for the terminal
  term = fdserial_open(31, 30, 0, 9600);

  char c;

  //servo_angle(16, gripDegree); //Orient gripper to half open on start
  //pause(3000);

  while (1)
  {
    c = fdserial_rxChar(term); //Get the character entered from the terminal
    if (c != -1)
    {
      //Use the below to see if any key input is being read by the terminal
      // dprint(term, "You typed: %c\n", c);

      //Link key presses to directional commands, and print the command to strings
      if (c == 'f') //press "f" fof forward
      {           
        Drive(ticks, ticks, maxSpeed);
        dprint(term, "ok\n");
      } 
      else if (c == 'b') //press "b" for backward
      { 
        Drive(-ticks, -ticks, maxSpeed);
        dprint(term, "ok\n");
      } 
      else if (c == 'r') //press "r" for right turn
      { 
        Drive(turnTick, -turnTick, maxTurnSpeed);
        dprint(term, "ok\n");
      } 
      else if (c == 'l') //press "l" for left turn
      { 
        Drive(-turnTick, turnTick, maxTurnSpeed);
        dprint(term, "ok\n");
      } 

      //Increasing and Decreasing Drive Speed
      else if (c == 'u') 
      {
        ticks = ticks + 2;
        if (ticks > maxSpeed) //clamp speed so it can't go over the maximum speed
        {
           ticks = maxSpeed;
        }
        dprint(term, "move_speed %d\n", ticks);
      } 
      else if (c == 'd') 
      {
        ticks = ticks - 2;
        if (ticks < minSpeed) //clamp speed so it can't go negative or 0
        {
          ticks = minSpeed;
        }
        dprint(term, "move_speed %d\n", ticks);
      }

      //Increase Turn Speed;
      else if (c == 't') 
      {
        turnTick = turnTick + 1;
        if (turnTick > maxTurnSpeed)
        {
          turnTick = maxTurnSpeed;
        }
        dprint(term, "turn_speed %d\n", turnTick);
      }
      
      //decrease turn speed
      else if (c == 'n')
      {
        turnTick = turnTick - 1;
        if (turnTick < minTurnSpeed)
          {
          turnTick = minTurnSpeed;
          }
        dprint(term, "turn_speed %d\n", turnTick);
      }

      else if (c == 'p') //ping distance
      {
        pingDistance = ping(8);
        dprint(term, "echo %d\n", pingDistance);
        dprint(term, "ok\n");
      }

      else if (c == 'k') // poke
      {
      }
      else if (c == 'o') //open gripper
      {
        gripState = 0;
        gripDegree = -1800;
      }
      else if (c == 'g') //close gripper
      {
        gripState = 1;
        gripDegree = 1800;
      }
    } // End of Read Character Function
  if (gripState != -1) 
  {
    Grip(gripDegree, 2000);
  }
  } // End of While Loop
} //End of Main Loop