-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
90 lines (83 loc) · 2.04 KB
/
main.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
79
80
81
82
83
84
85
86
87
88
89
90
input.onButtonPressed(Button.A, function () {
_speed = 40
move_F()
})
function move_R () {
_inMotion_F = 0
_inMotion_R = 1
if (_speed > _wheel_max_speed) {
_speed = _wheel_max_speed
}
if (_speed < _wheel_min_threshold) {
_speed = _wheel_min_threshold
}
motor.MotorRun(motor.Motors.M1, motor.Dir.CW, _speed)
motor.MotorRun(motor.Motors.M2, motor.Dir.CW, _speed)
motor.MotorRun(motor.Motors.M3, motor.Dir.CCW, _speed)
motor.MotorRun(motor.Motors.M4, motor.Dir.CCW, _speed)
basic.pause(2000)
}
function forward_L () {
}
function reverse_R () {
}
function reverse_L () {
}
function avoidCollision_F () {
}
input.onButtonPressed(Button.B, function () {
_speed = 40
move_R()
})
function forward_R () {
}
function move_F () {
_inMotion_F = 1
_inMotion_R = 0
if (_speed > _wheel_max_speed) {
_speed = _wheel_max_speed
}
if (_speed < _wheel_min_threshold) {
_speed = _wheel_min_threshold
}
motor.MotorRun(motor.Motors.M1, motor.Dir.CCW, _speed)
motor.MotorRun(motor.Motors.M2, motor.Dir.CCW, _speed)
motor.MotorRun(motor.Motors.M3, motor.Dir.CW, _speed)
motor.MotorRun(motor.Motors.M4, motor.Dir.CW, _speed)
basic.pause(2000)
}
input.onLogoEvent(TouchButtonEvent.Touched, function () {
motor.motorStopAll()
_inMotion_F = 0
_inMotion_R = 0
})
function avoidCollision_R () {
}
let _speed = 0
let _inMotion_R = 0
let _inMotion_F = 0
let _wheel_min_threshold = 0
let _wheel_max_speed = 0
motor.motorStopAll()
_wheel_max_speed = 150
_wheel_min_threshold = 50
_inMotion_F = 0
_inMotion_R = 0
basic.showIcon(IconNames.Heart)
basic.forever(function () {
let _collision = 0
serial.writeValue("_speed", _speed)
serial.writeValue("_inMotion_F", _inMotion_F)
if (_collision) {
if (_inMotion_F) {
avoidCollision_F()
} else if (_inMotion_R) {
avoidCollision_R()
}
} else {
if (_inMotion_F) {
move_F()
} else if (_inMotion_R) {
}
}
})