Shunta Muto, Osvaldo Calzada

Professor Ethan Danahy

January 24th, 2018

Finding the Wall Robot

For both tests, the car was assembled with the instruction manual. Ultrasonic sensor on the front will read the distance to the nearest object that the signal hits. Two motors control the right and left wheel respectively. We also made sure to plug in the motors and the sensor to appropriate port.

Image

CODE:

Bang-Bang Controller Code: This robot will stop when it reaches a wall

Bang bang control was implemented by setting the speed=0 when the car reaches within 10cm from the wall.

def main():

ev3 = Device('this')

Rmotor = ev3.LargeMotor('outC') #Large Motor Port C

Lmotor = ev3.LargeMotor('outB') #Large Motor Port B

UltraSonic = ev3.UltrasonicSensor('in4') #Ultrasonic Sensor Port 4

speed = 0 #initial speed

while True:

distance = UltraSonic.distance_centimeters #distance obtained from ultrasonic sensor

if (distance > 10): #travel as fast as possible if far away

speed = 1050

else:

speed = 0 # don't travel if slow

Rmotor.run_forever(speed_sp = speed) #executes speed

Lmotor.run_forever(speed_sp = speed)

if name == 'main':

main()

Proportional Controller Code: This robots will stop when it reaches a wall

Simple proportional control was implemented by making the speed proportional to the distance. The value of multiplier was determined by testing with few values.

def main():

ev3 = Device('this')

Rmotor = ev3.LargeMotor('outC') #Large Motor Port C

Lmotor = ev3.LargeMotor('outB') #Large Motor port B

UltraSonic = ev3.UltrasonicSensor('in4') #Ultrasonic Sensor Port 4

speed = 0

Kp = 10 #Proportional Control Value

while True:

distance = UltraSonic.distance_centimeters #Measured distance

if (distance < 5): #Car stops if within distance

speed = 0

else:

speed = distance *Kp #Speed value if further than 5 cm away

if (speed > 1050): #Constraints the motor speeeds to its max and min values

speed = 1050

if(speed < -1050):

speed = -1050

Rmotor.run_forever(speed_sp = speed)#Executes desired speed

Lmotor.run_forever(speed_sp = speed)

if name == 'main':

main()

Video

Above: Bang Bang Control

As shown in the video, the car stops immediately after it reaches within the set distance from the wall since the bang bang control sets the speed to 0.

Below: Proportional Control

As shown in the video, the car begins to decelerate after it reaches within the set distance. The deceleration continues until it reaches the wall. With the proportional control, the car's speed is determined by the distance from the wall. In other words, the closer the distance between the car and the wall, slower the car will move.