Exemple #1
0
 def loadSettings(self):
     self.settings = self.getSettings(self._appName)
     if self.settings['workPosition'] != "":
         workPositionPts = list(
             map(int, self.settings['workPosition'].split(',')))
         self.workPosition = Rectangle.Rectangle(
             Point.Point(workPositionPts[0], workPositionPts[1]),
             Point.Point(workPositionPts[2], workPositionPts[3]))
     self.workPositionThreshold = self.settings['workPositionThreshold']
Exemple #2
0
    def __init__(self, radius: float, point: Point):
        super(Circle, self)
        self.radius = radius
        self.point = point

        if radius is None or point is None:
            raise Exception(Messages.C_MS02)

        x = radius
        error = 1 - x
        y = 0

        while y <= x:
            self.points.append(Point(x=x + point.x, y=y + point.y))
            self.points.append(Point(x=y + point.x, y=x + point.y))
            self.points.append(Point(x=-x + point.x, y=y + point.y))
            self.points.append(Point(x=-y + point.x, y=x + point.y))
            self.points.append(Point(x=-x + point.x, y=-y + point.y))
            self.points.append(Point(x=-y + point.x, y=-x + point.y))
            self.points.append(Point(x=x + point.x, y=-y + point.y))
            self.points.append(Point(x=y + point.x, y=-x + point.y))
            y = y + 1
            if error < 0:
                error += 2 * y + 1
            else:
                x = x - 1
                error += 2 * (y - x + 1)
Exemple #3
0
    def __to_point(self, lua_table):
        if not lua_table:
            return None

        # assumption that this is a lua table type
        p = dict(zip('xyz', lua_table.values()))
        return Point(**p)
Exemple #4
0
 def createGameRectangle(self, minSize, xRange, yRange):
     widthPt = random.randint(xRange[0], xRange[1])
     heightPt = random.randint(yRange[0], yRange[1])
     if widthPt + minSize > xRange[1]:
         xRight = widthPt
         xLeft = widthPt - minSize
     else:
         xLeft = widthPt
         xRight = widthPt + minSize
     if heightPt + minSize > yRange[1]:
         yBottom = heightPt
         yTop = heightPt - minSize
     else:
         yTop = heightPt
         yBottom = heightPt + minSize
     rect = Rectangle.Rectangle(Point.Point(xLeft, yTop),
                                Point.Point(xRight, yBottom))
     return rect
Exemple #5
0
def test_find_most_suitable_station() -> None:
    stations = [
        Station(Point(0, 0), 10),
        Station(Point(20, 20), 5),
        Station(Point(10, 0), 12)
    ]
    assert find_most_suitable_station(stations, Device(Point(0, 0))) == \
        StationPower(Station(Point(0, 0), 10), 100.0)

    assert find_most_suitable_station(stations, Device(Point(100,
                                                             100))) is None

    station, power = find_most_suitable_station(stations, Device(Point(15,
                                                                       10)))
    assert station.point == Point(x=10, y=0)
    assert station.reach == 12
    assert round(power, 2) == 0.67

    station, power = find_most_suitable_station(stations, Device(Point(18,
                                                                       18)))
    assert station.point == Point(x=20, y=20)
    assert station.reach == 5
    assert round(power, 2) == 4.72
Exemple #6
0
def main():
    apoint = Point(x=100, y=80)
    bpoint = Point(x=160, y=200)
    cpoint = Point(x=220, y=80)
    circle = Circle(radius=10, point=apoint)
    triangle = Triangle(lines=[StraightLine(a=apoint, b=bpoint), StraightLine(a=apoint, b=cpoint),
                               StraightLine(a=bpoint, b=cpoint)])
    canvas1 = Canvas(250, 250, Point(x=200, y=200), "canvas1", [triangle, circle], show_cp=True)
    canvas2 = Canvas(260, 260, Point(x=450, y=450), "canvas2", [circle], show_cp=True)
    canvas3 = Canvas(270, 270, Point(x=710, y=710), "canvas3", [circle], show_cp=True)
    canvas_list = [canvas1, canvas2, canvas3]
    screen = TkinterScreen()
    screen.configure(canvas_list)
    board = Board(screen)
    board.draw_at()
Exemple #7
0
def stations_from_json(stations: str) -> List[Station]:
    return [Station(Point(station[0], station[1]), station[2])
            for station in json.loads(stations)]
Exemple #8
0
def device_from_json(point: str) -> Device:
    return Device(Point(*json.loads(point)))
Exemple #9
0
    vertices = mesh.vertices
    triangles = mesh.triangles
    normals = mesh.normals

    print 'Num vertices:', len(vertices)
    print 'Num triangles:', len(triangles)
    print 'Num normals:', len(normals)

    # 1. Generate candidate pairs of contact points

    # 2. Check for force closure

    # 3. Convert each grasp to a hand pose
    contact1 = vertices[500]
    contact2 = vertices[2000]
    T_obj_gripper = contacts_to_baxter_hand_pose(contact1, contact2)
    print 'Translation', T_obj_gripper.translation
    print 'Rotation', T_obj_gripper.quaternion

    pose_msg = T_obj_gripper.pose_msg

    # 3d visualization to help debug
    vis.figure()
    vis.mesh(mesh)
    vis.points(Point(contact1, frame='test'))
    vis.points(Point(contact2, frame='test'))
    vis.pose(T_obj_gripper, alpha=0.05)
    vis.show()

    # 4. Execute on the actual robot
Exemple #10
0
def test_point_from_json():
    assert device_from_json('[0, 0]') == Device(Point(0, 0))
Exemple #11
0
def test_stations_from_json():
    assert stations_from_json("[[0, 0, 10]]") == [Station(Point(0, 0), 10)]
Exemple #12
0
#!/usr/bin/env python

import sys; sys.path.append("..")

from core import Point, Sequence
from core import OFFSET_64, MIDI_PITCH, DURATION_64


## points

p1 = Point({
    OFFSET_64: 16,
    MIDI_PITCH: 50,
    DURATION_64: 16,
})

assert p1.tuple(OFFSET_64, DURATION_64) == (16, 16)


## sequences

p2 = Point({
    OFFSET_64: 32,
    MIDI_PITCH: 52,
    DURATION_64: 16,
})

s1 = Sequence([p1, p2])

assert s1 == [
    {DURATION_64: 16, OFFSET_64: 16, MIDI_PITCH: 50},
Exemple #13
0
def test_enrich_stations_with_power() -> None:
    stations = [Station(Point(0, 0), 10)]
    device = Device(Point(0, 0))
    assert list(enrich_stations_with_power(
        stations, device)) == [StationPower(Station(Point(0, 0), 10), 100.0)]
Exemple #14
0
def test_distance_to_station() -> None:
    assert distance_to_station(Point(0, 0), Point(0, 0)) == 0
    assert distance_to_station(Point(0, 0), Point(10, 0)) == 10.0
    assert distance_to_station(Point(10, 0), Point(0, 0)) == 10.0