Skip to content

solar_panels

DiscoverSolarPanelsAction #

Bases: Action

Use the camera to find orientation of solar panels.

Source code in cogip/tools/planner/actions/solar_panels.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
class DiscoverSolarPanelsAction(Action):
    """
    Use the camera to find orientation of solar panels.
    """

    def __init__(self, planner: "Planner", actions: Actions):
        super().__init__("DiscoverSolarPanel action", planner, actions)
        self.poses.append(
            Pose(
                x=-500,
                y=-1000,
                O=180,
                max_speed_linear=33,
                max_speed_angular=33,
                after_pose_func=self.get_solar_panels,
            )
        )

    async def get_solar_panels(self):
        await asyncio.sleep(2)
        solar_panels = await get_solar_panels(self.planner)
        for panel_id, angle in solar_panels.items():
            # Angle are given for yellow camp only
            log_prefix = f"Solar panel {panel_id}: angle={angle}"
            match angle:
                case angle if -5 <= angle < 20:
                    logger.info(f"{log_prefix}, need activation")
                    self.actions.append(SolarPanelAction(self.planner, self.actions, panel_id, angle))
                case angle if 20 <= angle <= 180:
                    logger.info(f"{log_prefix}, already activated")
                case angle if -179 <= angle <= -160:
                    logger.info(f"{log_prefix}, already activated")
                case _:
                    logger.info(f"{log_prefix}, cannot be activated")

    def weight(self) -> float:
        return 900000.0

SetRobotPositionAction #

Bases: Action

Use the camera and a table Aruco marker to find the current robot position.

Source code in cogip/tools/planner/actions/solar_panels.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class SetRobotPositionAction(Action):
    """
    Use the camera and a table Aruco marker to find the current robot position.
    """

    def __init__(self, planner: "Planner", actions: Actions):
        super().__init__("SetRobotPosition action", planner, actions)
        self.after_action_func = self.get_position

    async def get_position(self):
        await actuators.arm_panel_close(self.planner)

        pose = await get_robot_position(self.planner)
        if not pose:
            logger.error("Cannot find table marker and current robot position")
            return

        await self.planner.set_pose_start(pose)
        self.planner.pose_reached = False

        self.actions.append(DiscoverSolarPanelsAction(self.planner, self.actions))

    def weight(self) -> float:
        return 1000000.0

SolarPanelAction #

Bases: Action

Activate a solar panel.

Source code in cogip/tools/planner/actions/solar_panels.py
 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
105
106
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
class SolarPanelAction(Action):
    """
    Activate a solar panel.
    """

    def __init__(self, planner: "Planner", actions: Actions, panel_id: int, angle: float):
        super().__init__("SolarPanelAction action", planner, actions)
        self.panel_id = panel_id
        self.angle = angle
        solar_panel = solar_panels_positions[panel_id]

        robot_y = solar_panel.y - 30

        self.poses.append(
            Pose(
                x=-750,
                y=robot_y,
                O=180,
                max_speed_linear=33,
                max_speed_angular=33,
                after_pose_func=self.extend_arm,
            )
        )

        self.poses.append(
            Pose(
                x=-1000 + self.game_context.properties.robot_width / 2 + 20,
                y=robot_y,
                O=180,
                max_speed_linear=33,
                max_speed_angular=33,
                allow_reverse=False,
            )
        )

        self.poses.append(
            Pose(
                x=-750,
                y=robot_y,
                O=180,
                max_speed_linear=33,
                max_speed_angular=33,
                after_pose_func=self.fold_arm,
            )
        )

    async def extend_arm(self):
        await actuators.arm_panel_open(self.planner)

    async def fold_arm(self):
        await actuators.arm_panel_close(self.planner)

    def weight(self) -> float:
        return 800000.0 + self.panel_id