def publish_events(self): if not rospy.is_shutdown(): print white(" Monitoring controller events! ") try: while not rospy.is_shutdown(): rospy.sleep(1.0 / self.reading_rate_hz) (result, pControllerState) = (self.vrsystem.getControllerState( self.left_id)) d = self.from_controller_state_to_dict(pControllerState) # print '\n left controller:', self.last_unPacketNum_left, d['unPacketNum'] # print highlight_green('trigger value: ', d['trigger']) # print 'trackpad', d['trackpad_pressed'] # print 'trigger', d['trigger'] if (self.last_unPacketNum_left != d['unPacketNum']): self.last_unPacketNum_left = d['unPacketNum'] # print("Left controller:") # self.pp.pprint(d) if d['trigger'] == 1.0: self.ltrigger_pressed.publish(True) if d['trigger'] == 0.0: self.ltrigger_pressed.publish(False) (result, pControllerState) = (self.vrsystem.getControllerState( self.right_id)) d = self.from_controller_state_to_dict(pControllerState) # print 'right controller: ', self.last_unPacketNum_right, d['unPacketNum'] # print highlight_green('trigger value: ', d['trigger']) # print 'trackpad', d['trackpad_pressed'] # print 'trigger', d['trigger'] if (self.last_unPacketNum_right != d['unPacketNum']): self.last_unPacketNum_right = d['unPacketNum'] # print("Right controller:") # self.pp.pprint(d) if d['trigger'] == 1.0: self.rtrigger_pressed.publish(True) if d['trigger'] == 0.0: self.rtrigger_pressed.publish(False) if d['menu_button'] == 1.0: self.rmenu_button.publish(True) if d['menu_button'] == 0.0: self.rmenu_button.publish(False) if d['trackpad_pressed'] == 1.0: self.rtrackpad.publish(True) if d['trackpad_pressed'] == 0.0: self.rtrackpad.publish(False) except KeyboardInterrupt: print white("Control+C pressed, shutting down...") openvr.shutdown()
def waiting_for_connection(): print("\n\n") print( text.Text(" VIA Protocol", color='#288D28', shadow=False, skew=1, fsize=10)) print(bold(white("SENDER'S PLATFORM \n"))) print( bold( white( "Check logs in Sender-log.txt when the communication has ended\n" ))) print(bold(white("Type ':exit' to end the communication\n"))) print(bold(white("Waiting to connect"))) global connection animation = "|/-\\" idx = 0 while not connection: print(animation[idx % len(animation)], end="\r") idx += 1 time.sleep(0.1)
def __init__(self): ''' Initialization of KeyPress object. ''' rospy.init_node('ctrl_keypress') self.reading_rate_hz = 10 self.last_unPacketNum_left = 0 self.last_unPacketNum_right = 0 self.vive_loc_ready = False self.rtrigger_pressed = rospy.Publisher('ctrl_keypress/rtrigger', Bool, queue_size=1) self.ltrigger_pressed = rospy.Publisher('ctrl_keypress/ltrigger', Bool, queue_size=1) self.rmenu_button = rospy.Publisher('ctrl_keypress/rmenu_button', Bool, queue_size=1) self.rtrackpad = rospy.Publisher('ctrl_keypress/rtrackpad', Bool, queue_size=1) rospy.Subscriber('vive_localization/ready', Empty, self.vive_localization_ready) self.vrsystem = openvr.init(openvr.VRApplication_Other) # self.vrsystem = openvr.VRSystem() # Let system choose id's at first to make sure both controllers are # found. self.left_id, self.right_id = None, None print white(' Waiting for Vive controllers ...') try: while (not rospy.is_shutdown()) and (self.left_id is None or self.right_id is None): self.left_id, self.right_id = (self.get_controller_ids( self.vrsystem)) if self.left_id and self.right_id: break print white(' Waiting for Vive controllers ...') time.sleep(1.0) except KeyboardInterrupt: print white('----Control+C pressed, shutting down... ----') openvr.shutdown() # print '===========================' # print " Trigger id's: " # print(" * Right controller ID: " + str(self.right_id)) # print(" * Left controller ID: " + str(self.left_id)) # print("===========================") self.pp = pprint.PrettyPrinter(indent=4)
def exchange_public_keys(): global bobPublicKey global sock global connection data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes connection = True if (inception): print(bold(white("\nConnection Established!!\n\n"))) sock.settimeout(2) bobPublicKey = int(data.decode()[0:]) global alicePublicKey global ip alicePublicKey = (base**alicePrivateKey) % modulus sock.sendto(str(alicePublicKey).encode(), addr) ip = addr
def end_connection(): sock.close() print(bold(white("\n\nConnection closed!!!"))) print( text.Text(" END", color='#288D28', shadow=False, skew=1, fsize=10)) f.write( "\n\n ------------------------------------------------------------------------------\n" ) f.write("\n\nConnection Closed\n") f.write("Total Messages : " + str(counter) + "\n") f.write("Date and Iime : " + str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) + "\n\n") f.close()
def white(self): return ansi(c.white(self.txt))