Error: No module named linuxcnc
- SimonCNC123
- Offline
- Junior Member
Less
More
- Posts: 31
- Thank you received: 5
29 Apr 2022 12:47 #241636
by SimonCNC123
Error: No module named linuxcnc was created by SimonCNC123
Hi Folks, sorry to jump into your post with another question but it is in the same ballpark! ( I hope ), I am running LinuxCNC on a Raspberry Pi4 with all the install recommendations from this fantastic forum. My system is running perfectly and I now want to write a python interface to allow us to use an X-Box controller as a pendant to control Linuxcnc. I have no problems writing the python code and getting all the X-box inputs using 'evdev', but I can't seem to get the 'linuxcnc' library installed on the pi so that I can access it in python3. From what I have read, I need to install linuxcnc-dev, but I'm not having any luck doing that! Can anybody please point me in the right direction?.
FYI, this is my first pass code to: 1) Read the input from the X-Box controller, 2) determine if it is a boolian or analog function, 3) process the function and pass the X-Box values to the linuxcnc commands. This code is using the coolant flood function to test the boolian command, and a Jog X axis to test the analog functions! THIS CODE IS UNTESTED so I fully expect that I have made silly spelling and python mistakes... please ignore them!
````from evdev import InputDevice, ecodes
import linuxcnc
s = linuxcnc.stat()
c = linuxcnc.command()
# Declare the button and Joystick index values
Button_A = 304
Button_B = 305
Page = 314
Menu = 315
Left_Button = 310
Right_Button = 311
Left_Trigger = 2
Right_Trigger = 5
UD_Button = 17
LR_Button = 16
Button_X = 307
Button_Y = 308
Joystick_0 = 0
Joystick_1 = 1
Joystick_3 = 3
Joystick_4 = 4
def xb_connect(dev):
try:
gamepad = InputDevice(dev) # Connect to the xbox
return gamepad # Return the connection
except Exception as e:
print('WARNING-XBOX, FailedToConnectXBo={}, Err={}'.format(dev, e))
def proc_xbox(xb):
for event in xb.read_loop(): # Create a loop to continuosly monitor the controller
if event.type == ecodes.EV_KEY: # Pushbutton (Boolian) Events
tag = event.code # Event ID
val = int(event.value) # Event value
proc_bool_cmd(tag, val) # Process the event
if event.type == ecodes.EV_ABS: # Joystick (Ananlog) Events
tag = event.code # Event ID
val = int(event.value) # Event value
proc_int_cmd(tag, val) # Process the event
def proc_bool_cmd(code, val):
if code == Button_A: # Button A
if val == 1:
c.flood(linuxcnc.FLOOD_ON) # Coolant ON
else:
c.flood(linuxcnc.FLOOD_OFF) # Coolant OFF
def proc_int_cmd(code, val):
if code == Joystick_0: # X Axis Forward
if val > 100:
c.jog(linuxcnc.JOG_CONTINUOUS, 0, val)
else:
c.jog(linuxcnc.JOG_STOP, 0)
elif code == Joystick_1: # X Axis Reverse
if val > 100:
c.jog(linuxcnc.JOG_CONTINUOUS, 0, (val * -1))
else:
c.jog(linuxcnc.JOG_STOP, 0)
linuxcnc
if __name__ == '__main__':
port = '/dev/input/event0' # Set the port address
xb = xb_connect(port) # Connect to the controller
proc_xbox(xb) # Process the xbox commands
````
FYI, this is my first pass code to: 1) Read the input from the X-Box controller, 2) determine if it is a boolian or analog function, 3) process the function and pass the X-Box values to the linuxcnc commands. This code is using the coolant flood function to test the boolian command, and a Jog X axis to test the analog functions! THIS CODE IS UNTESTED so I fully expect that I have made silly spelling and python mistakes... please ignore them!
````from evdev import InputDevice, ecodes
import linuxcnc
s = linuxcnc.stat()
c = linuxcnc.command()
# Declare the button and Joystick index values
Button_A = 304
Button_B = 305
Page = 314
Menu = 315
Left_Button = 310
Right_Button = 311
Left_Trigger = 2
Right_Trigger = 5
UD_Button = 17
LR_Button = 16
Button_X = 307
Button_Y = 308
Joystick_0 = 0
Joystick_1 = 1
Joystick_3 = 3
Joystick_4 = 4
def xb_connect(dev):
try:
gamepad = InputDevice(dev) # Connect to the xbox
return gamepad # Return the connection
except Exception as e:
print('WARNING-XBOX, FailedToConnectXBo={}, Err={}'.format(dev, e))
def proc_xbox(xb):
for event in xb.read_loop(): # Create a loop to continuosly monitor the controller
if event.type == ecodes.EV_KEY: # Pushbutton (Boolian) Events
tag = event.code # Event ID
val = int(event.value) # Event value
proc_bool_cmd(tag, val) # Process the event
if event.type == ecodes.EV_ABS: # Joystick (Ananlog) Events
tag = event.code # Event ID
val = int(event.value) # Event value
proc_int_cmd(tag, val) # Process the event
def proc_bool_cmd(code, val):
if code == Button_A: # Button A
if val == 1:
c.flood(linuxcnc.FLOOD_ON) # Coolant ON
else:
c.flood(linuxcnc.FLOOD_OFF) # Coolant OFF
def proc_int_cmd(code, val):
if code == Joystick_0: # X Axis Forward
if val > 100:
c.jog(linuxcnc.JOG_CONTINUOUS, 0, val)
else:
c.jog(linuxcnc.JOG_STOP, 0)
elif code == Joystick_1: # X Axis Reverse
if val > 100:
c.jog(linuxcnc.JOG_CONTINUOUS, 0, (val * -1))
else:
c.jog(linuxcnc.JOG_STOP, 0)
linuxcnc
if __name__ == '__main__':
port = '/dev/input/event0' # Set the port address
xb = xb_connect(port) # Connect to the controller
proc_xbox(xb) # Process the xbox commands
````
Please Log in or Create an account to join the conversation.
02 May 2022 19:58 #241872
by andypugh
Replied by andypugh on topic Error: No module named linuxcnc
You might need to install linuxcnc-uspace-dev.
Try that as a first step.
Try that as a first step.
Please Log in or Create an account to join the conversation.
Time to create page: 0.057 seconds