-
-
+
+
diff --git a/translations/it/LC_MESSAGES/messages.po b/translations/it/LC_MESSAGES/messages.po
index bd70ca66..f4375c2c 100644
--- a/translations/it/LC_MESSAGES/messages.po
+++ b/translations/it/LC_MESSAGES/messages.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
-"POT-Creation-Date: 2015-04-04 00:32+0200\n"
+"POT-Creation-Date: 2015-07-13 13:16+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME \n"
"Language-Team: it \n"
@@ -64,16 +64,20 @@ msgstr "Funzioni"
msgid "Movement"
msgstr "Movimento"
-#: templates/blocks_adv.xml:229
+#: templates/blocks_adv.xml:229 templates/blocks_std.xml:61
+msgid "Arm"
+msgstr ""
+
+#: templates/blocks_adv.xml:233
msgid "Camera"
msgstr "Camera"
-#: templates/blocks_adv.xml:234 templates/blocks_std.xml:61
+#: templates/blocks_adv.xml:238 templates/blocks_std.xml:65
#: templates/config.html:14
msgid "Sensor"
msgstr "Sensore"
-#: templates/blocks_adv.xml:246 templates/blocks_std.xml:73
+#: templates/blocks_adv.xml:250 templates/blocks_std.xml:77
msgid "Sound"
msgstr "Suono"
@@ -82,7 +86,7 @@ msgstr "Suono"
msgid "Control"
msgstr "Controllo"
-#: templates/config.html:3 templates/control.html:63
+#: templates/config.html:3 templates/control.html:61
msgid "Back"
msgstr "Indietro"
@@ -102,7 +106,7 @@ msgstr "Avvio"
msgid "Button"
msgstr "Bottone"
-#: templates/config.html:18 templates/config.html:127
+#: templates/config.html:18 templates/config.html:128
msgid "User Interface"
msgstr "Interfaccia utente"
@@ -110,241 +114,257 @@ msgstr "Interfaccia utente"
msgid "WiFi"
msgstr ""
-#: templates/config.html:24 templates/config.html:63
+#: templates/config.html:20
+msgid "Restart, Halt"
+msgstr ""
+
+#: templates/config.html:25 templates/config.html:64
msgid "Movement assisted by vision"
msgstr "Movimento assistito da visione"
-#: templates/config.html:27
+#: templates/config.html:28
msgid "Step timing | distance / angle"
msgstr "Durata o lunghezza step (distanza / angolo)"
-#: templates/config.html:28 templates/config.html:66
+#: templates/config.html:29 templates/config.html:67
msgid "Forward speed"
msgstr "Avanti"
-#: templates/config.html:30 templates/config.html:68
+#: templates/config.html:31 templates/config.html:69
msgid "Forward elapse / distance"
msgstr "Durata / distanza avanti"
-#: templates/config.html:32 templates/config.html:70
+#: templates/config.html:33 templates/config.html:71
msgid "Turn speed"
msgstr "Velocità di rotazione"
-#: templates/config.html:34 templates/config.html:72
+#: templates/config.html:35 templates/config.html:73
msgid "Turn elapse / angle"
msgstr "Tempo / angolo di rotazione"
-#: templates/config.html:37
+#: templates/config.html:38
msgid "Show control counter"
msgstr "Mostra contatore mosse"
-#: templates/config.html:40
+#: templates/config.html:41
msgid "HUD image name"
msgstr "Nome immagine HUD"
-#: templates/config.html:45
+#: templates/config.html:46
msgid "Editor level"
msgstr "Livello editor"
-#: templates/config.html:47
+#: templates/config.html:48
msgid "Move"
msgstr "Movimento"
-#: templates/config.html:49
+#: templates/config.html:50
msgid "Basic"
msgstr "Base"
-#: templates/config.html:51
+#: templates/config.html:52
msgid "Standard"
msgstr "Normale"
-#: templates/config.html:53
+#: templates/config.html:54
msgid "Advanced"
msgstr "Avanzato"
-#: templates/config.html:56
+#: templates/config.html:57
msgid "Program editor details"
msgstr "Dettagli editor del programma"
-#: templates/config.html:57
+#: templates/config.html:58
msgid "Shows Editor scrollbars"
msgstr "Mostra le scrollbar dell'area di lavoro"
-#: templates/config.html:59
+#: templates/config.html:60
msgid "Save program before every run"
msgstr "Salva il programma prima di ogni esecuzione"
-#: templates/config.html:75
+#: templates/config.html:76
msgid "Other program parameters"
msgstr "Altri parametri del programma"
-#: templates/config.html:76
+#: templates/config.html:77
msgid "Auto record video on program run"
msgstr "Avvia automaticamente registrazione video all'avvio del programma"
-#: templates/config.html:79
+#: templates/config.html:80
msgid "Max number of blocks allowed"
msgstr "Numero massimo consentito di blocchi di programma"
-#: templates/config.html:83
+#: templates/config.html:84
msgid "Start sound"
msgstr "Suono avvio"
-#: templates/config.html:85
+#: templates/config.html:86
msgid "Stop sound"
msgstr "Suono stop"
-#: templates/config.html:87
+#: templates/config.html:88
msgid "Shutter sound"
msgstr "Suono avvio"
-#: templates/config.html:91
+#: templates/config.html:92
msgid "Camera parameters"
msgstr "Parametri videocamera"
-#: templates/config.html:92
+#: templates/config.html:93
msgid "Exposure mode"
msgstr "Esposizione"
-#: templates/config.html:103
+#: templates/config.html:104
msgid "Motor control mode"
msgstr "Tipo di motori (dc | servo)"
-#: templates/config.html:105
+#: templates/config.html:106
msgid "Power (target angle -15)"
msgstr "Potenza (angolo target -15)"
-#: templates/config.html:107
+#: templates/config.html:108
msgid "Power (target angle -4)"
msgstr "Potenza (angolo target -4)"
-#: templates/config.html:109
+#: templates/config.html:110
msgid "Power (target angle -1)"
msgstr "Potenza (angolo target -1)"
-#: templates/config.html:113
+#: templates/config.html:114
msgid "Load at start"
msgstr "Carica all'avvio"
-#: templates/config.html:118
+#: templates/config.html:119
msgid "Button function"
msgstr "Funzione del bottone"
-#: templates/config.html:119
+#: templates/config.html:120
msgid "None"
msgstr "Nessuno"
-#: templates/config.html:121
+#: templates/config.html:122
msgid "Start/Stop current program"
msgstr "Avvia/Ferma il programma caricato"
-#: templates/config.html:128
+#: templates/config.html:129
msgid "Show Control page"
msgstr "Mostra pagina Controllo"
-#: templates/config.html:130
+#: templates/config.html:131
msgid "Show Control movement commands"
msgstr "Mostra comandi movimento in pagina Controllo"
-#: templates/config.html:132
+#: templates/config.html:133
msgid "Show Program page"
msgstr "Nome programma"
-#: templates/config.html:134
+#: templates/config.html:135
msgid "Show Preferences button"
msgstr "Mostra bottone Preferenze"
-#: templates/config.html:139
+#: templates/config.html:140
msgid "WiFi Client access mode"
msgstr "WiFi in modalità Client"
-#: templates/config.html:142 templates/config.html:164
+#: templates/config.html:143
+msgid "Halt"
+msgstr "Stop"
+
+#: templates/config.html:144
+msgid "Restart"
+msgstr "Ricomincia"
+
+#: templates/config.html:145
+msgid "Reboot"
+msgstr ""
+
+#: templates/config.html:148 templates/config.html:169
msgid "Cancel"
msgstr "Annulla"
-#: templates/config.html:143 templates/program.html:18
+#: templates/config.html:149 templates/program.html:18
#: templates/program.html:26
msgid "Save"
msgstr "Salva"
-#: templates/config.html:151
+#: templates/config.html:156
msgid "WiFi Client mode access data"
msgstr "Dati di accesso alla rete WiFi"
-#: templates/config.html:153
+#: templates/config.html:158
msgid "WiFi mode"
msgstr "Modalità WiFi"
-#: templates/config.html:155
+#: templates/config.html:160
msgid "Access Point"
msgstr ""
-#: templates/config.html:157
+#: templates/config.html:162
msgid "Client"
msgstr ""
-#: templates/config.html:159
+#: templates/config.html:164
msgid "WiFi name"
msgstr "Nome rete WiFi"
-#: templates/config.html:161
+#: templates/config.html:166
msgid "WiFi password"
msgstr "Password WiFi"
-#: templates/config.html:165
+#: templates/config.html:170
msgid "Apply Wifi config"
msgstr "Applica le modifiche alla configurazione WiFi"
-#: templates/config.html:172
+#: templates/config.html:177
msgid "WiFi AP mode access"
msgstr "WiFi in modalità AP"
-#: templates/config.html:184
+#: templates/config.html:189
msgid "WiFi Client mode access"
msgstr "WiFi in modalità Client"
-#: templates/config_params.html:20
+#: templates/config_params.html:21
msgid "Say what:"
msgstr "Frase:"
-#: templates/config_params.html:21
+#: templates/config_params.html:22
msgid "Saved"
msgstr "Salvato"
-#: templates/config_params.html:22
+#: templates/config_params.html:23
msgid "Program saved"
msgstr "Programma salvato"
-#: templates/config_params.html:23
+#: templates/config_params.html:24
msgid "Program name already in use, overwrite?"
msgstr "Esiste già un programma con questo nome, sovrascriverlo?"
-#: templates/config_params.html:24
+#: templates/config_params.html:25
msgid "Delete"
msgstr "Cancella"
-#: templates/config_params.html:25
+#: templates/config_params.html:26
msgid "Delete photo"
msgstr "Cancellare la foto"
-#: templates/config_params.html:26
+#: templates/config_params.html:27
msgid "Reset move counter?"
msgstr "Azzera contatore mosse?"
-#: templates/config_params.html:27 templates/program.html:40
+#: templates/config_params.html:28 templates/program.html:40
msgid "is running"
msgstr "in esecuzione"
-#: templates/config_params.html:28
+#: templates/config_params.html:29
msgid "stopped"
msgstr "fermo"
-#: templates/config_params.html:29 templates/control.html:51
+#: templates/config_params.html:30 templates/control.html:49
#: templates/program.html:32
msgid "Stop"
msgstr "Ferma"
-#: templates/config_params.html:30
+#: templates/config_params.html:31
msgid "Close"
msgstr "Chiudi"
@@ -356,39 +376,39 @@ msgstr "Preferenze"
msgid "Program"
msgstr "Programma"
-#: templates/control.html:19
-msgid "Halt"
-msgstr "Stop"
-
-#: templates/control.html:24
+#: templates/control.html:21
msgid "Forward"
msgstr "Avanti"
-#: templates/control.html:27
+#: templates/control.html:24
msgid "Left"
msgstr "Sinistra"
-#: templates/control.html:28
+#: templates/control.html:25
msgid "Right"
msgstr "Destra"
-#: templates/control.html:31
+#: templates/control.html:28
msgid "Backward"
msgstr "Indietro"
-#: templates/control.html:40
+#: templates/control.html:37
msgid "Say"
msgstr "Parla"
-#: templates/control.html:45
+#: templates/control.html:42
msgid "Photo"
msgstr "Foto"
-#: templates/control.html:50
+#: templates/control.html:43
+msgid "Rotate"
+msgstr "Ruotare"
+
+#: templates/control.html:48
msgid "Rec"
msgstr "Registra"
-#: templates/control.html:54
+#: templates/control.html:52
msgid "Photos"
msgstr "Album"
diff --git a/viz/camera.py b/viz/camera.py
index 54fc8fda..0a261481 100644
--- a/viz/camera.py
+++ b/viz/camera.py
@@ -19,8 +19,9 @@ def __init__(self, props):
self.camera.resolution = (props.get('width', 640), props.get('height', 240))
self.camera.framerate = 30
self.camera.exposure_mode = props.get('exposure_mode')
+ self.camera.rotation = props.get('rotation')
self.out_jpeg = io.BytesIO()
- self.out_rgb = picamera.array.PiRGBArray(self.camera, size=(160,120))
+ self.out_rgb = picamera.array.PiRGBArray(self.camera, size=(640,480))#160,120
self.h264_encoder = None
self.recording = None
self.video_filename = None
@@ -59,7 +60,7 @@ def grab(self):
camera_port_0, output_port_0 = self.camera._get_ports(True, 0)
self.jpeg_encoder = self.camera._get_image_encoder(camera_port_0, output_port_0, 'jpeg', None, quality=40)
camera_port_1, output_port_1 = self.camera._get_ports(True, 1)
- self.rgb_encoder = self.camera._get_image_encoder(camera_port_1, output_port_1, 'bgr', (160, 120))
+ self.rgb_encoder = self.camera._get_image_encoder(camera_port_1, output_port_1, 'bgr', (640, 480))#160,120
#print "g.1: " + str(ts - time.time())
#ts = time.time()
@@ -102,7 +103,7 @@ def grab_start(self):
camera_port_0, output_port_0 = self.camera._get_ports(True, 0)
self.jpeg_encoder = self.camera._get_image_encoder(camera_port_0, output_port_0, 'jpeg', None, quality=40)
camera_port_1, output_port_1 = self.camera._get_ports(True, 1)
- self.rgb_encoder = self.camera._get_image_encoder(camera_port_1, output_port_1, 'bgr', (160, 120))
+ self.rgb_encoder = self.camera._get_image_encoder(camera_port_1, output_port_1, 'bgr', (640, 480)) #160,120
with self.camera._encoders_lock:
self.camera._encoders[0] = self.jpeg_encoder
diff --git a/viz/image.py b/viz/image.py
index 09855e18..331e0215 100644
--- a/viz/image.py
+++ b/viz/image.py
@@ -101,6 +101,10 @@ def find_blobs(self, minsize=0, maxsize=10000000):
return blobs
+ def find_contours(self):
+ contours, hierarchy = cv2.findContours(self._data, cv2.cv.CV_RETR_TREE, cv2.cv.CV_CHAIN_APPROX_SIMPLE)
+ return contours, hierarchy
+
def find_template(self, img_template):
# Initiate SIFT detector
sift = cv2.SIFT()
@@ -149,3 +153,8 @@ def to_jpeg(self):
return np.array(jpeg_array).tostring()
+ def draw_contour_bound_circle(self, contour, color=(0,255,0)):
+ (x,y),radius = cv2.minEnclosingCircle(contour)
+ center = (int(x), int(y))
+ radius = int(radius)
+ cv2.circle(self._data, center, radius, color, 2)
diff --git a/wifi.py b/wifi.py
index aa9c2610..d880eeee 100755
--- a/wifi.py
+++ b/wifi.py
@@ -9,12 +9,17 @@
import fcntl
import struct
import json
+import ConfigParser
+import StringIO
+from time import sleep
class WiFi():
CONFIG_FILE = "/etc/coderbot_wifi.conf"
- adapters = ["RT5370", "RTL8188CUS"]
- hostapds = {"RT5370": "hostapd.RT5370", "RTL8188CUS": "hostapd.RTL8188"}
+ HOSTAPD_CONF_FILE = "/etc/hostapd/hostapd.conf"
+ INTERFACES_FILE = "/etc/network/interfaces_cli"
+ adapters = ["RT5370", "RTL8188CUS", "RT3572"]
+ hostapds = {"RT5370": "hostapd.RT5370", "RTL8188CUS": "hostapd.RTL8188"}
web_url = "http://coderbotsrv.appspot.com/register_ip"
wifi_client_conf_file = "/etc/wpa_supplicant/wpa_supplicant.conf"
_config = {}
@@ -45,24 +50,84 @@ def get_adapter_type(cls):
@classmethod
def start_hostapd(cls):
- adapter = cls.get_adapter_type()
- hostapd_type = cls.hostapds.get(adapter)
try:
print "starting hostapd..."
- #os.system("start-stop-daemon --start --oknodo --quiet --exec /usr/sbin/" + hostapd_type + " -- /etc/hostapd/" + hostapd_type + " &")
- os.system("/usr/sbin/" + hostapd_type + " /etc/hostapd/" + hostapd_type + " -B")
-
+ os.system("sudo service hostapd restart")
except subprocess.CalledProcessError as e:
print e.output
@classmethod
def stop_hostapd(cls):
try:
- out = subprocess.check_output(["pkill", "-9", "hostapd"])
- print out
+ os.system("sudo service hostapd stop")
except subprocess.CalledProcessError as e:
print e.output
+ @classmethod
+ def set_hostapd_params(cls, wssid, wpsk):
+ config = ConfigParser.ConfigParser()
+ # configparser requires sections like '[section]'
+ # open hostapd.conf with dummy section '[hostapd]'
+ try:
+ with open(cls.HOSTAPD_CONF_FILE) as f:
+ conf_str = '[hostapd]\n' + f.read()
+ conf_fp = StringIO.StringIO(conf_str)
+ config.readfp(conf_fp)
+ except IOError as e:
+ print e
+ return
+
+ if len(str(wpsk)) < 8:
+ wpsk='coderbot'
+
+ config.set('hostapd','ssid',str(wssid))
+ config.set('hostapd','wpa_passphrase',str(wpsk))
+
+ try:
+ with open(cls.HOSTAPD_CONF_FILE, 'wb') as f:
+ conf_items = config.items('hostapd')
+ for (key,value) in conf_items:
+ f.write("{0}={1}\n".format(key, value))
+ f.write("\n")
+ except IOError as e:
+ print e
+
+ def set_client_params(cls, wssid, wpsk, number):
+ config = ConfigParser.ConfigParser()
+ # configparser requires sections like '[section]'
+ # open hostapd.conf with dummy section '[interfaces]'
+
+ try:
+ with open(cls.INTERFACES_FILE) as f:
+ inter_split = f.read().split("static")
+ inter_start = inter_split[0] + "static\n"
+ conf_str = '[interfaces]\n' + inter_split[1]
+ #parser needs = to work
+ conf_str = conf_str.replace(" ","=")
+ conf_fp = StringIO.StringIO(conf_str)
+ config.readfp(conf_fp)
+
+ except IOError as e:
+ print e
+ return
+
+ config.set('interfaces','address',"192.168.0.1" + number)
+ config.set('interfaces','wpa-ssid',str(wssid))
+ config.set('interfaces','wpa-psk',str(wpsk))
+
+ try:
+ with open(cls.INTERFACES_FILE, 'wb') as f:
+ conf_items = config.items('interfaces')
+ f.write(inter_start)
+ for (key,value) in conf_items:
+ #quick workaround for values with spaces in
+ value = value.replace("wlan0=inet=static","wlan0 inet static")
+ f.write("{0} {1}\n".format(key, value))
+ f.write("\n")
+ except IOError as e:
+ print e
+ shutil.copy(cls.INTERFACES_FILE, "/etc/network/interfaces")
+
@classmethod
def get_ipaddr(cls, ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@@ -86,50 +151,6 @@ def register_ipaddr(cls, ipaddr, botname):
raise
print botname, ": ", ipaddr
- @classmethod
- def get_wlans(cls):
- out = subprocess.check_output(["iwlist", "wlan0", "scan"])
-
- @classmethod
- def set_client_params(cls, wssid, wpsk):
- f = open (cls.wifi_client_conf_file, "w+")
- f.write("""ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
-update_config=1
-network={\n""")
- f.write(" ssid=\""+wssid+"\"\n")
- f.write(" psk=\""+wpsk+"\"\n")
- f.write("}")
-
- @classmethod
- def set_start_as_client(cls):
- shutil.copy("/etc/network/interfaces_cli", "/etc/network/interfaces")
- cls._config["wifi_mode"] = "client"
- cls.save_config()
-
- @classmethod
- def start_as_client(cls):
- cls.stop_hostapd()
- try:
- out = subprocess.check_output(["ifdown", "wlan0"])
- out = subprocess.check_output(["ifup", "wlan0"])
- print "registering ip..."
- cls.register_ipaddr(cls.get_ipaddr("wlan0"), "CoderBot")
- except subprocess.CalledProcessError as e:
- print e.output
- raise
-
- @classmethod
- def set_start_as_ap(cls):
- shutil.copy("/etc/network/interfaces_ap", "/etc/network/interfaces")
- cls._config["wifi_mode"] = "ap"
- cls.save_config()
-
- @classmethod
- def start_as_ap(cls):
- out = subprocess.check_output(["ifdown", "wlan0"])
- out = subprocess.check_output(["ifup", "wlan0"])
- cls.start_hostapd()
-
@classmethod
def start_service(cls):
config = cls.load_config()
@@ -143,25 +164,56 @@ def start_service(cls):
except:
print "Unable to register ip, revert to ap mode"
cls.start_as_ap()
+ elif config["wifi_mode"] == "local_client":
+ print "starting as local client..."
+ try:
+ cls.start_as_local_client()
+ except:
+ print "Unable to connect to WLAN, rever to ap mode"
+ cls.start_as_ap()
def main():
w = WiFi()
- if len(sys.argv) > 2 and sys.argv[1] == "updatecfg":
- if len(sys.argv) > 2 and sys.argv[2] == "ap":
- w.set_start_as_ap()
- w.start_as_ap()
- elif len(sys.argv) > 2 and sys.argv[2] == "client":
- if len(sys.argv) > 3:
- w.set_client_params(sys.argv[3], sys.argv[4])
- w.set_start_as_client()
- w.stop_hostapd()
- try:
- w.start_as_client()
- except:
- print "Unable to register ip, revert to ap mode"
- w.start_as_ap()
- else:
- w.start_service()
+ if len(sys.argv) < 2:
+ print 'Testing Client Connection...'
+ print 'Wait 5 seconds before checking connection to router...'
+ sleep(5)
+ print 'pinging router...'
+ #ping hub router
+ response = os.system('ping -c 1 192.168.0.1')
+ #healthy response is 0
+
+ if response == 0:
+ print 'Router has been found, staying on client mode'
+ else:
+ print 'Router not found, switching to AP mode'
+ #setup hotspot
+ shutil.copy("/etc/network/interfaces_ap", "/etc/network/interfaces")
+ print 'restart networking...'
+ os.system('sudo service networking restart')
+ w.start_hostapd()
+ print 'Waiting for hostapd to startup'
+ sleep(3)
+ print 'copying client interfaces back for next time'
+ shutil.copy("/etc/network/interfaces_cli", "/etc/network/interfaces")
+
+ elif sys.argv[1] == "updatecfg":
+ if len(sys.argv) == 3:
+ print "updating configs..."
+ #Update config to use this number, eg. for 7
+ #client ip goes to 192.168.0.7
+ w.set_client_params("Lboro_Coderbot_Hub","welovepis", sys.argv[2])
+ #hostspot ssid goes to Lboro Coderbot 7
+ w.set_hostapd_params("Lboro Coderbot " + sys.argv[2], "coderbot")
+ print "done!"
+ else:
+ if len(sys.argv) > 2 and sys.argv[2] == "ap":
+ if len(sys.argv) > 3:
+ w.set_hostapd_params(sys.argv[3], sys.argv[4])
+ elif len(sys.argv) > 2 and sys.argv[2] == "client":
+ if len(sys.argv) > 4:
+ w.set_client_params(sys.argv[3], sys.argv[4], sys.argv[5])
+
if __name__ == "__main__":
main()