Loading files
13ad6d618This file is pinned to the selected release. Download the original to open it in your design tool.
Files from this revision, including CAD and LFS contents. Git history is not included.
Or in GitHub Desktop, choose File → Clone repository → URL and paste this address.
Public repositories can be cloned without signing in. For pushing, use your ThingAtlas username and a Git access token as the password.
git lfs install git clone https://thingatlas.com/git/-unclaimed/stack-chan-374381865.git
Includes Git history, branches, and Git LFS files. Clones the repository’s default branch, regardless of the version shown here.
13ad6d618This file is pinned to the selected release. Download the original to open it in your design tool.
import TextDecoder from 'text/decoder'
/**
* @brief face tracking mod with UnitV2
* @param {*} robot
*/
function onRobotCreated(robot, device) {
const decoder = new TextDecoder()
const target = {
x: 0.8,
y: 0,
z: 0,
}
const client = new device.network.http.io({
...device.network.http,
host: 'unitv2.local',
port: 80,
})
const _request = client.request({
method: 'POST',
path: '/func/result',
onReadable(count) {
let result
try {
const text = decoder.decode(this.read(count))
result = JSON.parse(text.split('|')[0])
} catch (_e) {
trace('parse failed.\n')
return
}
const face = result.face?.[0]
if (face == null) {
trace('no face detected.\n')
return
}
const centerX = face.x + face.w / 2
const centerY = face.y + face.h / 2
target.y = 0.8 * ((320 - centerX) / 320)
target.z = centerY / 480
robot.lookAt([target.x, target.y, target.z])
},
})
}
export default {
onRobotCreated,
}