Add sync ecmc and grbl positions before enable. Comment out some printfs

This commit is contained in:
Anders Sandstrom
2022-01-24 16:05:52 +01:00
parent 438d9cf5a1
commit 5ff7e7fcd8
9 changed files with 3621 additions and 63 deletions

View File

@@ -2,6 +2,18 @@
"files.associations": {
"queue": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp"
"typeinfo": "cpp",
"*.tcc": "cpp",
"optional": "cpp",
"istream": "cpp",
"ostream": "cpp",
"ratio": "cpp",
"system_error": "cpp",
"array": "cpp",
"functional": "cpp",
"regex": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp"
}
}

View File

@@ -330,6 +330,7 @@ void ecmcGrbl::doMainWorker() {
if(destructs_) {
return;
}
delay_ms(1);
}
}
@@ -378,9 +379,43 @@ bool ecmcGrbl::getAllConfiguredAxisEnabled() {
return ena;
}
double ecmcGrbl::getEcmcAxisActPos(int axis) {
double pos=0;
getAxisEncPosAct(axis,
&pos);
return pos;
}
void ecmcGrbl::syncPositionIfNotEnabled() {
bool sync = 0;
if(cfgXAxisId_>=0) {
if(!getEcmcAxisEnabled(cfgXAxisId_)) {
sys_position[X_AXIS] = (int32_t)(double(settings.steps_per_mm[X_AXIS])*getEcmcAxisActPos(cfgXAxisId_));
sync = 1;
}
}
if(cfgYAxisId_>=0) {
if(!getEcmcAxisEnabled(cfgYAxisId_)) {
sys_position[Y_AXIS] = (int32_t)(double(settings.steps_per_mm[Y_AXIS])*getEcmcAxisActPos(cfgYAxisId_));
sync = 1;
}
}
if(cfgZAxisId_>=0) {
if(!getEcmcAxisEnabled(cfgZAxisId_)) {
sys_position[Z_AXIS] = (int32_t)(double(settings.steps_per_mm[Z_AXIS])*getEcmcAxisActPos(cfgZAxisId_));
sync = 1;
}
}
if(sync) {
plan_sync_position();
}
}
// grb realtime thread!!!
void ecmcGrbl::grblRTexecute() {
syncPositionIfNotEnabled();
autoEnableAtStart();
double sampleRateMs = 0.0;
@@ -416,6 +451,10 @@ void ecmcGrbl::grblRTexecute() {
// }
}
//void ecmcGrbl::setExecute(int execute) {
//
//}
// Avoid issues with std:to_string()
std::string ecmcGrbl::to_string(int value) {
std::ostringstream os;

View File

@@ -46,15 +46,14 @@ class ecmcGrbl : public asynPortDriver {
void grblRTexecute();
void addCommand(std::string command);
private:
void testGrbl();
void parseConfigStr(char *configStr);
void autoEnableAtStart();
bool getEcmcAxisEnabled(int axis_id);
bool getAllConfiguredAxisEnabled();
double getEcmcAxisActPos(int axis);
void syncPositionIfNotEnabled();
static std::string to_string(int value);
int cfgDbgMode_;
int cfgXAxisId_;

View File

@@ -120,15 +120,15 @@ uint8_t gc_execute_line(char *line)
else { char_counter = 0; }
while (line[char_counter] != 0) { // Loop until no more g-code words in line.
printf("1\n");
//printf("1\n");
// Import the next g-code word, expecting a letter followed by a value. Otherwise, error out.
letter = line[char_counter];
printf("letter=%c\n", letter);
//printf("letter=%c\n", letter);
if((letter < 'A') || (letter > 'Z')) { FAIL(STATUS_EXPECTED_COMMAND_LETTER); } // [Expected word letter]
char_counter++;
if (!read_float(line, &char_counter, &value)) { FAIL(STATUS_BAD_NUMBER_FORMAT); } // [Expected word value]
printf("value=%f\n", value);
//printf("value=%f\n", value);
// Convert values to smaller uint8 significand and mantissa values for parsing this word.
// NOTE: Mantissa is multiplied by 100 to catch non-integer command values. This is more
// accurate than the NIST gcode requirement of x10 when used for commands, but not quite
@@ -138,8 +138,8 @@ uint8_t gc_execute_line(char *line)
// Maybe update this later.
int_value = trunc(value);
mantissa = round(100*(value - int_value)); // Compute mantissa for Gxx.x commands.
printf("int_value=%d\n", int_value);
printf("mantissa=%d\n", mantissa);
//printf("int_value=%d\n", int_value);
//printf("mantissa=%d\n", mantissa);
// NOTE: Rounding must be used to catch small floating point errors.
// Check if the g-code word is supported or errors due to modal group violations or has
@@ -175,7 +175,7 @@ uint8_t gc_execute_line(char *line)
if (axis_command) { FAIL(STATUS_GCODE_AXIS_COMMAND_CONFLICT); } // [Axis word/command conflict]
axis_command = AXIS_COMMAND_MOTION_MODE;
// No break. Continues to next line.
printf("axis_command=%d\n", axis_command);
//printf("axis_command=%d\n", axis_command);
case 80:
word_bit = MODAL_GROUP_G1;
@@ -187,7 +187,7 @@ uint8_t gc_execute_line(char *line)
gc_block.modal.motion += (mantissa/10)+100;
mantissa = 0; // Set to zero to indicate valid non-integer G command.
}
printf("here!!\n");
//printf("here!!\n");
break;
case 17: case 18: case 19:
word_bit = MODAL_GROUP_G2;
@@ -244,13 +244,13 @@ uint8_t gc_execute_line(char *line)
break;
default: FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); // [Unsupported G command]
}
printf("here 2!!\n");
//printf("here 2!!\n");
if (mantissa > 0) { FAIL(STATUS_GCODE_COMMAND_VALUE_NOT_INTEGER); } // [Unsupported or invalid Gxx.x command]
// Check for more than one command per modal group violations in the current block
// NOTE: Variable 'word_bit' is always assigned, if the command is valid.
if ( bit_istrue(command_words,bit(word_bit)) ) { FAIL(STATUS_GCODE_MODAL_GROUP_VIOLATION); }
command_words |= bit(word_bit);
printf("here 3!!\n");
//printf("here 3!!\n");
break;
case 'M':
@@ -380,19 +380,19 @@ uint8_t gc_execute_line(char *line)
// Determine implicit axis command conditions. Axis words have been passed, but no explicit axis
// command has been sent. If so, set axis command to current motion mode.
printf("%s:%s:%d:axis_words=%d\n",__FILE__,__FUNCTION__,__LINE__,axis_words);
printf("%s:%s:%d:axis_command=%d\n",__FILE__,__FUNCTION__,__LINE__,axis_command);
//printf("%s:%s:%d:axis_words=%d\n",__FILE__,__FUNCTION__,__LINE__,axis_words);
//printf("%s:%s:%d:axis_command=%d\n",__FILE__,__FUNCTION__,__LINE__,axis_command);
if (axis_words) {
if (!axis_command) { axis_command = AXIS_COMMAND_MOTION_MODE; } // Assign implicit motion-mode
}
printf("%s:%s:%d:axis_command=%d\n",__FILE__,__FUNCTION__,__LINE__,axis_command);
//printf("%s:%s:%d:axis_command=%d\n",__FILE__,__FUNCTION__,__LINE__,axis_command);
// Check for valid line number N value.
if (bit_istrue(value_words,bit(WORD_N))) {
// Line number value cannot be less than zero (done) or greater than max line number.
if (gc_block.values.n > MAX_LINE_NUMBER) { FAIL(STATUS_GCODE_INVALID_LINE_NUMBER); } // [Exceeds max line number]
// if (gc_block.values.n > MAX_LINE_NUMBER) { FAIL(STATUS_GCODE_INVALID_LINE_NUMBER); } // [Exceeds max line number]
}
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
//printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
// bit_false(value_words,bit(WORD_N)); // NOTE: Single-meaning value word. Set at end of error-checking.
// Track for unused words at the end of error-checking.
@@ -407,13 +407,13 @@ uint8_t gc_execute_line(char *line)
// [2. Set feed rate mode ]: G93 F word missing with G1,G2/3 active, implicitly or explicitly. Feed rate
// is not defined after switching to G94 from G93.
// NOTE: For jogging, ignore prior feed rate mode. Enforce G94 and check for required F word.
printf("%s:%s:%d:gc_parser_flags=%d\n",__FILE__,__FUNCTION__,__LINE__,gc_parser_flags);
//printf("%s:%s:%d:gc_parser_flags=%d\n",__FILE__,__FUNCTION__,__LINE__,gc_parser_flags);
if (gc_parser_flags & GC_PARSER_JOG_MOTION) {
if (bit_isfalse(value_words,bit(WORD_F))) { FAIL(STATUS_GCODE_UNDEFINED_FEED_RATE); }
if (gc_block.modal.units == UNITS_MODE_INCHES) { gc_block.values.f *= MM_PER_INCH; }
} else {
printf("%s:%s:%d:gc_block.modal.feed_rate=%d\n",__FILE__,__FUNCTION__,__LINE__,gc_block.modal.feed_rate);
//printf("%s:%s:%d:gc_block.modal.feed_rate=%d\n",__FILE__,__FUNCTION__,__LINE__,gc_block.modal.feed_rate);
if (gc_block.modal.feed_rate == FEED_RATE_MODE_INVERSE_TIME) { // = G93
// NOTE: G38 can also operate in inverse time, but is undefined as an error. Missing F word check added here.
@@ -440,7 +440,7 @@ uint8_t gc_execute_line(char *line)
if (bit_istrue(value_words,bit(WORD_F))) {
if (gc_block.modal.units == UNITS_MODE_INCHES) { gc_block.values.f *= MM_PER_INCH; }
} else {
printf("%s:%s:%d:gc_state.feed_rate=%f\n",__FILE__,__FUNCTION__,__LINE__,gc_state.feed_rate);
//printf("%s:%s:%d:gc_state.feed_rate=%f\n",__FILE__,__FUNCTION__,__LINE__,gc_state.feed_rate);
gc_block.values.f = gc_state.feed_rate; // Push last state feed rate
}

View File

@@ -151,6 +151,7 @@ void protocol_main_loop()
}
}
delay_us(100);
}
// If there are no more characters in the serial read buffer to be processed and executed,

