First Year Seminar 102-20
Robotics, Computing, and Society

Denison

Lab/HW 2:

Objectives:

Our objectives by the end of this lab are to:

  1. Functions: In this first part of the lab, I want you to write functions so that we can design algorithms for our robot in more human turns ("draw a line that is 3.5 inches long" or "turn 30 degrees"), instead of being tied to the robot-related parameters of speed and duration. This will necessitate some experimentation, and you may need to adjust the functions here as you work on the last part of the lab. Some of you may have defined these functions in your first programming assignment, in which case you may copy the code to the python file you are using in this lab.
  1. For-loop Practice: Within the Python shell, write for-loops to perform the following:
  1. Light Sensors: On the scribbler2, on the side of the robot opposite the bluetooth dongle, are three light sensors. The Myro software gives us a function we can invoke to retrieve the current value of the light sensors, either all three as a single list, or individually by specifying a parameter that indicates which light sensor value we wish to retrieve. Try executing the following functions:
  1. Putting it all together: Write and test functions to perform the following:

Lab/HW 3 (due Wed. Oct. 5, 1:30pm):

Objectives:

Our objectives by the end of this lab are to:

  1. Boolean Expressions: For each of the following expressions, I want you to predict the result of Python evaluating the expression (then verify in the Python shell):
    • 200 == 200
    • 200 == 7
    • "robot" == "robot"
    • "robot" == "Robot"
    • 3.14 == 3.142
    • 7 == 7.0
    • a, b, c = 10, 20, 10
    • a == b
    • a == c
    • a == a
    • 4 > 5
    • 5 <= 10
    • 1 != 1
    • 67 > b
    • (3+4) >= (2-1)
    • (20 < 7) and (81 > 31)
    • not ( ( 20 < 7) and (81 > 31) )
    • (2 > 3) or (3 > 4)
    • 2 > 3 > 4
  2. Conditionals: In class, we have discussed the syntax and semantics of the if-statement and the if-else statement. We can extend the if-statement to help specify multiple options using the elif-statement as follows:
    if <condition-1>:
       <command set 1>
    elif <condition-2>:
       <command set 2>
    elif <condition-3>:
       <command set 3>
    ...
    ...
    else:
       <last command set>
    
    Each condition is replaced by a valid boolean expression. Note the else (with no condition) in the final clause. Now consider the following code segement that uses this extended if structure:
    if x < y:
        print x, "is less than",y
    elif x > y:
        print x, "is greater than",y
    else:
        print x, "and", y, "are equal"
    
    • Wrap this code in a function definition called compare(x, y). Call compare three times: one each where the first argument is less than, greater than, and equal to the second argument.
    • Write a function named is_divisible_by_3 that takes a single integer as an argument and prints "This number is divisible by 3." if the argument is evenly divisible by 3 and "This number is not divisible by 3." otherwise.
    • Generalize the divisibility function in the previous exercise into a function named is_divisible_by_n(x, n) that takes two integer arguments and prints out whether the first is divisible by the second.
  3. Sensors: Using your robot, get familiar with the following other (internal and external) sensors. For each write down the smallest and largest value that can be returned and the relative meaning of the value for each.
    • Internal time through currentTime()
    • Battery level
    • IR sensor on the scribbler
    • Line sensor on the scribbler
    • Stall sensor on the scribbler
    • Virtual light sensor on the fluke
    • IR obstacle sensor on the fluke
  4. FollowTheLight: Write a complete Python function called FollowTheLight(duration). The single parameter, duration, should provide the time, in seconds, for the robot brain to operate. The basic function is as we have discussed in class -- to have the robot orient toward the light and to move in the direction of the light.
    • Use comments to clearly define your strategy. This is another form of writing, used to convey to a reader the information to understand your program.
    • Look up the timeRemaining() function and use it in a while loop to build the basic top-level loop of your function.
    • Within your loop, you will "tune" things like the speed of turning, the speed of moving forward, the time between iterations, and perhaps others. Instead of using "hard-coded" numbers in your parameters, define variables for each of these tunable values, and initialize them with assignment statements outside the loop
    • Your goal is to make the robot behavior be as "smooth" as possible, so in the best solutions, the robot will appear almost like a natural being, such as an insect, reacting in an instinctual manner.
    • Have fun with this. Add sounds and/or speech on the robot that corresponds with what the robot is doing.
  5. RoundTheBox: Write a complete Python function called RoundTheBox(), that solves the following robot problem. Imagine your robot in an environment that has a walled corridor going around a square box. We want a program that allows the robot to achieve the goal of going 'round the box. You can use the box and hinged walls constructed by Dr. Tom to do this.
    • Use comments to clearly define your strategy and to convey this to the reader.
    • Your program should not use "dead-reckoning" to accomplish this task. It should use a loop that, as long as the goal is not attained, repeatedly (1) senses the environment, (2) based on the sensed state returned along with a "model" of the environment, determine the next robot action, (3) execute the action.
    • Your program may rely on the property that the inside box is a square, but it should be adaptable if the square were of a different size than the one given.
    • Your program may also rely on the property of the surrounding outside wall being "solid", and that it does, in fact, surround the inside square, but it may not necessarily provide parallel walls.
    • A beginning strategy that you may employ would be for the robot to go forward in a straight line (you may again determine initial placement of the robot) until it bumps into a block/wall. You can try to use the stall() function to see if the robot is trying to move, but cannot. You could also use the IR obstacle senosr on the fluke to determine how close obstacles are. Once an obstacle is encountered, you can make the robot back up a little and then make a turn.
    • You need to keep track of how many sides of the box you have traversed in order to know when your robot has achieved its goal. This maintenance of sides traversed, along with the implicit constraints of the box and the outside corridor, make up your model of the world.
    • Again use sounds to give personality to your robot.
  6. Readings: Read Chapters 5 and 6 of your text (these readings will also help with your assignment). If you use code given by someone else (including your text), you _must_ provide a citation in the comments of your code. This is also intellectual property.

