Welcome! Log In Create A New Profile

Advanced

How can I learn how Marlin works?

Posted by archy587 
How can I learn how Marlin works?
January 02, 2015 03:48PM
Hey all,

I am no programming expert but I have a general idea. I can write some arduino firmware and upload my own projects to an arduino board. Ive made some android apps and can get them uploaded on my phone.

So, I have the basic idea, and there's some things id love to build into marlin, but I really can't figure out how any of it works! actually, marlin is the only arduino code ive ever seen that opens multiple tabs in the arduino ide when you open the marlin.pde file. I dont even see how the program moves from one tab to the next, or how the arduino chip is doing so much at the same time (e.g. monitoring and pid controlling 3 temps, receiving serial commands, converting to motor output, and sending back serial data). Any of the programs I've written would get bogged down just by the sheer amount of serial data passing between computer and arduino.

So, how does marlin do all this? is there lots of threads going on?

is there any way to sort of step through the files and see how each task is being done and maybe what order everything is done in?

I feel like if I could get a grasp on how marlin is working I could add lots of fun stuff to use all the extra outputs from the mega, but as is, there's built in hardware on the rambo and ramps that I cant even tap into....

any advice on how to learn how this software works would be a great help!

thanks!
Re: How can I learn how Marlin works?
January 02, 2015 09:55PM
Most of it is interrupt driven... so difficult to trace threw.

basically read threw the source files, and ask specific questions
Re: How can I learn how Marlin works?
January 02, 2015 11:11PM
I see,

what if I wanted to unravel how the temperature control loop was carried out? lets say I have a dual extruder setup, but the extruders are not identical, so I dont want both of them to have the same Kp,Ki,Kd. In fact, I would rather have one of them be in bang bang control and one with PID. As is, it seems I have to choose one method or the other in configuration.h and if I choose PID, all extruders would have to have the same constants.

how could I figure out which files need to be modified in order to accomplish this?

thanks for the reply.
Re: How can I learn how Marlin works?
January 06, 2015 11:16AM
Hi,

I've been attempting to climb the Marlin mountain myself. I've been sifting through the code for about 3 weeks now.
I just have been going line by line through marlin_main.cpp and commenting it. The other files are covered whenever marlin_main calls on them.
It is a lot of work trying to figure this thing out yourself.
I frequently think about what Dust was saying about it being interrupt driven. That does add another level of complexity.

If you want to do things like add two different extruders with two different settings, then I think you will have to add your own code. And I dont think its so easy as to jump in and expect to get it done in a couple weeks.

Cheers
Re: How can I learn how Marlin works?
January 07, 2015 12:01PM
thanks for the comment aminkerr. i feel a little better knowing its a challenge even for someone who knows what they're doing. I can see I have to get a much better understanding of c++ before I could really make any progress with it.

for now I set up a second arduino to control all my extra stuff. If i stick with it maybe I can slowly move control over to the main arduino.

good luck with your progress on it.
Re: How can I learn how Marlin works?
December 14, 2015 08:29PM
HI Archy587 and Amikerr:
I want to unravel how the marlin code works because I want to add some extra features to my 3D printer. I'll really appreciate any knowledge you could bring me, or any web page. Thanks in advance.
Re: How can I learn how Marlin works?
December 14, 2015 11:09PM
Quote
AMINKERR
Hi,

I've been attempting to climb the Marlin mountain myself. I've been sifting through the code for about 3 weeks now.
I just have been going line by line through marlin_main.cpp and commenting it. The other files are covered whenever marlin_main calls on them.
Cheers

Yeah... Each tab is a different file of the Marlin code base. The other (smaller) sketches he has seen have been a single file. Marlin is large. But right now we are breaking up Marlin_main.cpp into many smaller files so things can be organized better and maintained. Check out the MarlinDev default branch. With that said... You won't see lots of tabs any more because Marlin had to turn into an library in order to keep going. Load up the MarlinDev fork and study that!

Quote
AMINKERR
It is a lot of work trying to figure this thing out yourself.
Cheers

Yes. But when you step back and look at it... Think how much work it was to write that code base! I'm trying to bring up my new Delta printer and I'm really impressed with the people that got the Delta code to work!

Quote
AMINKERR
I frequently think about what Dust was saying about it being interrupt driven. That does add another level of complexity.
Cheers

Well... I hear you but not really. The interrupt portion of it handles endstops getting hit and the stepper motors. If you are not actually messing with those two things directly, just ignore it. The big problem with the interrupt routines is they keep getting fatter and there is only so much processing power. (The LCD panels burn way more interrupt processing power than they should!!!!)

My suggestion to learn any code base is pick an area that interests you. And once you understand it, for sure it reaches out into other interesting areas. But don't try to eat the whole elephant. Too many people from too many areas of expertise contributed very large chunks of code. Find a section that interests you and dig in and have fun!!!

Edited 4 time(s). Last edit at 12/14/2015 11:26PM by Roxy.
Re: How can I learn how Marlin works?
December 15, 2015 03:40PM
When digging through the marlin source it has helped me to remember how the computer communicates with the arduino...via discrete g-codes. So when digging through to see how marlin handled moves I searched for "g0" and "g1" to find the case statement that deals with them, then followed the code from there. Same approach when I was looking into how it handles homing (g28) and auto-bed-leveling (g29). As far as I know there is no documentation or schema.
Sorry, only registered users may post in this forum.

Click here to login