Loading files
5e4094a64This file is pinned to the selected release. Download the original to open it in your design tool.
import Timer from 'timer'
const LED_NAME = 'head'
const STEP_MS = 1200
function delay(ms) {
return new Promise((resolve) => Timer.set(resolve, ms))
}
async function runSmoke(robot) {
trace('[M5StackChan CoreS3 smoke] start\n')
trace(
'[M5StackChan CoreS3 smoke] target=esp32:./host/platforms/m5stackchan_cores3 mod=mods/examples/m5stackchan_smoke\n',
)
try {
trace('[M5StackChan CoreS3 smoke] servo: torque on\n')
await robot.motion.setTorque(true)
trace('[M5StackChan CoreS3 smoke] servo: neutral pose\n')
await robot.motion.setPose({ rotation: { y: 0, p: 0, r: 0 } }, 0.5)
await delay(STEP_MS)
trace('[M5StackChan CoreS3 smoke] servo: small yaw/pitch check\n')
await robot.motion.setPose({ rotation: { y: 0.08, p: -0.06, r: 0 } }, 0.5)
await delay(STEP_MS)
trace('[M5StackChan CoreS3 smoke] servo: neutral pose\n')
await robot.motion.setPose({ rotation: { y: 0, p: 0, r: 0 } }, 0.5)
} catch (error) {
trace(`[M5StackChan CoreS3 smoke] servo: error ${error}\n`)
} finally {
try {
trace('[M5StackChan CoreS3 smoke] servo: torque off\n')
await robot.motion.setTorque(false)
} catch (error) {
trace(`[M5StackChan CoreS3 smoke] servo: torque off error ${error}\n`)
}
}
trace('[M5StackChan CoreS3 smoke] LED: lightOn red\n')
robot.lighting.lightOn(LED_NAME, 24, 0, 0)
await delay(STEP_MS)
trace('[M5StackChan CoreS3 smoke] LED: lightBlink green\n')
robot.lighting.lightBlink(LED_NAME, 0, 24, 0, 250)
await delay(STEP_MS * 2)
trace('[M5StackChan CoreS3 smoke] LED: lightRainbow\n')
robot.lighting.lightRainbow(LED_NAME)
await delay(STEP_MS * 2)
trace('[M5StackChan CoreS3 smoke] LED: lightOff\n')
robot.lighting.lightOff(LED_NAME)
trace('[M5StackChan CoreS3 smoke] complete\n')
}
export function onContextCreated(robot) {
Timer.set(() => {
void runSmoke(robot)
}, 1000)
}