CSSE 120 -- Intro. to Software Development

Homework 11

  1. If you have not already done so, complete the short survey on Angel to help me form your project teams:
        Lessons → Homework → Homework 14 → Survey to help us form your project team
    
  2. If you have not already done so, install the Create Simulator by following the instructions at:
        http://www.rose-hulman.edu/class/csse/resources/Robotics/InstallingCreateSimulator.htm
    
  3. Robot Functions. Checkout your 16-robot project and do all your work on the following in that project.
    1. Create a function called wander() that drives the robot in a random motion to explore an environment. The wander() function has three parameters, the robot, and linear and angular velocity. The parameters should be in the following order:
      1. robot
      2. [optional] Linear Velocity in cm/s, default = 15
      3. [optional] Angular Velocity in deg/s, default = 20
      To implement this function, select a random angle between or including -180 and 180 degrees (via randrange), turn the robot that much, select a random distance between 10 and 30 cm, and move the robot forward that much. Be sure that the sign on your velocities and distances are the same.
      • Use the wait-until-event loop pattern, getting sensor input as you do so.
      • Remember to sleep for about 50 ms in your loop, to avoid flooding the robot's processor/sensors.
      Repeat this random sequence of turn+drive 5 times or until its cliff sensor is triggered (i.e. pick it up): see WanderVideo.wmv for an example.

      Add code to the main function that tests your wander function.

    2. Cliff Sensors

      This problem requires you to read four sensors and control two LED actuators:

      • The front left and front right cliff sensors as an analog values
      • The left and right bumpers as digital values (to determine the program end)
      • The Play and Advance LEDs

      Create a function called cliffSensors() for your work on this problem.

      Your task is to read the front left and front right cliff sensors while moving a black line below the sensors.  Print out the black line PDF and use it for testing.  The location of the black line controls the state of the Play and Advance LEDs.

      When the black line is below the front right cliff sensor the Play LED should be off.  When the black line is below the left cliff sensor the Advance LED should be off.  When the black line is not below the sensor the corresponding LED should be on.

      In addition to the LEDs, print out the value of the analog sensor to the computer display using print.  In fact you should probably do the printing part first!  Since you will need to know where to set the threshold value to decide when the black line is present or absent for the LEDs, you will need to know the range of light and dark values.  The values of both sensors should print to the screen every 0.1 seconds using a well formatted print message.  For my program it was simply:

                      Cliff Sensors FL = 80 FR = 720

      This line btw was taken while the black line was below the Front Left Cliff Sensor. 

      Make note of what the white and black values are for your program for each sensor.  Personally, I'm curious how much they vary from robot to robot, so remember your values for white and black.

      The printing of the cliff sensor values and controlling of the LEDs should continue inside a while loop until the user pushes either the left or right bumper.  When a bumper press is observed the program should shutdown the robot and print a Goodbye message to the screen.

      Add code to the main function that tests your cliffSensors function.

    3. Create a function kittLights() that takes two parameters: the robot and numRepeats, and turns on the robot’s power, play and advance lights using the 12-step sequence given here. The 12-step sequence shown should repeat numRepeats times (see LightsVideo.wmv). Look up the setLEDs() function in the pycreate library documentation for details on how to turn on Create’s LEDs. For example:
      		robot.setLEDs(0,0,0,0) #turn off all of the robot's LEDS 
      robot.setLEDs(0,255,0,0)#turn on only the robot's power LED to green (see documentation)
      robot.setLEDs(0,0,1,0)#turn on only the robot's play LED

      You may notice that getting a yellow light from the power LED is not best to use r.setLEDs(128,255,0,0) as you might guess.
      Play with it until you find a good yellow.

      Add code to the main function that tests your kittLights function.