The function loads a model saved via model.save().
The function returns a Keras model instance. If the original model was compiled and saved with the optimizer, then the returned model will be compiled. Otherwise, the model will be left uncompiled. In the case that an uncompiled model is returned, a warning is displayed if the compile the argument is set to True.
Import Libraries
####################imports####################
#do not change
import cv2
import numpy as np
import tensorflow as tf
#do not change
####################imports####################
An IR sensor consists of 2 LEDs: one which transmits the IR light and one which receives the IR light. When the IR rays are transmitted, they bounce from the nearest surface and get back to the receiver LED. That’s how an IR sensor detects an object.
But to detect colors, we depend on the number of rays the surface reflects:
The dark surface will absorb more IR rays and as a result, the receiver will get fewer IR rays.
White or shiny objects will absorb fewer IR rays and as a result, the receiver will get more IR rays.
We can get the sensor values in PictoBlox and based on that value we can estimate whether the surface is black or white.
If the sensor detects the black line, its output value is increased. This means that the sensor is active.
If it detects the white area, its output value decreases. This means that the sensor is inactive.
We will call the threshold value above which the sensor detects the black line. If the sensor value is less than the threshold, it means that the sensor hasn’t detected the line yet.
Alert:IR sensors DON’T work in sunlight. IR rays from the sun increase the overall threshold of the sensors therefore they stay active all time. A closed environment or nighttime is the place/time to work with your line following robot.
Now, run the code by clicking the green flag and bringing the black line of the track close to the IR sensor. One of the following three conditions will happen:
Your calibration value is HIGH: The black region will not be detected in this case. Reduce the calibration value.
Your calibration value is LOW: The white region will not be detected in this case. Therefore, increase the calibration value.
Your calibration value is OK. The white and black regions are detected accurately.
Now modify the script to add the detection value for the right IR sensor.
sprite = Sprite('Tobi')
quarky = Quarky()
import random
quarky.cleardisplay()
for x in range(1, 8):
red = random.randrange(0, 255)
green = random.randrange(0, 255)
blue = random.randrange(0, 255)
quarky.setled(x, 1, [red, green, blue], 100)
sprite = Sprite('Tobi')
quarky = Quarky()
quarky.cleardisplay()
Y = 1
for i in range(0, 5):
X = 1
for i in range(0, Y):
quarky.setled(X, Y, [101, 255, 0], 100)
X += 1
Y += 1
Alert: You need to calibrate the IR sensor to get the best line detection by the robot. Also, you need to calibrate the speeds to make the robot follow the line correctly.
Alert: You need to calibrate the IR sensor to get the best line detection by the robot. Also, you need to calibrate the speeds to make the F, T1 and T2 speeds for the robot to follow the line correctly.
Alert: You need to calibrate the IR sensor to get the best line detection by the robot. Also, you need to calibrate the speeds to make the robot follow the line correctly.
The purpose of servo motor calibration is to align the angle of your servo motor properly.
Connecting Servo to Quarky
The Servo motor will be connected to the Quarky Servo Connector. There are two servo ports on Quarky. Always make sure that brown wire is on your left side.
sprite = Sprite('Tobi')
quarky = Quarky()
import time
Angle = 0
while True:
for i in range(0, 18):
Angle += 10
moveservo("Servo 1", Angle)
time.sleep(0.01)
for i in range(0, 18):
Angle += -10
moveservo("Servo 1", Angle)
time.sleep(0.01)
The purpose of servo motor calibration is to align the angle of your servo motor properly.
Connecting Servo to Quarky
The Servo motor will be connected to the Quarky Servo Connector. There are two servo ports on Quarky. Always make sure that brown wire is on your left side.