Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Roland.cpp « Platform « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8b87e779eb93895bc28a7d28b97db1fd1e9f6a75 (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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// This class allows the RepRap firmware to transmit commands to a Roland mill
// See: http://www.rolanddg.com/product/3d/3d/mdx-20_15/mdx-20_15.html
//      http://altlab.org/d/content/m/pangelo/ideas/rml_command_guide_en_v100.pdf

#include "RepRapFirmware.h"

#if SUPPORT_ROLAND

Roland::Roland(Platform& p) : platform(p)
{
}

void Roland::Init()
{
	pinMode(ROLAND_RTS_PIN, OUTPUT);
	pinMode(ROLAND_CTS_PIN, INPUT);
	digitalWrite(ROLAND_RTS_PIN, HIGH);

	sBuffer = new StringRef(buffer, ARRAY_SIZE(buffer));
	sBuffer->Clear();

	bufferPointer = 0;
	Zero(true);
	longWait = platform.Time();
	active = false;
}

void Roland::Spin()
{
	if (!Active())
	{
		platform.ClassReport(longWait);
		return;
	}

	// 'U' is 01010101 in binary (nice for an oscilloscope...)

	//SERIAL_AUX2_DEVICE.write('U');
	//SERIAL_AUX2_DEVICE.flush();
	//return;

	// Are we sending something to the Roland?

	if (Busy())	// Busy means we are sending something
	{
		if (digitalRead(ROLAND_CTS_PIN))
		{
			platform.ClassReport(longWait);
			return;
		}

		SERIAL_AUX2_DEVICE.write(buffer[bufferPointer]);
		SERIAL_AUX2_DEVICE.flush();
		bufferPointer++;
	}
	else		// Not sending.
	{
		// Finished talking to the Roland

		sBuffer->Clear();
		bufferPointer = 0;

		// Anything new to do?

		EndstopChecks endStopsToCheck;
		uint8_t moveType;
		FilePosition filePos;
		if (reprap.GetGCodes()->ReadMove(move, endStopsToCheck, moveType, filePos))
		{
			move[AXES] = move[DRIVES]; // Roland doesn't have extruders etc.
			ProcessMove();
		}
	}

	platform.ClassReport(longWait);
}

void Roland::Zero(bool feed)
{
	size_t lim = feed ? AXES + 1 : AXES;
	for(size_t axis = 0; axis < lim; axis++)
	{
		move[axis] = 0.0;
		coordinates[axis] = 0.0;
		oldCoordinates[axis] = 0.0;
		offset[axis] = 0.0;
	}

	if (reprap.Debug(moduleGcodes))
	{
		platform.Message(HOST_MESSAGE, "Roland zero\n");
	}
}

bool Roland::Busy()
{
	return buffer[bufferPointer] != 0;
}

bool Roland::ProcessHome()
{
	if (Busy())
	{
		return false;
	}

	sBuffer->copy("H;\n");
	Zero(false);
	if (reprap.Debug(moduleGcodes))
	{
		platform.MessageF(HOST_MESSAGE, "Roland home: %s", buffer);
	}
	return true;
}

bool Roland::ProcessDwell(long milliseconds)
{
	if (Busy())
	{
		return false;
	}

	sBuffer->printf("W%ld;", milliseconds);
	sBuffer->catf("Z %.4f,%.4f,%.4f;", oldCoordinates[0], oldCoordinates[1], oldCoordinates[2]);
	sBuffer->cat("W0;\n");
	if (reprap.Debug(moduleGcodes))
	{
		platform.MessageF(HOST_MESSAGE, "Roland dwell: %s", buffer);
	}
	return true;
}

bool Roland::ProcessG92(float v, size_t axis)
{
	if (Busy())
	{
		return false;
	}

	move[axis] = v;
	coordinates[axis] = move[axis]*ROLAND_FACTOR + offset[axis];
	offset[axis] = oldCoordinates[axis];
	oldCoordinates[axis] = coordinates[axis];
	if (reprap.Debug(moduleGcodes))
	{
		platform.Message(HOST_MESSAGE, "Roland G92\n");
	}
	return true;
}

bool Roland::ProcessSpindle(float rpm)
{
	if (Busy())
	{
		return false;
	}

	if (rpm < 0.5)	// Stop
	{
		sBuffer->printf("!MC 0;\n");
	}
	else			// Go
	{
		sBuffer->printf("!RC%ld;!MC 1;\n", (long)(rpm + 100.0));
	}

	if (reprap.Debug(moduleGcodes))
	{
		platform.MessageF(HOST_MESSAGE, "Roland spindle: %s", buffer);
	}
	return true;

}

void Roland::GetCurrentRolandPosition(float moveBuffer[])
{
	for(size_t axis = 0; axis < AXES; axis++)
	{
		moveBuffer[axis] = move[axis];
	}

	for(size_t axis = AXES; axis < DRIVES; axis++)
	{
		moveBuffer[axis] = 0.0;
	}

	moveBuffer[DRIVES] = move[AXES];
}

void Roland::ProcessMove()
{
	for(size_t axis = 0; axis < AXES; axis++)
	{
		coordinates[axis] = move[axis] * ROLAND_FACTOR + offset[axis];
	}
	coordinates[AXES] = move[AXES];

	// Start with feedrate; For some reason the Roland won't accept more than 4 d.p.

	sBuffer->printf("V %.4f;", coordinates[AXES]);

	// Now the move

	sBuffer->catf("Z %.4f,%.4f,%.4f;\n", coordinates[0], coordinates[1], coordinates[2]);

	for(size_t axis = 0; axis <= AXES; axis++)
	{
		oldCoordinates[axis] = coordinates[axis];
	}

	if (reprap.Debug(moduleGcodes))
	{
		platform.MessageF(HOST_MESSAGE, "Roland move: %s", buffer);
	}
}


bool Roland::RawWrite(const char* s)
{
	if (Busy())
	{
		return false;
	}

	sBuffer->copy(s);
	sBuffer->cat("\n");

	if (reprap.Debug(moduleGcodes))
	{
		platform.MessageF(HOST_MESSAGE, "Roland rawwrite: %s", buffer);
	}
	return true;
}

bool Roland::Active()
{
	return active;
}

void Roland::Activate()
{
	digitalWrite(ROLAND_RTS_PIN, LOW);
	active = true;

	if (reprap.Debug(moduleGcodes))
	{
		platform.Message(HOST_MESSAGE, "Roland started\n");
	}
}

bool Roland::Deactivate()
{
	if (Busy())
	{
		return false;
	}

	digitalWrite(ROLAND_RTS_PIN, HIGH);
	active = false;
	if (reprap.Debug(moduleGcodes))
	{
		platform.Message(HOST_MESSAGE, "Roland stopped\n");
	}
	return true;
}

#endif