I would like to activate the manual mode of my XArm 6 Lite only while pressing the space bar, if the space bar is not pressed the arm should go in the locked-in position.
I specifically want to use Python for that. What is the procedure to get there? Help would be really appreciated!
Here is an example.
- Install the libs with
pip install xarm-python-sdk keyboard
- Update with your Lite 6 IP, and running the codes.
import keyboard
from xarm.wrapper import XArmAPI
# Connect to Lite 6
arm = XArmAPI('192.168.1.xxx') # Update with your Lite 6 IP
arm.connect()
arm.motion_enable(True)
arm.set_mode(0) # Set to motion mode
arm.set_state(0)
# Key press event: enter teach mode
def enter_teach_mode(event):
print("Entering teach mode")
arm.set_mode(2) # Mode 2 is teach mode
arm.set_state(0)
# Key release event: exit teach mode
def exit_teach_mode(event):
print("Exiting teach mode")
arm.set_mode(0) # Back to motion mode
arm.set_state(0)
# Bind space key
keyboard.on_press_key('space', enter_teach_mode)
keyboard.on_release_key('space', exit_teach_mode)
print("Press and hold SPACE to enter teach mode, release SPACE to exit.")
keyboard.wait('esc') # Press ESC to exit the program
# Disconnect
arm.disconnect()
1 Like