-
Notifications
You must be signed in to change notification settings - Fork 1
/
wheels.ts
119 lines (108 loc) · 3.21 KB
/
wheels.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* Simple control of a pair of continous servos attached to P1 and P2.
*/
//% color=190 weight=100 icon="\uf021" block="Wheels"
namespace wheels {
/**
* Rotate left
* @param speed motor speed in percent; eg: 100
*/
//% blockId=wheels_rotate_left
//% block="rotate left at | %speed | percent"
//% advanced=true
//% speed.min=0 speed.max=100
export function rotateLeft(speed: number = 100): void {
servos.P1.run(-speed)
servos.P2.run(-speed)
}
/**
* Rotate right
* @param speed motor speed in percent; eg: 100
*/
//% blockId=wheels_rotate_right
//% block="rotate right at | %speed | percent"
//% advanced=true
//% speed.min=0 speed.max=100
export function rotateRight(speed: number = 100): void {
servos.P1.run(speed)
servos.P2.run(speed)
}
/**
* Move forward
* @param speed motor speed in percent; eg: 100
*/
//% blockId=wheels_move_forward
//% block="move forward at | %speed | percent"
//% advanced=true
//% speed.min=0 speed.max=100
export function moveForward(speed: number = 100): void {
servos.P1.run(speed)
servos.P2.run(-speed)
}
/**
* Move backward
* @param speed motor speed in percent; eg: 100
*/
//% blockId=wheels_move_backward
//% block="move backward at | %speed | percent"
//% advanced=true
//% speed.min=0 speed.max=100
export function moveBackward(speed: number = 100): void {
servos.P1.run(-speed)
servos.P2.run(speed)
}
/**
* Stop moving
*/
//% blockId=wheels_stop_moving
//% block="stop moving"
//% advanced=true
export function stopMoving(): void {
servos.P1.run(0)
servos.P2.run(0)
}
/**
* Rotate left for given interval
* @param interval time in seconds to execute command; eg: 1
*/
//% blockId=wheels_rotate_left_for
//% block="rotate left for | %interval | second(s)"
export function rotateLeftFor(interval: number = 1): void {
rotateLeft()
basic.pause(interval * 1000)
stopMoving()
}
/**
* Rotate right for given interval
* @param interval time in seconds to execute command; eg: 1
*/
//% blockId=wheels_rotate_right_for
//% block="rotate right for | %interval | second(s)"
export function rotateRightFor(interval: number = 1): void {
rotateRight()
basic.pause(interval * 1000)
stopMoving()
}
/**
* Move forward for given interval
* @param interval time in seconds to execute command; eg: 1
*/
//% blockId=wheels_move_forward_for
//% block="move forward for | %interval | second(s)"
export function moveForwardFor(interval: number = 1): void {
moveForward()
basic.pause(interval * 1000)
stopMoving()
}
/**
* Move backward for given interval
* @param interval time in seconds to execute command; eg: 1
*/
//% blockId=wheels_move_backward_for
//% block="move backward for | %interval | second(s)"
export function moveBackwardFor(interval: number = 1): void {
moveBackward()
basic.pause(interval * 1000)
stopMoving()
}
}