Skip to content

Commit

Permalink
Add stop button for Behaviour Tree
Browse files Browse the repository at this point in the history
  • Loading branch information
Chi-EEE committed Mar 20, 2024
1 parent e8a8996 commit 755bab3
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/admin_panel/js/behaviour_tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ function startBehaviourTree(_event, _args) {
websocket_server.startBehaviourTree();
}

function stopBehaviourTree(_event, _args) {
websocket_server.stopBehaviourTree()
}

ipcMain.handle('sendBehaviourTree', sendBehaviourTree);
ipcMain.handle('startBehaviourTree', startBehaviourTree);
ipcMain.handle('stopBehaviourTree', stopBehaviourTree);

module.exports = {
sendBehaviourTree: sendBehaviourTree,
startBehaviourTree: startBehaviourTree,
stopBehaviourTree: stopBehaviourTree,
}
2 changes: 1 addition & 1 deletion app/admin_panel/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const { websocket_server } = require('./websocket');
const { closeWebSocketServer } = require('./websocket_events');
const { selectRaspberryPi, unselectRaspberryPi, getRaspberryPiList, getSelectedRaspberryPi } = require('./raspberry_pi');
const { getLocalIPList } = require('./device');
const { sendBehaviourTree, startBehaviourTree } = require('./behaviour_tree');
const { sendBehaviourTree, startBehaviourTree, stopBehaviourTree } = require('./behaviour_tree');

function onClose() {
closeWebSocketServer();
Expand Down
1 change: 1 addition & 0 deletions app/admin_panel/js/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const WINDOW_API = {

sendBehaviourTree: (/** @type {any} */ args) => ipcRenderer.invoke("sendBehaviourTree", args),
startBehaviourTree: () => ipcRenderer.invoke("startBehaviourTree"),
stopBehaviourTree: () => ipcRenderer.invoke("stopBehaviourTree"),
}

contextBridge.exposeInMainWorld("api", WINDOW_API)
14 changes: 14 additions & 0 deletions app/admin_panel/js/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,20 @@ class WebSocketServer {
action: 'start',
}));
}

stopBehaviourTree() {
if (this._wss === undefined) {
return;
}
if (this._selected_raspberry_pi === undefined) {
return;
}
this._selected_raspberry_pi.ws.send(JSON.stringify({
type: 'command',
command: 'behaviour_tree',
action: 'stop',
}));
}
}

module.exports = { websocket_server: new WebSocketServer() };
18 changes: 15 additions & 3 deletions app/admin_panel/src/lib/CodeBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
let start_behaviour_tree_text = "Start Behaviour Tree";
/** @type {string} */
let start_behaviour_tree_color = "#89AAFF"
let start_behaviour_tree_color = "#89AAFF";
/** @type {boolean} */
let start_behaviour_tree_debounce = false;
Expand All @@ -34,7 +34,9 @@
}
send_behaviour_tree_debounce = true;
try {
await api.sendBehaviourTree({ data: xmlFormat.minify($behaviour_tree_xml_code) });
await api.sendBehaviourTree({
data: xmlFormat.minify($behaviour_tree_xml_code),
});
send_behaviour_tree_text = "Sent Behaviour Tree!";
send_behaviour_tree_color = "#3457AA";
} catch (error) {
Expand Down Expand Up @@ -67,10 +69,14 @@
start_behaviour_tree_debounce = false;
}, 1000);
}
async function stopBehaviourTree() {
await api.stopBehaviourTree();
}
</script>

<div class="h-full">
<div class="grid grid-cols-2 gap-2">
<div class="grid grid-cols-3 gap-2">
<button
on:mousedown={sendBehaviourTree}
class="p-2 rounded-lg shadow-lg relative inset-0"
Expand All @@ -83,6 +89,12 @@
style="background-color: {start_behaviour_tree_color}; color: white; width: 100%; border: none;"
>{start_behaviour_tree_text}</button
>
<button
on:mousedown={stopBehaviourTree}
class="p-2 rounded-lg shadow-lg relative inset-0"
style="background-color: #FF352F; color: white; width: 100%; border: none;"
>Stop Behaviour Tree</button
>
</div>
<CodeMirror
class="text-left h-full flex-auto font-mono text-lg font-bold"
Expand Down

0 comments on commit 755bab3

Please sign in to comment.