Notifications
Clear all

What language does Prusa use to program?  

  RSS
Kryssie
(@kryssie)
Trusted Member
What language does Prusa use to program?

Hi,

I'm interested in learning more about the actual coding of the printer (the stuff you edit in Arduino) and I would like to know what language is it? Just gcode? Java?

Fair farren

Posted : 29/10/2019 12:38 am
bobstro
(@bobstro)
Illustrious Member
RE: What language does Prusa use to program?

The firmware is coded in C++. PrusaSlicer has been (mostly?) ported from Slic3r's original PERL to C++. Actual parts are printed using gcode instructions which are really just instructions, not any sort of programming language as we generally think of it. 

My notes and disclaimers on 3D printing

and miscellaneous other tech projects
He is intelligent, but not experienced. His pattern indicates two dimensional thinking. -- Spock in Star Trek: The Wrath of Khan

Posted : 29/10/2019 2:27 am
Nikolai liked
Nikolai
(@nikolai)
Noble Member
RE: What language does Prusa use to program?

And here you will find all the source code: https://github.com/prusa3d

Often linked posts:
Going small with MMU2
Real Multi Material
My prints on Instagram

Posted : 29/10/2019 5:42 am
Kryssie
(@kryssie)
Trusted Member
Topic starter answered:
RE: What language does Prusa use to program?

@nikolai-r

Oh yeah, now I know what to look for, seen the C++ logo 🙄

Why is the printer firmware in C++, why not Java or another language? How come the Prusa firmware is designed in Linux using C++ (coz I didn't think Linux uses C++...)?

The reason I ask is: A)I'm curious, B) I have a printer I'm building and I want to base it's code on the Prusa but it will need considerable adjustments because it is very much bigger than Prusa MK3. To understand and edit the source code (or even write my own) I should know C++?

Fair farren

Posted : 29/10/2019 11:39 pm
Nikolai
(@nikolai)
Noble Member
RE: What language does Prusa use to program?

@kryss-e

Based on your questions I assume you're new to embedded programming (or software development at all?). In this case I would suggest to start with basic Arduino tutorials and how to control Displays, Servos, Switches ... and all the other hardware components. By building a new printer you're touching not only software but also hardware development. Without at least basic knowledge of both it will be hard to realize such a project successfully.

Often linked posts:
Going small with MMU2
Real Multi Material
My prints on Instagram

Posted : 29/10/2019 11:48 pm
Kryssie
(@kryssie)
Trusted Member
Topic starter answered:
RE: What language does Prusa use to program?

Yep, pretty new 🙂 I just need to know where to start. thanks 😎 

Fair farren

Posted : 30/10/2019 1:50 am
Nikolai
(@nikolai)
Noble Member
RE: What language does Prusa use to program?

@kryss-e

https://www.arduino.cc/en/Tutorial/HomePage

Often linked posts:
Going small with MMU2
Real Multi Material
My prints on Instagram

Posted : 30/10/2019 1:55 am
--
 --
(@)
Illustrious Member
RE: What language does Prusa use to program?

What most novice programmers lack is real time programming experience; and not understanding what that actually means often dooms projects that require real time functions such as interrupt handling and communications.  You can't go off and twiddle bits when motors are turning or bad things happen.

The other side of the coin is space: programming inside a SCC means you are required to use the available resources: EEPROM and even RAM is extremely limited. Using an extra byte or two can break things.

This post was modified 4 years ago by --
Posted : 30/10/2019 2:40 am
Nikolai
(@nikolai)
Noble Member
RE: What language does Prusa use to program?

@tim-m30

Newcomer need to start somewhere.

Often linked posts:
Going small with MMU2
Real Multi Material
My prints on Instagram

Posted : 30/10/2019 2:59 am
--
 --
(@)
Illustrious Member
RE: What language does Prusa use to program?

When an older novice runner wants to run in a 26 mile marathon, a few words of advice and caution can prevent heart attacks. 

Sure, a novice can learn C++ after using simpler languages.  But a complaint from said novice about the language as the first comment says the person wants the easy path.  Setting the expectation that the task is complex, requires suitable knowledge of key systems design, and not for the feint of heart, might actually be good advice.   

Yes, it is possible to learn all of this; classes are available and there are fair examples already in opensource libraries.  But even the Prusa code has examples of  someone coding that wasn't prepared to deal with these same issues and users suffer from their lack of knowledge and experience -- defects continue to evolve.  

On the other hand, maybe the logic of giving someone enough rope they hang themselves is my type of evil... hmm... good work!

Posted : 30/10/2019 3:25 am
Nikolai
(@nikolai)
Noble Member
RE: What language does Prusa use to program?

@tim-m30

