def ReadKeyboard(is_running, key_cmd, key_locker): kbhit = TKBHit() dt_hold = 0.1 t_prev = 0 while is_running[0]: c = kbhit.KBHit() if c is not None or time.time() - t_prev > dt_hold: with key_locker: key_cmd[0] = c t_prev = time.time() time.sleep(0.0025)
#!/usr/bin/python #\file kbhit4.py #\brief Testing "with" version of TKBHit. #\author Akihiko Yamaguchi, [email protected] #\version 0.1 #\date Jun.09, 2020 import sys import time from kbhit2 import TKBHit if __name__ == '__main__': with TKBHit(activate=True) as kbhit: disp = '.' while 1: c = kbhit.KBHit() if c is not None: sys.stdout.write('> %r\n' % c) sys.stdout.flush() if c == 'q': break else: disp = c for i in range(40): sys.stdout.write(disp) sys.stdout.flush() time.sleep(0.05) sys.stdout.write('\n') print 'done'
#!/usr/bin/python #Switching to enable and disable robot by pressing a key. from dxl_mikata6 import * import time from kbhit2 import TKBHit #Setup the device mikata = TMikata6() mikata.Setup() #mikata.EnableTorque() #mikata.SetPWM({jname:0 for jname in mikata.JointNames()}) state = 'disabled' try: kbhit = TKBHit() while True: c = kbhit.KBHit() if c == 'q': break elif c is not None: state = {'enabled': 'disabled', 'disabled': 'enabled'}[state] if state == 'enabled': mikata.EnableTorque() else: mikata.DisableTorque() time.sleep(0.0025) except KeyboardInterrupt: pass #mikata.DisableTorque() mikata.Quit()
speed_req= kortex_driver.srv.SendJointSpeedsCommandRequest() #NOTE: JointSpeed/value is in DEGREES per second. #cf. https://github.com/Kinovarobotics/kortex/blob/master/api_cpp/doc/markdown/messages/Base/JointSpeed.md rad2deg= lambda q:q/math.pi*180.0 for jidx,jname in enumerate(joint_names): joint_speed= kortex_driver.msg.JointSpeed() joint_speed.joint_identifier= jidx joint_speed.value= 0.0 speed_req.input.joint_speeds.append(joint_speed) raw_input('Press enter to start > ') t0= rospy.Time.now() rate= rospy.Rate(200) kbhit= TKBHit() try: while not rospy.is_shutdown(): if kbhit.IsActive(): key= kbhit.KBHit() if key is not None: #Press any key to stop. break; else: break t= (rospy.Time.now()-t0).to_sec() for joint_speed in speed_req.input.joint_speeds: #NOTE: JointSpeed/value is in DEGREES per second. joint_speed.value= rad2deg(0.04*math.sin(math.pi*t)) srv_joint_speeds.call(speed_req) rate.sleep()
def KBHit(): kbhit = TKBHit() return kbhit.KBHit(timeout=0.1)
def ReadKeyboard(is_running, key_cmd): kbhit = TKBHit() while is_running[0] and not rospy.is_shutdown(): c = kbhit.KBHit() key_cmd[0] = c rospy.sleep(0.0025)