From 00ca90234115836a818f43c9bbef909b34516fec Mon Sep 17 00:00:00 2001 From: reprappro Date: Mon, 15 Apr 2013 21:41:07 +0100 Subject: [PATCH] Making a start on the movement code. --- GCodes.h | 9 ++++++--- GCodes.ino | 23 ++++++++++++++++++++--- Heat.h | 12 +++++------- Heat.ino | 15 ++------------- Move.h | 11 ++++++++++- Move.ino | 29 +++++++++++++---------------- Platform.h | 13 ++++++++----- Platform.ino | 7 ++----- RepRapFirmware.h | 29 ++++------------------------- RepRapFirmware.ino | 23 +++++++++++++++++------ Webserver.ino | 10 ++-------- 11 files changed, 89 insertions(+), 92 deletions(-) diff --git a/GCodes.h b/GCodes.h index 694e13b..f1ab3ca 100644 --- a/GCodes.h +++ b/GCodes.h @@ -26,10 +26,12 @@ class GCodes { public: - GCodes(Platform* p, Move* m, Heat* h, Webserver* w); + GCodes(Platform* p, Webserver* w); void Spin(); void Init(); void Exit(); + boolean ReadMove(float* m); + boolean ReadHeat(float* h); private: @@ -37,12 +39,13 @@ class GCodes Platform* platform; boolean active; - Move* move; - Heat* heat; Webserver* webserver; unsigned long lastTime; char gcodeBuffer[GCODE_LENGTH]; int gcodePointer; + boolean moveAvailable; + boolean heatAvailable; + float moveBuffer[DRIVES]; }; #endif diff --git a/GCodes.ino b/GCodes.ino index 22f904f..efee0dd 100644 --- a/GCodes.ino +++ b/GCodes.ino @@ -21,13 +21,11 @@ Licence: GPL #include "RepRapFirmware.h" -GCodes::GCodes(Platform* p, Move* m, Heat* h, Webserver* w) +GCodes::GCodes(Platform* p, Webserver* w) { active = false; //Serial.println("GCodes constructor"); platform = p; - move = m; - heat = h; webserver = w; } @@ -41,6 +39,8 @@ void GCodes::Init() lastTime = platform->Time(); gcodePointer = 0; active = true; + moveAvailable = false; + heatAvailable = false; } @@ -80,3 +80,20 @@ void GCodes::Spin() } } + +boolean GCodes::ReadMove(float* m) +{ + if(!moveAvailable) + return false; + for(char i = 0; i < DRIVES; i++) + m[i] = moveBuffer[i]; + moveAvailable = false; +} + + +boolean GCodes::ReadHeat(float* h) +{ + +} + + diff --git a/Heat.h b/Heat.h index db0782c..f1a40bf 100644 --- a/Heat.h +++ b/Heat.h @@ -36,19 +36,17 @@ class Heat public: - Heat(Platform* p); + Heat(Platform* p, GCodes* g); void Spin(); void Init(); void Exit(); private: - Platform* platform; - boolean active; - unsigned long lastTime; - //float frac; - //float inc; - + Platform* platform; + GCodes* gCodes; + boolean active; + unsigned long lastTime; }; diff --git a/Heat.ino b/Heat.ino index 5322852..bc20d91 100644 --- a/Heat.ino +++ b/Heat.ino @@ -20,10 +20,10 @@ Licence: GPL #include "RepRapFirmware.h" -Heat::Heat(Platform* p) +Heat::Heat(Platform* p, GCodes* g) { - //Serial.println("Heat constructor"); platform = p; + gCodes = g; active = false; } @@ -49,15 +49,4 @@ void Heat::Spin() if(t - lastTime < 3000) return; lastTime = t; -/* if(frac > 1 || frac < 0) - { - inc = -inc; - //Serial.print("Temps: "); - //Serial.print(platform->getTemperature(0)); - // Serial.print(", "); - //Serial.println(platform->getTemperature(1)); - } - platform->setHeater(0, frac); - platform->setHeater(1, 1 - frac); - frac += inc;*/ } diff --git a/Move.h b/Move.h index 957f3f9..2b116b6 100644 --- a/Move.h +++ b/Move.h @@ -21,20 +21,29 @@ Licence: GPL #ifndef MOVE_H #define MOVE_H +#define BUFFER_LENGTH 10 + class Move { public: - Move(Platform* p); + Move(Platform* p, GCodes* g); void Init(); void Spin(); void Exit(); + void Qmove(); private: Platform* platform; + GCodes* gCodes; unsigned long lastTime; boolean active; + float currentPosition[AXES]; // Note - drives above AXES are always relative moves + float nextMove[DRIVES]; }; + + + #endif diff --git a/Move.ino b/Move.ino index 3085e47..6afbdfd 100644 --- a/Move.ino +++ b/Move.ino @@ -20,20 +20,19 @@ Licence: GPL #include "RepRapFirmware.h" -Move::Move(Platform* p) +Move::Move(Platform* p, GCodes* g) { //Serial.println("Move constructor"); platform = p; + gCodes = g; active = false; } void Move::Init() { lastTime = platform->Time(); - platform->SetDirection(X_AXIS, FORWARDS); - platform->SetDirection(Y_AXIS, FORWARDS); - platform->SetDirection(Z_AXIS, FORWARDS); - platform->SetDirection(3, FORWARDS); + for(char i = 0; i < DRIVES; i++) + platform->SetDirection(i, FORWARDS); active = true; } @@ -46,15 +45,13 @@ void Move::Spin() { if(!active) return; - - unsigned long t = platform->Time(); - if(t - lastTime < 300) - return; - lastTime = t; - //Serial.println("tick"); -/* platform->step(X_AXIS); - platform->step(Y_AXIS); - platform->step(Z_AXIS); - platform->step(3); - */ + Qmove(); +} + + +void Move::Qmove() +{ + if(!gCodes->ReadMove(nextMove)) + return; + } diff --git a/Platform.h b/Platform.h index 6534bfc..6a32370 100644 --- a/Platform.h +++ b/Platform.h @@ -65,6 +65,9 @@ Licence: GPL #define ENABLE 0 // What to send to enable... #define DISABLE 1 // ...and disable a drive #define DISABLE_DRIVES {false, false, true, false} // Set true to disable a drive when it becomes idle +#define LOW_STOP_PINS {3, 14, 17, -1} +#define HIGH_STOP_PINS {-1, -1, -1, -1} +#define ENDSTOP_HIT 1 // when a stop == this it is hit #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 DRIVE_STEPS_PER_UNIT {91.4286, 91.4286, 4000, 929} @@ -73,9 +76,7 @@ Licence: GPL // AXES -#define LOW_STOP_PINS {3, 14, 17} -#define HIGH_STOP_PINS {-1, -1, -1} -#define ENDSTOP_HIT 1 // when a stop == this it is hit + #define AXIS_LENGTHS {210, 210, 120} // mm #define FAST_HOME_FEEDRATES {50*60, 50*60, 1*60} // mm/min @@ -162,6 +163,8 @@ class Platform { public: + friend class Move; + Platform(RepRap* r); RepRap* GetRepRap(); @@ -248,6 +251,8 @@ class Platform char directionPins[DRIVES]; char enablePins[DRIVES]; boolean disableDrives[DRIVES]; + char lowStopPins[DRIVES]; + char highStopPins[DRIVES]; float maxFeedrates[DRIVES]; float maxAccelerations[DRIVES]; float driveStepsPerUnit[DRIVES]; @@ -256,8 +261,6 @@ class Platform // AXES - char lowStopPins[AXES]; - char highStopPins[AXES]; float axisLengths[AXES]; float fastHomeFeedrates[AXES]; diff --git a/Platform.ino b/Platform.ino index 2371562..4759c05 100644 --- a/Platform.ino +++ b/Platform.ino @@ -47,7 +47,6 @@ void Platform::Init() byte i; Serial.begin(BAUD_RATE); - //Serial.println("\n\n\nPlatform constructor"); lastTime = Time(); @@ -59,6 +58,8 @@ void Platform::Init() directionPins = DIRECTION_PINS; enablePins = ENABLE_PINS; disableDrives = DISABLE_DRIVES; + lowStopPins = LOW_STOP_PINS; + highStopPins = HIGH_STOP_PINS; maxFeedrates = MAX_FEEDRATES; maxAccelerations = MAX_ACCELERATIONS; driveStepsPerUnit = DRIVE_STEPS_PER_UNIT; @@ -67,8 +68,6 @@ void Platform::Init() // AXES - lowStopPins = LOW_STOP_PINS; - highStopPins = HIGH_STOP_PINS; axisLengths = AXIS_LENGTHS; fastHomeFeedrates = FAST_HOME_FEEDRATES; @@ -491,8 +490,6 @@ void Platform::Spin() if(Time() - lastTime < 2000000) return; lastTime = Time(); - //Serial.print("Client status: "); - //Serial.println(clientStatus); } diff --git a/RepRapFirmware.h b/RepRapFirmware.h index 8542cd1..072437b 100644 --- a/RepRapFirmware.h +++ b/RepRapFirmware.h @@ -42,12 +42,7 @@ class RepRap void Init(); void Spin(); void Exit(); - -// Platform* getPlatform(); -// Move* getMove(); -// Heat* getHeat(); -// GCodes* getGcodes(); -// Webserver* getWebserver(); + void Interrupt(); @@ -57,34 +52,18 @@ class RepRap boolean active; Move* move; Heat* heat; - GCodes* gcodes; + GCodes* gCodes; Webserver* webserver; }; #include "Configuration.h" #include "Platform.h" +#include "Webserver.h" +#include "GCodes.h" #include "Move.h" #include "Heat.h" -#include "GCodes.h" -#include "Webserver.h" -// Do nothing more in the constructor; put what you want in RepRap:Init() -inline RepRap::RepRap() -{ - active = false; - platform = new Platform(this); - move = new Move(platform); - heat = new Heat(platform); - webserver = new Webserver(platform); - gcodes = new GCodes(platform, move, heat, webserver); -} - -//inline Platform* RepRap::getPlatform() { return platform; } -//inline Move* RepRap::getMove() { return move; } -//inline Heat* RepRap::getHeat() { return heat; } -//inline GCodes* RepRap::getGcodes() { return gcodes; } -//inline Webserver* RepRap::getWebserver() { return webserver; } extern RepRap reprap; diff --git a/RepRapFirmware.ino b/RepRapFirmware.ino index 13a0dfc..0a2abae 100644 --- a/RepRapFirmware.ino +++ b/RepRapFirmware.ino @@ -52,14 +52,25 @@ RepRap reprap; //************************************************************************************************* +// Do nothing more in the constructor; put what you want in RepRap:Init() + +RepRap::RepRap() +{ + active = false; + platform = new Platform(this); + webserver = new Webserver(platform); + gCodes = new GCodes(platform, webserver); + move = new Move(platform, gCodes); + heat = new Heat(platform, gCodes); +} void RepRap::Init() { platform->Init(); + gCodes->Init(); + webserver->Init(); move->Init(); heat->Init(); - gcodes->Init(); - webserver->Init(); platform->Message(HOST_MESSAGE, "RepRapPro RepRap Firmware (Re)Started
\n"); active = true; } @@ -67,10 +78,10 @@ void RepRap::Init() void RepRap::Exit() { active = false; - webserver->Exit(); - gcodes->Exit(); heat->Exit(); move->Exit(); + gCodes->Exit(); + webserver->Exit(); platform->Exit(); } @@ -80,10 +91,10 @@ void RepRap::Spin() return; platform->Spin(); + webserver->Spin(); + gCodes->Spin(); move->Spin(); heat->Spin(); - gcodes->Spin(); - webserver->Spin(); } diff --git a/Webserver.ino b/Webserver.ino index 1633363..acf8cfb 100644 --- a/Webserver.ino +++ b/Webserver.ino @@ -119,7 +119,7 @@ boolean Webserver::MatchBoundary(char c) //**************************************************************************************************** -// Handling G Codes for the rest of the software +// Feeding G Codes to the GCodes class boolean Webserver::Available() { @@ -182,15 +182,9 @@ boolean Webserver::LoadGcodeBuffer(char* gc, boolean convertWeb) gcodeBuffer[gcodePointer] = 0; gcodePointer = 0; -// We intercept two G Codes so we can deal with file manipulation. That +// We intercept a G Code so we can deal with file manipulation. That // way things don't get out of sync. -/* if(StringStartsWith(gc, "M28")) // Upload file? - { - uploadFile(&gc[4]); - return; - }*/ - if(StringStartsWith(gcodeBuffer, "M30 ")) // Delete file? { if(!platform->DeleteFile(&gcodeBuffer[4]))