Repetier-Firmware  0.80
Repetier/Reptier.h File Reference
#include <avr/io.h>
#include "Configuration.h"
#include <inttypes.h>
#include "Print.h"
#include "WProgram.h"
#include "gcode.h"
#include "fastio.h"

Go to the source code of this file.

Data Structures

struct  TemperatureController
struct  Extruder
 Data to drive one extruder. More...
struct  PrinterState
struct  PrintLine

Defines

#define REPETIER_VERSION   "0.80dev"
#define INCLUDE_DEBUG_COMMUNICATION
#define ANALYZER_CH0   63
 print ops related debug info.
#define ANALYZER_CH1   40
#define ANALYZER_CH2   53
#define ANALYZER_CH3   65
#define ANALYZER_CH4   59
#define ANALYZER_CH5   64
#define ANALYZER_CH6   58
#define ANALYZER_CH7   57
#define ANALYZER_ON(a)
#define ANALYZER_OFF(a)
#define ANALOG_INPUT_BITS   10
#define ANALOG_INPUT_SAMPLE   5
#define ANALOG_REF_AREF   0
#define ANALOG_REF_AVCC   _BV(REFS0)
#define ANALOG_REF_INT_1_1   _BV(REFS1)
#define ANALOG_REF_INT_2_56   _BV(REFS0) | _BV(REFS1)
#define MICROSTEP1   LOW,LOW
#define MICROSTEP2   HIGH,LOW
#define MICROSTEP4   LOW,HIGH
#define MICROSTEP8   HIGH,HIGH
#define MICROSTEP16   HIGH,HIGH
#define NEW_XY_GANTRY
#define MM_PER_ARC_SEGMENT_BIG   MM_PER_ARC_SEGMENT
#define N_ARC_CORRECTION   25
#define KOMMA
#define EXT0_ANALOG_INPUTS   1
#define EXT0_SENSOR_INDEX   0
#define EXT0_ANALOG_CHANNEL   EXT0_TEMPSENSOR_PIN
#define KOMMA   ,
#define EXT1_ANALOG_INPUTS   0
#define EXT1_SENSOR_INDEX   EXT1_TEMPSENSOR_PIN
#define EXT1_ANALOG_CHANNEL
#define EXT2_ANALOG_INPUTS   0
#define EXT2_SENSOR_INDEX   EXT2_TEMPSENSOR_PIN
#define EXT2_ANALOG_CHANNEL
#define EXT3_ANALOG_INPUTS   0
#define EXT3_SENSOR_INDEX   EXT3_TEMPSENSOR_PIN
#define EXT3_ANALOG_CHANNEL
#define EXT4_ANALOG_INPUTS   0
#define EXT4_SENSOR_INDEX   EXT4_TEMPSENSOR_PIN
#define EXT4_ANALOG_CHANNEL
#define EXT5_ANALOG_INPUTS   0
#define EXT5_SENSOR_INDEX   EXT5_TEMPSENSOR_PIN
#define EXT5_ANALOG_CHANNEL
#define BED_ANALOG_INPUTS   1
#define BED_SENSOR_INDEX   EXT0_ANALOG_INPUTS+EXT1_ANALOG_INPUTS+EXT2_ANALOG_INPUTS+EXT3_ANALOG_INPUTS+EXT4_ANALOG_INPUTS+EXT5_ANALOG_INPUTS
#define BED_ANALOG_CHANNEL   KOMMA HEATED_BED_SENSOR_PIN
#define KOMMA   ,
#define DEBUG_MEMORY
#define ANALOG_INPUTS   (EXT0_ANALOG_INPUTS+EXT1_ANALOG_INPUTS+EXT2_ANALOG_INPUTS+EXT3_ANALOG_INPUTS+EXT4_ANALOG_INPUTS+EXT5_ANALOG_INPUTS+BED_ANALOG_INPUTS)
 number of analog input signals. Normally 1 for each temperature sensor
