Welcome! Log In Create A New Profile

Advanced

Redefining G28

Posted by JeMor 
Redefining G28
November 30, 2013 02:52PM
Hello there

I'm quite new to 3d-printing (or at least using 3d-printers). I have designed and built a 3d-printer from the buttom using primarily aluminum. One of the features I have added is that the z-axis homes using the tips of the hot-ends to home by touching the heat bed. - As seen on the attached photo


The big issue for me now is that I have to redefine the G28-command. What i need is to have the G28 make the printer do the following:

- Home the x-axis
- Home the y-axis
- Go to position: ( 0 , Y_MAX_LENGTH / 2 , current_position[Z_AXIS] )
- Home the z-axis
- Go to position: ( 0 , 0 , 10 )

Here is what I have written in the Marlin_main.cpp

(Continued in a comment)
Re: Redefining G28
November 30, 2013 02:53PM
    case 28: //G28 Home all Axis one at a time

#ifdef ENABLE_AUTO_BED_LEVELING //this is not enabled
      plan_bed_level_matrix.set_to_identity();  //Reset the plane ("erase" all leveling data)
#endif //ENABLE_AUTO_BED_LEVELING


      saved_feedrate = feedrate;
      saved_feedmultiply = feedmultiply;
      feedmultiply = 100;
      previous_millis_cmd = millis();

      enable_endstops(true);

      for(int8_t i=0; i < NUM_AXIS; i++) {
        destination = current_position;
      }
      feedrate = 0.0;

#ifdef DELTA // this is not a delta-printer
          // A delta can only safely home all axis at the same time
          // all axis have to home at the same time

          // Move all carriages up together until the first endstop is hit.
          current_position[X_AXIS] = 0;
          current_position[Y_AXIS] = 0;
          current_position[Z_AXIS] = 0;
          plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);

          destination[X_AXIS] = 3 * Z_MAX_LENGTH;
          destination[Y_AXIS] = 3 * Z_MAX_LENGTH;
          destination[Z_AXIS] = 3 * Z_MAX_LENGTH;
          feedrate = 1.732 * homing_feedrate[X_AXIS];
          plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
          st_synchronize();
          endstops_hit_on_purpose();

          current_position[X_AXIS] = destination[X_AXIS];
          current_position[Y_AXIS] = destination[Y_AXIS];
          current_position[Z_AXIS] = destination[Z_AXIS];

          // take care of back off and rehome now we are all at the top
          HOMEAXIS(X);
          HOMEAXIS(Y);
          HOMEAXIS(Z);

          calculate_delta(current_position);
          plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);

#else // NOT DELTA

      home_all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2])));

      #if Z_HOME_DIR > 0                      // If homing away from BED do Z first -> it does NOT home away from bed
      if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
        HOMEAXIS(Z);
      }
      #endif

      #ifdef QUICK_HOME // QUICK_HOME is false thus not using this feature
      if((home_all_axis)||( code_seen(axis_codes[X_AXIS]) && code_seen(axis_codes[Y_AXIS])) )  //first diagonal move
      {
        current_position[X_AXIS] = 0;current_position[Y_AXIS] = 0;

       #ifndef DUAL_X_CARRIAGE
        int x_axis_home_dir = home_dir(X_AXIS);
       #else
        int x_axis_home_dir = x_home_dir(active_extruder);
        extruder_duplication_enabled = false;
       #endif

        plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
        destination[X_AXIS] = 1.5 * max_length(X_AXIS) * x_axis_home_dir;destination[Y_AXIS] = 1.5 * max_length(Y_AXIS) * home_dir(Y_AXIS);
        feedrate = homing_feedrate[X_AXIS];
        if(homing_feedrate[Y_AXIS]<feedrate)
          feedrate =homing_feedrate[Y_AXIS];
        plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
        st_synchronize();

        axis_is_at_home(X_AXIS);
        axis_is_at_home(Y_AXIS);
        plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
        destination[X_AXIS] = current_position[X_AXIS];
        destination[Y_AXIS] = current_position[Y_AXIS];
        plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
        feedrate = 0.0;
        st_synchronize();
        endstops_hit_on_purpose();

        current_position[X_AXIS] = destination[X_AXIS];
        current_position[Y_AXIS] = destination[Y_AXIS];
        current_position[Z_AXIS] = destination[Z_AXIS];
      }
      #endif

      if((home_all_axis) || (code_seen(axis_codes[X_AXIS])))
      {
      #ifdef DUAL_X_CARRIAGE // not using dual x carriage
        int tmp_extruder = active_extruder;
        extruder_duplication_enabled = false;
        active_extruder = !active_extruder;
        HOMEAXIS(X);
        inactive_extruder_x_pos = current_position[X_AXIS];
        active_extruder = tmp_extruder;
        HOMEAXIS(X);
        // reset state used by the different modes
        memcpy(raised_parked_position, current_position, sizeof(raised_parked_position));
        delayed_move_time = 0;
        active_extruder_parked = true; 
      #else      
        HOMEAXIS(X);
      #endif         
      }
       
      if((home_all_axis) || (code_seen(axis_codes[Y_AXIS]))) {
        HOMEAXIS(Y);
      }
      
      if((home_all_axis)) { // I have added the following if-statements with the content tabbed
                                              current_position[X_AXIS]=MANUAL_X_HOME_POS;
                                              current_position[Y_AXIS]=MANUAL_Y_HOME_POS;

                                              feedrate=6000;

                                              destination[0]=X_MIN_POS;
                                              destination[1]=Y_MAX_LENGTH / 2;
                                              destination[2]=current_position[Z_AXIS];
                                              
                                              prepare_move();
                                              //ClearToSend();
      }

      #if Z_HOME_DIR < 0                      // If homing towards BED do Z last
      if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
        HOMEAXIS(Z);
      }
      
      if((home_all_axis)) {
                                              current_position[Z_AXIS]=MANUAL_Z_HOME_POS;
                                              
                                              feedrate=6000;

                                              destination[0]=current_position[X_AXIS];
                                              destination[1]=current_position[Y_AXIS];
                                              destination[2]= Z_MIN_POS + 10;
                                              
                                              prepare_move();
                                              //ClearToSend();
      }


      if((home_all_axis)) {

                                              feedrate=6000;

                                              destination[0]=current_position[X_AXIS];
                                              destination[1]=Y_MIN_POS;
                                              destination[2]=current_position[Z_AXIS];
                                              
                                              prepare_move();
                                              //ClearToSend();
      }
      
      #endif

      if(code_seen(axis_codes[X_AXIS]))
      {
        if(code_value_long() != 0) {
          current_position[X_AXIS]=code_value()+add_homeing[0];
        }
      }

      if(code_seen(axis_codes[Y_AXIS])) {
        if(code_value_long() != 0) {
          current_position[Y_AXIS]=code_value()+add_homeing[1];
        }
      }

      if(code_seen(axis_codes[Z_AXIS])) {
        if(code_value_long() != 0) {
          current_position[Z_AXIS]=code_value()+add_homeing[2];
        }
      }
      
      
      #ifdef ENABLE_AUTO_BED_LEVELING
         current_position[Z_AXIS] -= Z_PROBE_OFFSET_FROM_EXTRUDER;  //Add Z_Probe offset (the distance is negative)
      #endif
      plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
