[Home]ArcRevrse

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org

"Just wait, Gretel, until the moon rises, and then we shall see the crumbs of bread which I have strewn about, they will show us our way home again."
upload:charobin_hansel5.jpg Bros. Grimm
the backup is done by waypoints/breadcrumbs, we drop info about how to get-away, then how to get-back (home loretta)

News

2006 03 11: these new data structs mentioned below are unneccsary
            the math and fiddling to determine the beginning and center positions are unneccsary
            the difference between using R and IJK formats are no problem
            all the work has already been done and exists in th emc2 code ( maybe emc1 I didnt check )
            The absolute position of the arc beginning, center and end are known already
            wether R or IJK used, wether arc or helix, all done already!
            ( well not publicized, but already figgered out! )
            so the rest of these notes really describe what was already done!
            See arc_data_comp_ijk() and arc_data_comp_r(() for the nittygritty
            

Old Notes

to reverse an arc, you need 'prior-knowledge'
specificly 
 the startpoint of the arc, (the beginning position)

and gcode is destination oriented, 
 meaning the gcode for an arc says where to go and where to swing from,
 but not where to start from.

we need the startpoint, and that comes from the 'world-view'
the worldview is contained in an emc structure 'setup' and it's addr is 'setup_pointer'

the contents of the gcode is in an emc structure 'block', and it's addr is 'block_pointer'

the data needed to create the reversed arc are:
 3 points in space              begin ctr end
 1 gcode type			G_02 G_03
 1 'plane' info                 G_17 G_18 G_19

 the ctr and end points are from block_pointer and setup_pointer
  block_pointer will hold the data if it was stated in the text
  else, the coordinates/distances will be 'modal' and in contained in the setup_pointer

notes as code

  
  /*a new struct has 4 triplets ( xyz sets )
   beg  this is a position
   ctr            position
   end            position
   ijk            distance from beg to ctr, a relative position, used to find the real ctr
  */
  struct _pt{
   float x;
   float y;
   float z;
  } beg, ctr, end, ijk;  // ijk is really a vector, not a point, but same struct suffices
  struct _fwd_arc { 
   _pt beg;
   _pt ctr;
   _pt end;
   _pt ijk;
  } my_fwd, my_rev;
  
  /* collect the data for the fwd arc */
/* how to handle 'r' */
/* how to handle G91 arcs ? */
 /* is the data in block_pointer absolute ? */

  /* get coords of end point */
  if (block_pointer->x_flag == ON){
   my_fwd->end.xval = block_pointer->x_number;
  }else{ 					// there was no x value in the gcode text, so x remains unchanged
   my_fwd->end.xval = setup_pointer->x_number;
  }
  if (block_pointer->y_flag == ON){
   my_fwd->end.yval = block_pointer->y_number;
  }else{ 					// there was no y value in the gcode text, so y remains unchanged
   my_fwd->end.yval = setup_pointer->y_number;
  }
  if (block_pointer->z_flag == ON){
   my_fwd->end.zval = block_pointer->z_number;
  }else{ 					// there was no z value in the gcode text, so z remains unchanged
   my_fwd->end.zval = setup_pointer->z_number;
  }
  /* get coords of beg point */
  my_fwd->beg.xval = setup_pointer->x_number;
  my_fwd->beg.yval = setup_pointer->y_number;
  my_fwd->beg.zval = setup_pointer->z_number;
  /* get values for i j k */
  if (block_pointer->i_flag == ON){
   my_fwd->ctr.ival = block_pointer->i_number;
  }else{ 					// there was no x value in the gcode text, so x remains unchanged
   my_fwd->ctr.ival = 0;
  }
  if (block_pointer->j_flag == ON){
   my_fwd->ctr.jval = block_pointer->j_number;
  }else{ 					// there was no x value in the gcode text, so x remains unchanged
   my_fwd->ctr.jval = 0;
  }
  if (block_pointer->k_flag == ON){
   my_fwd->ctr.kval = block_pointer->k_number;
  }else{ 					// there was no x value in the gcode text, so x remains unchanged
   my_fwd->ctr.kval = 0;
  }
  /* get coords of ctr point */ 
  my_fwd->ctr.xval = ( my_fwd->ctr.xval + my_fwd->ctr.ival );
  my_fwd->ctr.yval = ( my_fwd->ctr.yval + my_fwd->ctr.jval );
  my_fwd->ctr.zval = ( my_fwd->ctr.zval + my_fwd->ctr.kval );

  /* calc the data for the rev arc */
  my_rev->beg.xval = my_fwd->end.x;        // swap the beg and end point data
  my_rev->beg.yval = my_fwd->end.y;
  my_rev->beg.zval = my_fwd->end.z;

  my_rev->end.xval = my_fwd->beg.;
  my_rev->end.yval = my_fwd->beg.y;
  my_rev->end.zval = my_fwd->beg.z;
    
  my_rev->ijk.i    = (my_fwd->ctr.x - my_fwd->beg.x);
  my_rev->ijk.j    = (my_fwd->ctr.y - my_fwd->beg.y);
  my_rev->ijk.k    = (my_fwd->ctr.z - my_fwd->beg.z);
  
  /* toggle the gcode */
  /* i hove no idea which element holds G02 or G03 but it oughta be static */
  n = indexForArcType;
  my_rev->gcode[n] = ( ( my_fwd->g_mode[n] == 20 ) ? 30 : 20 );
  
  /* format the reversed code */
  /* here's where some css or conf file is needed , for the %n.nD */

  /* make up the bits & pieces , then cat 'em */
  sprintf( begX_s, "X%s8.5", my_rev->end.x );
  sprintf( begY_s, "X%s8.5", my_rev->end.x );
  sprintf( begZ_s, "X%s8.5", my_rev->end.x );  // its ok to state all 3 axis as a helix with no dpth is still an arc
  
                                              // but make the ijk only ij jk ik depending on setup_pointer->gcode[n] for G17 18 19 
  n = indexForPlane;
  switch my_fwd->gcode[n] {
   case G_17:
    sprintf( ijkI_s, "I%s8.5", my_rev->ijk.i ); 
    sprintf( ijkJ_s, "J%s8.5", my_rev->ijk.j );
    sprintf( ijkK_s, "" );
    break;

   case G_18:
    sprintf( ijkI_s, "" );
    sprintf( ijkJ_s, "J%s8.5", my_rev->ijk.j ); 
    sprintf( ijkK_s, "K%s8.5", my_rev->ijk.k );
    break;to reverse an arc, you need 'prior-knowledge'
specificly the startpoint of the arc, the beginnin position
and gcode is destination oriented, meaning the gcode for an arc says where to go and where to swing from,
 but not where to start from.
 many contrls allows an arc to cause a linear move till onto the circumference of the circle, then to begin curving

we need the startpoint, that comes from the 'world-view'
the worldview is contaqined in a structure 'setup' and it's addr is 'setup_pointer'

the contentsd of the gcode is in a structure 'block', and it's addr is 'block_pointer'

the data needed to create the reversed arc is 
 3 points in space              begin ctr end
 1 gcode type			G02 G03
 
 the ctr and end points are from block_pointer and setup_pointer
  block_pointer will hold the data if it was stated in the text
  else, the coordinates/distances will be 'modal' and in contained in the setup_pointer
  
  /*a new struct has 4 triplets ( xyz sets )
   beg  this is a position
   ctr            position
   end            position
   ijk            distance from beg to ctr, a relative position, used to find the real ctr
  */
  struct _pt{
   float x;
   float y;
   float z;
  } beg, ctr, end, ijk;  // ijk is really a vector, not a point, but same struct suffices
  struct _fwd_arc { 
   _pt beg;
   _pt ctr;
   _pt end;
   _pt ijk;
  } my_fwd, my_rev;
  
  /* collect the data for the fwd arc */
/* how to handle 'r' */
/* how to handle G91 arcs ? */
 /* is the data in block_pointer absolute ? */

  /* get coords of end point */
  if (block_pointer->x_flag == ON){
   my_fwd->end.xval = block_pointer->x_number;
  }else{ 					// there was no x value in the gcode text, so x remains unchanged
   my_fwd->end.xval = setup_pointer->x_number;
  }
  if (block_pointer->y_flag == ON){
   my_fwd->end.yval = block_pointer->y_number;
  }else{ 					// there was no y value in the gcode text, so y remains unchanged
   my_fwd->end.yval = setup_pointer->y_number;
  }
  if (block_pointer->z_flag == ON){
   my_fwd->end.zval = block_pointer->z_number;
  }else{ 					// there was no z value in the gcode text, so z remains unchanged
   my_fwd->end.zval = setup_pointer->z_number;
  }
  /* get coords of beg point */
  my_fwd->beg.xval = setup_pointer->x_number;
  my_fwd->beg.yval = setup_pointer->y_number;
  my_fwd->beg.zval = setup_pointer->z_number;
  /* get values for i j k */
  if (block_pointer->i_flag == ON){
   my_fwd->ctr.ival = block_pointer->i_number;
  }else{ 					// there was no x value in the gcode text, so x remains unchanged
   my_fwd->ctr.ival = 0;
  }
  if (block_pointer->j_flag == ON){
   my_fwd->ctr.jval = block_pointer->j_number;
  }else{ 					// there was no x value in the gcode text, so x remains unchanged
   my_fwd->ctr.jval = 0;
  }
  if (block_pointer->k_flag == ON){
   my_fwd->ctr.kval = block_pointer->k_number;
  }else{ 					// there was no x value in the gcode text, so x remains unchanged
   my_fwd->ctr.kval = 0;
  }
  /* get coords of ctr point */ 
  my_fwd->ctr.xval = ( my_fwd->ctr.xval + my_fwd->ctr.ival );
  my_fwd->ctr.yval = ( my_fwd->ctr.yval + my_fwd->ctr.jval );
  my_fwd->ctr.zval = ( my_fwd->ctr.zval + my_fwd->ctr.kval );

  /* calc the data for the rev arc */
  my_rev->beg.xval = my_fwd->end.x;        // swap the beg and end point data
  my_rev->beg.yval = my_fwd->end.y;
  my_rev->beg.zval = my_fwd->end.z;

  my_rev->end.xval = my_fwd->beg.;
  my_rev->end.yval = my_fwd->beg.y;
  my_rev->end.zval = my_fwd->beg.z;
    
  my_rev->ijk.i    = (my_fwd->ctr.x - my_fwd->beg.x);
  my_rev->ijk.j    = (my_fwd->ctr.y - my_fwd->beg.y);
  my_rev->ijk.k    = (my_fwd->ctr.z - my_fwd->beg.z);
  
  /* toggle the gcode */
  /* i hove no idea which element holds G02 or G03 but it oughta be static */
  n = indexForArcType;
  my_rev->gcode[n] = ( ( my_fwd->g_mode[n] == 20 ) ? 30 : 20 );
  
  /* format the reversed code */
  /* here's where some css or conf file is needed , for the %n.nD */

  /* make up the bits & pieces , then cat 'em */
  sprintf( begX_s, "X%9.4f", my_rev->end.x );
  sprintf( begY_s, "X%9.4f", my_rev->end.x );
  sprintf( begZ_s, "X%9.4f", my_rev->end.x );  // its ok to state all 3 axis as a helix with no dpth is still an arc
  
                                              // but make the ijk only ij jk ik depending on setup_pointer->gcode[n] for G17 18 19 
  n = indexForPlane;
  switch my_fwd->gcode[n] {
   case G_17:
    sprintf( ijkI_s, "I%9.4f", my_rev->ijk.i ); 
    sprintf( ijkJ_s, "J%9.4f", my_rev->ijk.j );
    sprintf( ijkK_s, "" );
    break;

   case G_18:
    sprintf( ijkI_s, "" );
    sprintf( ijkJ_s, "J%9.4f", my_rev->ijk.j ); 
    sprintf( ijkK_s, "K%9.4f", my_rev->ijk.k );
    break;

   case G_19:
    sprintf( ijkI_s, "I%9.4f", my_rev->ijk.i ); 
    sprintf( ijkJ_s, "" );
    sprintf( ijkK_s, "K%9.4f", my_rev->ijk.k );
    break;

   default:
    sprintf( "oops" );
    return OOPS;
    break;
  }
  
  g_str = ( my_rev->gcode[indexForArcType == G_02 ? "G02" : "G03" );
  
  /* now cat 'em */
  *revbuf[0] = 0x0;
  strcat( revbuf, g_str) ;
  strcat( revbuf, begX_s);
  strcat( revbuf, begY_s);
  strcat( revbuf, begZ_s);
  strcat( revbuf, ijkI_s);  // one of the 3 ijk will be a null string, so print em all, and in this order
  strcat( revbuf, ijkJ_s);  
  strcat( revbuf, ijkK_s);
  strcat( revbuf, NEWLINE ); // was this necc in c?
  
  /* no send it to the file */
  fopen( otherpathfile, 'wa' )
  fprintf( otherpathfile, revbuf );
  fclose( otherpathfile );
  


   case G_19:
    sprintf( ijkI_s, "I%s8.5", my_rev->ijk.i ); 
    sprintf( ijkJ_s, "" );
    sprintf( ijkK_s, "K%s8.5", my_rev->ijk.k );
    break;

   default:
    sprintf( "oops" );
    return OOPS;
    break;
  }
  
  g_str = ( my_rev->gcode[indexForArcType == G_02 ? "G02" : "G03" );
  
  /* now cat 'em */
  *revbuf[0] = 0x0;
  strcat( revbuf, g_str) ;
  strcat( revbuf, begX_s);
  strcat( revbuf, begY_s);
  strcat( revbuf, begZ_s);
  strcat( revbuf, ijkI_s);  // one of the 3 ijk will be a null string, so print em all, and in this order
  strcat( revbuf, ijkJ_s);  
  strcat( revbuf, ijkK_s);
  strcat( revbuf, NEWLINE ); // was this necc in c?
  
  /* no send it to the file */
  fopen( otherpathfile, 'wa' )
  fprintf( otherpathfile, revbuf );
  fclose( otherpathfile );

where to add the code into emc2

from emctaskmain.cc
			    if (EMC_DEBUG & EMC_DEBUG_INTERP) {
				rcs_print
				    ("emcTaskPlanCommand(%s) called. (line_number=%d)\n",
				     ((char *) &emcStatus->task.command),
				     emcStatus->task.readLine);
			    }
// 2006 03 05
// TJP this is where the gcode has been parsed and is ok
// so here is where to put some debuggin print that shows the correct data needed
//  as proof of concept
// then later the construction of the new reverse path
// then the storing of the string into a file
// then figger how to trigger use of the reverse file
			    // and execute it
			    execRetval = emcTaskPlanExecute(0);
			    if (EMC_DEBUG & EMC_DEBUG_INTERP) {
				rcs_print
				    ("emcTaskPlanExecute(0) return %d\n",
				     execRetval);
			    }  

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org
This page is read-only. Follow the BasicSteps to edit pages. | View other revisions
Last edited March 19, 2006 8:54 pm by Tomp-Tag (diff)
Search:
Published under a Creative Commons License