Ask your own question, for FREE!
MIT 6.01SC Introduction to Electrical Engineering and Computer Science I 16 Online
OpenStudy (anonymous):

Design Lab 2: This code could be expanded to have the robot turn the opposite direction depending on the side of it that the sonar is being triggered upon. However, for simplicity when near walls, the robot halts and turns until it is free.

OpenStudy (anonymous):

class MySMClass(sm.SM): def __init__(self): self.startState = "Nothing" def getNextValues(self, state, inp): print "State :", state if state == "Nothing": if inp.sonars[3] < 0.5 or inp.sonars[4] < 0.5 or \ inp.sonars[2] < 0.5 or inp.sonars[5] < 0.5: action = io.Action(fvel = 0.0, rvel = 0.50) return ("Obsticle",action) else: action = io.Action(fvel = 0.3, rvel = 0.00) return ("Nothing",action) elif state == "Obsticle": if inp.sonars[3] > 0.75 and inp.sonars[4] > 0.75 and \ inp.sonars[2] > 0.5 and inp.sonars[5] > 0.5: action = io.Action(fvel = 0.05, rvel = 0.25) return ("Follow",action) else: action = io.Action(fvel = 0.0, rvel = 0.50) return ("Obsticle", action) else: if inp.sonars[2] > 0.35 and inp.sonars[5] > 0.35 and \ inp.sonars[1] > 0.30 and inp.sonars[6] > 0.30 and \ inp.sonars[0] > 0.25 and inp.sonars[7] > 0.25: action = io.Action(fvel = 0.3, rvel = 0.0) return ("Nothing", action) else: action = io.Action(fvel = 0.05, rvel = 0.25) return ("Follow", action)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!