def real_time_data_prompt(serial_socket): real_time_answer = raw_input("Would you like to plot real-time data? (y/n) ") if real_time_answer == 'y': real_time_data = 'ON' # Handshake with arduino to ensure RT data engaged python_send = 244 arduino_success = 11 arduino_fail = 13 message_success = "RT Data Enabled!" message_fail = "!!!RT Data failed to enable!!!" hs.hand_shake(serial_socket, python_send, arduino_success, arduino_fail, message_success, message_fail) else: real_time_data = 'OFF' # Handshake with arduino to ensure RT data engaged python_send = 245 arduino_success = 12 arduino_fail = 13 message_success = "RT Data Disabled!" message_fail = "!!!RT Data failed to disable!!!" hs.hand_shake(serial_socket, python_send, arduino_success, arduino_fail, message_success, message_fail) # HANDSHAKE COMPLETE return real_time_data
def collect_data(serial_socket): # Handshake with device for mode change python_send = 0 arduino_success = 126 arduino_fail = 128 hs.hand_shake(serial_socket, python_send, arduino_success, arduino_fail) # HANDSHAKE complete print("Plotting data now...") while True: while serial_socket.inWaiting() > 0: try: tempValue = ord(serial_socket.read(1)) * 0.004882814 degreesC = (tempValue - 0.5) * 100.0 print(degreesC) except SerialException: print("Fail")
def WaitingForLaunch(serial_socket): python_send = 211 arduino_success = 111 waiting = True print("Ready to launch? (y/n) ") while waiting: # Get launch from user launch = raw_input("> ") # launch 'y': Launch! if (launch == 'y'): hs.hand_shake(serial_socket, python_send, arduino_success) print("\tLaunching!") return
def download_data(serial_socket): # Handshake with device for mode change python_send = 1 arduino_success = 127 arduino_fail = 128 hs.hand_shake(serial_socket, python_send, arduino_success, arduino_fail) # HANDSHAKE COMPLETE choice = raw_input("Would you like to download now? (y/n) ") time.sleep(0.2) if choice == 'y': dl.downloader_main(serial_socket) else: print("Goodbye!") exit();
def collect_data(serial_socket): # Handshake with device for mode change python_send = 0 arduino_success = 126 arduino_fail = 128 hs.hand_shake(serial_socket, python_send, arduino_success, arduino_fail) # HANDSHAKE complete # Determine if RT data will be turned on real_time_data = real_time_data_prompt(serial_socket) if real_time_data == 'ON': print("Calculating rocket's initial position...") initial_position = initialize_rocket_position(serial_socket) x_0 = initial_position[0] y_0 = initial_position[1] z_0 = initial_position[2] # Primed for launch: WaitingForLaunch(serial_socket) print("Plotting data now...") # RT Data if real_time_data == 'ON': # Instantiate plot analog_plot = AnalogPlot(serial_socket) # set up animation # Attaching 3D axis to the figure fig = plt.figure() ax = p3.Axes3D(fig) ax.set_title('3D Test') ax.set_xlim3d([-5.0, 5.0]) ax.set_xlabel('X') ax.set_ylim3d([-5.0, 5.0]) ax.set_ylabel('Y') ax.set_zlim3d([0.0, 250.0]) ax.set_zlabel('Z') frame_num = 2500 data_lines = [np.empty((3, frame_num))] lines = [ax.plot([x_0], [y_0], [z_0])[0]] anim = animation.FuncAnimation(fig, analog_plot.update, frame_num, fargs=(data_lines, lines, ax), interval=50, blit=False) # show plot plt.show() # clean up analog_plot.close() print('exiting.') # NO RT Data elif real_time_data == 'OFF': while True: while serial_socket.inWaiting() > 0: try: print ord(serial_socket.read(1)) except SerialException: print("Fail")
def collect_data(serial_socket): # Handshake with device for mode change python_send = 0 arduino_success = 126 arduino_fail = 128 hs.hand_shake(serial_socket, python_send, arduino_success, arduino_fail) # HANDSHAKE complete real_time_data = real_time_data_prompt(serial_socket) print("Plotting data now...") # RT Data if real_time_data == 'ON': # Instantiate plot analog_plot = AnalogPlot(serial_socket) # set up animation # Attaching 3D axis to the figure fig = plt.figure() ax = p3.Axes3D(fig) ax.set_title('3D Test') ax.set_xlim3d([-5.0, 5.0]) ax.set_xlabel('X') ax.set_ylim3d([-5.0, 5.0]) ax.set_ylabel('Y') ax.set_zlim3d([0.0, 250.0]) ax.set_zlabel('Z') frame_num = 2500 data_lines = [np.empty((3, frame_num))] lines = [ax.plot([0], [0], [0])[0]] anim = animation.FuncAnimation(fig, analog_plot.update, frame_num, fargs=(data_lines, lines, ax), interval=50, blit=False) # show plot plt.show() # clean up analog_plot.close() print('exiting.') # NO RT Data elif real_time_data == 'OFF': while True: while serial_socket.inWaiting() > 0: print ord(serial_socket.read(1))