-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchimes_sub.nxc
72 lines (61 loc) · 1.67 KB
/
chimes_sub.nxc
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
// Constants for communication with main NXT
const byte REMOTE_STAY_ALIVE = 0x00;
const byte REMOTE_CALIBRATE = 0x01;
const byte REMOTE_HIT_LEFT = 0x02;
const byte REMOTE_HIT_RIGHT = 0x03;
const byte REMOTE_HIT_BOTH = 0x04;
inline void WaitForBluetoothConnection() {
until( BluetoothStatus(CONN_BT0) == NO_ERR ) {
ClearLine( LCD_LINE1 );
TextOut(0, LCD_LINE1, "... no connection ...");
Wait(100);
}
ClearLine( LCD_LINE1 );
TextOut(0, LCD_LINE1, "Bluetooth connected!");
}
byte NextCommand() {
long command;
until( ReceiveRemoteNumber(MAILBOX1, true, command) == NO_ERR );
return command;
}
inline void CalibrateMalletHitting() {
// More finegrained regulation than default (100ms)
SetMotorRegulationTime(MS_10);
// Move mallet hitting motors softly in reverse until they block
OnFwdReg(OUT_AB, 10, OUT_REGMODE_IDLE);
Wait(2000);
// Move forward to real zero position
RotateMotor(OUT_AB, 30, -50);
Wait(2000);
// Set zero position and motor speed
PosRegEnable(OUT_AB);
PosRegSetMax(OUT_AB, 75, 0);
}
inline void HitMalletLeft() {
PosRegAddAngle(OUT_B, -90);
}
inline void HitMalletRight() {
PosRegAddAngle(OUT_A, -90);
}
task main() {
WaitForBluetoothConnection();
while(true) {
switch(NextCommand()) {
case REMOTE_CALIBRATE:
CalibrateMalletHitting();
break;
case REMOTE_HIT_LEFT:
HitMalletLeft();
break;
case REMOTE_HIT_RIGHT:
HitMalletRight();
break;
case REMOTE_HIT_BOTH:
HitMalletLeft();
HitMalletRight();
break;
default:
break;
}
}
}