User Tools

Site Tools


quadricone-python-urbaines

This is an old revision of the document!



Warning: Declaration of syntax_plugin_wrap_div::handle($match, $state, $pos, Doku_Handler &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /var/www/kucjica/emperors-wiki/lib/plugins/wrap/syntax/div.php on line 43

Warning: Declaration of syntax_plugin_wrap_div::render($mode, Doku_Renderer &$renderer, $indata) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /var/www/kucjica/emperors-wiki/lib/plugins/wrap/syntax/div.php on line 81

Warning: Declaration of syntax_plugin_wrap_closesection::handle($match, $state, $pos, Doku_Handler &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /var/www/kucjica/emperors-wiki/lib/plugins/wrap/syntax/closesection.php on line 23

Warning: Declaration of syntax_plugin_wrap_closesection::render($mode, Doku_Renderer &$renderer, $indata) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /var/www/kucjica/emperors-wiki/lib/plugins/wrap/syntax/closesection.php on line 29

Warning: Declaration of syntax_plugin_wrap_span::handle($match, $state, $pos, Doku_Handler &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /var/www/kucjica/emperors-wiki/lib/plugins/wrap/syntax/span.php on line 43

Warning: Declaration of syntax_plugin_wrap_span::render($mode, Doku_Renderer &$renderer, $indata) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /var/www/kucjica/emperors-wiki/lib/plugins/wrap/syntax/span.php on line 63

Warning: Declaration of syntax_plugin_gallery::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /var/www/kucjica/emperors-wiki/lib/plugins/gallery/syntax.php on line 51

Warning: Declaration of syntax_plugin_gallery::render($mode, &$R, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /var/www/kucjica/emperors-wiki/lib/plugins/gallery/syntax.php on line 147

Warning: Declaration of syntax_plugin_vshare::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /var/www/kucjica/emperors-wiki/lib/plugins/vshare/syntax.php on line 47

Warning: Declaration of syntax_plugin_vshare::render($mode, &$R, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /var/www/kucjica/emperors-wiki/lib/plugins/vshare/syntax.php on line 107

Warning: preg_match(): Compilation failed: invalid range in character class at offset 3444 in /var/www/kucjica/emperors-wiki/inc/parser/lexer.php on line 118
A PCRE internal error occured. This might be caused by a faulty plugin

====== quadricone urbaines py ====== <code python> import serial, subprocess, 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) print "stop" def down_slow(self): self.move(100) print "down slow" def down(self): self.move(120) print "down" def up(self): self.move(80) print "up" ## 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() random.shuffle(Servos) how_many_times = [0, 0, 0, 0] ### 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 #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 'packetdiff:', packet_diff, '; go back up' globals()[servo].stop() time.sleep(0.3) globals()[servo].stop() elif 0 < packet_diff < 7: if how_many_times[i]<=6: print 'packetdiff:', packet_diff, '; up, little' globals()[servo].down_slow() time.sleep(0.5) globals()[servo].stop() how_many_times[i]+=0.5 else: globals()[servo].stop() time.sleep(0.3) how_many_times[i]-=2 elif 40 > packet_diff >= 7: if how_many_times[i]<=6: print 'packetdiff:', packet_diff, '; down, little' globals()[servo].down() time.sleep(0.5) globals()[servo].stop() how_many_times[i]+=0.5 else: globals()[servo].stop() time.sleep(0.3) how_many_times[i]-=2 elif 90 > packet_diff >= 40: if how_many_times[i]<=6: print 'packetdiff:', packet_diff, '; go down, 2' globals()[servo].down() time.sleep(1) globals()[servo].stop() how_many_times[i]+=1 else: globals()[servo].stop() time.sleep(0.3) how_many_times[i]-=2 elif 130 > packet_diff >= 90: if how_many_times[i]<=6: print 'packetdiff:', packet_diff, '; go down, 3' globals()[servo].down() time.sleep(1.5) globals()[servo].stop() how_many_times[i]+=1.5 else: globals()[servo].stop() time.sleep(0.3) how_many_times[i]-=2 elif packet_diff >= 130: print 'packetdiff:', packet_diff, '; go down, 4' globals()[servo].down() time.sleep(2) globals()[servo].stop() how_many_times[i]+=2 packet_list=new_packet_list # update packet list print "how many times?", how_many_times time.sleep(1) </code>

quadricone-python-urbaines.1354006090.txt.gz · Last modified: 2012/11/27 08:48 by 85.218.109.130