make the tick_info in Block a vector, assigning how ever many registered motors there are
authorJim Morris <morris@wolfman.com>
Tue, 21 Jun 2016 23:37:47 +0000 (16:37 -0700)
committerJim Morris <morris@wolfman.com>
Tue, 21 Jun 2016 23:37:47 +0000 (16:37 -0700)
  This may use slightly more memory in the long run (std::vector vs std::array), but it doesn't need the huge chunk to allocate
  which may fails as the heap is too fragmented after config

src/libs/Kernel.cpp
src/main.cpp
src/modules/robot/Block.cpp
src/modules/robot/Block.h
src/modules/robot/Conveyor.cpp
src/modules/robot/Conveyor.h
src/modules/robot/Robot.h
src/modules/utils/simpleshell/SimpleShell.cpp

index bff0af4..cc03040 100644 (file)
@@ -108,7 +108,7 @@ Kernel::Kernel(){
     add_module( this->slow_ticker = new SlowTicker());
 
     this->step_ticker = new StepTicker();
-    this->adc = new(AHB0) Adc();
+    this->adc = new Adc();
 
     // TODO : These should go into platform-specific files
     // LPC17xx-specific
@@ -150,8 +150,8 @@ Kernel::Kernel(){
     this->add_module( this->conveyor       = new Conveyor()      );
     this->add_module( this->simpleshell    = new SimpleShell()   );
 
-    this->planner = new(AHB0) Planner();
-    this->configurator   = new Configurator();
+    this->planner = new Planner();
+    this->configurator = new Configurator();
 }
 
 // return a GRBL-like query string for serial ?
index 157b875..028bd3b 100644 (file)
@@ -35,6 +35,7 @@
 #include "ConfigValue.h"
 #include "StepTicker.h"
 #include "SlowTicker.h"
+#include "Robot.h"
 
 // #include "libs/ChaNFSSD/SDFileSystem.h"
 #include "libs/nuts_bolts.h"
@@ -127,7 +128,6 @@ void init() {
     }
 #endif
 
-
     // Create and add main modules
     kernel->add_module( new(AHB0) Player() );
 
@@ -255,7 +255,7 @@ void init() {
     }
 
     // start the timers and interrupts
-    THEKERNEL->conveyor->start();
+    THEKERNEL->conveyor->start(THEROBOT->get_number_registered_motors());
     THEKERNEL->step_ticker->start();
     THEKERNEL->slow_ticker->start();
 }
index eff44e6..332aa15 100644 (file)
@@ -25,6 +25,8 @@ using std::string;
 #define STEP_TICKER_FREQUENCY THEKERNEL->step_ticker->get_frequency()
 #define STEP_TICKER_FREQUENCY_2 (STEP_TICKER_FREQUENCY*STEP_TICKER_FREQUENCY)
 
+uint8_t Block::n_actuators= 0;
+
 // A block represents a movement, it's length for each stepper motor, and the corresponding acceleration curves.
 // It's stacked on a queue, and that queue is then executed in order, to move the motors.
 // Most of the accel math is also done in this class
