-
Notifications
You must be signed in to change notification settings - Fork 1
/
Remote_draft.pas
116 lines (93 loc) · 2.61 KB
/
Remote_draft.pas
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
{$reference 'NKH.MindSqualls.dll'}
uses LEGORobot, GraphABC, ABCObjects, NKH.MindSqualls;
var robo : MyRobot;
Text1, Text2 : TextABC;
procedure ReactOnDistance(rob : MyRobot);
var dist : integer;
begin
dist := rob.Distance;
Text1.Text := 'Äèñòàíöèÿ (ñì) : ' + IntToStr(dist);
Text2.Text := 'TachoCount A : ' + IntToStr(rob.MotorA.TachoCount);
//exit;
if dist>40 then
begin
robo.MotorA.Run(30,60);
robo.MotorC.Run(30,60);
end
else
if dist<10 then
begin
robo.MotorA.Run(-30,60);
robo.MotorC.Run(-30,60);
end;
end;
procedure KeyDown(key : integer);
begin
case key of
VK_UP : begin // äâèæåíèå ïðÿìî
robo.MotorA.Run(30,360);
robo.MotorC.Run(30,360);
end;
VK_Right : begin // ïîâîðîò íàïðàâî
robo.MotorC.Run(25, 360);
robo.MotorA.Run(-25, 360);
end;
VK_Left : begin // ïîâîðîò íàëåâî
robo.MotorC.Run(-25, 360);
robo.MotorA.Run(25, 360);
end;
VK_Down : begin // äâèæåíèå íàçàä
robo.MotorA.Run(-25, 0);
robo.MotorC.Run(-25, 0);
end;
VK_Space : // îñòàíîâêà
begin
robo.Stop;
//robo.brick.CommLink.Disconnect;
end;
VK_Q : begin
robo.Destroy;
readln;
halt;
end;
end;
end;
begin
//Text1 := TextABC.Create(10,10,14,'Äèñòàíöèÿ...',clBlack);
//Text2 := TextABC.Create(10,50,14,'TachoCount...',clBlack);
// Ñîçäàåì ðîáîòà ñ óêàçàíèåì íîìåðà ïîðòà
robo := new MyRobot;
// Ñîçäàåì ìîòîðû
// robo.MotorA := RoboMotor.Create();
// robo.MotorC := RoboMotor.Create();
// Îïðåäåëÿåì óëüòðàçâóêîâîé ñåíñîð
//robo.AddSensor(sUltrasonic,4);
//robo.AddSensor(sColor,3);
// Äîáàëÿåì îáðàáîò÷èêè ñîáûòèé
//robo.Action := ReactOnDistance;
// Ñîåäèíåíèå ñ ðîáîòîì
if not robo.Connect(3) then
begin
write('Õüþñòîí, ó íàñ ïðîáëåìà!');
exit;
end;
// robo.brick.Sensor3 := new Nxt2ColorSensor();
//(robo.brick.Sensor3 as Nxt2ColorSensor).SetColorDetectorMode();
//(robo.brick.Sensor3 as Nxt2ColorSensor).PollInterval := 500;
OnKeyDown := KeyDown;
Window.Width := 700; Window.Height := 500;
CenterWindow;
sleep(100);
{while true do
begin
writeln('Öâåò : ' + robo.Color);
end;}
for var i:=1 to 1000 do
begin
{if (robo.brick.Sensor3 as Nxt2ColorSensor).Color.HasValue then
writeln(i,' - ',(robo.brick.Sensor3 as Nxt2ColorSensor).Color.ToString())
else
writeln(i,' - íåò çíà÷åíèÿ!');}
sleep(1000);
end;
end.