-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbacklash.c
158 lines (148 loc) · 4.03 KB
/
backlash.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include "machine.h"
int main( int argc, char *argv[] )
{
int arg = 1;
FILE * input_file;
char * line = NULL;
char * filename = NULL;
size_t len = 0;
size_t read;
cmdline_t machine;
cmdline_t current_line;
float backlash_x = 0;
float backlash_y = 0;
float backlash_z = 0;
float delay_x = 0;
float delay_y = 0;
float delay_z = 0;
if ( argc <= 1 ) {
printf( "help:\r\n"
"\r\n"
"-i <file> set input file name\r\n"
"-x <backlash> set x axis backlash in mm\r\n"
"-y <backlash> set y axis backlash in mm\r\n"
"-z <backlash> set z axis backlash in mm\r\n"
"-dx <delay> laser x axis on/off delay in second\r\n"
"-dy <delay> laser y axis on/off delay in second\r\n"
"-dz <delay> laser z axis on/off delay in second\r\n"
);
return(0);
}
/*
* zero out machine and current line state
*/
backlash_reset_line( &machine );
backlash_reset_line( ¤t_line );
/*
* read cmd parameter
*/
while( arg < argc ) {
if ( !strcmp( argv[ arg ], "-i" ) ) {
arg++;
if ( argv[ arg ] != NULL ) {
filename = argv[ arg ];
}
else {
return(1);
}
arg++;
}
else if ( !strcmp( argv[ arg ], "-x" ) ) {
arg++;
if ( argv[ arg ] != NULL ) {
backlash_x = atof( argv[ arg ] );
}
else {
return(1);
}
arg++;
}
else if ( !strcmp( argv[ arg ], "-y" ) ) {
arg++;
if ( argv[ arg ] != NULL ) {
backlash_y = atof( argv[ arg ] );
}
else {
return(1);
}
arg++;
}
else if ( !strcmp( argv[ arg ], "-z" ) ) {
arg++;
if ( argv[ arg ] != NULL ) {
backlash_z = atof( argv[ arg ] );
}
else {
return(1);
}
arg++;
}
else if ( !strcmp( argv[ arg ], "-dx" ) ) {
arg++;
if ( argv[ arg ] != NULL ) {
delay_x = atof( argv[ arg ] );
}
else {
return(1);
}
arg++;
}
else if ( !strcmp( argv[ arg ], "-dy" ) ) {
arg++;
if ( argv[ arg ] != NULL ) {
delay_y = atof( argv[ arg ] );
}
else {
return(1);
}
arg++;
}
else if ( !strcmp( argv[ arg ], "-dz" ) ) {
arg++;
if ( argv[ arg ] != NULL ) {
delay_z = atof( argv[ arg ] );
}
else {
return(1);
}
arg++;
}
}
if ( filename ) {
if ( ( input_file = fopen( filename, "r") ) == NULL )
{
fprintf( stderr, "%s: can't open open file '%s' for input: ", argv[0], filename );
perror("");
return(1);
}
}
else {
printf("no filename\r\n");
return(1);
}
/*
* read file line by line
*/
while ( ( read = getline( &line, &len, input_file ) ) != -1 ) {
/*
* pharse a gcode line into current line data
*/
backlash_pharse_line( line, ¤t_line );
/*
* calculate backlash based on last machine data
* after calculating backlash over currentline copy it
* into machine data for the next round
*/
backlash_calc_backlash( ¤t_line, &machine, backlash_x, backlash_y, backlash_z, delay_x, delay_y, delay_z );
/*
* printf out new gcode
*/
backlash_print_line( ¤t_line );
}
return(0);
}