Beispiel #1
0
    def draw(self, figure, ares=0):
        """Make the RoboDraw Draw the figure determined by the list of points"""

        #-- Transform the cartesian points into the angular space
        #-- by means of the inverse kinematics
        la = [(self.inverse_kin(p[0], p[1], 1)) for p in figure.lp]

        #-- Perform the sampling in the angular space
        angular_fig = fig.Figure(la).divide(ares)

        #-- Move the pencil up
        self.pen_up()
        time.sleep(0.400)

        #-- Move to the first position
        self.pose(angular_fig.lp[0][0], angular_fig.lp[0][1])

        #-- Move down the pencil
        self.pen_down()
        time.sleep(0.400)

        #-- Send the positions to the robot!
        for alpha, beta in angular_fig.lp:
            self.pose(alpha, beta)
            #time.sleep(0.1)  #-- extra time

        #-- Move the pencil up
        self.pen_up()
Beispiel #2
0
def test_pol():
    pol = [(32.324879, 901.84946), (210.111729, 106.06604),
           (-110.106629, 51.5178), (17.17259, 125.2589), (-142.43151, 4.0406),
           (-22.22335, -227.28434)]

    poly = fig.Figure(pol)
    poly.plot()
Beispiel #3
0
    def display_draw(self, figure, decimals=1, ares=0, display_points=False):
        """Draw the figure. 
    It is drawn
    by means of the virtual robot (applying inverse kinematics to
    the points, and then the direct kinematics"""

        #-- Transform the cartesian points into the angular space
        #-- by means of the inverse kinematics
        la = [(self.inverse_kin(p[0], p[1], decimals)) for p in figure.lp]

        #-- Perform the sampling in the angular space
        angular_fig = fig.Figure(la).divide(ares)

        #-- Transform the angular space into cartesian again, by means
        #-- of the direct kinematics
        lc = [(self.kinematics(a[0], a[1])) for a in angular_fig.lp]

        #-- Create a new figure
        new_fig = fig.Figure(lc)

        #-- Plot!
        new_fig.plot(display_points)
Beispiel #4
0
    def check_for_pawn(self, x_from, y_from, x_to, y_to):
        if self.board.board[y_to][x_to] is None:
            end_figure = Figures.Figure("none")
        else:
            end_figure = self.board.board[y_to][x_to]

        if isinstance(self.board.board[y_from][x_from], Figures.Pawn):
            if self.board.board[y_from][x_from].color == "white":
                return self.white_pawn_first_move(x_from, y_from, x_to, y_to, end_figure) or \
                       self.white_pawn_common_move(x_from, y_from, x_to, y_to, end_figure) or \
                       self.white_pawn_en_passant(y_from, x_to) or \
                       self.check_for_pawn_strike(x_from, y_from, x_to, y_to)
            elif self.board.board[y_from][
                    x_from].color == "black":  # same as white
                return self.black_pawn_first_move(x_from, y_from, x_to, y_to, end_figure) or \
                       self.black_pawn_common_move(x_from, y_from, x_to, y_to, end_figure) or \
                       self.black_pawn_en_passant(y_from, x_to) or \
                       self.check_for_pawn_strike(x_from, y_from, x_to, y_to)
        else:
            return False
Beispiel #5
0
 def check_and_move(self, start,
                    end):  # does rule checking and figure movement
     x_from, y_from = start
     x_to, y_to = end
     if self.board.board[y_to][x_to] is None:
         end_figure = Figures.Figure(
             "none"
         )  # у NoneType нет атрибута color, поэтому создаем виртуальный
     else:
         end_figure = self.board.board[y_to][x_to]
     if self.board.board[y_from][x_from] is not None:
         #figures color checking
         if (self.board.board[y_from][x_from].color == self.turn) and \
            (end_figure.color != self.board.board[y_from][x_from].color):
             #rules checking
             if self.is_able_to_go(x_from, y_from, x_to,
                                   y_to) or self.check_for_king(
                                       x_from, y_from, x_to, y_to):
                 #movement checking for castle
                 self.detect_first_move(x_from, y_from)
                 start_figure = self.board.board[y_from][x_from]
                 end_figure = self.board.board[y_to][x_to]
                 #actual moving
                 self.board.move_figure(
                     self.board.convert_position_backwards(start),
                     self.board.convert_position_backwards(end))
                 #acquiring new stricken cells
                 self.find_hit_cells()
                 #checking if king is in check, and if so, returning back to previous board state
                 if self.is_current_king_in_check():
                     self.board.move_figure(
                         self.board.convert_position_backwards(end),
                         self.board.convert_position_backwards(start))
                 else:  # check for pawns in last line and switch active player
                     self.find_pawn_for_replace()
                     if self.pawn_to_replace is not None:
                         self.ask_for_figure()
                     self.history.add_turn((x_from, y_from, x_to, y_to,
                                            start_figure, end_figure))
                     self.change_turn()
                     self.find_hit_cells()
Beispiel #6
0
    yc += y
    alp.append((xc, yc))
    
#-- Add the first point    
#alp.append(alp[0])
    
#-- Create the robot and set the connection
r = Robot.Robot(l1 = 73.0, l2 = 97.0)
r.test()
r.connect("/dev/ttyUSB0")
time.sleep(2)
r.speed(100)
    
    
#--- Create the figure with the absolute points!
f = fig.Figure(alp)

#-- Center the figure at origin (0,0)
f.center()

#-- Flip the y axis
f.flipy()

#f = f.divide(2)

#-- Scale the figure so that it fits the robot printing area
f.scale_fity(30)

#-- Translate the figure to the robot printing origin
f.translate(r.center)