Skip to content

Commit

Permalink
Add function to send simulator command to AI
Browse files Browse the repository at this point in the history
  • Loading branch information
emielsteerneman committed Aug 6, 2023
1 parent 12442c5 commit e454128
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion roboteam_interface_vue/src/modules/composables/ai-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useSTPDataStore } from '../stores/data-stores/stp-data-store'
import { useVisionDataStore } from '../stores/data-stores/vision-data-store'
import { useVisualizationStore } from '../stores/data-stores/visualization-store'
import { useProtoWebSocket } from './proto-websocket'
import { rand } from '@vueuse/core'

export const useAiController = defineStore('aiController', () => {
// Dependencies
Expand All @@ -29,6 +30,37 @@ export const useAiController = defineStore('aiController', () => {
// Actions
const setBallPos = (x: number, y: number) => send('setBallPos', { x, y })

const robotsToSide = ( () => {
let teleportRobot = []
for(const team of [proto.Team.BLUE, proto.Team.YELLOW]){
for (let i = 0; i < 16; i++) {
const x = -6 + i * 0.3
teleportRobot.push({
'id': { 'id': i, 'team': team },
'x' : (team === proto.Team.YELLOW ? x : -x),
'y' : -4.6,
'orientation' : 0
})
}
}
return teleportRobot
})()

const ballToCenter = {
'teleportBall' : {
'x' : 0, 'y' : 0, 'z' : 0, 'vx' : 0, 'vy' : 0, 'vz' : 0
}
}

const commandMap = new Map<string, Object>([
['robotsToSide', robotsToSide],
['ballToCenter', ballToCenter],
])

const sendSimulatorCommand = (command: string) => {
send('simulatorCommand', commandMap.get(command))
}

// Writable computed properties
const useReferee = computed({
get: () => aiData.state?.runtimeConfig?.useReferee!,
Expand Down Expand Up @@ -104,6 +136,7 @@ export const useAiController = defineStore('aiController', () => {
robotHubMode,
isPaused,
currentPlayName,
currentRuleset
currentRuleset,
sendSimulatorCommand
}
})

0 comments on commit e454128

Please sign in to comment.