#define ANALOG_INPUT_CHANNELS   {EXT0_ANALOG_CHANNEL EXT1_ANALOG_CHANNEL EXT2_ANALOG_CHANNEL EXT3_ANALOG_CHANNEL EXT4_ANALOG_CHANNEL EXT5_ANALOG_CHANNEL BED_ANALOG_CHANNEL}
#define ANALOG_PRESCALER   _BV(ADPS0)|_BV(ADPS1)|_BV(ADPS2)
#define HardwareSerial_h
#define COMPAT_PRE1
#define uint   uint16_t
#define uint8   uint8_t
#define int8   int8_t
#define uint32   uint32_t
#define int32   int32_t
#define EXTRUDER_TIMER_VECTOR   TIMER0_COMPA_vect
#define EXTRUDER_OCR   OCR0A
#define EXTRUDER_TCCR   TCCR0A
#define EXTRUDER_TIMSK   TIMSK0
#define EXTRUDER_OCIE   OCIE0A
#define PWM_TIMER_VECTOR   TIMER0_COMPB_vect
#define PWM_OCR   OCR0B
#define PWM_TCCR   TCCR0A
#define PWM_TIMSK   TIMSK0
#define PWM_OCIE   OCIE0B
#define PREVIOUS_PLANNER_INDEX(p)   {p--;if(p==255) p = MOVE_CACHE_SIZE-1;}
#define NEXT_PLANNER_INDEX(idx)   {++idx;if(idx==MOVE_CACHE_SIZE) idx=0;}
#define PRINTER_FLAG0_STEPPER_DISABLED   1
#define PRINTER_FLAG0_SEPERATE_EXTRUDER_INT   2
#define PRINTER_FLAG0_TEMPSENSOR_DEFECT   4
#define FLAG_WARMUP   1
#define FLAG_NOMINAL   2
#define FLAG_DECELERATING   4
#define FLAG_ACCELERATION_ENABLED   8
#define FLAG_CHECK_ENDSTOPS   16
#define FLAG_SKIP_ACCELERATING   32
#define FLAG_SKIP_DEACCELERATING   64
#define FLAG_BLOCKED   128
#define FLAG_JOIN_STEPPARAMS_COMPUTED   1
#define FLAG_JOIN_END_FIXED   2
#define FLAG_JOIN_START_FIXED   4
#define FLAG_JOIN_START_RETRACT   8
#define FLAG_JOIN_END_RETRACT   16
#define FLAG_JOIN_NO_RETRACT   32
#define FLAG_JOIN_WAIT_EXTRUDER_UP   64
#define FLAG_JOIN_WAIT_EXTRUDER_DOWN   128
#define BEGIN_INTERRUPT_PROTECTED   {byte sreg=SREG;__asm volatile( "cli" ::: "memory" );
#define END_INTERRUPT_PROTECTED   SREG=sreg;}
#define ESCAPE_INTERRUPT_PROTECTED   SREG=sreg;
#define SECONDS_TO_TICKS(s)   (unsigned long)(s*(float)F_CPU)
#define CELSIUS_EXTRA_BITS   3
#define ANALOG_REDUCE_BITS   0
#define ANALOG_REDUCE_FACTOR   1
#define NUM_TEMPERATURE_LOOPS   NUM_EXTRUDER
#define TEMP_INT_TO_FLOAT(temp)   ((float)(temp)/(float)(1<<CELSIUS_EXTRA_BITS))
#define TEMP_FLOAT_TO_INT(temp)   ((int)((temp)*(1<<CELSIUS_EXTRA_BITS)))
#define STR(s)   #s
#define XSTR(s)   STR(s)

Functions

void initExtruder ()
 Initalizes all extruder.
void initHeatedBed ()
void updateTempControlVars (TemperatureController *tc)
void extruder_select (byte ext_num)
 Select extruder ext_num.
void extruder_set_temperature (float temp_celsius, byte extr)
void heated_bed_set_temperature (float temp_celsius)
void extruder_set_direction (byte dir)
 Activates the extruder stepper and sets the direction.
