Example #1
0
from overdrive import Overdrive


def locationChangeCallback(addr, location, piece, speed, clockwise):
    # Print out addr, piece ID, location ID of the vehicle, this print everytime when location changed
    print("Location from " + addr + " : " + "Piece=" + str(piece) +
          " Location=" + str(location) + " Clockwise=" + str(clockwise))


car = Overdrive("F5:64:F7:27:C4:70")
car.setLocationChangeCallback(
    locationChangeCallback)  # Set location change callback to function above
car.changeSpeed(200,
                1000)  # Set car speed with speed = 500, acceleration = 1000
#car.changeLaneRight(1000, 1000) # Switch to next right lane with speed = 1000, acceleration = 1000
input()  # Hold the program so it won't end abruptly
Example #2
0
from overdrive import Overdrive


def locationChangeCallback(addr, params):
    # Print out addr, piece ID, location ID of the vehicle, this print everytime when location changed
    print(
        "Location from {addr} : Piece={piece} Location={location} Clockwise={clockwise}"
        .format(addr=addr, **params))


car = Overdrive("xx:xx:xx:xx:xx:xx")
car.setLocationChangeCallback(
    locationChangeCallback)  # Set location change callback to function above
car.changeSpeed(500, 500)  # Set car speed with speed = 500, acceleration = 500
car.changeLaneRight(
    500, 500)  # Switch to next right lane with speed = 500, acceleration = 500
input()  # Hold the program so it won't end abruptly
Example #3
0
tmp_clockwise = True
tmp_piece = 0


def locationChangeCallback(addr, location, piece, speed, clockwise):
    global tmp_clockwise, tmp_piece
    print(" Location from " + addr + " : " + "Piece=" + str(piece) +
          " Location=" + str(location) + " Clockwise=" + str(clockwise))
    tmp_clockwise = str(clockwise)
    tmp_piece = str(piece)


# UDP
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  # UDP
client.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
client.settimeout(0.1)
client.bind(("", 37020))

# Anki
car = Overdrive("E2:81:E9:52:65:97")
car.setLocationChangeCallback(locationChangeCallback)
car.changeSpeed(200, 300)

while True:
    message = str(tmp_clockwise) + " " + str(tmp_piece)
    client.sendto(message, ('172.27.0.3', 44444))
    data, addr = client.recvfrom(1024)
    if data == "0":
        car.changeSpeed(0, 1000)
input()
def main(input_speed):

    if not os.path.exists(MODEL_NAME + '/frozen_inference_graph.pb'):
        print('Downloading the model')
        opener = urllib.request.URLopener()
        opener.retrieve(DOWNLOAD_BASE + MODEL_FILE, MODEL_FILE)
        tar_file = tarfile.open(MODEL_FILE)
        for file in tar_file.getmembers():
            file_name = os.path.basename(file.name)
            if 'frozen_inference_graph.pb' in file_name:
                tar_file.extract(file, os.getcwd())
        print('Download complete')
    else:
        print('Model already exists')

    # ## Load a (frozen) Tensorflow model into memory.
    detection_graph = tf.Graph()
    with detection_graph.as_default():
        od_graph_def = tf.GraphDef()
        with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
            serialized_graph = fid.read()
            od_graph_def.ParseFromString(serialized_graph)
            tf.import_graph_def(od_graph_def, name='')

    # Loading label map:
    # Label maps map indices to category names, so that when our convolution
    # network predicts `5`, we know that this corresponds to `airplane`.  Here
    # we use internal utility functions, but anything that returns a dictionary
    # mapping integers to appropriate string labels would be fine

    label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
    categories = label_map_util.convert_label_map_to_categories(
        label_map, max_num_classes=NUM_CLASSES, use_display_name=True)
    category_index = label_map_util.create_category_index(categories)

    # Intializing the web camera device: 0 for internal and 1 for external camera
    # of the laptop used
    cap = cv2.VideoCapture(1)

    # Running the tensorflow session
    with detection_graph.as_default():
        with tf.Session(graph=detection_graph) as sess:
            ret = True

            # Select which cars to use on the track using MAC address of the device
            #car2 = Overdrive("CD:5A:27:DC:41:89")
            car3 = Overdrive("DE:83:21:EB:1B:2E")
            car2 = Overdrive("FB:76:00:CB:82:63")
            #car3 = Overdrive("DB:DE:FF:52:CB:9E")

            # Set initial car speed and acceleration for the two cars
            initial_car_speed = input_speed
            initial_car_acceleration = 800
            car2.changeSpeed(initial_car_speed, initial_car_acceleration)
            car3.changeSpeed(initial_car_speed, initial_car_acceleration)

            while (ret):
                ret, image_np = cap.read()
                print(image_np)
                # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
                image_np_expanded = np.expand_dims(image_np, axis=0)
                print(image_np_expanded)
                image_tensor = detection_graph.get_tensor_by_name(
                    'image_tensor:0')
                # Each box represents a part of the image where a particular object was detected.
                boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
                # Each score represent how level of confidence for each of the objects.
                # Score is shown on the result image, together with the class label.
                scores = detection_graph.get_tensor_by_name(
                    'detection_scores:0')
                classes = detection_graph.get_tensor_by_name(
                    'detection_classes:0')
                num_detections = detection_graph.get_tensor_by_name(
                    'num_detections:0')
                # Actual detection.
                (boxes, scores, classes, num_detections) = sess.run(
                    [boxes, scores, classes, num_detections],
                    feed_dict={image_tensor: image_np_expanded})
                # Visualization of the results of a detection.
                vis_util.visualize_boxes_and_labels_on_image_array(
                    image_np,
                    np.squeeze(boxes),
                    np.squeeze(classes).astype(np.int32),
                    np.squeeze(scores),
                    category_index,
                    use_normalized_coordinates=True,
                    line_thickness=8)
                classes_detected = classes[scores > 0.5]
                if 13 in classes_detected:
                    #print('detected')
                    car3.changeSpeed(0, initial_car_acceleration)
                    car2.changeSpeed(0, initial_car_acceleration)
                    #car3.changeLaneRight(250, 250)
                    car3.setLocationChangeCallback(locationChangeCallback)
                    #print(car3.piece)
                elif 10 in classes_detected:
                    print('verkeerslicht detected')
                    #print('detected')
                    car3.changeSpeed(0, initial_car_acceleration)
                    car2.changeSpeed(0, initial_car_acceleration)
                    #car3.changeLaneRight(250, 250)
                    car3.setLocationChangeCallback(locationChangeCallback)
                    """
          elif 1 in classes_detected:
              print('car detected')
              car3.changeSpeed(int(initial_car_speed/2), initial_car_acceleration)
              car2.changeSpeed(int(initial_car_speed/2), initial_car_acceleration)
              car3.setLocationChangeCallback(locationChangeCallback)
              """
                else:
                    car3.changeSpeed(initial_car_speed,
                                     initial_car_acceleration)
                    car2.changeSpeed(initial_car_speed,
                                     initial_car_acceleration)
                    car3.setLocationChangeCallback(locationChangeCallback)
                    #print(car3.piece)
                    #drive(cv2)
                #print(image_np,boxes,classes,scores,category_index)
                #plt.figure(figsize=IMAGE_SIZE)
                #plt.imshow(image_np)
                cv2.imshow('image', cv2.resize(image_np, (1280, 960)))
                if cv2.waitKey(25) & 0xFF == ord('q'):
                    cv2.destroyAllWindows()
                    cap.release()
                    break
