This firmware is intended to be a fully object-oriented highly modular control program for RepRap self-replicating 3D printers.
It owes a lot to Marlin and to the original RepRap FiveD_GCode.
This is the version for the RepRap Duet:
http://blog.think3dprint3d.com/2013/12/Duet-Arduino-Due-compatible-3DPrinter-controller.html
To edit and compile this you will also need the libraries in this repository:
https://github.com/jmgiacalone/Arduino-libraries
A complete uploadable executable version is in the directory Release/RepRapFirmware.bin in this repository. For details of how to flash it to a Duet see here:
For details of how to compile the source code, see below.
General design principles:
Naming conventions:
Structure:
There are eight main classes:
RepRap:
This is just a container class for the single instances of all the others, and otherwise does very little.
GCodes:
This class is fed GCodes, either from the web interface, or from GCode files, or from a serial interface, Interprets them, and requests actions from the RepRap machine via the other classes.
Heat:
This class implements all heating and temperature control in the RepRap machine.
Move:
This class controls all movement of the RepRap machine, both along its axes, and in its extruder drives.
Platform:
This is the only class that knows anything about the physical setup of the RepRap machine and its controlling electronics. It implements the interface between all the other classes and the RepRap machine. All the other classes are completely machine-independent (though they may declare arrays dimensioned to values #defined in Platform.h).
Network:
This class implements a basic TCP interface for the Webserver classes using LWIP.
Webserver:
This class talks to the network (via Platform) and implements a simple webserver to give an interactive interface to the RepRap machine. It uses the Knockout and Jquery Javascript libraries to achieve this. In addition, FTP and Telnet servers are provided for easier SD card file management and G-Code handling.
PrintMonitor:
This class provides methods to obtain statistics (height, filament usage etc.) from generated G-Code files and to calculate estimated print end-times for a live print.
When the software is running there is one single instance of each main class, and all the memory allocation is done on initialization. new/malloc should not be used in the general running code, and delete is never used. Each class has an Init() function that resets it to its boot-up state; the constructors merely handle that memory allocation on startup. Calling RepRap.Init() calls all the other Init()s in the right sequence.
There are other ancillary classes that are declared in the .h files for the master classes that use them. For example, Move has a DDA class that implements a Bresenham/digital differential analyser.
Timing:
There is a single interrupt chain entered via Platform.Interrupt(). This controls movement step timing, and this chain of code should be the only place that volatile declarations and structure/variable-locking are required. All the rest of the code is called sequentially and repeatedly as follows:
As of version 057r-dc42 the tick interrupt (which is set up by the Arduino core) is also used to set up ADC conversions, read the result of the last conversion, and shut down heaters when temperature errors are detected.
All the main classes have a Spin() function. These are called in a loop by the RepRap.Spin() function and implement simple timesharing. No class does, or ever should, wait inside one of its functions for anything to happen or call any sort of delay() function. The general rule is:
Can I do a thing? Yes - do it No - set a flag/timer to remind me to do it next-time-I'm-called/at-a-future-time and return.
The restriction this strategy places on almost all the code in the firmware (that it must execute quickly and never cause waits or delays) is balanced by the fact that none of that code needs to worry about synchronization, locking, or other areas of code accessing items upon which it is working. As mentioned, only the interrupt chain needs to concern itself with such problems. Unlike movement, heating (including PID controllers) does not need the fast precision of timing that interrupts alone can offer. Indeed, most heating code only needs to execute a couple of times a second.
Most data is transferred bytewise, with classes' Spin() functions typically containing code like this:
Is a byte available for me? Yes read it and add it to my buffer Is my buffer complete? Yes Act on the contents of my buffer No Return No Return
Note that it is simple to raise the "priority" of any class's activities relative to the others by calling its Spin() function more than once from RepRap.Spin().
Compiling from Source
RepRap Firmware was developed using the Eclipse IDE, which is much more powerful for big software projects than the Arduino IDE.
We use Eclipse Juno, which is available here:
http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/junosr1
You will also need the Eclipse Arduino support:
http://www.baeyens.it/eclipse/Install.html
And the Arduino IDE itself (make sure you get the one for the Due/Duet - version 1.5.5 at the time of writing):
http://arduino.cc/en/Main/Software
As of this firmware version 0.57r-dc42, the Arduino IDE must be patched to enable watchdog support. Locate function init() inside file variant.cpp (....\hardware\arduino\sam\variants\arduino_due_x) and comment out the call to WDT_disable(WDT). If you don't do this, the firmware will still work but you won't get the benefit of watchdog protection.
Finally you will need our libraries for driving the peripherals:
https://github.com/jmgiacalone/Arduino-libraries
Start by getting the Arduino IDE programming your Duet with a simple Hello World program that prints to the USB (SerialUSB.print("Hello World"); on the Due/Duet, not Serial.print("Hello World");... )
Then install Eclipse and the Arduino plugin.
Make temporary copies of RepRapFirmware.cpp and RepRapFirmware.h from your download in another folder (you will only need to do this once).
Finally use Eclipse to open the Arduino project called RepRapFirmware in the folder where you have downloaded the RepRap Firmware code. Tell Eclipse to use the Arduino-libraries files you downloaded as the local libraries. Eclipse will complain that the project already exists (which it does - it is your download). Ignore this and it will open the project anyway.
Annoyingly the first time it may also overwrite RepRapFirmware.cpp and RepRapFirmware.h. So close the project, overwrite its overwrites with the two files you saved, open the project again and refresh it. Everything should now be ship-shape. Add the libraries
Wire EMAC Lwip MCP4461 SamNonDuePin SD_HSMCI
to your project. Under no circumstances be tempted to add standard Arduino libraries for devices like Ethernet - these are for the Due, and will not work on the Duet.
You should now be able to compile the code and upload the result to the Duet.
Note on dc42 fork of this firmware:
As well as containing various bug fixes and performance improvements, I have added various functionality compared to the original RepRapPro version. The major changes are:
Note on zpl fork of this firmware:
Based on dc42's long-time proven Duet firmware fork, I have implemented a couple more features and (partially) merged in features from RepRapPro's development firmware branch. The most significant changes are:
See the "Changes in ... fork" text files for complete lists of all the changes dc42 and zpl have contributed.
Version 0.mn beta
Started: 2012-11-18 This README dated: 2014-10-12
Adrian Bowyer RepRap Professional Ltd http://reprappro.com
Licence: GPL