View File

@@ -84,7 +84,7 @@ static st_block_t st_block_buffer[SEGMENT_BUFFER_SIZE-1];
typedef struct {
uint16_t n_step; // Number of step events to be executed for this segment
uint16_t cycles_per_tick; // Step distance traveled per ISR tick, aka step rate.
double ecmc_interrupt_time_ms;
double ecmc_interrupt_time_ms; //Added for ecmc
uint8_t st_block_index; // Stepper block data index. Uses this information to execute this segment.
#ifdef ADAPTIVE_MULTI_AXIS_STEP_SMOOTHING
uint8_t amass_level; // Indicates AMASS level for the ISR to execute this segment
@@ -222,43 +222,6 @@ 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;
//}
//
// 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.
void st_wake_up()

View File

@@ -13,7 +13,7 @@ epicsEnvSet("ECMC_MOD_TYPE", "0") # For pos
#Encoder
epicsEnvSet("ECMC_ENC_SCALE_NUM" "-60")
epicsEnvSet("ECMC_ENC_SCALE_DENOM" "2000")
epicsEnvSet("ECMC_ENC_TYPE" "0") # Type: 0=Incremental, 1=Absolute
epicsEnvSet("ECMC_ENC_TYPE" "1") # Type: 0=Incremental, 1=Absolute
epicsEnvSet("ECMC_ENC_BITS" "16") # Total bit count of encoder raw data
epicsEnvSet("ECMC_ENC_ABS_BITS", "0") # Absolute bit count (for absolute encoders) always least significant part of ECMC_ENC_BITS
epicsEnvSet("ECMC_ENC_ABS_OFFSET" "0") # Encoder offset in eng units (for absolute encoders)
@@ -42,7 +42,7 @@ epicsEnvSet("ECMC_EC_DRV_ALARM_2", "ec0.s8.driveStatus01.14") # Sync
epicsEnvSet("ECMC_EC_DRV_WARNING", "ec0.s8.driveStatus01.2") # Warning
#Trajectory
epicsEnvSet("ECMC_TRAJ_TYPE" "1") # Trapetz: 0. S-Curve: 1
epicsEnvSet("ECMC_TRAJ_TYPE" "0") # Trapetz: 0. S-Curve: 1
epicsEnvSet("ECMC_VELO", "10.0")
epicsEnvSet("ECMC_JOG_VEL", "5")
epicsEnvSet("ECMC_JAR", "0.0") # JAR defaults to VELO/ACCL

3543
iocsh/log.log Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,7 @@
##############################################################################
## Example: Demo of ecmc SocketCAN plugin
## https://github.com/anderssandstrom/e3-ecmc_plugin_socketcan
## Example: Demo of ecmc grbl g-code plugin
## https://github.com/anderssandstrom/ecmc_plugin_grbl
## https://github.com/anderssandstrom/e3-ecmc_plugin_grbl
##
## The plugin exposes:
##