-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotors.ts
134 lines (116 loc) · 4.24 KB
/
motors.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//% color="#00A074" weight=88 icon="\uf021" block="서보모터"
namespace cck {
//% fixedInstances
export class Servo {
private _minAngle: number;
private _maxAngle: number;
private _stopOnNeutral: boolean;
constructor() {
this._minAngle = 0;
this._maxAngle = 180;
this._stopOnNeutral = true;
}
private clampDegrees(degrees: number): number {
degrees = degrees | 0;
degrees = Math.clamp(this._minAngle, this._maxAngle, degrees);
return degrees;
}
/**
* Set the servo angle
*/
//% weight=100 help=servos/set-angle
//% block="서보모터 %servo 각도를 %degrees=protractorPicker °"
//% degrees.defl=90
//% servo.fieldEditor="gridpicker"
//% servo.fieldOptions.width=220
//% servo.fieldOptions.columns=2
//% parts=microservo trackArgs=0
setAngle(degrees: number) {
degrees = this.clampDegrees(degrees);
this.internalSetAngle(degrees);
}
protected internalSetAngle(angle: number): void {
}
/**
* Set the throttle on a continuous servo
* @param speed the throttle of the motor from -100% to 100%
*/
//% weight=99 help=servos/run
//% blockId=servoservorun block="연속모터 %servo 속도를 %speed=speedPicker \\%"
//% servo.fieldEditor="gridpicker"
//% servo.fieldOptions.width=220
//% servo.fieldOptions.columns=2
//% parts=microservo trackArgs=0
run(speed: number): void {
const degrees = this.clampDegrees(Math.map(speed, -100, 100, this._minAngle, this._maxAngle));
const neutral = (this.maxAngle - this.minAngle) >> 1;
if (this._stopOnNeutral && degrees == neutral)
this.stop();
else
this.setAngle(degrees);
}
/**
* Stop sending commands to the servo so that its rotation will stop at the current position.
*/
// On a normal servo this will stop the servo where it is, rather than return it to neutral position.
// It will also not provide any holding force.
//% help=servos/stop
//% blockId=servoservostop block="모터정지 %servo"
//% servo.fieldEditor="gridpicker"
//% servo.fieldOptions.width=220
//% servo.fieldOptions.columns=2
//% parts=microservo trackArgs=0
stop() {
this.internalStop();
}
/**
* Gets the minimum angle for the servo
*/
public get minAngle() {
return this._minAngle;
}
/**
* Gets the maximum angle for the servo
*/
public get maxAngle() {
return this._maxAngle;
}
protected internalStop() { }
}
export class PinServo extends Servo {
private _pin: MicrobitPin;
constructor(pin: MicrobitPin) {
super();
this._pin = pin;
}
protected internalSetAngle(angle: number): void {
this._pin.servoWrite(angle);
}
protected internalStop() {
this._pin.digitalWrite(false);
}
}
//% block="P1" fixedInstance whenUsed
export const P1 = new cck.PinServo(new MicrobitPin(DigitalPin.P1));
//% block="P2" fixedInstance whenUsed
export const P2 = new cck.PinServo(new MicrobitPin(DigitalPin.P2));
//% block="P13" fixedInstance whenUsed
export const P13 = new cck.PinServo(new MicrobitPin(DigitalPin.P13));
//% block="P14" fixedInstance whenUsed
export const P14 = new cck.PinServo(new MicrobitPin(DigitalPin.P14));
//% blockId=secPicker block="$score"
//% blockHidden=true
//% colorSecondary="#FFFFFF"
//% score.fieldEditor="numberdropdown" score.fieldOptions.decompileLiterals=true
//% score.fieldOptions.data='[0.1, 0.2, 0.3, 0.4, 0.5, 1, 2, 3, 4, 5]'
export function __tennisScore(score: number): number {
return score;
}
//% color="#0090BB"
//% block="잠시쉬기 %time 초"
//% time.min=0 time.defl=1
//% time.shadow="secPicker"
export function pause(time: number): void {
basic.pause(time * 1000);
}
}