This commit is contained in:
Anders Sandstrom
2022-01-20 17:34:45 +01:00
parent 0b33512ffd
commit 08053a9896
7 changed files with 121 additions and 33554 deletions

View File

@@ -319,6 +319,15 @@ void ecmcGrbl::doMainWorker() {
// grb realtime thread!!!
void ecmcGrbl::grblRTexecute() {
printf("HEPP");
for(int i=0; i < 30; i++) {
if(!grblInitDone_) {
break;
}
ecmc_grbl_main_rt_thread();
}
printf("%s:%s:%d Positions(x,y,z)=%d,%d,%d..\n",__FILE__,__FUNCTION__,__LINE__,sys_position[X_AXIS], sys_position[Y_AXIS],sys_position[Z_AXIS] );
}

View File

@@ -64,7 +64,6 @@ int execute() {
return 0;
}
void deleteGrbl() {
if(grbl) {
delete (grbl);

View File

@@ -42,88 +42,6 @@ static int alreadyLoaded = 0;
int initDone = 0;
pthread_t tid;
void *ecmc_grbl_client_simulation_thread(void *ptr) {
// printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
// for(;;) {
// while(serial_get_tx_buffer_count()==0) {
// delay_ms(1);
// }
// printf("%c",ecmc_get_char_from_grbl_tx_buffer());
// }
}
// copied for grbl main.c
void *ecmc_grbl_main_thread(void *ptr) {
//printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
//
//// Initialize system upon power-up.
//serial_init(); // Setup serial baud rate and interrupts
//ecmc_init_file(); // create and clear file (simulated eeprom)
//settings_restore(0b1111); // restore all to defaults
//settings_init(); // Load Grbl settings from EEPROM
//stepper_init(); // Configure stepper pins and interrupt timers
//system_init(); // Configure pinout pins and pin-change interrupt
//memset(sys_position,0,sizeof(sys_position)); // Clear machine position.
////sei(); // Enable interrupts
//// Initialize system state.
//#ifdef FORCE_INITIALIZATION_ALARM
// // Force Grbl into an ALARM state upon a power-cycle or hard reset.
// sys.state = STATE_ALARM;
//#else
// sys.state = STATE_IDLE;
//#endif
//
//// Check for power-up and set system alarm if homing is enabled to force homing cycle
//// by setting Grbl's alarm state. Alarm locks out all g-code commands, including the
//// startup scripts, but allows access to settings and internal commands. Only a homing
//// cycle '$H' or kill alarm locks '$X' will disable the alarm.
//// NOTE: The startup script will run after successful completion of the homing cycle, but
//// not after disabling the alarm locks. Prevents motion startup blocks from crashing into
//// things uncontrollably. Very bad.
//#ifdef HOMING_INIT_LOCK
// if (bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { sys.state = STATE_ALARM; }
//#endif
// // Grbl initialization loop upon power-up or a system abort. For the latter, all processes
//// will return to this loop to be cleanly re-initialized.
//for(;;) {
// // Reset system variables.
// uint8_t prior_state = sys.state;
// memset(&sys, 0, sizeof(system_t)); // Clear system struct variable.
// sys.state = prior_state;
// sys.f_override = DEFAULT_FEED_OVERRIDE; // Set to 100%
// sys.r_override = DEFAULT_RAPID_OVERRIDE; // Set to 100%
// sys.spindle_speed_ovr = DEFAULT_SPINDLE_SPEED_OVERRIDE; // Set to 100%
// memset(sys_probe_position,0,sizeof(sys_probe_position)); // Clear probe position.
// sys_probe_state = 0;
// sys_rt_exec_state = 0;
// sys_rt_exec_alarm = 0;
// sys_rt_exec_motion_override = 0;
// sys_rt_exec_accessory_override = 0;
//
// // Reset Grbl primary systems.
// serial_reset_read_buffer(); // Clear serial read buffer
// gc_init(); // Set g-code parser to default state
// spindle_init();
// coolant_init();
// limits_init();
// probe_init();
// plan_reset(); // Clear block buffer and planner variables
// st_reset(); // Clear stepper subsystem variables.
//
// // Sync cleared gcode and planner positions to current system position.
// plan_sync_position();
// gc_sync_position();
//
// // Print welcome message. Indicates an initialization has occured at power-up or with a reset.
// report_init_message();
//
// // ready for commands through serial interface
// initDone = 1;
// protocol_main_loop();
//}
}
/** Optional.
* Will be called once after successfull load into ecmc.
* Return value other than 0 will be considered error.
@@ -141,94 +59,6 @@ int grblConstruct(char *configStr)
lastConfStr = strdup(configStr);
return createGrbl(lastConfStr, getEcmcSampleTimeMS());
// start grbl simulated client thread!
// int err;
//
// err = pthread_create(&(tid), NULL, *ecmc_grbl_client_simulation_thread, NULL);
// if (err != 0) {
// printf("\n Can't create thread :[%s]", strerror(err));
// return 1;
// }
// else {
// printf("\n grbl simulated client thread created successfully\n");
// }
//
// // start grbl main thread and wait for init done!
// printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
//
// err = pthread_create(&(tid), NULL, *ecmc_grbl_main_thread, NULL);
// if (err != 0) {
// printf("\n Can't create thread :[%s]", strerror(err));
// return 1;
// }
// else {
// printf("\n grbl main thread created successfully\n");
// }
// whait for initDone!
// printf("Waiting for grbl init..");
// while(!initDone) {
// sleep(1);
// printf(".");
// }
// printf("\n");
// printf("\n grbl ready for commands!\n");
// sleep(1);
//
// // test some commands
// printf("Test command:$\n");
// ecmc_write_command_serial("$\n");
// sleep(1);
// printf("Test command:G0X10Y100\n");
// ecmc_write_command_serial("G0X10Y100\n");
// sleep(1);
// printf("Test command:$G\n");
// ecmc_write_command_serial("$G\n");
// sleep(1);
// printf("Test command:G4P4\n");
// ecmc_write_command_serial("G4P4\n");
// printf("Test command:G1X20Y200F20\n");
// ecmc_write_command_serial("G1X20Y200F20\n");
// printf("Test command:G4P4\n");
// ecmc_write_command_serial("G4P4\n");
// printf("Test command:G2X40Y220R20\n");
// ecmc_write_command_serial("G2X40Y220R20\n");
// printf("Test command:$\n");
// ecmc_write_command_serial("$\n");
//
//printf("Test command:$J=X10.0Y-1.5\n");
//ecmc_write_command_serial("$J=X10.0Y-1.5\0");
//printf("Test command:#\n");
//ecmc_write_command_serial("#\n");
//printf("Test command:?\n");
//ecmc_write_command_serial("?\0");
//printf("Test command:G1X200Y100\n");
//ecmc_write_command_serial("G1X200Y100\0");
// printf("system_execute_line(G0 X11), %d \n ",system_execute_line("G0X11\0"));
// printf("end\n");
// printf("system_execute_line(G1X200Y100), %d \n",system_execute_line("G1X200Y100\0"));
// printf("end\n");
// printf("system_execute_line($$), %d \n",system_execute_line("$$\0"));
// printf("end\n");
// printf("system_execute_line($), %d \n",system_execute_line("$\0"));
// printf("end\n");
// printf("system_execute_line(#), %d \n",system_execute_line("#\0"));
// printf("end\n");
// printf("system_execute_line(?), %d \n",system_execute_line("?\0"));
// printf("end\n");
// printf("system_execute_line($J=X10.0Y-1.5), %d \n",system_execute_line("$J=X10.0Y-1.5\0"));
// printf("end\n");
// printf("gc_execute_line(G0 X100.25), %d \n",gc_execute_line("G0 X100.25\0"));
// printf("end\n");
// printf("gc_execute_line(G1X200Y100), %d \n",gc_execute_line("G1X200Y100\0"));
// printf("end\n");
//
// return 0; //createSocketCAN(configStr,getEcmcSampleTimeMS());
}
/** Optional function.
@@ -250,8 +80,10 @@ void grblDestruct(void)
**/
int grblRealtime(int ecmcError)
{
printf("ASDASDASDASDASdsadöjasjdalsdjlasdj\n");
lastEcmcError = ecmcError;
return 0; //execute();
execute();
return 0;
}
/** Link to data source here since all sources should be availabe at this stage

View File

@@ -221,41 +221,42 @@ static bool stepperInterruptEnable = 0;
are shown and defined in the above illustration.
*/
void ecmc_grbl_main_rt_thread();
pthread_t tid;
void *ecmc_dummy_thread(void *ptr) {
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
while (stepperInterruptEnable) {
for(int i=0; i < 30; i++) {
if(!stepperInterruptEnable) {
break;
}
ecmc_grbl_main_rt_thread();
}
printf("%s:%s:%d Positions(x,y,z)=%d,%d,%d..\n",__FILE__,__FUNCTION__,__LINE__,sys_position[X_AXIS], sys_position[Y_AXIS],sys_position[Z_AXIS] );
delay_ms(1);
}
fflush(stdout);
}
void ecmc_start_dummy_thread()
{
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
int i = 0;
int err;
err = pthread_create(&(tid), NULL, *ecmc_dummy_thread, NULL);
if (err != 0)
printf("\ncan't create thread :[%s]", strerror(err));
else
printf("\n Thread created successfully\n");
i++;
return;
}
//void ecmc_grbl_main_rt_thread();
//pthread_t tid;
//
//void *ecmc_dummy_thread(void *ptr) {
// printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
//
// while (stepperInterruptEnable) {
// for(int i=0; i < 30; i++) {
// if(!stepperInterruptEnable) {
// break;
// }
// ecmc_grbl_main_rt_thread();
// }
//
// printf("%s:%s:%d Positions(x,y,z)=%d,%d,%d..\n",__FILE__,__FUNCTION__,__LINE__,sys_position[X_AXIS], sys_position[Y_AXIS],sys_position[Z_AXIS] );
// delay_ms(1);
// }
// fflush(stdout);
//}
//
//void ecmc_start_dummy_thread()
//{
// printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
//
// int i = 0;
// int err;
//
// err = pthread_create(&(tid), NULL, *ecmc_dummy_thread, NULL);
// if (err != 0)
// printf("\ncan't create thread :[%s]", strerror(err));
// else
// printf("\n Thread created successfully\n");
// i++;
// return;
//}
//
// Stepper state initialization. Cycle should only start if the st.cycle_start flag is
// enabled. Startup init and limits call this function but shouldn't start the cycle.
@@ -285,7 +286,7 @@ void st_wake_up()
//TIMSK1 |= (1<<OCIE1A);
stepperInterruptEnable = 1;
//This should be linked to ecmc execute later
ecmc_start_dummy_thread();
//ecmc_start_dummy_thread();
}

View File

@@ -56,4 +56,8 @@ void st_update_plan_block_parameters();
// Called by realtime status reporting if realtime rate reporting is enabled in config.h.
float st_get_realtime_rate();
// main execution
void ecmc_grbl_main_rt_thread();
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -52,4 +52,6 @@ ecmcGrblAddCommand("$");
## PLC 0
# $(SCRIPTEXEC) $(ecmccfg_DIR)loadPLCFile.cmd, "PLC_ID=0, SAMPLE_RATE_MS=1000,FILE=./plc/can.plc")
$(SCRIPTEXEC) ($(ecmccfg_DIR)setAppMode.cmd)
iocInit()