Look at the Arduino project. Making complex stuff accessible and easier to understand at the first stage hooks up more people which are diving in the complexity later on. There are more ways leading to Rome. If someone is showing interest, it’s a good thing and I rather encourage people to make this step. 

Often linked posts:
Going small with MMU2
Real Multi Material
My prints on Instagram

Posted : 30/10/2019 6:01 am
--
 --
(@)
Illustrious Member
RE: What language does Prusa use to program?
Posted by: @nikolai-r

@tim-m30

Look at the Arduino project. Making complex stuff accessible and easier to understand at the first stage hooks up more people which are diving in the complexity later on. There are more ways leading to Rome. If someone is showing interest, it’s a good thing and I rather encourage people to make this step. 

I understand... but there are things in life I wish people would have explained were a lot more difficult than my expectation and experience allowed me to complete.  Had I known how steep the learning curve was, I would have taken a different path.  I am not Hannibal.

Posted : 30/10/2019 6:07 am
Kryssie
(@kryssie)
Trusted Member
Topic starter answered:
RE: What language does Prusa use to program?

Wow, what fascinating dialogue...

tim-m30 - I didn't complain about C++, my question was: why that over another language. If Prusa used Java, I would have asked, why that? I like details, and I thought maybe someone knows why C++, like, because it's fast or something.

