Skip to content

dynobstacle

DynBaseObstacleEntity #

Bases: QEntity

A dynamic obstacle detected by the robot.

Base class for rectangle and circle obstacles.

Source code in cogip/entities/dynobstacle.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class DynBaseObstacleEntity(Qt3DCore.QEntity):
    """
    A dynamic obstacle detected by the robot.

    Base class for rectangle and circle obstacles.
    """

    def __init__(self, parent: Qt3DCore.QEntity):
        """
        Class constructor.
        """
        super().__init__(parent)
        self.parent = parent
        self.points = []

        self.material = Qt3DExtras.QDiffuseSpecularMaterial(self)
        self.material.setDiffuse(QtGui.QColor.fromRgb(255, 0, 0, 100))
        self.material.setDiffuse(QtGui.QColor.fromRgb(255, 0, 0, 100))
        self.material.setSpecular(QtGui.QColor.fromRgb(255, 0, 0, 100))
        self.material.setShininess(1.0)
        self.material.setAlphaBlendingEnabled(True)
        self.addComponent(self.material)

        self.transform = Qt3DCore.QTransform(self)
        self.addComponent(self.transform)

        self.bb = PathEntity(QtCore.Qt.darkRed, self.parent)

    def set_bounding_box(self, points: list[models.Vertex]) -> None:
        if self.points == points:
            return

        self.points = points
        bb_points = []
        if points:
            for point in points:
                bb_points.append(models.Vertex(x=point.x, y=point.y, z=5))
            bb_points.append(models.Vertex(x=points[0].x, y=points[0].y, z=5))
        self.bb.set_points(bb_points)

    def setEnabled(self, isEnabled: bool) -> None:
        super().setEnabled(isEnabled)
        self.bb.setEnabled(isEnabled)

__init__(parent) #

Class constructor.

Source code in cogip/entities/dynobstacle.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def __init__(self, parent: Qt3DCore.QEntity):
    """
    Class constructor.
    """
    super().__init__(parent)
    self.parent = parent
    self.points = []

    self.material = Qt3DExtras.QDiffuseSpecularMaterial(self)
    self.material.setDiffuse(QtGui.QColor.fromRgb(255, 0, 0, 100))
    self.material.setDiffuse(QtGui.QColor.fromRgb(255, 0, 0, 100))
    self.material.setSpecular(QtGui.QColor.fromRgb(255, 0, 0, 100))
    self.material.setShininess(1.0)
    self.material.setAlphaBlendingEnabled(True)
    self.addComponent(self.material)

    self.transform = Qt3DCore.QTransform(self)
    self.addComponent(self.transform)

    self.bb = PathEntity(QtCore.Qt.darkRed, self.parent)

DynCircleObstacleEntity #

Bases: DynBaseObstacleEntity

A dynamic circle obstacle detected by the robot.

Represented as a transparent red cylinder.

Source code in cogip/entities/dynobstacle.py
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
class DynCircleObstacleEntity(DynBaseObstacleEntity):
    """
    A dynamic circle obstacle detected by the robot.

    Represented as a transparent red cylinder.
    """

    def __init__(self, parent: Qt3DCore.QEntity):
        """
        Class constructor.
        """
        super().__init__(parent)
        self.position: tuple[int, int, int] = None

        self.mesh = Qt3DExtras.QCylinderMesh()
        self.mesh.setLength(200)
        self.mesh.setRadius(400)
        self.addComponent(self.mesh)

        self.transform.setRotationX(90)

    def set_position(self, x: int, y: int, radius: int) -> None:
        """
        Set the position and size of the dynamic obstacle.

        Arguments:
            x: Center X position
            y: Center Y position
            radius: Obstacle radius
        """
        if self.position == (x, y, radius):
            return
        self.position = (x, y, radius)

        self.transform.setTranslation(QtGui.QVector3D(x, y, self.mesh.length() / 2))
        self.mesh.setRadius(radius)

__init__(parent) #

Class constructor.

Source code in cogip/entities/dynobstacle.py
114
115
116
117
118
119
120
121
122
123
124
125
126
def __init__(self, parent: Qt3DCore.QEntity):
    """
    Class constructor.
    """
    super().__init__(parent)
    self.position: tuple[int, int, int] = None

    self.mesh = Qt3DExtras.QCylinderMesh()
    self.mesh.setLength(200)
    self.mesh.setRadius(400)
    self.addComponent(self.mesh)

    self.transform.setRotationX(90)

set_position(x, y, radius) #

Set the position and size of the dynamic obstacle.

Parameters:

Name Type Description Default
x int

Center X position

required
y int

Center Y position

required
radius int

Obstacle radius

required
Source code in cogip/entities/dynobstacle.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
def set_position(self, x: int, y: int, radius: int) -> None:
    """
    Set the position and size of the dynamic obstacle.

    Arguments:
        x: Center X position
        y: Center Y position
        radius: Obstacle radius
    """
    if self.position == (x, y, radius):
        return
    self.position = (x, y, radius)

    self.transform.setTranslation(QtGui.QVector3D(x, y, self.mesh.length() / 2))
    self.mesh.setRadius(radius)

DynRectObstacleEntity #

Bases: DynBaseObstacleEntity

A dynamic rectangle obstacle detected by the robot.

Represented as a transparent red cube.

Source code in cogip/entities/dynobstacle.py
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
class DynRectObstacleEntity(DynBaseObstacleEntity):
    """
    A dynamic rectangle obstacle detected by the robot.

    Represented as a transparent red cube.
    """

    def __init__(self, parent: Qt3DCore.QEntity):
        """
        Class constructor.
        """
        super().__init__(parent)
        self.size: tuple[int, int] = None
        self.position: tuple[int, int, int] = None

        self.mesh = Qt3DExtras.QCuboidMesh()
        self.mesh.setZExtent(200)
        self.addComponent(self.mesh)

    def set_size(self, length: int, width: int) -> None:
        """
        Set the size of the dynamic obstacle.

        Arguments:
            length: Length
            width: Width
        """
        if self.size == (length, width):
            return

        self.size = (length, width)

        self.mesh.setXExtent(width)
        self.mesh.setYExtent(length)

    def set_position(self, x: int, y: int, rotation: int) -> None:
        """
        Set the position and orientation of the dynamic obstacle.

        Arguments:
            x: X position
            y: Y position
            rotation: Rotation
        """
        if self.position == (x, y, rotation):
            return

        self.position = (x, y, rotation)

        self.transform.setTranslation(QtGui.QVector3D(x, y, self.mesh.zExtent() / 2))
        self.transform.setRotationZ(rotation)

__init__(parent) #

Class constructor.

Source code in cogip/entities/dynobstacle.py
61
62
63
64
65
66
67
68
69
70
71
def __init__(self, parent: Qt3DCore.QEntity):
    """
    Class constructor.
    """
    super().__init__(parent)
    self.size: tuple[int, int] = None
    self.position: tuple[int, int, int] = None

    self.mesh = Qt3DExtras.QCuboidMesh()
    self.mesh.setZExtent(200)
    self.addComponent(self.mesh)

set_position(x, y, rotation) #

Set the position and orientation of the dynamic obstacle.

Parameters:

Name Type Description Default
x int

X position

required
y int

Y position

required
rotation int

Rotation

required
Source code in cogip/entities/dynobstacle.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def set_position(self, x: int, y: int, rotation: int) -> None:
    """
    Set the position and orientation of the dynamic obstacle.

    Arguments:
        x: X position
        y: Y position
        rotation: Rotation
    """
    if self.position == (x, y, rotation):
        return

    self.position = (x, y, rotation)

    self.transform.setTranslation(QtGui.QVector3D(x, y, self.mesh.zExtent() / 2))
    self.transform.setRotationZ(rotation)

set_size(length, width) #

Set the size of the dynamic obstacle.

Parameters:

Name Type Description Default
length int

Length

required
width int

Width

required
Source code in cogip/entities/dynobstacle.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
def set_size(self, length: int, width: int) -> None:
    """
    Set the size of the dynamic obstacle.

    Arguments:
        length: Length
        width: Width
    """
    if self.size == (length, width):
        return

    self.size = (length, width)

    self.mesh.setXExtent(width)
    self.mesh.setYExtent(length)