Example #5
0
        'Location from {addr} : Piece={piece} Location={location} Speed={speed} Clockwise={clockwise}'
        .format(**params))


car.setLocationChangeCallback(locationChangeCallback)


def transitionChangeCallback(addr, params):
    params['addr'] = addr
    print('Transition from {addr} From={piecePrev} To={piece} Offset={offset}'.
          format(**params))


car.setTransitionCallback(transitionChangeCallback)

car.changeSpeed(500, 800)

while True:
    inpt = input(
        '[ to change lane to left, ] to change lane to right, enter to stop.\n'
    )
    if inpt == '[':
        car.changeLaneLeft(500, 800)
    elif inpt == ']':
        car.changeLaneRight(500, 800)
    else:
        break

car.changeSpeed(0, 800)
car.disconnect()
Example #6
0
numa = 0
numl = 0
numr = 0
mcs = 800
nums = 0
if car.addr == caradress:
    print("car connected")
    while 1:
        events = get_gamepad()
        for event in events:
            if not event.ev_type == "Sync":
                if event.code == "ABS_RZ":
                        carspeed = event.state
                        if carspeed > mcs:
                            carspeed = mcs
                        car.changeSpeed(carspeed, 1000)
                        print(carspeed)
                else:
                    if event.code == "BTN_TR":
                        numr = numr+1
                        if numr == 2:
                            car.changeLaneRight(500, 800)
                            print("RIGHT")
                            numr = 0
                    else:
                        if event.code == "BTN_TL":
                            numl= numl+1
                            if numl == 2:
                                car.changeLaneLeft(500, 800)
                                print("LEFT")
                                numl = 0
category_index = label_map_util.create_category_index(categories)

#intializing the web camera device

import cv2
cap = cv2.VideoCapture(1)

# Running the tensorflow session
with detection_graph.as_default():
  with tf.Session(graph=detection_graph) as sess:
   ret = True
   #car2 = Overdrive("CD:5A:27:DC:41:89")
   car3 = Overdrive("DE:83:21:EB:1B:2E")
   car2 = Overdrive("FB:76:00:CB:82:63")
   #car3 = Overdrive("DB:DE:FF:52:CB:9E")
   car2.changeSpeed(500, 1000)
   car3.changeSpeed(500, 1000)
   while (ret):
      ret,image_np = cap.read()
      # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
      image_np_expanded = np.expand_dims(image_np, axis=0)
      image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
      # Each box represents a part of the image where a particular object was detected.
      boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
      # Each score represent how level of confidence for each of the objects.
      # Score is shown on the result image, together with the class label.
      scores = detection_graph.get_tensor_by_name('detection_scores:0')
      classes = detection_graph.get_tensor_by_name('detection_classes:0')
      num_detections = detection_graph.get_tensor_by_name('num_detections:0')
      # Actual detection.
      (boxes, scores, classes, num_detections) = sess.run(
Example #8
0
from overdrive import Overdrive

# Global variables for the cars and the directionchange
# Select which cars to use on the track using MAC address of the device
#car2 = Overdrive("CD:5A:27:DC:41:89") #Brandbaar
#car3 = Overdrive("DE:83:21:EB:1B:2E") #GAS
car3 = Overdrive("FB:76:00:CB:82:63")  #Explosief
car2 = Overdrive("DB:DE:FF:52:CB:9E")  #Radioactief

initial_car_speed = 300
initial_car_acceleration = 800
car2.changeSpeed(initial_car_speed, initial_car_acceleration)
car3.changeSpeed(initial_car_speed, initial_car_acceleration)