Intro CS Assignments
Assignments by week:
Fall Term:
Winter Term:
Spring Term:
Monday, May 6
Description
Homework
  • Begin work on Capture the Flag. Some rules:

    • The room will be divided in half. On each side there will be a flag that the opposing team needs to capture.
    • There will be an area around each flag zone where the defending team may not go, unless they are actively engaged in attacking an opposing team's robot.
    • Every robot must have two touch sensors, one on the left side of the robot, and one on the right side. The sensors must protrude away from the robot more than any other item on that side (so nothing interferes with pressing it). The sensor must not be abnormally high, low, or otherwise unreachable (I will provide judgement on this). Finally, the sensor must have a "bumper" installed over it to make it easier to hit. I can provide examples in class.
    • When your robot's sensor is pressed, the robot must stop responding to any input for 15 seconds. The position of your robot doesn't matter; you can be disabled on your own side of the playing field.
    • To score a point, the flag must be brought over the halfway line to the opposing team's side, and must be touched by a member of the opposing team.
    • If a robot is disabled (flipped over, unplugged, parts knocked off), it may be picked up and repaired. However, the robot must be placed at the back of the field (on its own side) and its program relaunched before it may be restarted.
    • You may use any parts, sensors, and motors from your standard kit. You may even combine multiple control bricks together if you wish!
  • You should make a copy of your ComputerClient and RobotServer projects and modify them for this assignment.
Tuesday, May 7
Description
Capture the Flag
Homework
  • In order to make the competition fair, everyone will need to add some standard code to their robot. You'll need to make changes to your RobotServer class in three places:
    1. Near the top, with your other variables, please paste in the following:

      /** A "kill switch" for the robot that can be activated by pressing
       *  one of the touch sensors.  When true, the robot should not respond
       *  to commands.  Additionally, the robot should release any grip or
       *  activated features when this is true.
       */
      private boolean killed = false;
      
      /** Amount of time robot should be disabled (in milliseconds) */
      private static final int KILL_DELAY_MS = 10000;
      
      /** Amount of time robot should be invincible after being killed (in milliseconds) */
      private static final int RECOVERY_DELAY_MS = 3000;
        
    2. In your RobotServer constructor, you should remove the Escape-key button press listener code and replace it with the code below. This code will both listen for the escape key, and also for the touch sensors. You will need to change the "S1" and "S2" to match the ports where you have connected your touch sensors.

      // create a thread that listens for touch sensor input and
      // disables the robot for a period of time.  It also listens
      // for the escape key being pressed and quits when that happens.
      new Thread()
      {
              public void run() {
                      // Get sensor modes for both touch sensors
                      SensorMode[] ts = new SensorMode[] {
                                      new EV3TouchSensor(brick.getPort("S1")).getTouchMode(),
                                      new EV3TouchSensor(brick.getPort("S2")).getTouchMode()
                      };
      
                      float[] s = new float[1];
                      
                      Key esc = brick.getKey("Escape");
      
                      // keep checking sensors until the user presses Escape
                      while (esc.isUp()) {
                              for (SensorMode sm : ts) {
                                      sm.fetchSample(s, 0);
                                      if (s[0] > 0.5) {
                                              println("Touch detected");
                                              killed = true;
                                      }
                              }
      			if (killed) {
      			        request("KILLED");
      			        Button.LEDPattern(2); // red
                                      Delay.msDelay(KILL_DELAY_MS-1000);
      			        Button.LEDPattern(3); // amber
                                      Delay.msDelay(1000);
                                      println("Touch delay expired");
                                      killed = false;
      			        Button.LEDPattern(1); // green
      				Delay.msDelay(RECOVERY_DELAY_MS);
      				Button.LEDPattern(0); // off
                                      println("Touch recovery expired");
                              }
                              else {
                                      Delay.msDelay(200);
                              }
                      }
                      
                      // escape was pressed, so exit the program
                      println("Exiting");
                      System.exit(0);
              }
      }.start();
      
    3. Finally, you'll need to add your own code to your request() method. This will vary for each person, so what is below is only a starting point:

      if (killed) {
          return "Robot is disabled";
      }
        

      If you put that at the top of your method, it will prevent any other code from running while the robot is "killed". However, you may need to add extra statements to stop all the motors, "release" any grips or other features you've enabled, or other steps to make the robot stop after it's been killed.

Thursday, May 9
Description
Capture the Flag
Homework
Friday, May 10
Description
Capture the Flag
Homework