#endif // else DELTA

      #ifdef ENDSTOPS_ONLY_FOR_HOMING
        enable_endstops(false);
      #endif

      feedrate = saved_feedrate;
      feedmultiply = saved_feedmultiply;
      previous_millis_cmd = millis();
      endstops_hit_on_purpose();
      break;

(Comtinued)
Re: Redefining G28
November 30, 2013 02:54PM
The added code works partly. As for the moving to coordinates it works correctly BUT: For some reason my changes to the G28 makes the printer ignore the following values from the Configuration.h (the ones with arrows):

MANUAL_X_HOME_POS -60
MANUAL_Y_HOME_POS -10   <-
MANUAL_Z_HOME_POS -3.3  <-

X_MAX_POS 205                    <-
X_MIN_POS 0                         <-
Y_MAX_POS 205
Y_MIN_POS 0
Z_MAX_POS 370
Z_MIN_POS 0

I guess this is caused by the setting of destinations as it is set to current position during the first few lines of the G28.
I hope anyone can either tell why my code does not work or even better: A working way to have the printer do what I am attempting.

Best regards
Re: Redefining G28
December 01, 2013 05:31AM
Quote

- Home the x-axis
- Home the y-axis
- Go to position: ( 0 , Y_MAX_LENGTH / 2 , current_position[Z_AXIS] )
- Home the z-axis
- Go to position: ( 0 , 0 , 10 )

Can all be done in G-code, no firmware modification neccessary:
G28 XY
G1 X0 Y100
G28 Z
G1 X Y Z10


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Redefining G28
December 01, 2013 01:59PM
Sure. That was also my first way of doing it. The thing is that I want to print from an sd-card on my RAMPS 1.4 and for some reason it always calls G28 before reading a file on the sd-card... - therefore I cannot make do of that solution.

Edited 2 time(s). Last edit at 12/02/2013 04:15AM by JeMor.
Re: Redefining G28
January 13, 2014 05:32PM
edit from before:
marlin support currently has this:

SD card folders:

If you place a file auto[0-9].g into the root of the sd card, it will be automatically executed if you boot the printer. The same file will be executed by selecting "Autostart" from the menu. First *0 will be performed, than *1 and so on. That way, you can heat up or even print automatically without user interaction.

if you have latest vesion of marlin do this:

auto[0-9].g

so look at your sd card for an auto folder, and if no file exists create auto0.g with the init info.

marlin firmware is here: [github.com]

Edited 4 time(s). Last edit at 01/14/2014 09:40AM by jamesdanielv.
Sorry, only registered users may post in this forum.

Click here to login