Beispiel #1
0
    def _on_left_down(self, event):
        #TODO: change event to fire with mouse key down, not only at the moment press
        dxy = event.GetPosition()
        dc = wx.ClientDC(self.canvas)
        dc.SetPen(wx.Pen('WHITE', 1))
        self.canvas.Draw(True)
        dc.DrawLine(self.canvas_size / 2, self.canvas_size / 2, dxy[0], dxy[1])
        dc.DrawCircle(dxy[0], dxy[1], 3)

        coordinates = event.GetCoords()
        self.runner(self.bot.shift_body_angle,
                    MathTools.coordinates2angle(*coordinates),
                    MathTools.vector_length(*coordinates))
        self.runner(self.bot.sleep, 0.5)
Beispiel #2
0
 def _angles2positions(self, alist):
     plist = []
     for a in alist:
         if 'position' not in a.keys():
             if a['servo'] in self.inverted:
                 a['position'] = int(round(
                     MathTools.interpolate(a['angle'], 180, -180, MY_DRIVE_SPEED_MIN, MY_DRIVE_SPEED_MAX)
                 ))
             else:
                 a['position'] = int(round(
                     MathTools.interpolate(a['angle'], -180, 180, MY_DRIVE_SPEED_MIN, MY_DRIVE_SPEED_MAX)
                 ))
         plist.append(a)
     return plist
Beispiel #3
0
    def _on_left_down(self, event):
        #TODO: change event to fire with mouse key down, not only at the moment press
        dxy = event.GetPosition()
        dc = wx.ClientDC(self.canvas)
        dc.SetPen(wx.Pen('WHITE', 1))
        self.canvas.Draw(True)
        dc.DrawLine(self.canvas_size / 2, self.canvas_size / 2, dxy[0], dxy[1])
        dc.DrawCircle(dxy[0], dxy[1], 3)

        coordinates = event.GetCoords()
        angle = MathTools.interpolate(MathTools.vector_length(coordinates[0], coordinates[1]), 0, self.canvas_size, 0, 30)
        self.runner(self.bot.rotate_body,
                    angle,
                    (coordinates[1], -coordinates[0], 0))
        self.runner(self.bot.sleep, 0.5)
Beispiel #4
0
 def rotate_body(self, angle=0, axis_vector=(0, 0, 0)):
     from math import cos, sin
     angle = math.radians(angle)
     (l, m, n) = MathTools.normalize(*axis_vector)
     rotation_matrix = numpy.array([[l * l * (1 - cos(angle)) + cos(angle),
                                     m * l * (1 - cos(angle)) - n * sin(angle),
                                     n * l * (1 - cos(angle)) + m * sin(angle)],
                                    [l * m * (1 - cos(angle)) + n * sin(angle),
                                     m * m * (1 - cos(angle)) + cos(angle),
                                     n * m * (1 - cos(angle)) - l * sin(angle)],
                                    [l * n * (1 - cos(angle)) - m * sin(angle),
                                     m * n * (1 - cos(angle)) + l * sin(angle),
                                     n * n * (1 - cos(angle)) + cos(angle)]])
     bot_command = []
     for l in self.legs:
         bot_command.extend(l.rotate(rotation_matrix))
     self._send(bot_command)
Beispiel #5
0
 def _on_left_down(self, event):
     self.runner(self.bot.make_step, MathTools.coordinates2angle(*event.GetCoords()))