Advertisement
Sirallens

Untitled

Mar 13th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1. def H2D(x):
  2.     if x >8388607:
  3.         x = x - 16777216
  4.        
  5.  
  6.     return x
  7.  
  8.  
  9. import os
  10. import serial
  11. import sys
  12. import time
  13.  
  14.  
  15. read_command = "$0wn00,70$1"
  16.  
  17. get_x = "$0wnA4rm$1"
  18.  
  19. get_y = "$0wnA7rm$1"
  20.  
  21. get_z = "$0wnAArm$1"
  22.  
  23. get_all = "$0wnA4mmm$1"
  24.  
  25. port = 'COM3'
  26.  
  27. fx = open("datax.txt", "w+")
  28. fy = open("datay.txt", "w+")
  29. fz = open("dataz.txt", "w+")
  30.  
  31.  
  32.  
  33. XYZ = open("dataXYZ_152am.txt","w+")
  34.  
  35.  
  36.  
  37. command = " "
  38. s = serial.Serial(port, 115200, timeout=1)
  39.  
  40.  
  41.  
  42.  
  43. if s.isOpen() == False:
  44.     s.open()
  45. else:
  46.     s.close()    
  47.     s.open()
  48.  
  49.     k = 100
  50.  
  51. #-----------------------------------------------------------
  52.  
  53. for i in range(0,7):
  54.     #------Get one Measurement command----
  55.     for k in range(0,100):      
  56.         command = read_command
  57.         s.write(command.encode())
  58.         time.sleep(.05)
  59.         #------------ Ends Measurement Command---
  60.  
  61.         #retrieve data
  62.  
  63.         command = get_x
  64.         s.write(command.encode())
  65.         respuesta = s.read(6)
  66.         time.sleep(.05)
  67.         x = H2D(int(respuesta.decode('utf-8'),16))
  68.         time.sleep(.05)
  69.         fx.write(str(x)+"\n")
  70.  
  71.         command = get_y
  72.         s.write(command.encode())
  73.         respuesta = s.read(6)
  74.         time.sleep(.05)
  75.         y = H2D(int(respuesta.decode('utf-8'),16))
  76.         fy.write(str(y) +'\n')
  77.  
  78.         time.sleep(.05)
  79.         command = get_z
  80.         s.write(command.encode())
  81.         respuesta = s.read(6)
  82.         time.sleep(.05)
  83.         z = H2D(int(respuesta.decode('utf-8'),16))
  84.         fz.write(str(z)+ "\n")
  85.  
  86.         XYZ.write(str(x)+ " " + str(y) + " " +str(z)+"\n")
  87.  
  88.         print(  "x= " + str(x) + "  y= " + str(y) + "  z= " + str(z))
  89.        
  90.         k = k - 1
  91.     print("Ronda " + str(i) + "terminada \n")
  92.     time.sleep(60)
  93. #---------
  94.  
  95.  
  96.  
  97.  
  98.  
  99. XYZ.close()  
  100. fx.close()
  101. fy.close()
  102. fz.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement