summaryrefslogtreecommitdiffstats
path: root/examples/magpi-9-cambot2
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2013-12-25 13:25:16 +0100
committermanuel <manuel@mausz.at>2013-12-25 13:25:16 +0100
commit0c8c9ad976879f7c90f9915a60845ccb0cdb337d (patch)
tree162951b4713f3836f4114958a423e2c90ecf9c6b /examples/magpi-9-cambot2
downloadwebiopi-0c8c9ad976879f7c90f9915a60845ccb0cdb337d.tar.gz
webiopi-0c8c9ad976879f7c90f9915a60845ccb0cdb337d.tar.bz2
webiopi-0c8c9ad976879f7c90f9915a60845ccb0cdb337d.zip
initial commit
Diffstat (limited to 'examples/magpi-9-cambot2')
-rw-r--r--examples/magpi-9-cambot2/cambot.py117
-rw-r--r--examples/magpi-9-cambot2/index.html70
-rwxr-xr-xexamples/magpi-9-cambot2/stream.sh11
3 files changed, 198 insertions, 0 deletions
diff --git a/examples/magpi-9-cambot2/cambot.py b/examples/magpi-9-cambot2/cambot.py
new file mode 100644
index 0000000..f1013ab
--- /dev/null
+++ b/examples/magpi-9-cambot2/cambot.py
@@ -0,0 +1,117 @@
1# This version uses new-style automatic setup/destroy/mapping
2# Need to change /etc/webiopi
3
4# Imports
5import webiopi
6
7# Retrieve GPIO lib
8GPIO = webiopi.GPIO
9
10# -------------------------------------------------- #
11# Constants definition #
12# -------------------------------------------------- #
13
14# Left motor GPIOs
15L1=17 # H-Bridge 1
16L2=18 # H-Bridge 2
17LS=21 # H-Bridge 1,2EN
18
19# Right motor GPIOs
20R1=23 # H-Bridge 3
21R2=24 # H-Bridge 4
22RS=25 # H-Bridge 3,4EN
23
24# -------------------------------------------------- #
25# Convenient PWM Function #
26# -------------------------------------------------- #
27
28# Set the speed of two motors
29def set_speed(speed):
30 GPIO.pulseRatio(LS, speed)
31 GPIO.pulseRatio(RS, speed)
32
33# -------------------------------------------------- #
34# Left Motor Functions #
35# -------------------------------------------------- #
36
37def left_stop():
38 GPIO.output(L1, GPIO.LOW)
39 GPIO.output(L2, GPIO.LOW)
40
41def left_forward():
42 GPIO.output(L1, GPIO.HIGH)
43 GPIO.output(L2, GPIO.LOW)
44
45def left_backward():
46 GPIO.output(L1, GPIO.LOW)
47 GPIO.output(L2, GPIO.HIGH)
48
49# -------------------------------------------------- #
50# Right Motor Functions #
51# -------------------------------------------------- #
52def right_stop():
53 GPIO.output(R1, GPIO.LOW)
54 GPIO.output(R2, GPIO.LOW)
55
56def right_forward():
57 GPIO.output(R1, GPIO.HIGH)
58 GPIO.output(R2, GPIO.LOW)
59
60def right_backward():
61 GPIO.output(R1, GPIO.LOW)
62 GPIO.output(R2, GPIO.HIGH)
63
64# -------------------------------------------------- #
65# Macro definition part #
66# -------------------------------------------------- #
67@webiopi.macro
68def go_forward():
69 left_forward()
70 right_forward()
71
72@webiopi.macro
73def go_backward():
74 left_backward()
75 right_backward()
76
77@webiopi.macro
78def turn_left():
79 left_backward()
80 right_forward()
81
82@webiopi.macro
83def turn_right():
84 left_forward()
85 right_backward()
86
87@webiopi.macro
88def stop():
89 left_stop()
90 right_stop()
91
92# Called by WebIOPi at script loading
93def setup():
94 # Setup GPIOs
95 GPIO.setFunction(LS, GPIO.PWM)
96 GPIO.setFunction(L1, GPIO.OUT)
97 GPIO.setFunction(L2, GPIO.OUT)
98
99 GPIO.setFunction(RS, GPIO.PWM)
100 GPIO.setFunction(R1, GPIO.OUT)
101 GPIO.setFunction(R2, GPIO.OUT)
102
103 set_speed(0.5)
104 stop()
105
106
107# Called by WebIOPi at server shutdown
108def destroy():
109 # Reset GPIO functions
110 GPIO.setFunction(LS, GPIO.IN)
111 GPIO.setFunction(L1, GPIO.IN)
112 GPIO.setFunction(L2, GPIO.IN)
113
114 GPIO.setFunction(RS, GPIO.IN)
115 GPIO.setFunction(R1, GPIO.IN)
116 GPIO.setFunction(R2, GPIO.IN)
117
diff --git a/examples/magpi-9-cambot2/index.html b/examples/magpi-9-cambot2/index.html
new file mode 100644
index 0000000..db69b41
--- /dev/null
+++ b/examples/magpi-9-cambot2/index.html
@@ -0,0 +1,70 @@
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta name="viewport" content = "height = device-height, width = 420, user-scalable = no" />
6 <title>CamBot</title>
7 <script type="text/javascript" src="/webiopi.js"></script>
8 <script type="text/javascript">
9 function init() {
10 var button;
11
12 button = webiopi().createButton("bt_up", "/\\", go_forward, stop);
13 $("#up").append(button);
14
15 button = webiopi().createButton("bt_left", "<", turn_left, stop);
16 $("#middle").append(button);
17
18 button = webiopi().createButton("bt_stop", "X", stop);
19 $("#middle").append(button);
20
21 button = webiopi().createButton("bt_right", ">", turn_right, stop);
22 $("#middle").append(button);
23
24 button = webiopi().createButton("bt_down", "\\/", go_backward, stop);
25 $("#down").append(button);
26 }
27
28 function go_forward() {
29 webiopi().callMacro("go_forward");
30 }
31
32 function go_backward() {
33 webiopi().callMacro("go_backward");
34 }
35
36 function turn_right() {
37 webiopi().callMacro("turn_right");
38 }
39
40 function turn_left() {
41 webiopi().callMacro("turn_left");
42 }
43
44 function stop() {
45 webiopi().callMacro("stop");
46 }
47
48 webiopi().ready(init);
49
50 </script>
51 <style type="text/css">
52 button {
53 margin: 5px 5px 5px 5px;
54 width: 50px;
55 height: 50px;
56 font-size: 24pt;
57 font-weight: bold;
58 color: black;
59 }
60 </style>
61</head>
62<body>
63 <div id="content" align="center">
64 <img width="320" height="240" src="http://raspberrypi:8001/?action=stream"><br/>
65 <div id="up"></div>
66 <div id="middle"></div>
67 <div id="down"></div>
68 </div>
69</body>
70</html>
diff --git a/examples/magpi-9-cambot2/stream.sh b/examples/magpi-9-cambot2/stream.sh
new file mode 100755
index 0000000..12d6579
--- /dev/null
+++ b/examples/magpi-9-cambot2/stream.sh
@@ -0,0 +1,11 @@
1#!/bin/sh
2
3STREAMER=mjpg_streamer
4DEVICE=/dev/video0
5RESOLUTION=320x240
6FRAMERATE=25
7HTTP_PORT=8001
8
9PLUGINPATH=/usr/local/lib
10
11$STREAMER -i "$PLUGINPATH/input_uvc.so -n -d $DEVICE -r $RESOLUTION -f $FRAMERATE" -o "$PLUGINPATH/output_http.so -n -p $HTTP_PORT"