User Tools

Site Tools


quadricone-python-urbaines

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revision Both sides next revision
quadricone-python-urbaines [2012/11/24 20:44]
85.218.109.130 created
quadricone-python-urbaines [2013/03/14 09:02]
152.160.22.43 FxnUVJiEJWeQbO
Line 1: Line 1:
-====== quadricone urbaines py ====== +HeO5UX ​[url=http://xfvvhkednhzr.com/]xfvvhkednhzr[/url], [link=http://ldelohejkkow.com/]ldelohejkkow[/link], http://​kgfriysxfysx.com/
- +
- +
-<code python>​ +
-import serialsubprocess, glob, time, csv, random +
- +
- +
-### assign arduino'​s serial port +
-usbport=glob.glob("​/dev/tty*"​)[0] +
-### set up serial baud rate +
-ser = serial.Serial(usbport,​ 9600, timeout=1) +
- +
- +
-### the moving part ------------------- +
- +
-class Servo: +
-    def __init__(self,​ servoID): +
-        self.servoID=servoID +
-        self.stop() # when initiated, stop! +
- +
-    def move(self, speed): +
-        self.speed=speed +
-        if (0 <= self.speed <= 180): +
-            ser.write(chr(255)) +
-            ser.write(chr(self.servoID)) +
-            ser.write(chr(self.speed)) +
-        else: +
-            print "Servo position must be an integer between 0 and 180.\n"​ +
- +
-    def stop(self):​ +
-        self.move(90) +
- +
-    def down_slow(self):​ +
-        self.move(100) +
- +
-    def down(self):​ +
-        self.move(120) +
- +
-    def up(self): +
-        self.move(80) +
-         +
-## initiate the morots and put them all in the STOP (90) position +
-## alternative +
- +
-Servos = ["​raja","​gaja","​vlaja",​ "​zlaja"​] +
-for i,servo in enumerate(Servos):​ +
-    globals()[servo]=Servo(i+1) +
-    globals()[servo].stop() +
-     +
- +
-### the scanning part ----------------- +
- +
-# airodump-ng is running and logging the results into a csv file +
-# with the following command: sudo airodump-ng -o csv -w manuf mon0 +
-# subprocess looks for the last edited csv file in current folder +
-# this file is parsed by the csv module to find the number of data packets that have passed through the network since the last check  +
- +
-csvs=subprocess.Popen("​ls -t1 *csv | head -1"shell=True, stdout=subprocess.PIPE,​ stderr=subprocess.PIPE) +
-csv_last=csvs.communicate()[0].strip() +
- +
-key_value=(' # IV') # look up this value in the scan dump +
- +
-def lookup(dump): +
-    datas=[] +
-    results=[] +
-    scan=open(dump,​ "​rU"​) +
-    next(scan) +
-    scanDict=csv.DictReader((line.replace('​\0',''​) for line in scan), delimiter=','​) +
-    for adict in scanDict: +
-        if adict.has_key(key_value) and adict.get(key_value)!=None:​ +
-            try: +
-                datas.append(int(adict.get(key_value))) +
-            except: +
-                pass +
-    datas.sort(reverse=True) +
-    for i in range(4): +
-        results.append(datas[i]) +
-    return results +
- +
- +
-### the main loop ---------------------- +
- +
-packet_list=lookup(csv_last) +
-print '​packet_list',​ packet_list +
-#​random.shuffle(servo_list) +
-#print '​servo_list',​ servo_list +
-time.sleep(3) +
- +
-while True: +
-    new_packet_list=lookup(csv_last) +
-    print "////////////////////////"​ +
-    print " " +
-    print '​new_packet_list',​ new_packet_list +
-    print '​calculating the movements...'​ +
-    for i,servo in enumerate(Servos):​ +
-        print '​servo',​ servo +
-        packet_diff=new_packet_list[i]-packet_list[i] +
-        print '​packet_diff:'​packet_diff +
-        if packet_diff==0: +
-            print 'go back up' +
-            globals()[servo].up() +
-            time.sleep(1) +
-            globals()[servo].stop() +
-        elif packet_diff < 10: +
-            print 'up, little'​ +
-            globals()[servo].up() +
-            time.sleep(0.5) +
-            globals()[servo].stop() +
-        elif packet_diff >= 10: +
-            print 'down, little'​ +
-            globals()[servo].down_slow() +
-            time.sleep(1) +
-            globals()[servo].stop() +
-        elif packet_diff >= 100: +
-            print 'go down, big' +
-            globals()[servo].down() +
-            time.sleep(2) +
-            globals()[servo].stop() +
-    packet_list=new_packet_list # update packet list +
-    time.sleep(15) +
- +
-</code>+
quadricone-python-urbaines.txt · Last modified: 2013/04/22 17:09 by zoza