Minor tidying.

This commit is contained in:
reprappro 2013-01-13 20:56:24 +00:00
parent f4da09dbfb
commit 8635fde719
8 changed files with 123 additions and 78 deletions

View file

@ -24,7 +24,7 @@ Heat::Heat(Platform* p)
{ {
Serial.println("Heat constructor"); Serial.println("Heat constructor");
platform = p; platform = p;
time = platform->time(); lastTime = platform->time();
} }
void Heat::spin() void Heat::spin()

2
Heat.h
View file

@ -42,7 +42,7 @@ class Heat
private: private:
Platform* platform; Platform* platform;
unsigned long time; unsigned long lastTime;
}; };

View file

@ -24,16 +24,22 @@ Move::Move(Platform* p)
{ {
Serial.println("Move constructor"); Serial.println("Move constructor");
platform = p; platform = p;
time = platform->time(); lastTime = platform->time();
platform->setDirection(X_AXIS, FORWARDS); platform->setDirection(X_AXIS, FORWARDS);
platform->setDirection(Y_AXIS, FORWARDS);
platform->setDirection(Z_AXIS, FORWARDS);
platform->setDirection(3, FORWARDS);
} }
void Move::spin() void Move::spin()
{ {
unsigned long t = platform->time(); unsigned long t = platform->time();
if(t - time < 3000000) if(t - lastTime < 300)
return; return;
time = t; lastTime = t;
Serial.println("tick"); //Serial.println("tick");
platform->step(X_AXIS); platform->step(X_AXIS);
platform->step(Y_AXIS);
platform->step(Z_AXIS);
platform->step(3);
} }

2
Move.h
View file

@ -31,7 +31,7 @@ class Move
private: private:
Platform* platform; Platform* platform;
unsigned long time; unsigned long lastTime;
}; };

View file

@ -36,22 +36,26 @@ void loop()
//************************************************************************************************* //*************************************************************************************************
Platform::Platform() Platform::Platform(RepRap* r)
{ {
reprap = r;
init();
}
void Platform::init()
{
uint8_t i;
Serial.begin(9600); Serial.begin(9600);
Serial.println("Platform constructor"); Serial.println("Platform constructor");
if(loadFromStore()) if(!loadFromStore())
return; {
uint8_t i;
// DRIVES // DRIVES
stepPins = STEP_PINS; stepPins = STEP_PINS;
directionPins = DIRECTION_PINS; directionPins = DIRECTION_PINS;
enablePins = ENABLE_PINS; enablePins = ENABLE_PINS;
enableOn = ENABLE_ON;
disableDrives = DISABLE_DRIVES; disableDrives = DISABLE_DRIVES;
maxFeedrates = MAX_FEEDRATES; maxFeedrates = MAX_FEEDRATES;
maxAccelerations = MAX_ACCELERATIONS; maxAccelerations = MAX_ACCELERATIONS;
@ -59,6 +63,27 @@ Platform::Platform()
jerks = JERKS; jerks = JERKS;
driveRelativeModes = DRIVE_RELATIVE_MODES; driveRelativeModes = DRIVE_RELATIVE_MODES;
// AXES
lowStopPins = LOW_STOP_PINS;
highStopPins = HIGH_STOP_PINS;
axisLengths = AXIS_LENGTHS;
fastHomeFeedrates = FAST_HOME_FEEDRATES;
// HEATERS - Bed is assumed to be the first
tempSensePins = TEMP_SENSE_PINS;
heatOnPins = HEAT_ON_PINS;
thermistorBetas = THERMISTOR_BETAS;
thermistorSeriesRs = THERMISTOR_SERIES_RS;
thermistor25Rs = THERMISTOR_25_RS;
usePid = USE_PID;
pidKis = PID_KIS;
pidKds = PID_KDS;
pidKps = PID_KPS;
pidILimits = PID_I_LIMITS;
}
for(i = 0; i < DRIVES; i++) for(i = 0; i < DRIVES; i++)
{ {
if(stepPins[i] >= 0) if(stepPins[i] >= 0)
@ -66,16 +91,11 @@ Platform::Platform()
if(directionPins[i] >= 0) if(directionPins[i] >= 0)
pinMode(directionPins[i], OUTPUT); pinMode(directionPins[i], OUTPUT);
if(enablePins[i] >= 0) if(enablePins[i] >= 0)
{
pinMode(enablePins[i], OUTPUT); pinMode(enablePins[i], OUTPUT);
digitalWrite(enablePins[i], ENABLE);
}
} }
// AXES
lowStopPins = LOW_STOP_PINS;
highStopPins = HIGH_STOP_PINS;
endstopsInverting = ENDSTOPS_INVERTING;
axisLengths = AXIS_LENGTHS;
fastHomeFeedrates = FAST_HOME_FEEDRATES;
for(i = 0; i < AXES; i++) for(i = 0; i < AXES; i++)
{ {
@ -91,18 +111,6 @@ Platform::Platform()
} }
} }
// HEATERS - Bed is assumed to be the first
tempSensePins = TEMP_SENSE_PINS;
heatOnPins = HEAT_ON_PINS;
thermistorBetas = THERMISTOR_BETAS;
thermistorSeriesRs = THERMISTOR_SERIES_RS;
thermistor25Rs = THERMISTOR_25_RS;
usePid = USE_PID;
pidKis = PID_KIS;
pidKds = PID_KDS;
pidKps = PID_KPS;
pidILimits = PID_I_LIMITS;
for(i = 0; i < HEATERS; i++) for(i = 0; i < HEATERS; i++)
{ {
@ -121,25 +129,7 @@ bool Platform::loadFromStore()
return false; return false;
} }
void Platform::spin()
{
}
unsigned long Platform::time()
{
return micros();
}
void Platform::setDirection(uint8_t drive, bool direction)
{
digitalWrite(directionPins[drive], direction);
}
void Platform::step(uint8_t drive)
{
digitalWrite(stepPins[drive], !digitalRead(stepPins[drive]));
}
//=========================================================================== //===========================================================================

