Skip to content

Commit ea7da9f

Browse files
authored
Merge pull request #143 from cogip/142-dashboard-add-starter-feedback-and-emulation
142 dashboard add starter feedback and emulation
2 parents 5971c55 + e048afb commit ea7da9f

File tree

9 files changed

+44
-21
lines changed

9 files changed

+44
-21
lines changed

cogip/tools/dashboard/static/js/wizardModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ function createChoiceButton(inputType, choice, value, index) {
315315
class:
316316
"w-[15px] h-[15px] me-2 rounded-md inline-block bg-white checked:accent-red-cogip",
317317
value: choice,
318-
checked: isChecked,
319318
});
319+
if (isChecked) button.checked = true
320320
return button;
321321
}
322322
// Helper function to create labels for choice inputs

cogip/tools/dashboard/templates/dashboard.html

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,21 @@
5353
</div>
5454

5555
<footer class="mt-auto bg-zinc-900 text-grey-color mx-2">
56-
<div class="container-lg pt-2">
57-
<span class="text-muted float-left" id="connection">
56+
<div class="container-lg pt-2 flex items-center justify-between">
57+
<span class="text-muted inline" id="connection">
5858
<pre
59-
class="text-grey-color text-sm inline"><img class="mr-5 w-[20px] inline" src="{{ url_for('static', path='img/cross_red_circle.svg') }}" /></pre>
59+
class="text-grey-color text-sm"><img class="mr-5 w-[20px]" src="{{ url_for('static', path='img/cross_red_circle.svg') }}" /></pre>
6060
</span>
6161
{% if robot_id != 0 %}
62-
<span class="text-muted float-right inline" id="state">
62+
<span class="text-muted text-sm inline" id="state">
6363
<pre id="state_robot"></pre>
6464
<pre id="order_robot"></pre>
6565
</span>
66+
<span class="text-muted text-sm z-10" id="starter">
67+
<label>
68+
<input type="checkbox" class="checked:accent-red-cogip checked:border-red-cogip" disabled> Starter
69+
</label>
70+
</span>
6671
{% endif %}
6772
</div>
6873
</footer>
@@ -147,9 +152,13 @@ <h5 class="text-lg font-medium text-grey-color">Score</h5>
147152
socket.on("connect", function () {
148153
socketModule.onConnection(this);
149154
})
150-
.on("disconnect", function () {
155+
.on("disconnect", function () {
151156
socketModule.onDisconnect();
152157
})
158+
.on("virtual", function (robot_id, msg) {
159+
console.log(!msg)
160+
document.querySelector("#starter input").disabled = !msg;
161+
})
153162
.on("tool_menu", function (menu) {
154163
socketModule.onMenu(menu, "tool", this);
155164
virtualKeyboard._actualize();
@@ -178,8 +187,16 @@ <h5 class="text-lg font-medium text-grey-color">Score</h5>
178187
})
179188
.on("obstacles", function (robot_id, msg) {
180189
drawModule.updateObstacles(robot_id, msg);
190+
})
191+
.on("starter_changed", function(robot_id, pushed) {
192+
document.querySelector("#starter input").checked = pushed;
181193
});
182194

195+
// add event listener on click for starter input
196+
document.querySelector("#starter input").addEventListener("click", function () {
197+
socket.emit("starter_changed", this.checked);
198+
});
199+
183200
if (robotId !== 0) {
184201
import("../static/js/scoreModule.js").then((scoreModule) => {
185202
socket.on("score", function (score) {
@@ -218,11 +235,10 @@ <h5 class="text-lg font-medium text-grey-color">Score</h5>
218235
console.log(`Delete robot ${robot_id} dashboard`);
219236
drawModule.deleteTab(robot_id);
220237
})
221-
222238
}
223239
});
224240

225241
</script>
226242
</body>
227243

228-
</html>
244+
</html>

cogip/tools/monitor/mainwindow.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,10 @@ def starter_toggled(self, robot_id: int, checked: bool):
623623

624624
def starter_changed(self, robot_id: int, checked: bool):
625625
if starter_checkbox := self.robot_starters.get(robot_id):
626+
enabled = starter_checkbox.isEnabled()
627+
starter_checkbox.setEnabled(False)
626628
starter_checkbox.setChecked(checked)
629+
starter_checkbox.setEnabled(enabled)
627630

628631
def closeEvent(self, event: QtGui.QCloseEvent):
629632
settings = QtCore.QSettings("COGIP", "monitor")

cogip/tools/monitor/socketiocontroller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def actuators_closed(self):
161161

162162
@qtSlot(int, bool)
163163
def starter_changed(self, robot_id, pushed: bool):
164-
self.sio.emit("starter_changed", pushed, namespace="/monitor")
164+
self.sio.emit("starter_changed", pushed, namespace="/dashboard")
165165

166166
def on_menu(self, menu_name: str, data):
167167
menu = models.ShellMenu.model_validate(data)
@@ -334,7 +334,7 @@ def on_cmd_reset() -> None:
334334
"""
335335
self.signal_planner_reset.emit()
336336

337-
@self.sio.on("starter_changed", namespace="/monitor")
337+
@self.sio.on("starter_changed", namespace="/dashboard")
338338
def on_starter_changed(robot_id: int, pushed: bool) -> None:
339339
"""
340340
Change the state of a starter.

cogip/tools/planner/wizard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ async def request_strategy(self):
127127
async def response_strategy(self, message: dict[str, Any]):
128128
value = message["value"]
129129
self.game_strategy = Strategy[value]
130-
self.game_context.strategy = Strategy.AlignTest
130+
self.game_context.strategy = Strategy.TestAlign
131131
await self.planner.soft_reset()
132132

133133
async def request_starter_for_calibration(self):

cogip/tools/server/namespaces/dashboard.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ async def on_connected(self, sid):
2626
if self.context.shell_menu:
2727
await self.emit("shell_menu", (self.context.robot_id, self.context.shell_menu.model_dump()), to=sid)
2828

29+
if self.context.virtual:
30+
await self.emit("virtual", (self.context.robot_id, self.context.virtual), to=sid)
31+
2932
def on_disconnect(self, sid):
3033
logger.info("Dashboard disconnected.")
3134

@@ -97,3 +100,10 @@ async def on_wizard(self, sid, data: dict[str, Any]):
97100
namespace = data.pop("namespace")
98101
await self.emit("wizard", data, namespace=namespace)
99102
await self.emit("close_wizard")
103+
104+
async def on_starter_changed(self, sid, pushed: bool):
105+
"""
106+
Callback on starter_changed message.
107+
"""
108+
await self.emit("starter_changed", pushed, namespace="/planner")
109+
await self.emit("starter_changed", (self.context.robot_id, pushed), namespace="/dashboard", skip_sid=[sid])

cogip/tools/server/namespaces/monitor.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,3 @@ async def on_connected(self, sid):
3131
def on_disconnect(self, sid):
3232
self.context.monitor_sid = None
3333
logger.info("Monitor disconnected.")
34-
35-
async def on_starter_changed(self, sid, pushed: bool):
36-
"""
37-
Callback on starter_changed message.
38-
"""
39-
await self.emit("starter_changed", pushed, namespace="/planner")

cogip/tools/server/namespaces/planner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async def on_starter_changed(self, sid, pushed: bool):
9696
"""
9797
Callback on starter_pushed message.
9898
"""
99-
await self.emit("starter_changed", (self.context.robot_id, pushed), namespace="/monitor")
99+
await self.emit("starter_changed", (self.context.robot_id, pushed), namespace="/dashboard")
100100

101101
async def on_close_wizard(self, sid):
102102
"""

cogip/tools/server_beacon/robot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ async def pami_reset():
104104
strategy: actions.Strategy | None = None
105105
match robot_id:
106106
case 2:
107-
strategy = actions.Strategy.PAMI2
107+
strategy = actions.Strategy.Pami2
108108
case 3:
109-
strategy = actions.Strategy.PAMI3
109+
strategy = actions.Strategy.Pami3
110110
case 4:
111-
strategy = actions.Strategy.PAMI4
111+
strategy = actions.Strategy.Pami4
112112

113113
if strategy:
114114
await robot.sio.emit(

0 commit comments

Comments
 (0)