Skip to content

Commit

Permalink
Update robot/protocol.ts, robot/robot.ts, robot/micromaqueenrobot.ts,…
Browse files Browse the repository at this point in the history
… robot/radio.ts
  • Loading branch information
pelikhan committed Sep 19, 2023
1 parent f826589 commit 369fd67
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 19 deletions.
3 changes: 0 additions & 3 deletions robot/micromaqueenrobot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ namespace microcode {
maqueen.motorRun(maqueen.Motors.All, right < 0 ? maqueen.Dir.CCW : maqueen.Dir.CW, right)
}
}
motorStop() {
maqueen.motorStop(maqueen.Motors.All)
}
}

robot = new MicroMaqqueenRobot()
Expand Down
4 changes: 1 addition & 3 deletions robot/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ namespace microcode {
const MESSAGE_MAGIC = 0xf498

export enum RobotCommand {
SetRobotDriver = 0x0001,
MotorRun = 0x0002,
MotorStop = 0x0003,
MotorRun = 0x0001,
}
export enum RobotDrivers {
MicroMaqqueen = 0x01
Expand Down
11 changes: 3 additions & 8 deletions robot/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace microcode {

export function setGroup(newGroup: number) {
if (newGroup < 0)
newGroup += MAX_GROUPS
newGroup += MAX_GROUPS
group = newGroup % MAX_GROUPS
radio.setGroup(group)
showRadioStatus()
Expand All @@ -40,17 +40,12 @@ namespace microcode {
const payload = msg.payload
switch (cmd) {
case RobotCommand.MotorRun: {
const left = payload.getNumber(NumberFormat.Int8LE, 0)
const right = payload.getNumber(NumberFormat.Int8LE, 1)
const left = Math.clamp(-255, 255, payload.getNumber(NumberFormat.Int16LE, 0))
const right = Math.clamp(-255, 255, payload.getNumber(NumberFormat.Int16LE, 2))
console.log(`motor run ${left} ${right}`)
robot.motorRun(left, right)
break
}
case RobotCommand.MotorStop: {
console.log(`motor stop`)
robot.motorStop()
break
}
}
})
}
7 changes: 2 additions & 5 deletions robot/robot.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
namespace microcode {
export interface Robot {
/*
Set the power on motors
Set the power on motors where `left` and `right` are in [-255,255]
Set left and right to 0 to stop.
*/
motorRun(left: number, right: number): void;
/**
* Stop and brake
*/
motorStop(): void;
}

export let robot: Robot
Expand Down

0 comments on commit 369fd67

Please sign in to comment.