Daily Coding: Day 1

Today’s Coding Project wasn’t that exciting, but something I kind of needed to do.  I actually wrote a series of programs today for robots.  The first was a Wall Following Program and the second was a Find the Object program.  I’m using these as examples for my Middle School students. I’ve written similar programs before but not these specific ones.  I also wrote them in both Python and Jigsaw.  Here’s the Python code:

from Myro import *

init()

wallleft = getObstacle("left")
wallright = getObstacle("right")
obstacle = getObstacle("center")

while obstacle < 100:     forward(1)     obstacle = getObstacle("center")     if obstacle > 500:
        turnBy(90)
        wallleft = getObstacle("left")
        wallright = getObstacle("right")
        obstacle = getObstacle("center")
        if obstacle < 100 and (wallleft > 100 or wallright > 100):
            forward(1)

And here’s the Find Object one:

from Myro import *
from random import *

init()

def checkObstacle():
    forward(1)
    obstacle = getObstacle("center")
    left = getObstacle ("left")
    right = getObstacle("right")
    return obstacle,left,right

while True:
    obstacle,left,right = checkObstacle()
    if obstacle > 100 or left > 100 or right > 100:
        stop()
        thing = askQuestion("What am I bumping into?",["Wall","Ball","Block"])
        if thing == "Wall":
            backward(.5,.5)
            turnBy(randint(90,180))
            obstacle = checkObstacle()
        if thing == "Ball":
            pic = takePicture()
            show(pic)
        if thing == "Block":
            backward(.5,.5)
            turnBy(randint(90,180))
            obstacle = checkObstacle()

At least I got started!

Leave a Reply

Your email address will not be published. Required fields are marked *