Repetier-Firmware 0.2
Repetier/Reptier.h
Go to the documentation of this file.
00001 /*
00002     This file is part of Repetier-Firmware.
00003 
00004     Repetier-Firmware is free software: you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation, either version 3 of the License, or
00007     (at your option) any later version.
00008 
00009     Foobar is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017     This firmware is a nearly complete rewrite of the sprinter firmware
00018     by kliment (https://github.com/kliment/Sprinter)
00019     which based on Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
00020 */
00021 
00022 #include <WProgram.h>
00023 #include "gcode.h"
00024 #include "fastio.h"
00025 #ifdef SDSUPPORT
00026 #include "Sd2Card.h"
00027 #include "SdFat.h"
00028 extern void initsd();
00029 #endif
00030 
00031 #define uint uint16_t
00032 #define uint8 uint8_t
00033 #define int8 int8_t
00034 #define uint32 uint32_t
00035 #define int32 int32_t
00036 
00042 typedef struct { // Size: 12*1 Byte+12*4 Byte+4*2Byte = 68 Byte
00043   byte id;
00044   long xOffset;
00045   long yOffset;
00046   float stepsPerMM; 
00047   byte sensorType; 
00048   byte sensorPin; 
00049   byte heaterPin; 
00050   byte enablePin; 
00051   byte directionPin; 
00052   byte stepPin; 
00053   byte enableOn;
00054   byte invertDir; 
00055   float maxFeedrate;
00056   float maxAcceleration; 
00057   float maxStartFeedrate; 
00058   long extrudePosition; 
00059   int currentTemperature; 
00060   int targetTemperature; 
00061   int currentTemperatureC; 
00062   int targetTemperatureC; 
00063   long lastTemperatureUpdate; 
00064   byte heatManager; 
00065   int watchPeriod; 
00066   float advanceK; 
00067 #ifdef TEMP_PID
00068   long tempIState; 
00069   byte pidDriveMax; 
00070   long pidPGain; 
00071   long pidIGain; 
00072   long pidDGain;  
00073   byte pidMax; 
00074 #endif
00075 } Extruder;
00076 
00077 
00078 #if HEATED_BED_TYPE!=0
00079 extern long last_bed_check = 0;
00080 extern int current_bed_raw = 0;
00081 extern int target_bed_raw = 0;
00082 #endif
00083 #ifdef USE_ADVANCE
00084 extern int maxadv;
00085 extern float maxadvspeed;
00086 #endif
00087 
00088 extern Extruder *current_extruder;
00089 extern Extruder extruder[];
00090 // Initalize extruder and heated bed related pins
00091 extern void initExtruder();
00092 extern void extruder_select(byte ext_num);
00093 // Set current extruder position
00094 //extern void extruder_set_position(float pos,bool relative);
00095 // set the temperature of current extruder
00096 extern void extruder_set_temperature(int temp_celsius);
00097 extern int extruder_get_temperature();
00098 // Set temperature of heated bed
00099 extern void heated_bed_set_temperature(int temp_celsius);
00100 //extern long extruder_steps_to_position(float value,byte relative);
00101 extern void extruder_set_direction(byte steps);
00102 extern void extruder_disable();
00107 inline void extruder_step() {
00108 #if NUM_EXTRUDER==1
00109   WRITE(EXT0_STEP_PIN,HIGH);
00110 #else
00111   digitalWrite(current_extruder->stepPin,HIGH);
00112 #endif
00113 }
00118 inline void extruder_unstep() {
00119 #if NUM_EXTRUDER==1
00120   WRITE(EXT0_STEP_PIN,LOW);
00121 #else
00122   digitalWrite(current_extruder->stepPin,LOW);
00123 #endif
00124 }
00126 inline void extruder_set_direction(byte dir) {  
00127 #if NUM_EXTRUDER==1
00128   if(dir)
00129     WRITE(EXT0_DIR_PIN,!EXT0_INVERSE);
00130   else
00131     WRITE(EXT0_DIR_PIN,EXT0_INVERSE);
00132 #else
00133   digitalWrite(current_extruder->directionPin,dir!=0 ? (!(current_extruder->invertDir)) : current_extruder->invertDir);
00134 #endif
00135 }
00136 inline void extruder_enable() {
00137 #if NUM_EXTRUDER==1
00138 #if EXT0_ENABLE_PIN>-1
00139     WRITE(EXT0_ENABLE_PIN,EXT0_ENABLE_ON ); 
00140 #endif
00141 #else
00142   if(current_extruder->enablePin > -1) 
00143     digitalWrite(current_extruder->enablePin,current_extruder->enableOn); 
00144 #endif
00145 }
00146 // Read a temperature and return its value in °C
00147 // this high level method supports all known methods
00148 extern int read_raw_temperature(byte type,byte pin);
00149 extern int heated_bed_get_temperature();
00150 // Convert a raw temperature value into °C
00151 extern int conv_raw_temp(byte type,int raw_temp);
00152 // Converts a temperture temp in °C into a raw value
00153 // which can be compared with results of read_raw_temperature
00154 extern int conv_temp_raw(byte type,int temp);
00155 // Updates the temperature of all extruders and heated bed if it's time.
00156 // Toggels the heater power if necessary.
00157 extern void manage_temperatures(bool critical);
00158 
00159 extern byte manage_monitor;
00160 
00161 void process_command(GCode *code);
00162 
00163 void manage_inactivity(byte debug);
00164 
00165 extern void update_ramps_parameter();
00166 extern void finishNextSegment();
00167 extern byte get_coordinates(GCode *com);
00168 extern void queue_move(byte check_endstops);
00169 extern void linear_move(long steps_remaining[]);
00170 extern inline void disable_x();
00171 extern inline void disable_y();
00172 extern inline void disable_z();
00173 extern inline void enable_x();
00174 extern inline void enable_y();
00175 extern inline void enable_z();
00176 
00177 extern void kill(byte only_steppers);
00178 
00179 extern float axis_steps_per_unit[];
00180 extern float inv_axis_steps_per_unit[];
00181 extern float max_feedrate[];
00182 extern float homing_feedrate[];
00183 extern float max_start_speed_units_per_second[];
00184 extern long max_acceleration_units_per_sq_second[];
00185 extern long max_travel_acceleration_units_per_sq_second[];
00186 extern unsigned long axis_steps_per_sqr_second[];
00187 extern unsigned long axis_travel_steps_per_sqr_second[];
00188 extern byte relative_mode;    
00189 extern byte relative_mode_e;  
00190 
00191 extern byte unit_inches;
00192 extern unsigned long previous_millis_cmd;
00193 extern unsigned long max_inactive_time;
00194 extern unsigned long stepper_inactive_time;
00195 
00196 extern void setupTimerInterrupt();
00197 
00198 typedef struct { // RAM usage: 72 Byte
00199   byte timer0Interval;              
00200   long interval;                    
00201 #if USE_OPS==1
00202   bool filamentRetracted;           
00203 #endif
00204   volatile int extruderStepsNeeded; 
00205   unsigned long timer;              
00206   unsigned long stepNumber;         
00207 #ifdef USE_ADVANCE
00208   int advance_executed;             
00209 #endif
00210   long currentPositionSteps[4];     
00211   long destinationSteps[4];         
00212   float extruderSpeed;              
00213 #if USE_OPS==1
00214   int opsRetractSteps;              
00215   int opsPushbackSteps;             
00216   float opsMinDistance;
00217   float opsRetractDistance;
00218   float opsRetractBackslash;
00219   byte opsMode;                     
00220   float opsMoveAfter;               
00221   int opsMoveAfterSteps;            
00222 #endif
00223   long xMaxSteps;                   
00224   long yMaxSteps;                   
00225   long zMaxSteps;                   
00226   float feedrate;                   
00227   float maxJerk;                    
00228   float maxZJerk;                   
00229   long offsetX;                     
00230   long offsetY;                     
00231 } PrinterState;
00232 extern PrinterState printer_state;
00233 
00235 #define FLAG_WARMUP 1
00236 #define FLAG_ACCELERATING 2
00237 #define FLAG_DECELERATING 4
00238 #define FLAG_ACCELERATION_ENABLED 8
00239 #define FLAG_CHECK_ENDSTOPS 16
00240 #define FLAG_SKIP_ACCELERATING 32
00241 #define FLAG_SKIP_DEACCELERATING 64
00242 #define FLAG_BLOCKED 128
00243 
00245 #define FLAG_JOIN_STEPPARAMS_COMPUTED 1
00246 
00247 #define FLAG_JOIN_END_FIXED 2
00248 
00249 #define FLAG_JOIN_START_FIXED 4
00250 
00251 #define FLAG_JOIN_START_RETRACT 8
00252 
00253 #define FLAG_JOIN_END_RETRACT 16
00254 
00255 #define FLAG_JOIN_NO_RETRACT 32
00256 
00257 #define FLAG_JOIN_WAIT_EXTRUDER_UP 64
00258 
00259 #define FLAG_JOIN_WAIT_EXTRUDER_DOWN 128
00260 // Printing related data
00261 typedef struct { // RAM usage: 24*4+15 = 111 Byte
00262   byte primaryAxis;
00263   byte flags;
00264   byte joinFlags;
00265   byte halfstep;                  
00266   byte dir;                       
00267   long delta[4];                  
00268   long error[4];                  
00269   float speedX;                   
00270   float speedY;                   
00271   float speedZ;                   
00272   float fullSpeed;                
00273   float acceleration;             
00274   float distance;
00275   float startFactor;
00276   float endFactor;
00277   unsigned long fullInterval;     
00278   unsigned long stepsRemaining;   
00279   unsigned int accelSteps;        
00280   unsigned int decelSteps;        
00281   unsigned long accelerationPrim; 
00282   unsigned long facceleration;    
00283   unsigned int vMax;              
00284   unsigned int vStart;            
00285   unsigned int vEnd;              
00286 #ifdef USE_ADVANCE
00287   long advanceRate;               
00288   long advanceFull;               
00289   long advanceStart;
00290   long advanceEnd;
00291 #endif
00292 #if USE_OPS==1
00293   long opsReverseSteps;           
00294 #endif
00295 } PrintLine;
00296 
00297 extern PrintLine lines[];
00298 extern byte lines_write_pos; // Position where we write the next cached line move
00299 extern byte lines_pos; // Position for executing line movement
00300 extern volatile byte lines_count; // Number of lines cached 0 = nothing to do
00301 extern byte printmoveSeen;
00302 extern long baudrate;
00303 #if OS_ANALOG_INPUTS>0
00304 // Get last result for pin x
00305 extern volatile uint osAnalogInputValues[OS_ANALOG_INPUTS];
00306 #endif
00307 #define BEGIN_INTERRUPT_PROTECTED {byte sreg=SREG;__asm volatile( "cli" ::: "memory" );
00308 #define END_INTERRUPT_PROTECTED SREG=sreg;}
00309 #define ESCAPE_INTERRUPT_PROTECTED SREG=sreg;
00310 
00311 #define SECONDS_TO_TICKS(s) (unsigned long)(s*(float)F_CPU)
00312 extern long CPUDivU2(unsigned int divisor);
00313 
00314 #ifdef SDSUPPORT
00315 extern Sd2Card card; // ~14 Byte
00316 extern SdVolume volume;
00317 extern SdFile root;
00318 extern SdFile file;
00319 extern uint32_t filesize;
00320 extern uint32_t sdpos;
00321 extern bool sdmode;
00322 extern bool sdactive;
00323 extern bool savetosd;
00324 extern int16_t n;
00325 
00326 #endif
00327 
 All Data Structures Files Functions Variables Typedefs Friends Defines