View file

@ -57,10 +57,11 @@ Licence: GPL
#define STEP_PINS {54, 60, 46, 26} #define STEP_PINS {54, 60, 46, 26}
#define DIRECTION_PINS {55, 61, 48, 28} #define DIRECTION_PINS {55, 61, 48, 28}
#define FORWARDS 1 #define FORWARDS 1 // What to send to go...
#define BACKWARDS 0 #define BACKWARDS 0 // ...in each direction
#define ENABLE_PINS {38, 38, 62, 38} #define ENABLE_PINS {38, -1, 62, -1}
#define ENABLE_ON {0, 0, 0, 0} // For inverting stepper enable pins (active low) use 0, non inverting (active high) use 1. #define ENABLE 0 // What to send to enable...
#define DISABELE 1 // ...and disable a drive
#define DISABLE_DRIVES {false, false, true, false} // Set true to disable a drive when it becomes idle #define DISABLE_DRIVES {false, false, true, false} // Set true to disable a drive when it becomes idle
#define MAX_FEEDRATES {300, 300, 3, 45} // mm/sec #define MAX_FEEDRATES {300, 300, 3, 45} // mm/sec
#define MAX_ACCELERATIONS {800, 800, 30, 250} // mm/sec^2?? Maximum start speed for accelerated moves. #define MAX_ACCELERATIONS {800, 800, 30, 250} // mm/sec^2?? Maximum start speed for accelerated moves.
@ -72,7 +73,7 @@ Licence: GPL
#define LOW_STOP_PINS {3, 14, 17} #define LOW_STOP_PINS {3, 14, 17}
#define HIGH_STOP_PINS {-1, -1, -1} #define HIGH_STOP_PINS {-1, -1, -1}
#define ENDSTOPS_INVERTING {false, false, false} // set to true to invert the logic of the endstops; assumes LOW and HIGH behave the same #define ENDSTOPS_INVERTING false // set to true to invert the logic of the endstops (i.e. 0 = hit)
#define AXIS_LENGTHS {210, 210, 120} // mm #define AXIS_LENGTHS {210, 210, 120} // mm
#define FAST_HOME_FEEDRATES {50*60, 50*60, 1*60} // mm/min #define FAST_HOME_FEEDRATES {50*60, 50*60, 1*60} // mm/min
@ -82,7 +83,7 @@ Licence: GPL
// HEATERS - Bed is assumed to be the first // HEATERS - Bed is assumed to be the first
#define TEMP_SENSE_PINS {10, 9} // Analogue numbering #define TEMP_SENSE_PINS {10, 9} // Analogue pin numbers
#define HEAT_ON_PINS {8, 9} #define HEAT_ON_PINS {8, 9}
#define THERMISTOR_BETAS {3480.0, 3960.0} // Bed thermistor: RS 484-0149; EPCOS B57550G103J; Extruder thermistor: RS 198-961 #define THERMISTOR_BETAS {3480.0, 3960.0} // Bed thermistor: RS 484-0149; EPCOS B57550G103J; Extruder thermistor: RS 198-961
#define THERMISTOR_SERIES_RS {4700, 4700} // Ohms in series with the thermistors #define THERMISTOR_SERIES_RS {4700, 4700} // Ohms in series with the thermistors
@ -109,11 +110,13 @@ Licence: GPL
/****************************************************************************************************/ /****************************************************************************************************/
class RepRap;
class Platform class Platform
{ {
public: public:
Platform(); Platform(RepRap* r);
//------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------
@ -128,6 +131,10 @@ class Platform
unsigned long time(); // Returns elapsed microseconds since some arbitrary time unsigned long time(); // Returns elapsed microseconds since some arbitrary time
void setInterrupt(long t); // Set a regular interrupt going every t microseconds; if t is -ve turn interrupt off
void interrupt(); // The function that the interrupt calls
// Communications and data storage; opening something unsupported returns -1. // Communications and data storage; opening something unsupported returns -1.
char* FileList(); // Returns a comma-separated?? list of all the files on local storage (for example on an SD card). char* FileList(); // Returns a comma-separated?? list of all the files on local storage (for example on an SD card).
@ -161,10 +168,13 @@ class Platform
bool loadFromStore(); bool loadFromStore();
RepRap* reprap;
// DIRIVES
int8_t stepPins[DRIVES]; int8_t stepPins[DRIVES];
int8_t directionPins[DRIVES]; int8_t directionPins[DRIVES];
int8_t enablePins[DRIVES]; int8_t enablePins[DRIVES];
int8_t enableOn[DRIVES];
bool disableDrives[DRIVES]; bool disableDrives[DRIVES];
float maxFeedrates[DRIVES]; float maxFeedrates[DRIVES];
float maxAccelerations[DRIVES]; float maxAccelerations[DRIVES];
@ -176,7 +186,6 @@ class Platform
int8_t lowStopPins[AXES]; int8_t lowStopPins[AXES];
int8_t highStopPins[AXES]; int8_t highStopPins[AXES];
bool endstopsInverting[AXES];
float axisLengths[AXES]; float axisLengths[AXES];
float fastHomeFeedrates[AXES]; float fastHomeFeedrates[AXES];
@ -195,5 +204,35 @@ class Platform
}; };
inline unsigned long Platform::time()
{
return micros();
}
inline void Platform::spin()
{
}
inline void Platform::setInterrupt(long t)
{
}
inline void Platform::interrupt()
{
reprap->interrupt(); // Put nothing else in here
}
inline void Platform::setDirection(uint8_t drive, bool direction)
{
digitalWrite(directionPins[drive], direction);
}
inline void Platform::step(uint8_t drive)
{
digitalWrite(stepPins[drive], !digitalRead(stepPins[drive]));
}
#endif #endif

