User Tools

Site Tools


quadricone-python-zurich-noservo

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 zurich noservo py ====== <code python> import subprocess, glob, time, csv, random ''' some naming clarifications: Servo is a class for motors, where movement is defined Servos is a dictionary of servo names and positions servo is used in the while loop to refer to an item of the Servos dictionary ''' ### the moving part ------------------- class Servo: def __init__(self, servoID): self.servoID=servoID self.startPos() # when initiated, go to zero def move(self, position): self.position=position print self.servoID, "\'s given position is", self.position if (10 <= self.position <= 120): print "everything OK, will write", self.position elif 120 < self.position < 170: print "will adjust to 160", self.position self.position=160 elif self.position > 170: print "MAX", self.servoID, "is in maximum position" self.position=180 print "MAX: Servo will now go to", self.position elif self.position<10: print "MIN", self.servoID, "is in minimum position" self.position=0 print "MIN: Servo will now go to", self.position else: print "how did this happen?" def startPos(self): self.move(0) ## initiate the morots and put them all in the start (0) position ## alternative Servos={"raja":0, "gaja":0, "vlaja":0, "zlaja":0} for i,servo in enumerate(Servos): globals()[servo]=Servo(i+1) globals()[servo].startPos() #key_pos=[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 #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...' print "starting key positions: ", Servos for i,servo in enumerate(Servos): print "i!!!!i!!!!i!!!!!" print 'servo:', servo pos=Servos.get(servo) packet_diff=new_packet_list[i]-packet_list[i] print 'packet_diff:', packet_diff if packet_diff==0: new_pos=pos-10 print 'go down', new_pos globals()[servo].move(new_pos) time.sleep(0.2) if new_pos<0: Servos[servo]=0 else: Servos[servo]=new_pos elif 12 > packet_diff >= 1: new_pos=Servos.get(servo)+5 if new_pos < 10: new_pos=10 print 'go up very small', new_pos globals()[servo].move(new_pos) time.sleep(0.2) Servos[servo]=new_pos # update key position for the next round elif 36 > packet_diff >= 12: new_pos=Servos.get(servo)+8 if new_pos < 10: new_pos=10 print 'go up small', new_pos globals()[servo].move(new_pos) time.sleep(0.2) Servos[servo]=new_pos # update key position for the next round elif 80 > packet_diff >= 36: new_pos=Servos.get(servo)+10 print 'go up middle', new_pos globals()[servo].move(new_pos) time.sleep(0.2) Servos[servo]=new_pos # update key position for the next round elif 180 > packet_diff >= 80: new_pos=Servos.get(servo)+20 print 'go up big', new_pos globals()[servo].move(new_pos) time.sleep(0.2) if new_pos > 180: Servos[servo]=180 else: Servos[servo]=new_pos # update key position for the next round elif packet_diff >= 180: new_pos=Servos.get(servo)+50 print 'go up very big', new_pos globals()[servo].move(new_pos) time.sleep(0.2) if new_pos > 180: Servos[servo]=180 else: Servos[servo]=new_pos # update key position for the next round else: print 'key_pos:', Servos.get(servo) , 'packet_diff:', packet_diff, 'and i am out of options' print "!!!!!!!!!!!!!!!!!!!!" print "new list of key pos", Servos packet_list=new_packet_list # update packet list time.sleep(10) </code>

quadricone-python-zurich-noservo.1353789526.txt.gz · Last modified: 2012/11/24 20:38 by 85.218.109.130