Ejemplo n.º 1
0
    def handle(self, dmap, a):
        min_d = 2
        center_blocked = ac.central_dist(dmap) == min_d
        next_left = ac.column_min_dist(dmap, 0) > min_d
        next_right = ac.column_min_dist(dmap, -1) > min_d

        # save visual data
        self.map.see_offset((0, 1), blocked=center_blocked)
        if next_left:
            self.map.see_offset((-1, 1))
        if next_right:
            self.map.see_offset((1, 1))
        self.map.print_current()
        print self.map.get_view((-1, 1)), self.map.get_view((1, 1)), next_left, next_right, self.map.yaw

        # turn to the next unobserved point
        angle = 0
        current_offset = (0, 1)
        for i in range(4):
            current_offset = mp.MapTracker.compensate_yaw(current_offset, 90)
            angle += 90
            if self.map.get_view(current_offset) == mp.MapTracker.Unknown:
                self.move = ac.turn_left(ac.empty(), arg=angle)
                return
        self.finished = True
        self.move = ac.empty()
Ejemplo n.º 2
0
    def action(self):
        self.similar_frames = self.similar_frames + 1 if not collector.image_changed else 0

        time_for_action = self.similar_frames >= WAIT_NO_CHANGE
        if not time_for_action:
            return ac.empty()

        if self.side_step_repeat > 0:
            self.side_step_repeat -= 1
            return self.side_step_action
        self.similar_frames = 0
        action = ac.empty()

        phase = PHASES[int(self.step / LENGTH)%len(PHASES)]
        substep = self.step % LENGTH
        # print(phase, substep, substep % 2)
        use_x_axis = substep % 2 == 0
        # make steps along extremes longer
        if self.step / LENGTH % 2 == 1:
            use_x_axis = not use_x_axis
        print('ph:%d ss:%d/%d F:%s  \t%d \t%s' % (self.step / LENGTH,
                                                  substep + 1,
                                                  LENGTH,
                                                  str(use_x_axis),
                                                  collector._counter,
                                                  str(phase)))
        if use_x_axis:
            action = ac.step(action, forward=phase[0])
        else:
            self.side_step_action = ac.step_aside(action, right=phase[1])
            self.side_step_repeat = SIDE_REPEAT - 1
            action = self.side_step_action
        collector.register_action(action)
        self.step += 1
        return action
Ejemplo n.º 3
0
 def _turn_action(self):
     t = 5
     if self._turn_count == 0:
         self._turn_turns += 1
         print ('frame: %d \t turn: %d \t angle: %d' % (self._turn_total, self._turn_turns, self.currentAngle))
         self._turn_count = self._turn_cycle - 1
         return ac.turn_left(ac.empty(), t)
     else:
         self._turn_count -= 1
         return ac.empty()
Ejemplo n.º 4
0
    def subturn(self, direction):
        '''Turn by 1 degree and make a step every STEP turns'''
        self.substep = self.substep + 1 if self.substep < STEP else 0
        action = ac.turn_left(ac.empty(), arg=direction)

        # skip a bit once a circle
        if self.turn != 0 and self.turn % 360 == 0 and self.substep == 0:
            action = ac.empty()
            print('SKIPPED A BIT')

        if self.substep == 0:
            action = ac.step(action, forward=True)
        return action
Ejemplo n.º 5
0
    def action(self):
        if self.delay():
            return self.delay_action

        if self.state == 0:
            return ac.turn_left(ac.empty(), arg=90)
        elif self.state == 1:
            return ac.turn_left(ac.empty(), arg=180)
        elif self.state == 2:
            return ac.turn_left(ac.empty(), arg=90)
        else:
            self.position += 1 if self.direction else -1
            return ac.step_aside(ac.empty(), right=self.direction)
Ejemplo n.º 6
0
 def move_to_faceforward(self, next_tile):
     curr = (self.x, self.y)
     delta = (-curr[0] +next_tile[0], -curr[1] +next_tile[1])
     assert (delta[0] < 2 and delta[1] == 0) or (delta[1] < 2 and delta[0] == 0)
     offset = self._decompensate_yaw(delta)
     print 'move offset to delta %s -%3d-> %s' % (delta, self.yaw, offset)
     if offset[0] == 0:
         if offset[1] < 0:
             return ac.turn_left(ac.empty(), arg = 180), next_tile
         self.x, self.y = next_tile
         return self.move_to_action(ac.empty(), offset), None
     else:
         ang = 90 if offset[0] > 1 else 270
         return ac.turn_left(ac.empty(), arg = ang), next_tile