View file

@ -27,10 +27,9 @@ Licence: GPL
#define DATE "2012-11-18" #define DATE "2012-11-18"
#define LAST_AUTHOR "reprappro.com" #define LAST_AUTHOR "reprappro.com"
#include "Configuration.h" class Platform;
#include "Platform.h" class Move;
#include "Move.h" class Heat;
#include "Heat.h"
class RepRap class RepRap
{ {
@ -39,6 +38,7 @@ class RepRap
RepRap(); RepRap();
void init(); void init();
void spin(); void spin();
void interrupt();
private: private:
@ -47,6 +47,11 @@ class RepRap
Heat* heat; Heat* heat;
}; };
#include "Configuration.h"
#include "Platform.h"
#include "Move.h"
#include "Heat.h"
// Do nothing in the constructor; put what you want in RepRap:init() // Do nothing in the constructor; put what you want in RepRap:init()
inline RepRap::RepRap() {} inline RepRap::RepRap() {}

View file

@ -49,7 +49,7 @@ RepRap reprap;
void RepRap::init() void RepRap::init()
{ {
platform = new Platform(); platform = new Platform(this);
move = new Move(platform); move = new Move(platform);
heat = new Heat(platform); heat = new Heat(platform);
} }
@ -61,6 +61,11 @@ void RepRap::spin()
heat->spin(); heat->spin();
} }
void RepRap::interrupt()
{
}