# CamJam EduKit 3 - Robotics # Worksheet 3 - Motor Test Code import time # Import the Time library from gpiozero import CamJamKitRobot # Import the CamJam GPIO Zero Library robot = CamJamKitRobot() # Turn the motors on print('Starting') robot.forward() # Wait for 1 seconds time.sleep(1) # Turn the motors off robot.stop() print('Stopping')
# CamJam EduKit 3 - Robotics # Worksheet 9 – Obstacle Avoidance GPIO Zero version # by Neil Bizzell (@PiVangelist) from gpiozero import DistanceSensor, CamJamKitRobot # Import DistanceSensor and CamJamKitRobot Classes from the GPIOzero library from time import sleep # Import sleep function from the time library # define the pins for the motor (fixed in the GPIO Zero library) robot = CamJamKitRobot() # Define GPIO pins to use for the ultrasonic sensor sensor = DistanceSensor(echo=18, trigger=17) #define how to avoid the obstacle (simple version, just turn away) def AvoidObstacle(): robot.left() #turn left sleep(0.5) #repeat the next indented block forever while True: robot.forward()#drive forward sleep(0.1) if sensor.distance < 0.3: #check if sensor distance is less than 0.3m robot.stop() #stop the robot AvoidObstacle() #call the AvoidObstacle function
#import libraries from gpiozero import CamJamKitRobot #if you don't have this board switch this with Robot from contours import get_saturated_colors, setup_camera #import from the contours program #Setup the robot, and camera function #These are the instructions if you don't own the CamJam Edukit 3 #Let's say you use the pins 27 and 17 for left and 24 and 23 for right. Then alter it as such: #robot = Robot(left=(27, 17), right=(24,23)) devastator_robot = CamJamKitRobot() camera, capture_buffer = setup_camera() #Set things up for movement for raw in camera.capture_continuous(capture_buffer, format="bgr"): image = raw.array masked, contours, found_color = get_saturated_colors( image) #This is called from the contours script print( f"Color {found_color}, h value: {found_color[0]}" ) #This will print the color name as well as the value in an RBG array if 5 < found_color[ 0] < 40: #This chooses the first value of the array. This chooses values based on the color wheel print("yellow") devastator_robot.backward() elif 100 < found_color[0] < 135: print("blue") devastator_robot.forward() else: devastator_robot.stop() capture_buffer.truncate(0)
# CamJam EduKit 3 - Robotics # Worksheet 3 - Motor Test Code GPIO Zero Version # by Neil Bizzell (@PiVangelist) from gpiozero import CamJamKitRobot # Import the CAMJamKitRobot Class from teh GPIO Zero library from time import sleep # import the sleep function from the time library #define robot robot = CamJamKitRobot() #turn on the motors in a forward direction for 2 seconds robot.forward(1) sleep(2)