예제 #1
0
    def test_drive_distance_at_lower_bound(self):
        img_src = self._pictures_dir + "straight_no_turn_3in.jpg"

        follower = Follower(test_img_src=img_src)
        follower.follow()

        self.assertEqual(follower._speed, 0)
예제 #2
0
    def test_drive_distance_valid(self):
        img_src = self._pictures_dir + "straight_no_turn_5in.jpg"

        follower = Follower(test_img_src=img_src)
        follower.follow()

        self.assertEqual(follower._speed, LEADER_MAX_SPEED)
예제 #3
0
    def test_drive_distance_below_lower_bound(self):
        img_src = self._pictures_dir + "straight_no_turn_third_car_length.jpg"

        follower = Follower(test_img_src=img_src)
        follower.follow()

        self.assertAlmostEqual(follower._speed, 0)
예제 #4
0
    def test_detect_tag_not_found(self):
        img_src = self._pictures_dir + "no_tag.jpg"

        follower = Follower(test_img_src=img_src)
        follower.follow()

        self.assertEqual(follower._tag_data, self._default_tag_data)
예제 #5
0
    def test_detect_tag_found(self):
        img_src = self._pictures_dir + "straight_no_turn_5in.jpg"

        follower = Follower(test_img_src=img_src)
        follower.follow()

        self.assertNotEqual(follower._tag_data, self._default_tag_data)
예제 #6
0
def main():
    tag = TagRecognition()
    bt = Bluetoothctl()
    BT_ADDR = "5C:BA:37:26:6D:9A"

    # If an ARTag is detected, the vehicle will become a follower.
    # If an ARTag is not detected, the vehicle will become a leader.
    if tag.detect():
        vehicle = Follower()
    else:
        if not is_controller_connected():
            # If a controller is not connected, remove it to avoid problems
            # connecting with it again.
            disconnect_and_remove_device(bt, BT_ADDR)
            bt.start_scan()

            while not is_controller_connected():
                bt.connect(BT_ADDR)
                sleep(Follower.CYCLE_TIME)

        vehicle = Leader()

    # This loop makes the vehicle move. If the vehicle sees an ARTag then
    # it is a follower vehicle, otherwise it is a leader vehicle.
    timer_set = False
    start_time = time.time()

    while True:
        tag_visible = tag.detect()
        if isinstance(vehicle, Leader):
            vehicle.lead()

            if tag_visible:
                while is_controller_connected():
                    bt.disconnect('5C:BA:37:26:6D:9A')
                    sleep(Follower.CYCLE_TIME)
                vehicle = Follower()
        else:
            vehicle.follow()
            if tag_visible:
                timer_set = False
            elif not timer_set:
                start_time = time.time()
                timer_set = True

            if (time.time() - start_time) > 5 and timer_set:
                timer_set = False

                disconnect_and_remove_device(bt,BT_ADDR)
                bt.start_scan()
                bt.connect('5C:BA:37:26:6D:9A')
                sleep(Follower.CYCLE_TIME)

                if is_controller_connected():
                    vehicle = Leader()
                else:
                    start_time = time.time()
                    timer_set = True
예제 #7
0
def main() -> None:
    args = parseArguments()

    follower = Follower(args["detector"], args["tracker"], args["classifier"],
                        args["sourceFPS"], args["videoIn"], args["useGPU"])

    follower.setHyperparam(slowStartPhase=args["firstPhase"],
                           trackOverDetect=args["ratioToverD"],
                           k=args["knn"],
                           driftRatio=0.05,
                           driftTollerance=100)
    follower.setLogParam(showLog=args["showLog"],
                         destImgs=args["imgsOut"],
                         destVideo=args["videoOut"],
                         destFps=10)

    while True:
        end = follower.follow()
        if end is None:
            break
        elif end == (-1, -1):
            print("Unknown position...")
        else:
            print("Leader position:", end)