Skip to main content
Version: QTrobot V3

Motor

robot.motor lists motors, controls torque/homing/velocity, and streams joint state and commands. These examples assume you already have a connected robot — see Connection if you haven't set one up yet.

Setup

<script src="https://cdn.jsdelivr.net/npm/@luxai-qtrobot/robot-sdk/dist/qtrobot-sdk.umd.js"></script>
npm install @luxai-qtrobot/robot-sdk

List motors

const motors = await robot.motor.list()
console.log(`Available motors: ${JSON.stringify(Object.keys(motors))}`)

Joint state — callback style

import type { JointStateFrame } from '@luxai-qtrobot/robot-sdk'

const unsubscribe = robot.motor.onJointsState((frame: JointStateFrame) => {
for (const joint of frame.joints()) {
console.log(` [${joint}] pos=${frame.position(joint).toFixed(2)} vel=${frame.velocity(joint).toFixed(1)}`)
}
})

await new Promise(r => setTimeout(r, 3000))
unsubscribe()

Joint state — async iterator style

const reader = robot.motor.jointsStateReader()
let count = 0
for await (const frame of reader) {
console.log(` frame ${++count}: HeadYaw pos=${frame.position('HeadYaw').toFixed(2)}`)
if (count >= 3) break
}
reader.close()

Joint state — direct read

const reader = robot.motor.jointsStateReader()
try {
const frame = await reader.read(5.0)
console.log(`Got frame. Joints: ${JSON.stringify(frame.joints())}`)
} finally {
reader.close()
}

All three styles read the exact same stream — pick whichever fits your control flow.

Send a joint command

import { JointCommandFrame } from '@luxai-qtrobot/robot-sdk'

const writer = robot.motor.openJointsCommandWriter()
const cmd = new JointCommandFrame()
cmd.setJoint('HeadYaw', { position: 15, velocity: 40 })
await writer.write(cmd)
writer.close()

Home all motors

const ret = await robot.motor.homeAll()
console.log(`All motors homed. response: ${JSON.stringify(ret)}`)

Next steps

Continue with the Microphone tutorial, or see the full robot.motor namespace in the TypeScript/Node.js API Reference.