Finalising (probably not...) the structure.
This commit is contained in:
parent
4f58b8fe58
commit
f4da09dbfb
8 changed files with 215 additions and 51 deletions
10
Heat.cpp
10
Heat.cpp
|
@ -20,4 +20,14 @@ Licence: GPL
|
|||
|
||||
#include "RepRapFirmware.h"
|
||||
|
||||
Heat::Heat(Platform* p)
|
||||
{
|
||||
Serial.println("Heat constructor");
|
||||
platform = p;
|
||||
time = platform->time();
|
||||
}
|
||||
|
||||
void Heat::spin()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
7
Heat.h
7
Heat.h
|
@ -36,11 +36,14 @@ class Heat
|
|||
|
||||
public:
|
||||
|
||||
Heat();
|
||||
void ControlHeaters();
|
||||
Heat(Platform* p);
|
||||
void spin();
|
||||
|
||||
private:
|
||||
|
||||
Platform* platform;
|
||||
unsigned long time;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
18
Move.cpp
18
Move.cpp
|
@ -19,3 +19,21 @@ Licence: GPL
|
|||
****************************************************************************************************/
|
||||
|
||||
#include "RepRapFirmware.h"
|
||||
|
||||
Move::Move(Platform* p)
|
||||
{
|
||||
Serial.println("Move constructor");
|
||||
platform = p;
|
||||
time = platform->time();
|
||||
platform->setDirection(X_AXIS, FORWARDS);
|
||||
}
|
||||
|
||||
void Move::spin()
|
||||
{
|
||||
unsigned long t = platform->time();
|
||||
if(t - time < 3000000)
|
||||
return;
|
||||
time = t;
|
||||
Serial.println("tick");
|
||||
platform->step(X_AXIS);
|
||||
}
|
||||
|
|
6
Move.h
6
Move.h
|
@ -25,10 +25,14 @@ class Move
|
|||
{
|
||||
public:
|
||||
|
||||
Move();
|
||||
Move(Platform* p);
|
||||
void spin();
|
||||
|
||||
private:
|
||||
|
||||
Platform* platform;
|
||||
unsigned long time;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
132
Platform.cpp
132
Platform.cpp
|
@ -21,36 +21,124 @@ Licence: GPL
|
|||
|
||||
#include "RepRapFirmware.h"
|
||||
|
||||
// Arduino initialise and loop functions
|
||||
// Put nothing in these other than calls to the RepRap equivalents
|
||||
|
||||
void setup()
|
||||
{
|
||||
reprap.init();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
reprap.spin();
|
||||
}
|
||||
|
||||
//*************************************************************************************************
|
||||
|
||||
Platform::Platform()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("Platform constructor");
|
||||
|
||||
}
|
||||
if(loadFromStore())
|
||||
return;
|
||||
|
||||
uint8_t i;
|
||||
|
||||
// DRIVES
|
||||
|
||||
void Platform::setDirection(int drive, bool forwards)
|
||||
{
|
||||
stepPins = STEP_PINS;
|
||||
directionPins = DIRECTION_PINS;
|
||||
enablePins = ENABLE_PINS;
|
||||
enableOn = ENABLE_ON;
|
||||
disableDrives = DISABLE_DRIVES;
|
||||
maxFeedrates = MAX_FEEDRATES;
|
||||
maxAccelerations = MAX_ACCELERATIONS;
|
||||
driveStepsPerUnit = DRIVE_STEPS_PER_UNIT;
|
||||
jerks = JERKS;
|
||||
driveRelativeModes = DRIVE_RELATIVE_MODES;
|
||||
|
||||
}
|
||||
|
||||
void Platform::step(int drive)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
// Don't put anything else in here; put it in
|
||||
// the Platform constructor (m/c dependent), reprap->init() (m/c independent);
|
||||
// or reprap->spin() and the other functions it calls.
|
||||
|
||||
void setup()
|
||||
for(i = 0; i < DRIVES; i++)
|
||||
{
|
||||
reprap->init();
|
||||
if(stepPins[i] >= 0)
|
||||
pinMode(stepPins[i], OUTPUT);
|
||||
if(directionPins[i] >= 0)
|
||||
pinMode(directionPins[i], OUTPUT);
|
||||
if(enablePins[i] >= 0)
|
||||
pinMode(enablePins[i], OUTPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
||||
// 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++)
|
||||
{
|
||||
reprap->spin();
|
||||
}
|
||||
if(lowStopPins[i] >= 0)
|
||||
{
|
||||
pinMode(lowStopPins[i], INPUT);
|
||||
digitalWrite(lowStopPins[i], HIGH); // Turn on pullup
|
||||
}
|
||||
if(highStopPins[i] >= 0)
|
||||
{
|
||||
pinMode(highStopPins[i], INPUT);
|
||||
digitalWrite(highStopPins[i], HIGH); // Turn on pullup
|
||||
}
|
||||
}
|
||||
|
||||
// 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++)
|
||||
{
|
||||
if(tempSensePins[i] >= 0)
|
||||
pinMode(tempSensePins[i], INPUT);
|
||||
if(heatOnPins[i] >= 0)
|
||||
pinMode(heatOnPins[i], OUTPUT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Load settings from local storage; return true if successful, false otherwise
|
||||
|
||||
bool Platform::loadFromStore()
|
||||
{
|
||||
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]));
|
||||
}
|
||||
|
||||
|
||||
|
|
66
Platform.h
66
Platform.h
|
@ -38,6 +38,10 @@ Licence: GPL
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
// Platform specific includes
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
/**************************************************************************************************/
|
||||
|
||||
// The physical capabilities of the machine
|
||||
|
@ -53,6 +57,8 @@ Licence: GPL
|
|||
|
||||
#define STEP_PINS {54, 60, 46, 26}
|
||||
#define DIRECTION_PINS {55, 61, 48, 28}
|
||||
#define FORWARDS 1
|
||||
#define BACKWARDS 0
|
||||
#define ENABLE_PINS {38, 38, 62, 38}
|
||||
#define ENABLE_ON {0, 0, 0, 0} // For inverting stepper enable pins (active low) use 0, non inverting (active high) use 1.
|
||||
#define DISABLE_DRIVES {false, false, true, false} // Set true to disable a drive when it becomes idle
|
||||
|
@ -116,6 +122,11 @@ class Platform
|
|||
void init(); // Set the machine up after a restart. If called subsequently this should set the machine up as if
|
||||
// it has just been restarted; it can do this by executing an actual restart if you like, but beware the
|
||||
// loop of death...
|
||||
void spin(); // This gets called in the main loop and should do any housekeeping needed
|
||||
|
||||
// Timing
|
||||
|
||||
unsigned long time(); // Returns elapsed microseconds since some arbitrary time
|
||||
|
||||
// Communications and data storage; opening something unsupported returns -1.
|
||||
|
||||
|
@ -132,28 +143,57 @@ class Platform
|
|||
|
||||
// Movement
|
||||
|
||||
void setDirection(int drive, bool forwards);
|
||||
void step(int drive);
|
||||
void disable(int drive); // There is no drive enable; drives get enabled automatically the first time they are used.
|
||||
void home(int axis);
|
||||
void setDirection(uint8_t drive, bool direction);
|
||||
void step(uint8_t drive);
|
||||
void disable(uint8_t drive); // There is no drive enable; drives get enabled automatically the first time they are used.
|
||||
void home(uint8_t axis);
|
||||
|
||||
// Heat and temperature
|
||||
|
||||
float getTemperature(int heater);
|
||||
void setTemperature(int heater, float temperature);
|
||||
float getTemperature(uint8_t heater);
|
||||
void setTemperature(uint8_t heater, float temperature);
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
// Load settings from local storage
|
||||
|
||||
bool loadFromStore();
|
||||
|
||||
int8_t stepPins[DRIVES];
|
||||
int8_t directionPins[DRIVES];
|
||||
int8_t enablePins[DRIVES];
|
||||
int8_t enableOn[DRIVES];
|
||||
bool disableDrives[DRIVES];
|
||||
float maxFeedrates[DRIVES];
|
||||
float maxAccelerations[DRIVES];
|
||||
float driveStepsPerUnit[DRIVES];
|
||||
float jerks[DRIVES];
|
||||
bool driveRelativeModes[DRIVES];
|
||||
|
||||
// AXES
|
||||
|
||||
int8_t lowStopPins[AXES];
|
||||
int8_t highStopPins[AXES];
|
||||
bool endstopsInverting[AXES];
|
||||
float axisLengths[AXES];
|
||||
float fastHomeFeedrates[AXES];
|
||||
|
||||
// HEATERS - Bed is assumed to be the first
|
||||
|
||||
int8_t tempSensePins[HEATERS];
|
||||
int8_t heatOnPins[HEATERS];
|
||||
float thermistorBetas[HEATERS];
|
||||
float thermistorSeriesRs[HEATERS];
|
||||
float thermistor25Rs[HEATERS];
|
||||
bool usePid[HEATERS];
|
||||
float pidKis[HEATERS];
|
||||
float pidKds[HEATERS];
|
||||
float pidKps[HEATERS];
|
||||
float pidILimits[HEATERS];
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void setup(void);
|
||||
void loop(void);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -45,10 +45,12 @@ class RepRap
|
|||
Platform* platform;
|
||||
Move* move;
|
||||
Heat* heat;
|
||||
|
||||
|
||||
};
|
||||
|
||||
extern RepRap* reprap;
|
||||
// Do nothing in the constructor; put what you want in RepRap:init()
|
||||
|
||||
inline RepRap::RepRap() {}
|
||||
|
||||
extern RepRap reprap;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -40,26 +40,25 @@ Licence: GPL
|
|||
|
||||
#include "RepRapFirmware.h"
|
||||
|
||||
// We just need one instance of RepRap; everything else is contaied within it and hidden
|
||||
|
||||
RepRap reprap;
|
||||
|
||||
RepRap* reprap = new RepRap();
|
||||
Platform* p;
|
||||
//*************************************************************************************************
|
||||
|
||||
RepRap::RepRap()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RepRap::init()
|
||||
{
|
||||
p = new Platform();
|
||||
p->setDirection(X_AXIS, true);
|
||||
platform = new Platform();
|
||||
move = new Move(platform);
|
||||
heat = new Heat(platform);
|
||||
}
|
||||
|
||||
void RepRap::spin()
|
||||
{
|
||||
p->step(X_AXIS);
|
||||
delay(5);
|
||||
platform->spin();
|
||||
move->spin();
|
||||
heat->spin();
|
||||
}
|
||||
|
||||
|
||||
|
|
Reference in a new issue