forked from onebody/robot_car
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobot_motor.html
150 lines (122 loc) · 4.61 KB
/
robot_motor.html
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="height = device-height, width = 420, user-scalable = no"/>
<title>WIFI小车-电机测试</title>
<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript">
function init() {
var button;
button = webiopi().createButton("bt_up", "/\\", go_forward, stop);
$("#up").append(button);
button = webiopi().createButton("bt_left", "<", turn_left, stop);
$("#middle").append(button);
button = webiopi().createButton("bt_stop", "Auto", auto);
$("#middle").append(button);
button = webiopi().createButton("bt_right", ">", turn_right, stop);
$("#middle").append(button);
button = webiopi().createButton("bt_down", "\\/", go_backward, stop);
$("#down").append(button);
button = webiopi().createButton("bt_webCam_left", "左", webCam_left);
$("#webCam").append(button);
button = webiopi().createButton("bt_webCam_right", "右", webCam_right);
$("#webCam").append(button);
// setInterval("showTime()", 1000);
}
var camFlag = true;
function webCam_left() {
if (camFlag == false) {
webiopi().callMacro("webcamStepMotor_setup", "8,11,25,7,0.01,20");
camFlag = true;
}
webiopi().callMacro("webcamStepMotor_turnWebcam", "20,0,0.01");
}
function webCam_right() {
if (camFlag == false) {
webiopi().callMacro("webcamStepMotor_setup", "8,11,25,7,0.01,20");
camFlag = true;
}
webiopi().callMacro("webcamStepMotor_turnWebcam", "20,1,0.01");
}
var init_flag = false;
function init_robotMotor() {
if (init_flag == false) {
webiopi().callMacro("robotMotor_setup", "22,27,7,17,18,9");
init_flag = true;
}
}
function go_forward() {
init_robotMotor();
webiopi().callMacro("robotMotor_control", "forward");
}
function go_backward() {
init_robotMotor();
webiopi().callMacro("robotMotor_control", "backward");
}
function turn_right() {
init_robotMotor();
webiopi().callMacro("robotMotor_control", "turn_right_forward");
}
function turn_left() {
init_robotMotor();
webiopi().callMacro("robotMotor_control", "turn_left_forward");
}
function stop() {
webiopi().callMacro("robotMotor_control", "stop");
}
var autoStart = false;
function auto() {
init_robotMotor();
if (autoStart == false) {
webiopi().callMacro("robotMotor_control", "auto");
autoStart = true;
}
else {
webiopi().callMacro("robotMotor_control", "auto_stop");
autoStart = false;
}
}
webiopi().ready(init);
// 不自动刷新界面
webiopi().refreshGPIO(false);
var beforeDistance = "";
var afterDistance = "";
function showTime() {
var today = new Date();
webiopi().callMacro("rangingSensor_Distance", "23,24", function (s, a, d) {
beforeDistance = d;
});
webiopi().callMacro("rangingSensor_Distance", "3,4", function (s, a, d) {
afterDistance = d;
});
var html = "当前时间: " + today.toString() + "</br>";
html += "前方距离:" + beforeDistance + " CM</br>";
html += "后方距离:" + afterDistance + " CM";
document.getElementById("tip").innerHTML = html;
if (beforeDistance < 30 || afterDistance < 30)
stop();
}
</script>
<style type="text/css">
button {
margin: 5px 5px 5px 5px;
width: 50px;
height: 50px;
font-size: 24pt;
font-weight: bold;
color: black;
}
</style>
</head>
<body>
<div id="content" align="center">
<div id="tip">哈</div>
<!--<img width="320" height="240" src="http://192.168.1.102:8081/?action=stream"><br/>-->
<div id="up"></div>
<div id="middle"></div>
<div id="down"></div>
<div id="webCam"></div>
</div>
</body>
</html>