Trees | Indices | Help |
---|
|
1 #stella's velocity demo code! 2 3 if __name__!="__main__": 4 import sys 5 sys.exit() 6 7 import ckbot.logical #need to make sure modules can populate and the pcan can recognise the node ID 8 import joy #used to call the feedbackrate function 9 import time #used for all of the time related functions 10 import numpy 11 #from pylab import plot, show, xlim, xlabel, ylabel, title, grid, savefig 12 import pylab 13 c = ckbot.logical.Cluster() #program recognises how many and which modules are attached 14 15 c.populate() # node IDs of modules are stored 16 17 c.at.Nx05.get_od() #getting object dictionary 18 19 c.at.Nx05.od.set_feedbackrate(100) #will get feedback from modules at a rate of 100 Hz 20 21 c.at.Nx05.reset() # stores feedback rate in eeprom memory. only have to do once then can delete from code. 22 23 time.sleep(5) #has code wait for 5 seconds. for more information type 'help()' then time in the ipython console. 24 25 c.at.Nx05.set_pos(-5000) 26 27 time.sleep(3) 28 29 T0 = time.time() # sets a variable to be equal to the actual time since the start of the epoch. 30 31 c.at.Nx05.set_pos(5000) 32 33 period = 3 34 35 pos = [] #creates an empty position list 36 t = [] 37 start_time = time.time() #sets a new variable to a later time 38 39 while(T0 - start_time < period): 40 val = str(c.at.Nx05.get_pos()/100) 41 pos.append(val) #first appends the position value, then right after it the corresponding time. 42 t.append(time.time() - start_time) #akes the 43 T0 = time.time() #re defines T0 as a later time, which eventually will end the while loop when T0-start_time becomes >= 3 seconds (the period) 44 45 #print time_list, list 46 47 pylab.plot(t[:31], pos[:31]) 48 49 pylab.xlabel('time (s)') 50 pylab.ylabel('position (deg)') 51 pylab.title('Position Plot') 52 pylab.grid(True) 53 54 pylab.savefig('position_plot') 55 56 pylab.show() #so we can graph the position and time values 57 58 59 vel = [] 60 61 for i in range(len(pos)-1): 62 vel.append((pos[i+1]-pos[i])/(t[i+1]-t[i])) 63 64 pylab.plot(t[:31], vel[:31]) 65 66 pylab.xlabel('time (s)') 67 pylab.ylabel('velocity (deg/s)') 68 pylab.title('Velocity Plot') 69 pylab.grid(True) 70 71 pylab.savefig('velocity_plot') 72 73 pylab.show() #so we can graph the position and time values 74
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Thu Jan 4 16:46:17 2018 | http://epydoc.sourceforge.net |