Ejemplo n.º 7
0
 def assign_precise_search(self):
     print('current best: %d %f' % (self.bestAngle, self.bestQuality))
     width = 1   # check in *width current steps apart
     move = ac.turn_left(ac.empty(), self.bestAngle + width * self.step - self.currentAngle)
     self.targetAngle = self.bestAngle - width * self.step
     self.step = 1
     self.precise_mode = True
     return move
Ejemplo n.º 8
0
 def action(self):
     if not self.direction_selected:
         self.directions_checked += 1
         if self.directions_checked == self.min_angle + 4:
             self.direction_selected = True
         return ac.turn_left(ac.empty(), arg=90)
     else:
         return self.subturn()
Ejemplo n.º 9
0
    def action(self):
        self.count += 1

        a = ac.empty()
        i = (self.count / self.frequency) % len(a)

        a[i] = 1
        if self.count % self.frequency == 0:
            print(self.count, i, a)
        return a
Ejemplo n.º 10
0
 def move_to(self, next_tile):
     curr = (self.x, self.y)
     delta = (next_tile[0] - curr[0], next_tile[1] - curr[1])
     print 'delta', delta
     assert delta[0] < 2
     assert delta[1] < 2
     self.move(delta[0], delta[1])
     action = self.move_to_action(ac.empty(), delta)
     print 'act', action
     return action
Ejemplo n.º 11
0
    def action(self):
        if self.path is None:
            path = self.map.path_to_unvisited()

            if path is None:
                print 'YOUVE SEEN EVERYTHING, BOY'
                return ac.empty()

            self.path = iter(path)

        if self.target_tile is None:
            self.target_tile = next(self.path, None)

        if self.target_tile is None:
            self.path = None
            self.finished = True
            return ac.empty()

        next_action, self.target_tile = self.map.move_to_faceforward(self.target_tile)
        return next_action
Ejemplo n.º 12
0
    def action(self):
        self.move = ac.empty()
        self._turn_total += 1     # count the frames
        if not self.skipped(): return self.move

        dist = float(self.targetAngle - self.currentAngle)
        if math.fabs(dist/self.step) > 0.5:
            turn = int(self.step * np.sign(dist))
            self.assigned += turn
            self.move = ac.turn_left(self.move, turn)
        else:
            # assign new target
            if self.precise_mode:
                print('current best: %d %f' % (self.bestAngle, self.bestQuality))
                if self.dance_around == 0:
                    self.finished = True
                    self.map.reset_yaw()
                self.dance_around *= -1
                self.targetAngle = self.bestAngle
                self.move = ac.turn_left(ac.empty(), self.bestAngle - self.currentAngle + self.dance_around)
            else:
                self.move = self.assign_precise_search()
        return self.move
Ejemplo n.º 13
0
    def action(self):
        if not self.direction_selected:
            self.angle += 1
            if self.angle == self.min_angle + 4:
                self.direction_selected = True
            return ac.turn_left(ac.empty(), arg=90)

        if self.turn % 360 == 0:
            self.turn_back = 0;

        print(self.turn, self.turn_back)
        if self.turn == TOTAL + 2*STEP:
            exit(0)

        else:
            if (self.turn % 360) != 180 or self.turn_back == 360:
                self.turn += 1
                return self.subturn(1)
            else:
                self.turn_back += 1
                return self.subturn(-1)
Ejemplo n.º 14
0
 def action(self):
     if self.skipped():
         self.finished = True
     return ac.empty()
Ejemplo n.º 15
0
 def action(self):
     return ac.empty()
Ejemplo n.º 16
0
 def action(self):
     self.finished = self.skipped()
     return ac.empty()
Ejemplo n.º 17
0
 def delay(self):
     delay = 0
     self.delay_loop = self.delay_loop + 1 if self.delay_loop < delay else 0
     self.delay_action = ac.empty()
     return self.delay_loop > 0