Lab/HW 4 (due Mon. Oct. 31, 1:30pm):

Objectives:

Our objectives by the end of this lab are to:

Reading

Lab Procedure

  1. Loading Pictures -- Start by going to the web and finding some copyright free images, try www.copyright-free-images.com, and download some images to work with. Select images that are fairly small. Then, in the Python shell, use a combination of pickAFile() to get a string representing the disk location of a selected image, along with the makePicture() function to create pictures and assign them to variables. Use the show() function on your pictures to display them in a window on your computer display. You will still need to import the myro library for this step, but you will not need to check out a robot, nor initialize a robot.
  2. Write a function drawHorizontal(pic, y) that takes two parameters, pic, a variable associated with a picture object, and y, a coordinate between 0 and the height of the picture. The function should draw a white line across all x coordinates and fixed on the given y coordinate. Repeat by writing a function drawVertical(pic, x).
  3. Write a loop using getPixels() that computes the sum of the red intensity level across all the pixels in an image, and then computes the average red intensity. Next, place that loop into a function that computes and returns the value of the average. Write a second variation of the function that uses nested loops to do the same thing. You can name these functions anything you wish, but each should take a picture reference as its only parameter.
  4. Avoiding Obstacles in the "Arena" -- This mission has some similarity with the RoundTheBox assignment in HW3. Your robot will be randomly placed in the Arena (the hinged wall units with colored poster board on the wall segments). You need to write a program to move your robot without hitting walls. Constraints:

Your function should be called Avoid() and should be in a file named HW4-avoid.py, which should be a _well commented_, all-inclusive file with any required imports, robot initialization, and invocation of the Avoid function. Do not use hard-coded parameters and try and decompose the problem into smaller functions. Talk with your Lab Assistant or Dr. Tom for ideas.

  1. Find the Yellow Wall -- Here you will extend your wall avoiding abilities learned in the last program and extend it to perform the following mission: Your robot will be randomly placed in the Arena. The Arena will have exactly one segment that has a yellow wall, but you don't know which one. You need to write a program to get your robot to within 6 inches of the yellow wall segment within two (2) minutes, without hitting walls of other colors. The robot needs to be moving a a minimum of 1/3 speed. Once the robot has achieved its goal, it _must_ celebrate.

Your function should be called FindYellow() and should be in a file named HW4-yellow.py, which should be a _well commented_, all-inclusive file with any required imports, robot initialization, and invocation of the FindYellow() function. Do not use hard-coded parameters and try and decompose the problem into smaller functions. Talk with your Lab Assistant or Dr. Tom for ideas.

Lab/HW 5 (due Wed. Dec. 7-12, 1:30pm):

Objectives:

Our objectives by the end of this lab are to:

Lab Procedure

  1. Download the support files HistoryWin.py and LineFollowP.py from the schedule page.
  2. Practice with the HistoryWin class by creating an object and then using both the update and the checkMouse methods of the class.
  3. Implement the remainder of the acquireLine function in LineFollowP.py. The function assumes an initial position based on the initialization of the globals that places the robot to the right of the line to be acquired. Your function should, in addition to moving until one or more of the line sensors detects a line, seed the distance history with values. It should also check for a mouse click in the HistoryWin indicating the user's desire to stop processing.
  4. Implement the lineDistance function where, based on 0/1 values for left and right, it should determine the current 'distance' from being directly over the line (from FARRIGHT at -2 to FARLEFT at +2). It should add the determined distance to the distance history, as well as to _return_ the calculated value. In the case of left and right both being 0, it should process the distance history to resolve the ambiguity.
  5. For the proportional control algorithm, implement the followLineP() function, looping for the duration of time (in seconds), and using a calculation of the output parameters of translation speed and rotation speed based on the input of the distance and using experimentally arrived at constants of proportionality. These outputs are then passed to the move() function in the body of the loop.

The Porportional Control algorithm will be evaluated based on both how far the robot is able to follow the line as well as the speed the robot requires to cover a fixed distance on the course.

For extra credit, create a copy of LineFollowP.py named LineFollowPD.py and implement a Proportional-Derivative feedback control algorithm.