Welcome! Log In Create A New Profile

Advanced

Programming custom G29 command (Marlin)

Posted by JanJans 
Programming custom G29 command (Marlin)
August 29, 2016 02:23PM
Hi to you all,
I have a problem with my 3D printer. The original firmware was really bad. So I set out to write my own firmware. The printer is a rather obscure one with what I think is a one of a kind table calibration method.

Here is a video of the original firmware at work.
[www.youtube.com]

I'm trying to write a custom G29 command in Marlin_main.cpp. This is way above my head. I'm a absolute beginner.
What I have done so far is deleting all the code surrounding the G29 code. I successfully programmed most of the movements in my new G29 code. The rotating disc however remains problematic. I wrote a simple program which worked fine on its own. When I copy paste this simple program into the Marlin, it works for only several seconds. Then the whole printer freezes. All steppers are disabled and it is impossible to connect to the printer. It seams like some kind of time out.

Here are the problematic parts of the code. The problem happens within the for loop and while loop. This is a part of Marlin_main.cpp
Quote

st_synchronize();
refresh_cmd_timeout(); // to prevent stepper_inactive_time from running out

//0. Declareren variabelen
int Speed = 500; /

//Posities voor tafel calibratie
int BedPositieA = 2400;
int BedPositieB = 4500;
int BedPositieC = 7000;

pinMode(BED_ENABLE_PIN, OUTPUT);//Enable
pinMode(BED_DIR_PIN, OUTPUT);//direction
pinMode(BED_STEP_PIN, OUTPUT);//step
pinMode(BED_ENDSTOP_PIN, INPUT); //z+ eindstop voor tafel

digitalWrite(BED_ENABLE_PIN,LOW); //Enable

deleted working code

st_synchronize();
for (int i=0; i <= (BedPositieB-BedPositieA); i++){
digitalWrite(BED_DIR_PIN,LOW);
digitalWrite(BED_STEP_PIN,HIGH);
delayMicroseconds(Speed);
digitalWrite(BED_STEP_PIN,LOW);
delayMicroseconds(Speed);
}
refresh_cmd_timeout();

deleted working code

st_synchronize();
for (int i=0; i <= BedPositieA; i++){
digitalWrite(BED_DIR_PIN,LOW);
digitalWrite(BED_STEP_PIN,HIGH);
delayMicroseconds(Speed);
digitalWrite(BED_STEP_PIN,LOW);
delayMicroseconds(Speed);
}
refresh_cmd_timeout();

Does anyone know why Marlin shuts the program down after some seconds?

Edited 3 time(s). Last edit at 08/29/2016 02:28PM by JanJans.
Re: Programming custom G29 command (Marlin)
August 29, 2016 03:40PM
Could be the watchdog that they use for the temperature controls.
Re: Programming custom G29 command (Marlin)
August 30, 2016 04:02AM
That could be the case.
I personally think it has something to do with the way I programmed the movement of the disc. The printer sends a busy response through the serial connection while executing a XYZ movement (G1). So normally the printer is running multiple processes at the same time. My code seems to prevent multiple processes. There is no response through the serial. I think the program is stuck in the waiting times that I used for manipulating the servo drive. Therefore the printer is no longer able to do anything else besides operating the servo which leads to some kind of internal error.

In other words, I should be programming the movement of the disc in such way that it doesn't use those waiting times. But again, I'm a absolute beginner in these kind of things.
Re: Programming custom G29 command (Marlin)
August 30, 2016 08:55PM
adding a call to:

idle();

in any long loop will help. By default, idle() needs to be called every 4 seconds. But I think I would argue a replacement G29 is operating at a fairly high level. It should not be reaching down and touching the stepper motors directly. (I am referencing your call to st_synchronize(); ) My thinking is you do not need to be using anything other than the probe_pt() routine and do_blocking_move() routines to get all of the movement done.

Incidentally... I do understand your desire to re-invent the G29 code. I'm pretty far along on my re-write: [github.com]

Edited 1 time(s). Last edit at 08/30/2016 08:57PM by Roxy.
Re: Programming custom G29 command (Marlin)
August 31, 2016 03:28AM
Thank you for your response. I added idle(); to the loop and it works!
I agree that editing de G29 in such a way is a ugly way of doing things. I decided to try it this way because I don't think there is any function in Marlin that supports this strange way of calibrating the table. There is no probe involved in this procedure. The head presses down on the table. The amount of mm that the head is pressed into the table is a predefined number set in the eeprom by a M530 command. You have to set these numbers by hand. So it is not really an automatic bed levelling feature at all. It is incredibly consistent though, when set correctly.

Thanks for your help smiling smiley
Sorry, only registered users may post in this forum.

Click here to login