-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtester.ts
78 lines (73 loc) · 2.25 KB
/
tester.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
namespace robot.test {
/**
* Starts a testing mode to be used when building a robot
*/
export function startTestMode() {
setAssist(RobotAssist.LineFollowing, false)
onLineDetected(function () {
playTone(600, 50)
})
onLineLeftRightDetected(true, true, () => {
playTone(640, 50)
led.toggle(0, 2)
})
onLineLeftMiddleRightDetected(true, true, true, () => {
playTone(680, 50)
})
onLineOuterLeftLeftOuterRightDetected(true, true, true, true, () => {
playTone(720, 50)
})
onObstacleDistanceChanged(function () {
playTone(768, 50)
})
input.onButtonPressed(Button.A, () => {
const d = 1000
playTone(440, 200)
setColor(0xff0000)
motorTank(-100, 100)
pause(d)
playTone(440, 200)
setColor(0xff0000)
motorTank(100, -100)
pause(d)
playTone(840, 200)
setColor(0x000000)
motorStop()
})
input.onButtonPressed(Button.B, () => {
const d = 600
motorTank(50, 50, d)
motorTank(0, 0, d)
motorTank(-50, -50, d)
motorStop()
motorSteer(0, 100, d)
motorSteer(0, 0, d)
motorSteer(0, -100, d)
motorStop()
})
input.onButtonPressed(Button.AB, () => {
setAssist(RobotAssist.LineFollowing, true)
let last = 0
onLineLeftRightDetected(true, true, () => {
console.log(`x x`)
last = 0
motorSteer(0, 100)
})
onLineLeftRightDetected(false, false, () => {
console.log(`o o`)
if (last < 0) motorSteer(-200, 100)
else motorSteer(200, 100)
})
onLineLeftRightDetected(true, false, () => {
console.log(`x o`)
last = -1
motorSteer(-100, 100)
})
onLineLeftRightDetected(false, true, () => {
console.log(`o x`)
last = 1
motorSteer(100, 100)
})
})
}
}