void extruder_disable ()
 Disable stepper motor of current extruder.
void autotunePID (float temp, int controllerId)
void extruder_step ()
 Sends the high-signal to the stepper for next extruder step.
void extruder_unstep ()
 Sets stepper signal to low for current extruder.
void extruder_enable ()
int read_raw_temperature (byte type, byte pin)
float heated_bed_get_temperature ()
float conv_raw_temp (byte type, int raw_temp)
int conv_temp_raw (byte type, float temp)
void manage_temperatures ()
bool reportTempsensorError ()
 Report defect sensors.
void process_command (GCode *code, byte bufferedCommand)
 Execute the command stored in com.
void manage_inactivity (byte debug)
void wait_until_end_of_move ()
 Waits until movement cache is empty.
void update_ramps_parameter ()
void update_extruder_flags ()
void finishNextSegment ()
void printPosition ()
void defaultLoopActions ()
void change_feedrate_multiply (int factor)
 Set feedrate multiplier.
void set_fan_speed (int speed, bool wait)
void home_axis (bool xaxis, bool yaxis, bool zaxis)
 Set fan speed 0..255.
byte get_coordinates (GCode *com)
 Home axis.
void move_steps (long x, long y, long z, long e, float feedrate, bool waitEnd, bool check_endstop)
void queue_move (byte check_endstops, byte pathOptimize)
void linear_move (long steps_remaining[])
void disable_x ()
 Disable stepper motor for x direction.
void disable_y ()
 Disable stepper motor for y direction.
void disable_z ()
 Disable stepper motor for z direction.
void enable_x ()
 Enable stepper motor for x direction.
void enable_y ()
 Enable stepper motor for y direction.
void enable_z ()
 Enable stepper motor for z direction.
void kill (byte only_steppers)
 Stop heater and stepper motors. Disable power,if possible.
void setupTimerInterrupt ()
void current_control_init ()
void microstep_init ()
void print_temperatures ()
void check_mem ()
long CPUDivU2 (unsigned int divisor)
 approximates division of F_CPU/divisor
void write_monitor ()
 Writes monitored temperatures.
void check_periodical ()
void updateStepsParameter (PrintLine *p)

Variables

const uint8 osAnalogInputChannels[] PROGMEM
uint8 osAnalogInputCounter [ANALOG_INPUTS]
uint osAnalogInputBuildup [ANALOG_INPUTS]
uint8 osAnalogInputPos
volatile uint osAnalogInputValues [ANALOG_INPUTS]
byte pwm_pos [NUM_EXTRUDER+3]
int maxadv2
float maxadvspeed
Extrudercurrent_extruder
Extruder extruder []
void(* resetFunc )(void)
byte manage_monitor
 Temp. we want to monitor with our host. 1+NUM_EXTRUDER is heated bed.
float axis_steps_per_unit []
 Number of steps per mm needed.
float inv_axis_steps_per_unit []
 Inverse of axis_steps_per_unit for faster conversion.
float max_feedrate []
 Maximum allowed feedrate.
float homing_feedrate []
float max_start_speed_units_per_second []
long max_acceleration_units_per_sq_second []
 X, Y, Z and E max acceleration in mm/s^2 for printing moves or retracts.
long max_travel_acceleration_units_per_sq_second []
 X, Y, Z max acceleration in mm/s^2 for travel moves.
unsigned long axis_steps_per_sqr_second []
unsigned long axis_travel_steps_per_sqr_second []
byte relative_mode
 Determines absolute (false) or relative Coordinates (true).
byte relative_mode_e
 Determines Absolute or Relative E Codes while in Absolute Coordinates mode. E is always relative in Relative Coordinates mode.
byte unit_inches
 0 = Units are mm, 1 = units are inches.
unsigned long previous_millis_cmd
unsigned long max_inactive_time
unsigned long stepper_inactive_time
PrinterState printer_state
PrintLine lines []
 Cache for print moves.
byte lines_write_pos
 Position where we write the next cached line move.
byte lines_pos
 Position for executing line movement.
volatile byte lines_count
 Number of lines cached 0 = nothing to do.
byte printmoveSeen
long baudrate
 Communication speed rate.
unsigned int counter_periodical
volatile byte execute_periodical
byte counter_250ms
TemperatureControllertempController [NUM_TEMPERATURE_LOOPS]
byte autotuneIndex
int waitRelax

Define Documentation

#define ANALOG_INPUT_BITS   10
#define ANALOG_INPUT_SAMPLE   5

number of analog input signals. Normally 1 for each temperature sensor

#define ANALOG_PRESCALER   _BV(ADPS0)|_BV(ADPS1)|_BV(ADPS2)
#define ANALOG_REDUCE_BITS   0
#define ANALOG_REDUCE_FACTOR   1
#define ANALOG_REF_AREF   0
#define ANALOG_REF_AVCC   _BV(REFS0)
#define ANALOG_REF_INT_1_1   _BV(REFS1)
#define ANALOG_REF_INT_2_56   _BV(REFS0) | _BV(REFS1)
#define ANALYZER_CH0   63

print ops related debug info.

Allows M111 so set bit 6 (32) which disables moves, at the first tried step. In combination with a dry run, you can test the speed of path computations, which are still performed. Writes the free RAM to output, if it is less then at the last test. Should always return values >500 for safety, since it doesn't catch every function call. Nice to tweak cache usage or for seraching for memory induced errors. Switch it off for production, it costs execution time. If enabled, writes the created generic table to serial port at startup. If enabled, steps to move and moved steps are compared.

#define ANALYZER_CH1   40
#define ANALYZER_CH2   53
#define ANALYZER_CH3   65
#define ANALYZER_CH4   59
#define ANALYZER_CH5   64
#define ANALYZER_CH6   58
#define ANALYZER_CH7   57
#define ANALYZER_OFF (   a)
#define ANALYZER_ON (   a)
#define BED_ANALOG_INPUTS   1
#define BEGIN_INTERRUPT_PROTECTED   {byte sreg=SREG;__asm volatile( "cli" ::: "memory" );
#define CELSIUS_EXTRA_BITS   3
#define COMPAT_PRE1
#define DEBUG_MEMORY
#define END_INTERRUPT_PROTECTED   SREG=sreg;}
#define ESCAPE_INTERRUPT_PROTECTED   SREG=sreg;
#define EXT0_ANALOG_INPUTS   1
#define EXT0_SENSOR_INDEX   0
#define EXT1_ANALOG_INPUTS   0
#define EXT2_ANALOG_INPUTS   0
#define EXT2_SENSOR_INDEX   EXT2_TEMPSENSOR_PIN
#define EXT3_ANALOG_INPUTS   0
#define EXT3_SENSOR_INDEX   EXT3_TEMPSENSOR_PIN
#define EXT4_ANALOG_INPUTS   0
#define EXT4_SENSOR_INDEX   EXT4_TEMPSENSOR_PIN
#define EXT5_ANALOG_INPUTS   0
#define EXT5_SENSOR_INDEX   EXT5_TEMPSENSOR_PIN
#define EXTRUDER_OCIE   OCIE0A
#define EXTRUDER_OCR   OCR0A
#define EXTRUDER_TCCR   TCCR0A
#define EXTRUDER_TIMER_VECTOR   TIMER0_COMPA_vect
#define EXTRUDER_TIMSK   TIMSK0
#define FLAG_ACCELERATION_ENABLED   8
#define FLAG_BLOCKED   128
#define FLAG_CHECK_ENDSTOPS   16
#define FLAG_DECELERATING   4
#define FLAG_JOIN_END_FIXED   2

The right speed is fixed. Don't check this block or any block to the left.

#define FLAG_JOIN_END_RETRACT   16

Wait for filament pushback, before ending move

#define FLAG_JOIN_NO_RETRACT   32

Disable retract for this line

#define FLAG_JOIN_START_FIXED   4

The left speed is fixed. Don't check left block.

#define FLAG_JOIN_START_RETRACT   8

Start filament retraction at move start

Are the step parameter computed

#define FLAG_JOIN_WAIT_EXTRUDER_DOWN   128

Wait for the extruder to finish it's down movement

#define FLAG_JOIN_WAIT_EXTRUDER_UP   64

Wait for the extruder to finish it's up movement

#define FLAG_NOMINAL   2
#define FLAG_SKIP_ACCELERATING   32
#define FLAG_SKIP_DEACCELERATING   64
#define FLAG_WARMUP   1

Marks the first step of a new move

Uncomment, to see detailed data for every move. Only for debugging purposes! Allows M111 to set bit 5 (16) which disables all commands except M111. This can be used to test your data througput or search for communication problems.

#define int32   int32_t
#define int8   int8_t
#define KOMMA
#define KOMMA   ,
#define KOMMA   ,
#define MICROSTEP1   LOW,LOW
#define MICROSTEP16   HIGH,HIGH
#define MICROSTEP2   HIGH,LOW
#define MICROSTEP4   LOW,HIGH
#define MICROSTEP8   HIGH,HIGH
#define MM_PER_ARC_SEGMENT_BIG   MM_PER_ARC_SEGMENT
#define N_ARC_CORRECTION   25
#define NEW_XY_GANTRY
#define NEXT_PLANNER_INDEX (   idx)    {++idx;if(idx==MOVE_CACHE_SIZE) idx=0;}
#define PREVIOUS_PLANNER_INDEX (   p)    {p--;if(p==255) p = MOVE_CACHE_SIZE-1;}
#define PWM_OCIE   OCIE0B
#define PWM_OCR   OCR0B
#define PWM_TCCR   TCCR0A
#define PWM_TIMER_VECTOR   TIMER0_COMPB_vect
#define PWM_TIMSK   TIMSK0
#define REPETIER_VERSION   "0.80dev"
#define SECONDS_TO_TICKS (   s)    (unsigned long)(s*(float)F_CPU)
#define STR (   s)    #s
#define TEMP_FLOAT_TO_INT (   temp)    ((int)((temp)*(1<<CELSIUS_EXTRA_BITS)))
#define TEMP_INT_TO_FLOAT (   temp)    ((float)(temp)/(float)(1<<CELSIUS_EXTRA_BITS))
#define uint   uint16_t
#define uint32   uint32_t
#define uint8   uint8_t
#define XSTR (   s)    STR(s)

Function Documentation

void autotunePID ( float  temp,
int  controllerId 
)
void change_feedrate_multiply ( int  factor)

Set feedrate multiplier.

void check_mem ( )
void check_periodical ( )
float conv_raw_temp ( byte  type,
int  raw_temp 
)
int conv_temp_raw ( byte  type,
float  temp 
)
long CPUDivU2 ( unsigned int  divisor)

approximates division of F_CPU/divisor

In the stepper interrupt a division is needed, which is a slow operation. The result is used for timer calculation where small errors are ok. This function uses lookup tables to find a fast approximation of the result.

void disable_x ( ) [inline]

Disable stepper motor for x direction.

void disable_y ( ) [inline]

Disable stepper motor for y direction.

void disable_z ( ) [inline]

Disable stepper motor for z direction.

void enable_x ( ) [inline]

Enable stepper motor for x direction.

void enable_y ( ) [inline]

Enable stepper motor for y direction.

void enable_z ( ) [inline]

Enable stepper motor for z direction.

void extruder_disable ( )

Disable stepper motor of current extruder.

void extruder_enable ( ) [inline]
void extruder_select ( byte  ext_num)

Select extruder ext_num.

This function changes and initalizes a new extruder. This is also called, after the eeprom values are changed.

void extruder_set_direction ( byte  steps) [inline]

Activates the extruder stepper and sets the direction.

void extruder_set_temperature ( float  temp_celsius,
byte  extr 
)
void extruder_step ( ) [inline]

Sends the high-signal to the stepper for next extruder step.

Call this function only, if interrupts are disabled.

void extruder_unstep ( ) [inline]

Sets stepper signal to low for current extruder.

Call this function only, if interrupts are disabled.

byte get_coordinates ( GCode com)

Home axis.

Home axis.

For the computation of the destination, the following facts are considered:

  • Are units inches or mm.
  • Reltive or absolute positioning with special case only extruder relative.
  • Offset in x and y direction for multiple extruder support.
void heated_bed_set_temperature ( float  temp_celsius)
void home_axis ( bool  xaxis,
bool  yaxis,
bool  zaxis 
)

Set fan speed 0..255.

void initExtruder ( )

Initalizes all extruder.

Updates the pin configuration needed for the extruder and activates extruder 0. Starts a interrupt based analog input reader, which is used by simple thermistors for temperature reading.

void initHeatedBed ( )
void kill ( byte  only_steppers)

Stop heater and stepper motors. Disable power,if possible.

void linear_move ( long  steps_remaining[])
void manage_inactivity ( byte  debug)

Makes updates to temperatures and heater state every call.

Is called every 100ms.

void microstep_init ( )
void move_steps ( long  x,
long  y,
long  z,
long  e,
float  feedrate,
bool  waitEnd,
bool  check_endstop 
)

Move printer the given number of steps. Puts the move into the queue. Used by e.g. homing commands.

void printPosition ( )
void process_command ( GCode code,
byte  bufferedCommand 
)

Execute the command stored in com.

void queue_move ( byte  check_endstops,
byte  pathOptimize 
)

Put a move to the current destination coordinates into the movement cache. If the cache is full, the method will wait, until a place gets free. During wait communication and temperature control is enabled.

Parameters:
check_endstopsRead endstop during move.
int read_raw_temperature ( byte  type,
byte  pin 
)

Report defect sensors.

void set_fan_speed ( int  speed,
bool  wait 
)

Acceleration in steps/s^3 in printing mode.

Acceleration in steps/s^2 in movement mode.

Update parameter used by updateTrapezoids

Computes the acceleration/decelleration steps and advanced parameter associated.

Waits until movement cache is empty.

Some commands expect no movement, before they can execute. This function waits, until the steppers are stopped. In the meanwhile it buffers incoming commands and manages temperatures.

void write_monitor ( )

Writes monitored temperatures.

This function is called every 250ms to write the monitored temperature. If monitoring is disabled, the function is not called.


Variable Documentation

unsigned long axis_steps_per_sqr_second[]

Acceleration in steps/s^3 in printing mode.

Number of steps per mm needed.

Acceleration in steps/s^2 in movement mode.

long baudrate

Communication speed rate.

unsigned int counter_periodical
volatile byte execute_periodical
float homing_feedrate[]

Inverse of axis_steps_per_unit for faster conversion.

Cache for print moves.

volatile byte lines_count

Number of lines cached 0 = nothing to do.

byte lines_pos

Position for executing line movement.

Position where we write the next cached line move.

Temp. we want to monitor with our host. 1+NUM_EXTRUDER is heated bed.

X, Y, Z and E max acceleration in mm/s^2 for printing moves or retracts.

float max_feedrate[]

Maximum allowed feedrate.

unsigned long max_inactive_time

X, Y, Z max acceleration in mm/s^2 for travel moves.

int maxadv2
float maxadvspeed
unsigned long previous_millis_cmd
const uint8 osAnalogInputChannels [] PROGMEM

Determines absolute (false) or relative Coordinates (true).

Determines Absolute or Relative E Codes while in Absolute Coordinates mode. E is always relative in Relative Coordinates mode.

void(* resetFunc)(void)
unsigned long stepper_inactive_time

0 = Units are mm, 1 = units are inches.

int waitRelax
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Defines