@@ -37,11 +39,6 @@ Block::Block()
 
 void Block::clear()
 {
-    //commands.clear();
-    //travel_distances.clear();
-    //gcodes.clear();
-    //std::vector<Gcode>().swap(gcodes); // this resizes the vector releasing its memory
-
     this->steps.fill(0);
 
     steps_event_count   = 0;
@@ -65,6 +62,9 @@ void Block::clear()
     acceleration_per_tick= 0;
     deceleration_per_tick= 0;
     total_move_ticks= 0;
+    if(tick_info.size() != n_actuators) {
+        tick_info.resize(n_actuators);
+    }
     for(auto &i : tick_info) {
         i.steps_per_tick= 0;
         i.counter= 0;
@@ -80,7 +80,7 @@ void Block::clear()
 void Block::debug() const
 {
     THEKERNEL->streams->printf("%p: steps-X:%04lu Y:%04lu Z:%04lu ", this, this->steps[0], this->steps[1], this->steps[2]);
-    for (size_t i = E_AXIS; i < k_max_actuators; ++i) {
+    for (size_t i = E_AXIS; i < n_actuators; ++i) {
         THEKERNEL->streams->printf("E%d:%04lu ", i-E_AXIS, this->steps[i]);
     }
     THEKERNEL->streams->printf("(max:%4lu) nominal:r%1.4f/s%1.4f mm:%1.4f acc:%1.2f accu:%5lu decu:%5lu rates:%10.4f entry/max: %10.4f/%10.4f ready:%d locked:%d ticking:%d recalc:%d nomlen:%d time:%f\r\n",
@@ -290,11 +290,11 @@ float Block::max_exit_speed()
 }
 
 // prepare block for the step ticker, called everytime the block changes
-// this is done during planning so does not delay tick generation and step ticker can simplh grab the next block during the interrupt
+// this is done during planning so does not delay tick generation and step ticker can simply grab the next block during the interrupt
 void Block::prepare()
 {
     float inv = 1.0F / this->steps_event_count;
-    for (uint8_t m = 0; m < k_max_actuators; m++) {
+    for (uint8_t m = 0; m < n_actuators; m++) {
         uint32_t steps = this->steps[m];
         this->tick_info[m].steps_to_move = steps;
         if(steps == 0) continue;
index 4c3477c..5a8e9fc 100644 (file)
@@ -5,15 +5,12 @@
       You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
 */
 
-#ifndef BLOCK_H
-#define BLOCK_H
+#pragma once
 
 #include <vector>
 #include <bitset>
 #include "ActuatorCoordinates.h"
 
-class Gcode;
-
 class Block {
     public:
         Block();
@@ -63,7 +60,9 @@ class Block {
         };
 
         // need info for each active motor
-        std::array<tickinfo_t, k_max_actuators> tick_info;
+        //std::array<tickinfo_t, k_max_actuators> tick_info;
+        std::vector<tickinfo_t> tick_info;
+        static uint8_t n_actuators;
 
         struct {
             bool recalculate_flag:1;             // Planner flag to recalculate trapezoids on entry junction
@@ -73,6 +72,3 @@ class Block {
             volatile bool locked:1;              // set to true when the critical data is being updated, stepticker will have to skip if this is set
         };
 };
-
-
-#endif
index 5e0d95b..8855012 100644 (file)
@@ -80,8 +80,9 @@ void Conveyor::on_module_loaded()
 }
 
 // we allocate the queue here after config is completed so we do not run out of memory during config
-void Conveyor::start()
+void Conveyor::start(uint8_t n)
 {
+    Block::n_actuators= n; // set the number of motors which determines how big the tick info vector is
     queue.resize(queue_size);
     running = true;
 }
index eda9f29..bd83824 100644 (file)
@@ -21,7 +21,7 @@ class Conveyor : public Module
 {
 public:
     Conveyor();
-    void start();
+    void start(uint8_t n_actuators);
 
     void on_module_loaded(void);
     void on_idle(void *);
index 8935440..a7dcf05 100644 (file)
@@ -58,6 +58,7 @@ class Robot : public Module {
         void set_last_probe_position(std::tuple<float, float, float, uint8_t> p) { last_probe_position = p; }
         bool solo_move(const float target[], float rate_mm_s, uint8_t naxis);
         uint8_t register_motor(StepperMotor*);
+        uint8_t get_number_registered_motors() const {return n_motors; }
 
         BaseSolution* arm_solution;                           // Selected Arm solution ( millimeters to step calculation )
 
@@ -138,9 +139,8 @@ class Robot : public Module {
         uint8_t selected_extruder;
         uint8_t n_motors;                                    //count of the motors/axis registered
 
-        // Used by Stepper, Planner
+        // Used by Planner
         friend class Planner;
-        friend class Stepper;
 };
 
 
index 0ff9fb8..874b9c4 100644 (file)
@@ -28,6 +28,7 @@
 #include "BaseSolution.h"
 #include "StepperMotor.h"
 #include "Configurator.h"
+#include "Block.h"
 
 #include "TemperatureControlPublicAccess.h"
 #include "EndstopsPublicAccess.h"
@@ -571,6 +572,8 @@ void SimpleShell::mem_command( string parameters, StreamOutput *stream)
         AHB0.debug(stream);
         AHB1.debug(stream);
     }
+
+    stream->printf("Block size: %u bytes\n", sizeof(Block));
 }
 
 static uint32_t getDeviceType()