I have edited Prusa firmware (in fact I have to edit every firmware release because my printers are customised) so I'm not so new to the idea of editing code. As I see it, it's like trying to read a foreign language text by looking up the words as I read. This works, but it's inefficient. I want to be able to grasp what I read as I read it. That's why I wanted to know what language Prusa firmware uses, so I could go find out about said language and be able to understand the coding, like why there are over 100 .h / .cpp files in the firmware and what each is for (I do know some of them, the ones I have to change) - and that statement probably just confirmed how green I am. 🤔 (Why are there a mix or .cpp and .h files? Obviously .cpp is C++, but what's .h...? Ah, a header file, referenced by a C++ file. Cool!)

While I appreciate your concern for my welfare, I will be very careful not to hang myself (not to sound pompous, but I've got quite a lot of practice at that).

Thank you @nikolai-r for the link, I will check it out 🙂

 

 

This post was modified 4 years ago 2 times by Kryssie

Fair farren

Posted : 30/10/2019 8:46 am
--
 --
(@)
Illustrious Member
RE: What language does Prusa use to program?

dot H files are common in many languages.  Essentially where key variables and constants are defined that need to be common across larger code domains, or mentioned so they can be handled properly at compile. As for other extensions, .cpp is in lieu of C++. Historically the extension is the language name for source code. .c for C, .cs for C#, .bas for BASIC, . pas for Pascal, .for for Fortran, etc. - old school notions. 

If you've been building firmware and making changes, great.  But seeing the code and not knowing it is language X, well, implies inexperience. And that's what I went with.   There are real pitfalls in machine control.  Failure to honor handshaking protocols and timing requirements is pretty common - improper handling of stacks - ignorance of hardware limitations; it all makes for a steep learning curve. It's easy for novices to see a great stack of code and think everything is taken care of.  But it isn't, it's pretty easy to bury an I/O routine with overhead if you aren't diligent. Or if you miss and IRQ while handling another, or polling for something. 

That said, real time is fun.  Do some reading up on RTOS.  Not quite the same as embedded RT control in the printers here, but the basics apply.

 

I'll step down off the soap box now ...

This post was modified 4 years ago by --
Posted : 30/10/2019 9:23 am
Sembazuru
(@sembazuru)
Prominent Member
RE: What language does Prusa use to program?

To answer the basic question as to why Prusa firmware is in C++ is because of legacy.

The early reprap printers (the forefathers of our Prusa printers) were all Arduino based. Many used a shield of stepper drivers on an Arduino Mega. The current Einsy board that the MK3 (and MK3S) uses still uses the same processor as the Arduino Mega. The Arduino ecosystem is all based on the gcc compiler (the C++ compiler from the gnu foundation), it is a free and well supported compiler. The Arduino IDE allows writing in C++ without needing to also create the .h files in most cases. (The Arduino pre-processor creates the .h file dynamically from the Arduino .ino sketch file. There are some special advanced cases that can confuse the pre-processor though.) But you can compile .cpp files in the Arduino IDE but then you need to provide the appropriate .h files. I don't know all the reasons why the Arduino folks decided on C++, so I don't know if it was an intentional choice based on the easy availability of the gcc compiler, legacy from forking from the Processing IDE, or if there were other reasons.

I do know that when programming for Arduino, advanced memory tricks can be dangerous. The microcontrollers don't have any sort of memory management units so if one isn't careful the memory could become fragmented and the stack will eventually collide with the heap causing strange crashes. It is fairly easy in C and C++ to avoid some of the techniques that would lead to memory fragmentation (for example: never use String objects, keep strings to cstrings or the continual allocation and deallocation of a variable length String object will fragment the memory), I don't know if that sort of low-level memory control is available in java or other higher level languages.

See my (limited) designs on:
Printables - https://www.printables.com/@Sembazuru
Thingiverse - https://www.thingiverse.com/Sembazuru/designs

Posted : 30/10/2019 10:41 pm
bobstro
(@bobstro)
Illustrious Member
RE: What language does Prusa use to program?
Posted by: @kryss-e

[...] Why are there a mix or .cpp and .h files? Obviously .cpp is C++, but what's .h...? Ah, a header file, referenced by a C++ file.

There are a lot of variations out there of course, but in many cases where code is intended to be used across multiple architectures or modified for specific uses, isolating all of the custom/architecture-specific settings in a header (.h) file allows those definitions to be kept separate from the main vetted code. In many cases, those header files just contain a series of definitions that are pulled into the compiler by the source (.cpp) code. With a bit of care, local .h files could be maintained and used across multiple updates of the main source (.cpp) code.

In general terms, C++ is a high(er) level language that will compile down to machine code for speed and space efficiency. It isolates the programmer from some of the underlying machine specifics while still producing efficient code. It is well suited for code that is speed, timing and space limited such as operating systems. Many higher-level languages such as Java, python and others are partially or fully interpreted which adds overhead that is prohibitive in resource-limited machines such as those used in the Mk3. Many higher-level languages allow calling C++ code where speed is needed. @sembazuru give a nice summary of the CPU history and limitations of the Mk3. I'm sure someone will object to th semantics of some of this, but that's the general idea.

Oh, and if this is of interest: It's ".cpp" and not ".c++" because of special character limitations in older filesystems. Punctuation and special characters often had specific meanings to the OS and could not be used in filenames.

 

 

My notes and disclaimers on 3D printing

and miscellaneous other tech projects
He is intelligent, but not experienced. His pattern indicates two dimensional thinking. -- Spock in Star Trek: The Wrath of Khan

Posted : 31/10/2019 12:01 am
--
 --
(@)
Illustrious Member
RE: What language does Prusa use to program?
Posted by: @sembazuru

I do know that when programming for Arduino, advanced memory tricks can be dangerous. The microcontrollers don't have any sort of memory management units so if one isn't careful the memory could become fragmented and the stack will eventually collide with the heap causing strange crashes. It is fairly easy in C and C++ to avoid some of the techniques that would lead to memory fragmentation (for example: never use String objects, keep strings to cstrings or the continual allocation and deallocation of a variable length String object will fragment the memory), I don't know if that sort of low-level memory control is available in java or other higher level languages.

Heap management is a giant problem for real time.  You can't afford to let some external process interrupt something important like timing of events. So memory management is crucial to good RT design.

Posted : 31/10/2019 1:06 am
Nikolai
(@nikolai)
Noble Member
RE: What language does Prusa use to program?
Posted by: @kryss-e

(Why are there a mix or .cpp and .h files? Obviously .cpp is C++, but what's .h...? Ah, a header file, referenced by a C++ file. Cool!)

There are tutorials out there which explains things in much more detail. For example this one:

https://www.learncpp.com/cpp-tutorial/header-files/

Often linked posts:
Going small with MMU2
Real Multi Material
My prints on Instagram

Posted : 31/10/2019 6:22 am
ArmedLeftist
(@armedleftist)
Eminent Member
RE: What language does Prusa use to program?
Posted by: @tim-m30

When an older novice runner wants to run in a 26 mile marathon, a few words of advice and caution can prevent heart attacks. 

Sure, a novice can learn C++ after using simpler languages.  But a complaint from said novice about the language as the first comment says the person wants the easy path.  Setting the expectation that the task is complex, requires suitable knowledge of key systems design, and not for the feint of heart, might actually be good advice.   

Yes, it is possible to learn all of this; classes are available and there are fair examples already in opensource libraries.  But even the Prusa code has examples of  someone coding that wasn't prepared to deal with these same issues and users suffer from their lack of knowledge and experience -- defects continue to evolve.  

On the other hand, maybe the logic of giving someone enough rope they hang themselves is my type of evil... hmm... good work!

New guy here.

I see no “complaint”, but I do now see pedantry. Bummer.

seems to me the OP was forthright and instantly humble. Refreshing  

 

Every man I meet is in some way my superior. --Ralph Waldo Emerson

Posted : 23/02/2020 4:15 pm
Background
(@background)
New Member
RE: What language does Prusa use to program?

I just need to know where to start. thanks

I like hot Latina girls

Posted : 26/02/2020 3:00 pm
Share: