Skip to content

Commit c9df2a5

Browse files
committed
update
1 parent e98cdb1 commit c9df2a5

14 files changed

Lines changed: 491 additions & 166 deletions

src/motion_control.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969
float x= target[X_AXIS], y= target[Y_AXIS], z = target[Z_AXIS];
7070

71-
coord_effect2arm( &x, &y, &z ); // calculate the effect offset
71+
coord_effect2arm( &x, &y, &z ); // calculate the arm current coord
7272
coord_to_angle( x, y, z,
7373
&final_angle[X_AXIS], &final_angle[Y_AXIS], &final_angle[Z_AXIS] ); // calculate final angle
7474
/*
@@ -78,28 +78,33 @@
7878
dtostrf( final_angle[Z_AXIS], 5, 4, b_str );
7979
8080
DB_PRINT_STR( "final_angle: %s, %s, %s\r\n", l_str, r_str, b_str );*/
81+
// final_angle[X_AXIS] += 0.15;
82+
// final_angle[Y_AXIS] -= 0.15;
8183

8284
if( is_angle_legal( final_angle[X_AXIS], final_angle[Y_AXIS], final_angle[Z_AXIS] ) == false ){ // check the angle
83-
//DB_PRINT_STR( "E22 position cnan't reach\n" );
84-
//uarm.coord_error_flag = true;
8585
return UARM_COORD_ERROR;
8686
}
87+
88+
// angle_to_coord( final_angle[X_AXIS], final_angle[Y_AXIS], final_angle[Z_AXIS], &x, &y, &z );
89+
// coord_arm2effect( &x, &y, &z );
90+
91+
// target[X_AXIS] = x;
92+
// target[Y_AXIS] = y;
93+
// target[Z_AXIS] = z;
8794

8895
step_to_coord( uarm.target_step[X_AXIS], uarm.target_step[Y_AXIS], uarm.target_step[Z_AXIS],
89-
&current_coord[X_AXIS], &current_coord[Y_AXIS], &current_coord[Z_AXIS]); // calculate the current coord
96+
&current_coord[X_AXIS], &current_coord[Y_AXIS], &current_coord[Z_AXIS]); // calculate the arm current coord
97+
coord_arm2effect( &current_coord[X_AXIS], &current_coord[Y_AXIS], &current_coord[Z_AXIS] ); // calculate the effect current coord
9098
settings_init();
9199
switch( mode ){
92100
case MOTION_MODE_SEEK: // <! G0
93101
divide_numbers=1;
94-
/*settings.steps_per_mm[X_AXIS] = 50000;
95-
settings.steps_per_mm[Y_AXIS] = 50000;
96-
settings.steps_per_mm[Y_AXIS] = 50000;*/
97102
break;
98103
case MOTION_MODE_LINEAR: // <! G1
99104
if( feed_rate > 100 ){ feed_rate = 100; }
100-
divide_numbers = sqrt((x - current_coord[X_AXIS])*(x - current_coord[X_AXIS]) + // unit is mm
101-
(y - current_coord[Y_AXIS])*(y - current_coord[Y_AXIS]) +
102-
(z - current_coord[Z_AXIS])*(z - current_coord[Z_AXIS])) * 30 / feed_rate;
105+
divide_numbers = sqrt((target[X_AXIS] - current_coord[X_AXIS])*(target[X_AXIS] - current_coord[X_AXIS]) + // unit is mm
106+
(target[Y_AXIS] - current_coord[Y_AXIS])*(target[Y_AXIS] - current_coord[Y_AXIS]) +
107+
(target[Z_AXIS] - current_coord[Z_AXIS])*(target[Z_AXIS] - current_coord[Z_AXIS])) * 30 / feed_rate;
103108

104109
if( divide_numbers < 10 ){ divide_numbers = 10; }
105110

@@ -114,18 +119,22 @@
114119
}
115120

116121
// DB_PRINT_STR( "divide num : %d\r\n", divide_numbers );
122+
117123
float delta_coord[3];
118-
delta_coord[X_AXIS] = (x - current_coord[X_AXIS]) / divide_numbers; // calculate delta coord
119-
delta_coord[Y_AXIS] = (y - current_coord[Y_AXIS]) / divide_numbers;
120-
delta_coord[Z_AXIS] = (z - current_coord[Z_AXIS]) / divide_numbers;
124+
delta_coord[X_AXIS] = (target[X_AXIS] - current_coord[X_AXIS]) / divide_numbers; // calculate delta coord
125+
delta_coord[Y_AXIS] = (target[Y_AXIS] - current_coord[Y_AXIS]) / divide_numbers;
126+
delta_coord[Z_AXIS] = (target[Z_AXIS] - current_coord[Z_AXIS]) / divide_numbers;
121127

122128
float final_coord[3];
123129
float final_step[3];
124130
for( int i = 1; i <= divide_numbers; i++ ){
131+
125132
final_coord[X_AXIS] = current_coord[X_AXIS] + delta_coord[X_AXIS] * i;
126133
final_coord[Y_AXIS] = current_coord[Y_AXIS] + delta_coord[Y_AXIS] * i;
127134
final_coord[Z_AXIS] = current_coord[Z_AXIS] + delta_coord[Z_AXIS] * i;
128135

136+
coord_effect2arm( &final_coord[X_AXIS], &final_coord[Y_AXIS], &final_coord[Z_AXIS] );
137+
129138
uarm.coord_x = final_coord[X_AXIS];
130139
uarm.coord_y = final_coord[Y_AXIS];
131140
uarm.coord_z = final_coord[Z_AXIS];

src/protocol.c

Lines changed: 73 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void protocol_main_loop()
6363
// ------------------------------------------------------------
6464

6565
// Print welcome message
66-
report_init_message();
66+
// report_init_message();
6767

6868
// Check for and report alarm state after a reset, error, or an initial power up.
6969
if (sys.state == STATE_ALARM) {
@@ -89,6 +89,7 @@ void protocol_main_loop()
8989
uint8_t line_remain = 0;
9090
uint8_t line_num = 0;
9191
uint8_t line_execute_p = 0;
92+
9293
for (;;) {
9394

9495
// Process one line of incoming serial data, as the data becomes available. Performs an
@@ -100,71 +101,80 @@ void protocol_main_loop()
100101
// exceed 256 characters, but the Arduino Uno does not have the memory space for this.
101102
// With a better processor, it would be very easy to pull this initial parsing out as a
102103
// seperate task to be shared by the g-code parser and Grbl's system commands.
103-
104-
while((c = serial_read()) != SERIAL_NO_DATA) {
105-
if ((c == '\n') || (c == '\r')) { // End of line reached
106-
line[char_counter] = 0; // Set string termination character.
107-
receive_cmd_line(line);
108-
comment = COMMENT_NONE;
109-
char_counter = 0;
110-
break;
111-
} else {
112-
if (comment != COMMENT_NONE) {
113-
// Throw away all comment characters
114-
if (c == ')') {
115-
// End of comment. Resume line. But, not if semicolon type comment.
116-
if (comment == COMMENT_TYPE_PARENTHESES) { comment = COMMENT_NONE; }
117-
}
118-
} else {
119-
if (c <= ' ') {
120-
// Throw away whitepace and control characters
121-
} else if (c == '/') {
122-
// Block delete NOT SUPPORTED. Ignore character.
123-
// NOTE: If supported, would simply need to check the system if block delete is enabled.
124-
} else if (c == '(') {
125-
// Enable comments flag and ignore all characters until ')' or EOL.
126-
// NOTE: This doesn't follow the NIST definition exactly, but is good enough for now.
127-
// In the future, we could simply remove the items within the comments, but retain the
128-
// comment control characters, so that the g-code parser can error-check it.
129-
comment = COMMENT_TYPE_PARENTHESES;
130-
} else if (c == ';') {
131-
// NOTE: ';' comment to EOL is a LinuxCNC definition. Not NIST.
132-
comment = COMMENT_TYPE_SEMICOLON;
133-
134-
// TODO: Install '%' feature
135-
// } else if (c == '%') {
136-
// Program start-end percent sign NOT SUPPORTED.
137-
// NOTE: This maybe installed to tell Grbl when a program is running vs manual input,
138-
// where, during a program, the system auto-cycle start will continue to execute
139-
// everything until the next '%' sign. This will help fix resuming issues with certain
140-
// functions that empty the planner buffer to execute its task on-time.
104+
if( uarm.effect_origin_check ){
105+
end_effector_check_limit();
106+
}else{
107+
while((c = serial_read()) != SERIAL_NO_DATA) {
108+
if ((c == '\n') || (c == '\r')) { // End of line reached
109+
line[char_counter] = 0; // Set string termination character.
110+
receive_cmd_line(line);
111+
comment = COMMENT_NONE;
112+
char_counter = 0;
113+
break;
114+
} else {
115+
if (comment != COMMENT_NONE) {
116+
// Throw away all comment characters
117+
if (c == ')') {
118+
// End of comment. Resume line. But, not if semicolon type comment.
119+
if (comment == COMMENT_TYPE_PARENTHESES) { comment = COMMENT_NONE; }
120+
}
121+
} else {
122+
if (c <= ' ') {
123+
// Throw away whitepace and control characters
124+
} else if (c == '/') {
125+
// Block delete NOT SUPPORTED. Ignore character.
126+
// NOTE: If supported, would simply need to check the system if block delete is enabled.
127+
} else if (c == '(') {
128+
// Enable comments flag and ignore all characters until ')' or EOL.
129+
// NOTE: This doesn't follow the NIST definition exactly, but is good enough for now.
130+
// In the future, we could simply remove the items within the comments, but retain the
131+
// comment control characters, so that the g-code parser can error-check it.
132+
comment = COMMENT_TYPE_PARENTHESES;
133+
} else if (c == ';') {
134+
// NOTE: ';' comment to EOL is a LinuxCNC definition. Not NIST.
135+
comment = COMMENT_TYPE_SEMICOLON;
136+
137+
// TODO: Install '%' feature
138+
// } else if (c == '%') {
139+
// Program start-end percent sign NOT SUPPORTED.
140+
// NOTE: This maybe installed to tell Grbl when a program is running vs manual input,
141+
// where, during a program, the system auto-cycle start will continue to execute
142+
// everything until the next '%' sign. This will help fix resuming issues with certain
143+
// functions that empty the planner buffer to execute its task on-time.
141144

142-
} else if (char_counter >= (LINE_BUFFER_SIZE-1)) {
143-
// Detect line buffer overflow. Report error and reset line buffer.
144-
report_status_message(STATUS_OVERFLOW);
145-
comment = COMMENT_NONE;
146-
char_counter = 0;
147-
} else if (c >= 'a' && c <= 'z') { // Upcase lowercase
148-
line[char_counter++] = c-'a'+'A';
149-
} else {
150-
line[char_counter++] = c;
151-
}
152-
}
153-
}
154-
}
155-
parse_cmd_line();
156-
157-
// If there are no more characters in the serial read buffer to be processed and executed,
158-
// this indicates that g-code streaming has either filled the planner buffer or has
159-
// completed. In either case, auto-cycle start, if enabled, any queued moves.
160-
//uarm_swift_tick_run();
161-
protocol_auto_cycle_start();
162-
protocol_execute_realtime(); // Runtime command check point.
163-
if (sys.abort) { return; } // Bail to main() program loop to reset system.
145+
} else if (char_counter >= (LINE_BUFFER_SIZE-1)) {
146+
// Detect line buffer overflow. Report error and reset line buffer.
147+
report_status_message(STATUS_OVERFLOW);
148+
comment = COMMENT_NONE;
149+
char_counter = 0;
150+
} else if (c >= 'a' && c <= 'z') { // Upcase lowercase
151+
line[char_counter++] = c-'a'+'A';
152+
} else {
153+
line[char_counter++] = c;
154+
}
155+
}
156+
}
157+
}
158+
//if( position_origin_flag && end_angle_origin_flag ){
159+
parse_cmd_line();
160+
//}
161+
162+
// If there are no more characters in the serial read buffer to be processed and executed,
163+
// this indicates that g-code streaming has either filled the planner buffer or has
164+
// completed. In either case, auto-cycle start, if enabled, any queued moves.
165+
//uarm_swift_tick_run();
166+
protocol_auto_cycle_start();
167+
protocol_execute_realtime(); // Runtime command check point.
168+
if (sys.abort) { return; } // Bail to main() program loop to reset system.
169+
170+
report_parse_result();
171+
if( uarm.motor_position_check ){
172+
check_motor_positon();
173+
}
164174

165-
report_parse_result();
166-
check_motor_positon();
175+
}
167176
}
177+
168178
return; /* Never reached */
169179
}
170180

src/report.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ void report_probe_parameters()
297297
// Prints Grbl NGC parameters (coordinate offsets, probing)
298298
void report_ngc_parameters()
299299
{
300+
300301
float coord_data[N_AXIS];
301302
uint8_t coord_select, i;
302303
for (coord_select = 0; coord_select <= SETTING_INDEX_NCOORD; coord_select++) {
@@ -327,12 +328,14 @@ void report_ngc_parameters()
327328
printFloat_CoordValue(gc_state.tool_length_offset);
328329
printPgmString(PSTR("]\r\n"));
329330
report_probe_parameters(); // Print probe parameters. Not persistent in memory.
331+
330332
}
331333

332334

333335
// Print current gcode parser mode state
334336
void report_gcode_modes()
335337
{
338+
336339
printPgmString(PSTR("["));
337340

338341
switch (gc_state.modal.motion) {
@@ -401,7 +404,7 @@ void report_gcode_modes()
401404
// Prints specified startup line
402405
void report_startup_line(uint8_t n, char *line)
403406
{
404-
printPgmString(PSTR("$N")); print_uint8_base10(n);
407+
printPgmString(PSTR("$N")); print_uint8_base10(n);
405408
printPgmString(PSTR("=")); printString(line);
406409
printPgmString(PSTR("\r\n"));
407410
}

src/settings.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ uint8_t read_global_settings() {
168168
} else {
169169
return(false);
170170
}
171+
/*
172+
if( settings.steps_per_mm[X_AXIS]!=7000 || settings.steps_per_mm[Y_AXIS]!=7000 || settings.steps_per_mm[Z_AXIS]!=7000 ){
173+
return(false);
174+
}*/
175+
171176
return(true);
172177
}
173178

@@ -277,21 +282,21 @@ uint8_t settings_store_global_setting(uint8_t parameter, float value) {
277282
// Initialize the config subsystem
278283
void settings_init() {
279284
if(!read_global_settings()) {
280-
report_status_message(STATUS_SETTING_READ_FAIL);
285+
//report_status_message(STATUS_SETTING_READ_FAIL);
281286
settings_restore(SETTINGS_RESTORE_ALL); // Force restore all EEPROM data.
282-
report_grbl_settings();
287+
//report_grbl_settings();
283288
}
284289

285290
// NOTE: Checking paramater data, startup lines, and build info string should be done here,
286291
// but it seems fairly redundant. Each of these can be manually checked and reset or restored.
287292
// Check all parameter data into a dummy variable. If error, reset to zero, otherwise do nothing.
288-
// float coord_data[N_AXIS];
289-
// uint8_t i;
290-
// for (i=0; i<=SETTING_INDEX_NCOORD; i++) {
291-
// if (!settings_read_coord_data(i, coord_data)) {
292-
// report_status_message(STATUS_SETTING_READ_FAIL);
293-
// }
294-
// }
293+
float coord_data[N_AXIS];
294+
uint8_t i;
295+
for (i=0; i<=SETTING_INDEX_NCOORD; i++) {
296+
if (!settings_read_coord_data(i, coord_data)) {
297+
report_status_message(STATUS_SETTING_READ_FAIL);
298+
}
299+
}
295300
// NOTE: Startup lines are checked and executed by protocol_main_loop at the end of initialization.
296301
}
297302

0 commit comments

Comments
 (0)