General 3D Printing

Maqueen Wall Following MAZE

userHead james.Maitland 2023-05-25 16:12:43 1238 Views2 Replies

After some trialing and modifications I have 3d printed. a holder for the maqueen to allow a 90 deg mounting of the ultra sonic an 2 touch sensors.

 

I will update with access to videos, 3d files for printing and the iterations of code

 

#wall runner using side facing ultrasonic and push button

ideal_follow = 4

#assumes 4cm is a good distance to follow wall

distance = ideal_follow

#sets the initial distance to the ideal_follow distance

wall_range = 1

#sets the amount the robot can be away from the wall

waitonce = 0

#used to pause the robot for 5 seconds to position it correctly


 

def on_forever():

global distance

global waitonce

global ideal_follow

global wall_range

#accessess the global variables in all functions

if waitonce == 0:

basic.show_icon(IconNames.SQUARE)

basic.pause(3000)

waitonce = 1 #resets so id does not pause again


 

# get a new reading

distance = maqueen.ultrasonic(PingUnit.CENTIMETERS)


 

if distance > ideal_follow and distance < ideal_follow + wall_range: #the ideal range

maqueen.motor_run(maqueen.Motors.ALL, maqueen.Dir.CW, 50)

basic.show_arrow(ArrowNames.NORTH)


 

elif distance < ideal_follow: #getting too close to the side wall

maqueen.motor_run(maqueen.Motors.M1, maqueen.Dir.CW, 50) # slow turn left

maqueen.motor_run(maqueen.Motors.M2, maqueen.Dir.CW, 25)

basic.show_icon(IconNames.SAD)


 

elif distance > 10:

maqueen.motor_run(maqueen.Motors.M1, maqueen.Dir.CCW, 15) # fast right left no wall left

maqueen.motor_run(maqueen.Motors.M2, maqueen.Dir.CW, 45)

basic.pause(65) #change this to the time it take to turn 90 deg #opening in wall 90 deg left turn


 

else: #getting too far from the side wall

maqueen.motor_run(maqueen.Motors.M1, maqueen.Dir.CW, 25) # slow right left

maqueen.motor_run(maqueen.Motors.M2, maqueen.Dir.CW, 50)

basic.show_icon(IconNames.HAPPY)


 

if input.pin_is_pressed(TouchPin.P1): #hit the wall at the front

maqueen.motor_run(maqueen.Motors.ALL, maqueen.Dir.CCW, 75) # fast reverse

basic.pause(200)

maqueen.motor_run(maqueen.Motors.M1, maqueen.Dir.CW, 45) # fast right left

maqueen.motor_run(maqueen.Motors.M2, maqueen.Dir.CCW, 15)

basic.show_arrow(ArrowNames.NORTH_EAST)

basic.pause(65) #change this to the time it take to turn 90 deg

 

basic. Forever(on_forever)


 

2023-05-26 18:47:37

Here is the photo But How do I load the Student activity and STL files

userHeadPic james.Maitland
2023-05-26 18:45:57

Here is the final prototype of the Ultrasonic holder. It now has extra clearance for the LED's on the right and 1.5mm pilot holes for the microswitch screws. And some lugs for doing cable management

userHeadPic james.Maitland