-
Notifications
You must be signed in to change notification settings - Fork 5
/
cramps.py
135 lines (114 loc) · 5.24 KB
/
cramps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from machinekit import hal
from machinekit import rtapi as rt
from machinekit import config as c
from fdm.config import base
def hardware_read():
hal.addf('hpg.capture-position', 'servo-thread')
hal.addf('bb_gpio.read', 'servo-thread')
def hardware_write():
hal.addf('hpg.update', 'servo-thread')
hal.addf('bb_gpio.write', 'servo-thread')
def init_hardware():
watchList = []
# load low-level drivers
rt.loadrt('hal_bb_gpio', output_pins='816,822,823,824,825,826,914,923,925', input_pins='807,808,809,810,817,911,913')
prubin = '%s/%s' % (c.Config().EMC2_RTLIB_DIR, c.find('PRUCONF', 'PRUBIN'))
rt.loadrt(c.find('PRUCONF', 'DRIVER'),
pru=0, num_stepgens=6, num_pwmgens=6,
prucode=prubin, halname='hpg')
# Python user-mode HAL module to read ADC value and generate a thermostat output for PWM
defaultThermistor = 'semitec_103GT_2'
hal.loadusr('hal_temp_bbb',
name='temp',
interval=0.05,
filter_size=1,
cape_board='CRAMPS',
channels='04:%s,05:%s,02:%s,03:%s'
% (c.find('HBP', 'THERMISTOR', defaultThermistor),
c.find('EXTRUDER_0', 'THERMISTOR', defaultThermistor),
c.find('EXTRUDER_1', 'THERMISTOR', defaultThermistor),
c.find('EXTRUDER_2', 'THERMISTOR', defaultThermistor)),
wait_name='temp')
watchList.append(['temp', 0.1])
base.usrcomp_status('temp', 'temp-hw', thread='servo-thread')
base.usrcomp_watchdog(watchList, 'estop-reset', thread='servo-thread',
errorSignal='watchdog-error')
def setup_hardware(thread):
# PWM
hal.Pin('hpg.pwmgen.00.pwm_period').set(10000000) # 100Hz
hal.Pin('hpg.pwmgen.00.out.00.pin').set(811)
hal.Pin('hpg.pwmgen.00.out.01.pin').set(915)
hal.Pin('hpg.pwmgen.00.out.02.pin').set(927)
hal.Pin('hpg.pwmgen.00.out.03.pin').set(921)
hal.Pin('hpg.pwmgen.00.out.04.pin').set(941)
hal.Pin('hpg.pwmgen.00.out.05.pin').set(922)
# HBP
hal.Pin('hpg.pwmgen.00.out.00.enable').set(True)
hal.Pin('hpg.pwmgen.00.out.00.value').link('hbp-temp-pwm')
# configure extruders
for n in range(0, 3):
hal.Pin('hpg.pwmgen.00.out.%02i.enable' % (n + 1)).set(True)
hal.Pin('hpg.pwmgen.00.out.%02i.value' % (n + 1)).link('e%i-temp-pwm' % n)
# configure fans
for n in range(0, 1):
hal.Pin('hpg.pwmgen.00.out.%02i.enable' % (n + 4)).link('f%i-pwm-enable' % n)
hal.Pin('hpg.pwmgen.00.out.%02i.value' % (n + 4)).link('f%i-pwm' % n)
hal.Signal('f%i-pwm-enable' % n).set(True)
# configure hotend cooling fan
hal.Pin('hpg.pwmgen.00.out.05.enable').link('exp0-pwm-enable')
hal.Pin('hpg.pwmgen.00.out.05.value').set(1.0)
hal.Pin('hpg.pwmgen.00.out.05.value').link('exp0-pwm')
# configure leds
# none
# GPIO
hal.Pin('bb_gpio.p8.in-07').link('limit-0-home') # X
hal.Pin('bb_gpio.p8.in-08').link('limit-0-min') # X
hal.Pin('bb_gpio.p8.in-09').link('limit-1-home') # Y
hal.Pin('bb_gpio.p8.in-10').link('limit-1-min') # Y
hal.Pin('bb_gpio.p9.in-11').link('limit-2-home') # Z
hal.Pin('bb_gpio.p9.in-13').link('limit-2-min') # Z
# probe ...
# Adjust as needed for your switch polarity
hal.Pin('bb_gpio.p8.in-08.invert').set(False)
hal.Pin('bb_gpio.p8.in-07.invert').set(False)
hal.Pin('bb_gpio.p8.in-10.invert').set(False)
hal.Pin('bb_gpio.p8.in-09.invert').set(False)
hal.Pin('bb_gpio.p9.in-13.invert').set(False)
hal.Pin('bb_gpio.p9.in-11.invert').set(False)
# ADC
hal.Pin('temp.ch-04.value').link('hbp-temp-meas')
hal.Pin('temp.ch-05.value').link('e0-temp-meas')
hal.Pin('temp.ch-02.value').link('e1-temp-meas')
hal.Pin('temp.ch-03.value').link('e2-temp-meas')
# Stepper
hal.Pin('hpg.stepgen.00.steppin').set(813)
hal.Pin('hpg.stepgen.00.dirpin').set(812)
hal.Pin('hpg.stepgen.01.steppin').set(815)
hal.Pin('hpg.stepgen.01.dirpin').set(814)
hal.Pin('hpg.stepgen.02.steppin').set(819)
hal.Pin('hpg.stepgen.02.dirpin').set(818)
hal.Pin('hpg.stepgen.03.steppin').set(916)
hal.Pin('hpg.stepgen.03.dirpin').set(912)
hal.Pin('hpg.stepgen.04.steppin').set(917)
hal.Pin('hpg.stepgen.04.dirpin').set(918)
hal.Pin('hpg.stepgen.05.steppin').set(924)
hal.Pin('hpg.stepgen.05.dirpin').set(926)
# machine power
hal.Pin('bb_gpio.p9.out-23').link('emcmot-0-enable')
#hal.Pin('bb_gpio.p9.out-23.invert').set(True)
# Monitor estop input from hardware
hal.Pin('bb_gpio.p8.in-17').link('estop-in')
hal.Pin('bb_gpio.p8.in-17.invert').set(True)
# drive estop-sw
hal.Pin('bb_gpio.p8.out-26').link('estop-out')
hal.Pin('bb_gpio.p8.out-26.invert').set(True)
# Tie machine power signal to the Parport Cape LED
# Feel free to tie any other signal you like to the LED
hal.Pin('bb_gpio.p9.out-25').link('emcmot-0-enable')
# hal.Pin('bb_gpio.p9.out-25.invert').set(True)
# link emcmot.xx.enable to stepper driver enable signals
hal.Pin('bb_gpio.p9.out-14').link('emcmot-0-enable')
hal.Pin('bb_gpio.p9.out-14.invert').set(True)
def setup_exp(name):
hal.newsig('%s-pwm' % name, hal.HAL_FLOAT, init=0.0)
hal.newsig('%s-pwm-enable' % name, hal.HAL_BIT, init=False)