Objective

The objective of this lab was to communicate with a base station from our robot. We have one arduino with the robot transmitting its current location and information about that location, and one arduino communicating with the TA's GUI to show what the robot is thinking.



Materials Used


Sub Teams

Pablo and Katie worked on radio transmission and GUI while Ben and Caroline worked on line following and wall detection. Everyone contributed to all parts of the lab.


Procedure

Getting the Radios Working

The first thing we did was get the radios working with the default messages. We wired up the radios as described in the lab report, and changed the code to the given "Getting Started" code from the github. We also changed our address to send and recieve based on our lab group and day, so we had C and D as our identifiers. The only thing we really had to change here was the identifiers as seen below.

     const uint64_t pipes[2] = { 0x000000000CLL, 0x000000000DLL};
    

Once we had these set up, we started transmitting. At first we had an issue where we weren't able to send a signal back, but we eventually realized that the knock-off Arduinos just weren't powerful enough for the radios, so we hooked up the external power supply and we got them communicating with each other! See the screencap below

radio communication

Fig.1: Screenshot of serial monitor showing radio communication between arduino and base station


Sending Our Own Information

After we confirmed that we could send and recieve packets, we decided to change the packets we were sending to fit with the maze information we wanted to send. We decided to encode the information as 6 bytes, which could in the future be encoded slightly more efficiently, but was plenty efficient for the sake of this lab. The bytes were : 0 = x coordinate, 1 = y coordinate, 2 = wall north, 3 = wall east, 4 = wall south, 5 = wall west We have included a code snippet to show how we identified the direction of our robot.


    //at intersection, if there is a front wall (which means Gary will be making a turn)
    if(frontw()){ 
      if (dir_facing == 0) dataArray[0] --; // If robot is facing north
      else if (dir_facing == 1) dataArray [1] ++; // If robot is facing east
      else if (dir_facing == 2) dataArray [0] ++; // If robot is facing south
      else if (dir_facing == 3) dataArray [1] --; // If robot is facing west
      digitalWrite(wall, HIGH);
      if(dir_facing == 0) dataArray[2] = 1; // North=true
      else if (dir_facing == 1) dataArray[3] =1; // East=true
      else if (dir_facing == 2) dataArray[4] =1; // South=true
      else if (dir_facing == 3) dataArray[5] =1; // West=true
     // if there is a right wall but no left wall
      if(rightw() && !leftw()){
       turn_left();
       //update direction Gary is going
       if(dir_facing == 0) {
        dataArray[3] = 1; // If robot faces north, East=true
       }
       else if (dir_facing == 1) {
        dataArray[4] =1; // If robot faces east, South=true
       }
       else if (dir_facing == 2) {
        dataArray[5] =1; // If robot faces south, West=true
       }
       else if (dir_facing == 3) {
        dataArray[2] =1; // If robot faces west, North=true
       }
       if (dir_facing == 0) dir_facing = 3;
       else dir_facing --; // Update dir_facing for left turning robot
      }
      //if there is a left wall but no right wall
      else if (leftw() && !rightw())
      {  
        turn_right();
        //update direction Gary is going
        if(dir_facing == 0) {
          dataArray[5] = 1; // If robot faces north, West=true
        }
        else if (dir_facing == 1) {
          dataArray[2] =1; // If robot faces east, North=true
        }
        else if (dir_facing == 2) {
          dataArray[3] =1; // If robot faces south, East=true
        }
        else if (dir_facing == 3) {
          dataArray[4] =1; // If robot faces west, South=true
        }
        if (dir_facing == 3) dir_facing = 0;
        else dir_facing ++; // Update dir_facing for right turning robot
        
      }
      // if there are both left and right walls
      else if(leftw() && rightw())
      {
        dataArray[3] = 1; //east = true
        dataArray[5] = 1; //west = true
        turn_around();
        // Update Gary's direction
        if(dir_facing == 0){
          dataArray[3] = 1; // If robot faces north, East=true
          dataArray[5] = 1; // If robot faces north, West=true
        }
        else if (dir_facing == 1) {
          dataArray[4] =1; // If robot faces east, South=true
          dataArray[2] =1; // If robot faces east, North=true
        }
        else if (dir_facing == 2) {
          dataArray[5] =1; // If robot faces south, West=true
          dataArray[3] =1; // If robot faces south, East=true
        }
        else if (dir_facing == 3) {
          dataArray[2] =1; // If robot faces west, North=true
          dataArray[4] =1; // If robot faces west, South=true
        }
          // Update dir_facing for robot turning around
          if (dir_facing == 0) dir_facing = 2;
          else if (dir_facing == 2) dir_facing = 0;
          else if (dir_facing == 1) dir_facing = 3;
          else if (dir_facing == 3) dir_facing = 1; 
      }
      else
      {
        turn_left();
      }
      digitalWrite(wall, LOW);
    } 
 }

Putting it all together

To see the information about the robot (line following, wall following, avoiding IR) see our Milestone 2 page on our website.
After we had our radios working and knew how we wanted to encode the info as shown above, we integrated the radio sending into our wall/line following algorithm. Whenever the robot reached an intersection, we would check which direction it was moving in, update the location (x, y) of the robot accordingly, and according to the walls sensed we would send that information back to the bay station using the radios we had set up earlier. The code shows how we did this.

      //After Gary turns or stays straight and updates direction
      //check for other robots
      for (size_t i = 0; i < 3; i++) {
        check_IR();
      }
      // send information to the radio station
      Serial.println(dataArray[0]); 
      Serial.println(dataArray[1]);
      Serial.println("write");
      radioWrite(dataArray);
    
The information was read in by the base station robot and converted into language the GUI could read, IE north=true and the like. See below for a video of our robot completing all necessary tasks!



As for IR, please see previous labs/milestones to see demos of this functionality. The functionality was maintained for lab 3.