4.4.3.1 准备清单
除了嵌入式控制板本身以外,用户还需要一些其他的配件才能完成下面的实验。下面列一个简单的清单。
(1)USB摄像头,最好是Linux下免驱的并且可以直接插在树莓派上用,不需要外部供电的(有些摄像头的电流太大,嵌入式的USB负担不了)。
(2)USB无线网卡。
(3)双USB接口的移动电源(一个给机器人控制系统供电;另一个给所有的电机供电)。
4.4.3.2 软件安装
第一步:下载mjpg-steamer软件,编译并安装:
Wget http://sourceforge.net/code-snapshots/svn/m/mj/mjpg-streamer/code/ mjpg-streamer-code-182.zip
unzip mjpg-streamer-code-182.zip
cd mjpg-streamer-code-182/mjpg-streamer
第二步:运行并将之复制到嵌入式控制板中源程序目录下的“stream.sh”文件:
pi@raspberrypi:/home/camtank# sudo chmod 777 stream.sh
pi@raspberrypi:/home/camtank# sudo ./stream.sh
其运行结果如图4.4.2所示。
图4.4.2 运行结果
第三步:在运行程序时,如果发生错误,可能是之前运行过,进程仍然在工作,导致没法再运行,可以先运行PS,查看运行中的进程和进程ID号,再使用“kill -9”杀掉进程,如图4.4.3所示。
图4.4.3 使用“kill-9”杀掉进程
第四步:在PC上运行源程序目录下的“index.html”文件,其远程监控图像如图4.4.4所示。
图4.4.4 远程监控图像
index.html源代码如下:
〈!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〉Cam Bot〈/title〉
〈script type="text/javascript" src="/webiopi.js"〉〈/script〉
〈script type="text/javascript"〉
function init() {
var button;
button = webiopi().create Button("bt_up", "/\\", go_forward, stop);
$("#up").append(button);
button = webiopi().create Button("bt_left", "〈", turn_left, stop);
$("#middle").append(button);
button = webiopi().create Button("bt_stop", "X", stop);
$("#middle").append(button);
button = webiopi().create Button("bt_right", "〉", turn_right, stop);
$("#middle").append(button);
}
function go_forward() {
webiopi().call Macro("go_forward");
}
function turn_right() {
webiopi().call Macro("turn_right");
}
function turn_left() {
webiopi().call Macro("turn_left");
}
function stop() {
webiopi().call Macro("stop");
}
webiopi().ready(init);
〈/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"〉
〈img width="320" height="240"
src="http://raspberrypi:8001/?action=stream"〉〈br/〉
〈div id="up"〉〈/div〉
〈div id="middle"〉〈/div〉
〈div id="down"〉〈/div〉
〈/div〉
〈/body〉
〈/html〉
免责声明:以上内容源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。