summaryrefslogtreecommitdiff
path: root/trunk/users/stef/pyRepRap/scripts/reprapcontrol
blob: b5f40c2740277fe4303fb455e82e49ccc867f5cb (plain)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/python
import serial, reprap, time, sys

reprap.openSerial( 0, 19200, 60 )

# these devices are present in network
reprap.cartesian.x.active = True
reprap.cartesian.y.active = True
reprap.cartesian.z.active = True
reprap.extruder.active = True
reprap.cartesian.x.setNotify()
reprap.cartesian.y.setNotify()
reprap.cartesian.z.setNotify()
reprap.cartesian.x.limit = 2700
reprap.cartesian.y.limit = 2500
reprap.cartesian.y.limit = 2000

def printHelp():
	print "\nreprapcontrol command [args]"
	print "    Commands:"
	print "        stop                 Stop all axies"
	print "        reset                Send all axies to home"
	print "        pos                  Print current position"
	print "        goto [x] [y] [z]     Go to specified position"
	print "        power [0 to 63]      Set power level"
	print "        speed [0 to 255]     Set steper speed"
	print "        go                   Test routine"
	print "        free                 Power off steper motors"
	print "        run [x/y] [speed]    Spin motor forwards"
	print "        runb [x/y] [speed]   Spin motor backwards"
	print "        step [x/y/z]         Step motor forward"
	print "        stepb [x/y/z]        Step motor backwards"

def printPos():
	x, y, z = reprap.cartesian.getPos()
	print "Location [" + str(x) + ", " + str(y) + ", " + str(z) + "]"

print "================================================================"

if len(sys.argv) < 2:
	printHelp()



########### Cartesian control commands #########

# Stop all steppers
if sys.argv[1] == "stop":
	reprap.cartesian.stop()

# Reset all axies
elif sys.argv[1] == "reset":
	reprap.cartesian.homeReset( waitArrival = True, speed = 220 )

# Print current positon
elif sys.argv[1] == "pos":
	printPos()

# Goto a specific location
elif sys.argv[1] == "goto":
	reprap.cartesian.seek( ( int(sys.argv[2]), int(sys.argv[3]), int(sys.argv[4]) ), speed = 200, waitArrival = True)

# Set stepper power (%)
elif sys.argv[1] == "power":
	reprap.cartesian.setPower( int( sys.argv[2] ) )	# This is a value from 0 to 63 (6 bits)

# Free motors (switch off all coils)
elif sys.argv[1] == "free":
	reprap.cartesian.free()

# Test routine
elif sys.argv[1] == "go":
	reprap.cartesian.seek( (1000, 1000, 0), 200, True )	
	time.sleep(2)
	reprap.cartesian.seek( (500, 1000, 0), 200, True )
	time.sleep(2)
	reprap.cartesian.seek( (500, 500, 0), 200, True )
	time.sleep(2)
	reprap.cartesian.seek( (10, 10, 0), 200, True )



############## control of individual steppers #############

# Spin stepper forwards
elif sys.argv[1] == "run":	# run axis
	if sys.argv[2] == "x":
		reprap.cartesian.x.forward( int(sys.argv[3]) )
	elif sys.argv[2] == "y":
		reprap.cartesian.y.forward( int(sys.argv[3]) )
	elif sys.argv[2] == "z":
		reprap.cartesian.z.forward( int(sys.argv[3]) )

# Spin stepper backwards
elif sys.argv[1] == "runb":	#runb axis
	if sys.argv[2] == "x":
		reprap.cartesian.x.backward( int(sys.argv[3]) )
	elif sys.argv[2] == "y":
		reprap.cartesian.y.backward( int(sys.argv[3]) )
	elif sys.argv[2] == "z":
		reprap.cartesian.z.backward( int(sys.argv[3]) )

# Step motor forwards
elif sys.argv[1] == "step":
	if sys.argv[2] == "x":
		reprap.cartesian.x.forward1()
	elif sys.argv[2] == "y":
		reprap.cartesian.y.forward1()	
	elif sys.argv[2] == "z":
		reprap.cartesian.z.forward1()	

# Step motor backwards
elif sys.argv[1] == "stepb":
	if sys.argv[2] == "x":
		reprap.cartesian.x.backward1()
	elif sys.argv[2] == "y":
		reprap.cartesian.y.backward1()	
	elif sys.argv[2] == "z":
		reprap.cartesian.z.backward1()	



################# control of extruder #####################

# Test extrder motor
elif sys.argv[1] == "motor":
	nn = 0
	while 1:
		if nn > 0:
			nn = 0
		else:
			nn = 150
		reprap.extruder.setMotor(reprap.CMD_REVERSE, nn)
		time.sleep(1)

elif sys.argv[1] == "getinfo":
	mtype = reprap.extruder.getModuleType()
	version = reprap.extruder.getVersion()
	print "module", mtype, "version", version

elif sys.argv[1] == "heat":
	reprap.extruder.setHeat(255, 255, 255, 255)

#setHeat(self, lowHeat, highHeat, tempTarget, tempMax

elif sys.argv[1] == "temp":
	print "Temp is ", reprap.extruder.getTemp()



############### scan network for devices ###################

# Scan snap network
elif sys.argv[1] == "scan":
	reprap.scanNetwork()

# Test comms
elif sys.argv[1] == "test":
	reprap.testComms()


else:
	printHelp()

reprap.closeSerial()