Broke up planner.h
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Wed, 23 Mar 2016 22:01:25 +0000 (15:01 -0700)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Wed, 23 Mar 2016 22:01:25 +0000 (15:01 -0700)
21 files changed:
src/canonical_machine.c
src/controller.c
src/plan/arc.c
src/plan/arc.h
src/plan/buffer.c
src/plan/buffer.h [new file with mode: 0644]
src/plan/command.c
src/plan/command.h
src/plan/dwell.c
src/plan/exec.c
src/plan/exec.h [new file with mode: 0644]
src/plan/feedhold.c
src/plan/feedhold.h [new file with mode: 0644]
src/plan/jog.c
src/plan/line.c
src/plan/line.h [new file with mode: 0644]
src/plan/planner.c
src/plan/planner.h
src/plan/zoid.c
src/plan/zoid.h [new file with mode: 0644]
src/stepper.c

index acc4d56a2d25f8bb718a5e0d0c5324643f9bf218..8664b5b9403b96f51fc36bb7ff823e39a2dffb33 100644 (file)
 #include "usart.h"            // for serial queue flush
 
 #include "plan/planner.h"
+#include "plan/buffer.h"
+#include "plan/feedhold.h"
 #include "plan/dwell.h"
 #include "plan/command.h"
 #include "plan/arc.h"
+#include "plan/line.h"
 
 #include <stdbool.h>
 #include <string.h>
index 52d00d0dd9ed8c12951c1692b2ce50d231f50208..205a4b6c193a193a1cab78243e20cf13d35082c8 100644 (file)
@@ -43,8 +43,9 @@
 #include "command.h"
 #include "report.h"
 
+#include "plan/buffer.h"
 #include "plan/arc.h"
-#include "plan/planner.h"
+#include "plan/feedhold.h"
 
 #include <string.h>
 #include <stdio.h>
index 1d4008f4fc6ab1fcd9f8a260b0426062ce66a891..21e2e98d4794bc0f4652a8468e22c48492cc0751 100644 (file)
@@ -34,7 +34,8 @@
 
 #include "arc.h"
 
-#include "planner.h"
+#include "buffer.h"
+#include "line.h"
 #include "config.h"
 #include "util.h"
 
index ba8bb539d52f7bfa12177323c1e042b3d9ce6e85..272ddb7fb8f88931f2c5d5958167c9b70fa97989 100644 (file)
 
 #pragma once
 
-#include "status.h"
+#include "planner.h"
+
+#define ARC_SEGMENT_LENGTH      0.1 // mm
+#define MIN_ARC_RADIUS          0.1
+#define MIN_ARC_SEGMENT_TIME    (MIN_ARC_SEGMENT_USEC / MICROSECONDS_PER_MINUTE)
 
 stat_t cm_arc_callback();
 void cm_abort_arc();
index 2354890c812501c78e765154f52a95e78c106908..38b0cdf44009291eb8ab9c7b6c02dbd55772a3d3 100644 (file)
  *    (test, get and unget have no effect)
  */
 
-#include "planner.h"
+#include "buffer.h"
 
 #include <string.h>
 
-/// buffer incr & wrap
-#define _bump(a) ((a < PLANNER_BUFFER_POOL_SIZE - 1) ? a + 1 : 0)
+
+typedef struct mpBufferPool {           // ring buffer for sub-moves
+  uint8_t buffers_available;            // running count of available buffers
+  mpBuf_t *w;                           // get_write_buffer pointer
+  mpBuf_t *q;                           // queue_write_buffer pointer
+  mpBuf_t *r;                           // get/end_run_buffer pointer
+  mpBuf_t bf[PLANNER_BUFFER_POOL_SIZE]; // buffer storage
+} mpBufferPool_t;
+
+
+mpBufferPool_t mb; // move buffer queue
 
 
 /// Returns # of available planner buffers
 uint8_t mp_get_planner_buffers_available() {return mb.buffers_available;}
 
 
+/// buffer incr & wrap
+#define _bump(a) ((a < PLANNER_BUFFER_POOL_SIZE - 1) ? a + 1 : 0)
+
+
 /// Initializes or resets buffers
 void mp_init_buffers() {
   mpBuf_t *pv;
@@ -73,7 +86,7 @@ void mp_init_buffers() {
   pv = &mb.bf[PLANNER_BUFFER_POOL_SIZE - 1];
 
   // setup ring pointers
-  for (uint8_t i = 0; i < PLANNER_BUFFER_POOL_SIZE; i++) {
+  for (int i = 0; i < PLANNER_BUFFER_POOL_SIZE; i++) {
     mb.bf[i].nx = &mb.bf[_bump(i)];
     mb.bf[i].pv = pv;
     pv = &mb.bf[i];
diff --git a/src/plan/buffer.h b/src/plan/buffer.h
new file mode 100644 (file)
index 0000000..945fe79
--- /dev/null
@@ -0,0 +1,138 @@
+/******************************************************************************\
+
+                This file is part of the Buildbotics firmware.
+
+                  Copyright (c) 2015 - 2016 Buildbotics LLC
+                            All rights reserved.
+
+     This file ("the software") is free software: you can redistribute it
+     and/or modify it under the terms of the GNU General Public License,
+      version 2 as published by the Free Software Foundation. You should
+      have received a copy of the GNU General Public License, version 2
+     along with the software. If not, see <http://www.gnu.org/licenses/>.
+
+     The software is distributed in the hope that it will be useful, but
+          WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+               Lesser General Public License for more details.
+
+       You should have received a copy of the GNU Lesser General Public
+                License along with the software.  If not, see
+                       <http://www.gnu.org/licenses/>.
+
+                For information regarding this software email:
+                  "Joseph Coffland" <joseph@buildbotics.com>
+
+\******************************************************************************/
+
+#pragma once
+
+#include "canonical_machine.h"
+
+#include <stdbool.h>
+
+/* PLANNER_BUFFER_POOL_SIZE
+ *  Should be at least the number of buffers requires to support optimal
+ *  planning in the case of very short lines or arc segments.
+ *  Suggest 12 min. Limit is 255
+ */
+#define PLANNER_BUFFER_POOL_SIZE 32
+
+/// Buffers to reserve in planner before processing new input line
+#define PLANNER_BUFFER_HEADROOM 4
+
+
+typedef enum {             // bf->move_type values
+  MOVE_TYPE_NULL,          // null move - does a no-op
+  MOVE_TYPE_ALINE,         // acceleration planned line
+  MOVE_TYPE_DWELL,         // delay with no movement
+  MOVE_TYPE_COMMAND,       // general command
+  MOVE_TYPE_JOG,           // interactive jogging
+} moveType_t;
+
+typedef enum {
+  MOVE_OFF,               // move inactive (MUST BE ZERO)
+  MOVE_NEW,               // general value if you need an initialization
+  MOVE_RUN,               // general run state (for non-acceleration moves)
+  MOVE_SKIP_BLOCK         // mark a skipped block
+} moveState_t;
+
+typedef enum {
+  SECTION_OFF,            // section inactive
+  SECTION_NEW,            // uninitialized section
+  SECTION_1st_HALF,       // first half of S curve
+  SECTION_2nd_HALF        // second half of S curve or running a BODY (cruise)
+} sectionState_t;
+
+// All the enums that equal zero must be zero. Don't change this
+typedef enum {                    // bf->buffer_state values
+  MP_BUFFER_EMPTY,                // struct is available for use (MUST BE 0)
+  MP_BUFFER_LOADING,              // being written ("checked out")
+  MP_BUFFER_QUEUED,               // in queue
+  MP_BUFFER_PENDING,              // marked as the next buffer to run
+  MP_BUFFER_RUNNING               // current running buffer
+} mpBufferState_t;
+
+
+// Callbacks
+typedef void (*cm_exec_t)(float[], float[]);
+struct mpBuffer;
+typedef stat_t (*bf_func_t)(struct mpBuffer *bf);
+
+
+typedef struct mpBuffer {         // See Planning Velocity Notes
+  struct mpBuffer *pv;            // pointer to previous buffer
+  struct mpBuffer *nx;            // pointer to next buffer
+
+  bf_func_t bf_func;              // callback to buffer exec function
+  cm_exec_t cm_func;              // callback to canonical machine
+
+  float naive_move_time;
+
+  mpBufferState_t buffer_state;   // used to manage queuing/dequeuing
+  moveType_t move_type;           // used to dispatch to run routine
+  uint8_t move_code;              // byte used by used exec functions
+  moveState_t move_state;         // move state machine sequence
+  bool replannable;               // true if move can be re-planned
+
+  float unit[AXES];               // unit vector for axis scaling & planning
+
+  float length;                   // total length of line or helix in mm
+  float head_length;
+  float body_length;
+  float tail_length;
+  // See notes on these variables, in aline()
+  float entry_velocity;           // entry velocity requested for the move
+  float cruise_velocity;          // cruise velocity requested & achieved
+  float exit_velocity;            // exit velocity requested for the move
+
+  float entry_vmax;               // max junction velocity at entry of this move
+  float cruise_vmax;              // max cruise velocity requested for move
+  float exit_vmax;                // max exit velocity possible (redundant)
+  float delta_vmax;               // max velocity difference for this move
+  float braking_velocity;         // current value for braking velocity
+
+  uint8_t jerk_axis;              // rate limiting axis used to compute jerk
+  float jerk;                     // maximum linear jerk term for this move
+  float recip_jerk;               // 1/Jm used for planning (computed & cached)
+  float cbrt_jerk;                // cube root of Jm (computed & cached)
+
+  GCodeState_t gm;                // Gode model state, used by planner & runtime
+} mpBuf_t;
+
+
+uint8_t mp_get_planner_buffers_available();
+void mp_init_buffers();
+mpBuf_t *mp_get_write_buffer();
+void mp_unget_write_buffer();
+void mp_commit_write_buffer(const uint8_t move_type);
+mpBuf_t *mp_get_run_buffer();
+uint8_t mp_free_run_buffer();
+mpBuf_t *mp_get_first_buffer();
+mpBuf_t *mp_get_last_buffer();
+/// Returns pointer to prev buffer in linked list
+#define mp_get_prev_buffer(b) ((mpBuf_t *)(b->pv))
+/// Returns pointer to next buffer in linked list
+#define mp_get_next_buffer(b) ((mpBuf_t *)(b->nx))
+void mp_clear_buffer(mpBuf_t *bf);
+void mp_copy_buffer(mpBuf_t *bf, const mpBuf_t *bp);
index 6de36dfbf98f5abb4e432a6f25dabea3ba668476..a2ef363445c0717f50e468ade75b23dca3155e02 100644 (file)
@@ -45,6 +45,8 @@
  */
 
 #include "command.h"
+
+#include "buffer.h"
 #include "canonical_machine.h"
 #include "stepper.h"
 
index 07272b1fe5ba0a63f0b254c33f779f94403b663a..1db6f8172b5e066f412049ab95d9708310a6039a 100644 (file)
@@ -27,7 +27,7 @@
 
 #pragma once
 
-#include "plan/planner.h"
+#include "plan/buffer.h"
 
 void mp_queue_command(cm_exec_t cm_exec, float *value, float *flag);
 void mp_runtime_command(mpBuf_t *bf);
index 4fa26210f95b6dfaa578e0e7614ec0cf861b6ff3..f1f6e299ba8d78bd1c08fea0cae14d132643f016 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "dwell.h"
 
-#include "planner.h"
+#include "buffer.h"
 #include "canonical_machine.h"
 #include "stepper.h"
 
index 014a0c4d2f9ad0f99ef5d509071deae9053a1ef2..2c68580a6a32ae0165d7971ef86600e4298070a4 100644 (file)
@@ -28,6 +28,7 @@
 \******************************************************************************/
 
 #include "planner.h"
+#include "buffer.h"
 #include "kinematics.h"
 #include "stepper.h"
 #include "encoder.h"
diff --git a/src/plan/exec.h b/src/plan/exec.h
new file mode 100644 (file)
index 0000000..c73bb1c
--- /dev/null
@@ -0,0 +1,33 @@
+/******************************************************************************\
+
+                This file is part of the Buildbotics firmware.
+
+                  Copyright (c) 2015 - 2016 Buildbotics LLC
+                            All rights reserved.
+
+     This file ("the software") is free software: you can redistribute it
+     and/or modify it under the terms of the GNU General Public License,
+      version 2 as published by the Free Software Foundation. You should
+      have received a copy of the GNU General Public License, version 2
+     along with the software. If not, see <http://www.gnu.org/licenses/>.
+
+     The software is distributed in the hope that it will be useful, but
+          WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+               Lesser General Public License for more details.
+
+       You should have received a copy of the GNU Lesser General Public
+                License along with the software.  If not, see
+                       <http://www.gnu.org/licenses/>.
+
+                For information regarding this software email:
+                  "Joseph Coffland" <joseph@buildbotics.com>
+
+\******************************************************************************/
+
+#pragma once
+
+#include "buffer.h"
+
+stat_t mp_exec_move();
+stat_t mp_exec_aline(mpBuf_t *bf);
index 14cb1b576f4fce04368f2963d144bf1c0aae2617..8016c18a49d656a9ea2c53d114e9f72940363301 100644 (file)
 
 \******************************************************************************/
 
+#include "feedhold.h"
+
 #include "planner.h"
+#include "buffer.h"
+#include "line.h"
+#include "zoid.h"
 #include "util.h"
 
 #include <stdbool.h>
diff --git a/src/plan/feedhold.h b/src/plan/feedhold.h
new file mode 100644 (file)
index 0000000..c02c366
--- /dev/null
@@ -0,0 +1,33 @@
+/******************************************************************************\
+
+                This file is part of the Buildbotics firmware.
+
+                  Copyright (c) 2015 - 2016 Buildbotics LLC
+                            All rights reserved.
+
+     This file ("the software") is free software: you can redistribute it
+     and/or modify it under the terms of the GNU General Public License,
+      version 2 as published by the Free Software Foundation. You should
+      have received a copy of the GNU General Public License, version 2
+     along with the software. If not, see <http://www.gnu.org/licenses/>.
+
+     The software is distributed in the hope that it will be useful, but
+          WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+               Lesser General Public License for more details.
+
+       You should have received a copy of the GNU Lesser General Public
+                License along with the software.  If not, see
+                       <http://www.gnu.org/licenses/>.
+
+                For information regarding this software email:
+                  "Joseph Coffland" <joseph@buildbotics.com>
+
+\******************************************************************************/
+
+#pragma once
+
+#include "status.h"
+
+stat_t mp_plan_hold_callback();
+stat_t mp_end_hold();
index 6e5cf36f92403bc4d86e272207286a6a38340534..3bc3fa36aec62e7d1bf9c2acad550bcbdcb6fadb 100644 (file)
@@ -26,7 +26,9 @@
 \******************************************************************************/
 
 #include "jog.h"
+
 #include "planner.h"
+#include "buffer.h"
 #include "stepper.h"
 #include "motor.h"
 #include "canonical_machine.h"
index 9cc58682cac1cdc00ac99ae21ee8d1f383af8695..0a1be46f04234e3001ffcd332c7ecf8512032d99 100644 (file)
 
 \******************************************************************************/
 
-#include "planner.h"
+#include "line.h"
 
+#include "planner.h"
+#include "exec.h"
+#include "buffer.h"
+#include "zoid.h"
 #include "controller.h"
 #include "canonical_machine.h"
 #include "stepper.h"
diff --git a/src/plan/line.h b/src/plan/line.h
new file mode 100644 (file)
index 0000000..eca0dfc
--- /dev/null
@@ -0,0 +1,33 @@
+/******************************************************************************\
+
+                This file is part of the Buildbotics firmware.
+
+                  Copyright (c) 2015 - 2016 Buildbotics LLC
+                            All rights reserved.
+
+     This file ("the software") is free software: you can redistribute it
+     and/or modify it under the terms of the GNU General Public License,
+      version 2 as published by the Free Software Foundation. You should
+      have received a copy of the GNU General Public License, version 2
+     along with the software. If not, see <http://www.gnu.org/licenses/>.
+
+     The software is distributed in the hope that it will be useful, but
+          WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+               Lesser General Public License for more details.
+
+       You should have received a copy of the GNU Lesser General Public
+                License along with the software.  If not, see
+                       <http://www.gnu.org/licenses/>.
+
+                For information regarding this software email:
+                  "Joseph Coffland" <joseph@buildbotics.com>
+
+\******************************************************************************/
+
+#pragma once
+
+#include "buffer.h"
+
+void mp_plan_block_list(mpBuf_t *bf, uint8_t *mr_flag);
+stat_t mp_aline(GCodeState_t *gm_in);
index cb90406c60728f91a3115557f70818bf8e0624aa..af276a43fabe21bf48a181e795c48ab1930b646f 100644 (file)
@@ -58,6 +58,8 @@
  */
 
 #include "planner.h"
+
+#include "buffer.h"
 #include "arc.h"
 #include "canonical_machine.h"
 #include "kinematics.h"
@@ -69,7 +71,6 @@
 #include <stdio.h>
 
 
-mpBufferPool_t mb;              // move buffer queue
 mpMoveMasterSingleton_t mm;     // context for line planning
 mpMoveRuntimeSingleton_t mr;    // context for line runtime
 
index a5eb65a1e5f4298af2113f058964575a0c3b3524..439beb13005f291906f9ffdc9af63780d2716d56 100644 (file)
 #include "util.h"
 #include "config.h"
 
-typedef enum {             // bf->move_type values
-  MOVE_TYPE_NULL,          // null move - does a no-op
-  MOVE_TYPE_ALINE,         // acceleration planned line
-  MOVE_TYPE_DWELL,         // delay with no movement
-  MOVE_TYPE_COMMAND,       // general command
-  MOVE_TYPE_JOG,           // interactive jogging
-} moveType_t;
-
-typedef enum {
-  MOVE_OFF,               // move inactive (MUST BE ZERO)
-  MOVE_NEW,               // general value if you need an initialization
-  MOVE_RUN,               // general run state (for non-acceleration moves)
-  MOVE_SKIP_BLOCK         // mark a skipped block
-} moveState_t;
-
 typedef enum {
   SECTION_HEAD,           // acceleration
   SECTION_BODY,           // cruise
-  SECTION_TAIL            // deceleration
+  SECTION_TAIL,           // deceleration
+  SECTIONS                // section count
 } moveSection_t;
-#define SECTIONS 3
-
-typedef enum {
-  SECTION_OFF,            // section inactive
-  SECTION_NEW,            // uninitialized section
-  SECTION_1st_HALF,       // first half of S curve
-  SECTION_2nd_HALF        // second half of S curve or running a BODY (cruise)
-} sectionState_t;
 
 // Most of these factors are the result of a lot of tweaking.
 // Change with caution.
-#define ARC_SEGMENT_LENGTH      ((float)0.1) // Arc segment size (mm).(0.03)
-#define MIN_ARC_RADIUS          ((float)0.1)
-
-#define JERK_MULTIPLIER         ((float)1000000)
+#define JERK_MULTIPLIER         1000000.0
 /// precision jerk must match to be considered same
-#define JERK_MATCH_PRECISION    ((float)1000)
+#define JERK_MATCH_PRECISION    1000.0
 
-#define NOM_SEGMENT_USEC        ((float)5000) // nominal segment time
+#define NOM_SEGMENT_USEC        5000.0 // nominal segment time
 /// minimum segment time / minimum move time
-#define MIN_SEGMENT_USEC        ((float)2500)
-#define MIN_ARC_SEGMENT_USEC    ((float)10000) // minimum arc segment time
+#define MIN_SEGMENT_USEC        2500.0
+#define MIN_ARC_SEGMENT_USEC    10000.0 // minimum arc segment time
 
 #define NOM_SEGMENT_TIME        (NOM_SEGMENT_USEC / MICROSECONDS_PER_MINUTE)
 #define MIN_SEGMENT_TIME        (MIN_SEGMENT_USEC / MICROSECONDS_PER_MINUTE)
-#define MIN_ARC_SEGMENT_TIME    (MIN_ARC_SEGMENT_USEC / MICROSECONDS_PER_MINUTE)
 /// minimum time a move can be is one segment
 #define MIN_TIME_MOVE           MIN_SEGMENT_TIME
 /// factor for minimum size Gcode block to process
@@ -88,93 +62,6 @@ typedef enum {
 #define MIN_SEGMENT_TIME_PLUS_MARGIN \
   ((MIN_SEGMENT_USEC + 1) / MICROSECONDS_PER_MINUTE)
 
-/* PLANNER_BUFFER_POOL_SIZE
- *  Should be at least the number of buffers requires to support optimal
- *  planning in the case of very short lines or arc segments.
- *  Suggest 12 min. Limit is 255
- */
-#define PLANNER_BUFFER_POOL_SIZE 32
-/// Buffers to reserve in planner before processing new input line
-#define PLANNER_BUFFER_HEADROOM 4
-
-// Parameters for _generate_trapezoid()
-
-/// Max iterations for convergence in the HT asymmetric case.
-#define TRAPEZOID_ITERATION_MAX             10
-
-/// Error percentage for iteration convergence. As percent - 0.01 = 1%
-#define TRAPEZOID_ITERATION_ERROR_PERCENT   ((float)0.10)
-
-/// Tolerance for "exact fit" for H and T cases
-/// allowable mm of error in planning phase
-#define TRAPEZOID_LENGTH_FIT_TOLERANCE      ((float)0.0001)
-
-/// Adaptive velocity tolerance term
-#define TRAPEZOID_VELOCITY_TOLERANCE        (max(2, bf->entry_velocity / 100))
-
-
-/// Callback to canonical_machine execution function
-typedef void (*cm_exec_t)(float[], float[]);
-
-
-// All the enums that equal zero must be zero. Don't change this
-typedef enum {                    // bf->buffer_state values
-  MP_BUFFER_EMPTY,                // struct is available for use (MUST BE 0)
-  MP_BUFFER_LOADING,              // being written ("checked out")
-  MP_BUFFER_QUEUED,               // in queue
-  MP_BUFFER_PENDING,              // marked as the next buffer to run
-  MP_BUFFER_RUNNING               // current running buffer
-} mpBufferState_t;
-
-
-typedef struct mpBuffer {         // See Planning Velocity Notes
-  struct mpBuffer *pv;            // static pointer to previous buffer
-  struct mpBuffer *nx;            // static pointer to next buffer
-  stat_t (*bf_func)(struct mpBuffer *bf); // callback to buffer exec function
-  cm_exec_t cm_func;              // callback to canonical machine
-
-  float naiive_move_time;
-
-  uint8_t buffer_state;           // used to manage queuing/dequeuing
-  uint8_t move_type;              // used to dispatch to run routine
-  uint8_t move_code;              // byte used by used exec functions
-  uint8_t move_state;             // move state machine sequence
-  uint8_t replannable;            // TRUE if move can be re-planned
-
-  float unit[AXES];               // unit vector for axis scaling & planning
-
-  float length;                   // total length of line or helix in mm
-  float head_length;
-  float body_length;
-  float tail_length;
-  // See notes on these variables, in aline()
-  float entry_velocity;           // entry velocity requested for the move
-  float cruise_velocity;          // cruise velocity requested & achieved
-  float exit_velocity;            // exit velocity requested for the move
-
-  float entry_vmax;               // max junction velocity at entry of this move
-  float cruise_vmax;              // max cruise velocity requested for move
-  float exit_vmax;                // max exit velocity possible (redundant)
-  float delta_vmax;               // max velocity difference for this move
-  float braking_velocity;         // current value for braking velocity
-
-  uint8_t jerk_axis;              // rate limiting axis used to compute jerk
-  float jerk;                     // maximum linear jerk term for this move
-  float recip_jerk;               // 1/Jm used for planning (computed & cached)
-  float cbrt_jerk;                // cube root of Jm (computed & cached)
-
-  GCodeState_t gm;                // Gode model state, used by planner & runtime
-} mpBuf_t;
-
-
-typedef struct mpBufferPool {           // ring buffer for sub-moves
-  uint8_t buffers_available;            // running count of available buffers
-  mpBuf_t *w;                           // get_write_buffer pointer
-  mpBuf_t *q;                           // queue_write_buffer pointer
-  mpBuf_t *r;                           // get/end_run_buffer pointer
-  mpBuf_t bf[PLANNER_BUFFER_POOL_SIZE]; // buffer storage
-} mpBufferPool_t;
-
 
 /// common variables for planning (move master)
 typedef struct mpMoveMasterSingleton {
@@ -254,11 +141,10 @@ typedef struct mpMoveRuntimeSingleton { // persistent runtime variables
 
 
 // Reference global scope structures
-extern mpBufferPool_t mb;           // move buffer queue
 extern mpMoveMasterSingleton_t mm;  // context for line planning
 extern mpMoveRuntimeSingleton_t mr; // context for line runtime
 
-// planner.c functions
+
 void planner_init();
 void mp_flush_planner();
 void mp_set_planner_position(uint8_t axis, const float position);
@@ -270,37 +156,3 @@ float mp_get_runtime_absolute_position(uint8_t axis);
 void mp_set_runtime_work_offset(float offset[]);
 void mp_zero_segment_velocity();
 uint8_t mp_get_runtime_busy();
-
-// line.c functions
-void mp_plan_block_list(mpBuf_t *bf, uint8_t *mr_flag);
-stat_t mp_aline(GCodeState_t *gm_in);
-
-// zoid.c functions
-void mp_calculate_trapezoid(mpBuf_t *bf);
-float mp_get_target_length(const float Vi, const float Vf, const mpBuf_t *bf);
-float mp_get_target_velocity(const float Vi, const float L, const mpBuf_t *bf);
-
-// exec.c functions
-stat_t mp_exec_move();
-stat_t mp_exec_aline(mpBuf_t *bf);
-
-// feedhold.c functions
-stat_t mp_plan_hold_callback();
-stat_t mp_end_hold();
-
-// buffer.c functions
-uint8_t mp_get_planner_buffers_available();
-void mp_init_buffers();
-mpBuf_t *mp_get_write_buffer();
-void mp_unget_write_buffer();
-void mp_commit_write_buffer(const uint8_t move_type);
-mpBuf_t *mp_get_run_buffer();
-uint8_t mp_free_run_buffer();
-mpBuf_t *mp_get_first_buffer();
-mpBuf_t *mp_get_last_buffer();
-/// Returns pointer to prev buffer in linked list
-#define mp_get_prev_buffer(b) ((mpBuf_t *)(b->pv))
-/// Returns pointer to next buffer in linked list
-#define mp_get_next_buffer(b) ((mpBuf_t *)(b->nx))
-void mp_clear_buffer(mpBuf_t *bf);
-void mp_copy_buffer(mpBuf_t *bf, const mpBuf_t *bp);
index 4df3314ebe8d0ccfa92cb9a3b189ab2373090a8d..f09096e45a42e59602f5c881d9a3c76dace42ec5 100644 (file)
 
 \******************************************************************************/
 
+#include "zoid.h"
+
 #include "planner.h"
 #include "util.h"
 
 #include <math.h>
 
+
 /*
  * This rather brute-force and long-ish function sets section lengths
  * and velocities based on the line length and velocities
@@ -150,10 +153,10 @@ void mp_calculate_trapezoid(mpBuf_t *bf) {
   // velocity you can get given the delta_vmax (maximum velocity slew)
   // supportable.
 
-  bf->naiive_move_time =
+  bf->naive_move_time =
     2 * bf->length / (bf->entry_velocity + bf->exit_velocity); // average
 
-  if (bf->naiive_move_time < MIN_SEGMENT_TIME_PLUS_MARGIN) {
+  if (bf->naive_move_time < MIN_SEGMENT_TIME_PLUS_MARGIN) {
     bf->cruise_velocity = bf->length / MIN_SEGMENT_TIME_PLUS_MARGIN;
     bf->exit_velocity = max(0.0, min(bf->cruise_velocity,
                                      (bf->entry_velocity - bf->delta_vmax)));
@@ -167,7 +170,7 @@ void mp_calculate_trapezoid(mpBuf_t *bf) {
   }
 
   // B" case: Block is short, but fits into a single body segment
-  if (bf->naiive_move_time <= NOM_SEGMENT_TIME) {
+  if (bf->naive_move_time <= NOM_SEGMENT_TIME) {
     bf->entry_velocity = bf->pv->exit_velocity;
 
     if (fp_NOT_ZERO(bf->entry_velocity)) {
diff --git a/src/plan/zoid.h b/src/plan/zoid.h
new file mode 100644 (file)
index 0000000..d948d4c
--- /dev/null
@@ -0,0 +1,48 @@
+/******************************************************************************\
+
+                This file is part of the Buildbotics firmware.
+
+                  Copyright (c) 2015 - 2016 Buildbotics LLC
+                            All rights reserved.
+
+     This file ("the software") is free software: you can redistribute it
+     and/or modify it under the terms of the GNU General Public License,
+      version 2 as published by the Free Software Foundation. You should
+      have received a copy of the GNU General Public License, version 2
+     along with the software. If not, see <http://www.gnu.org/licenses/>.
+
+     The software is distributed in the hope that it will be useful, but
+          WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+               Lesser General Public License for more details.
+
+       You should have received a copy of the GNU Lesser General Public
+                License along with the software.  If not, see
+                       <http://www.gnu.org/licenses/>.
+
+                For information regarding this software email:
+                  "Joseph Coffland" <joseph@buildbotics.com>
+
+\******************************************************************************/
+
+#pragma once
+
+#include "buffer.h"
+
+/// Max iterations for convergence in the HT asymmetric case.
+#define TRAPEZOID_ITERATION_MAX             10
+
+/// Error percentage for iteration convergence. As percent - 0.01 = 1%
+#define TRAPEZOID_ITERATION_ERROR_PERCENT   0.1
+
+/// Tolerance for "exact fit" for H and T cases
+/// allowable mm of error in planning phase
+#define TRAPEZOID_LENGTH_FIT_TOLERANCE      0.0001
+
+/// Adaptive velocity tolerance term
+#define TRAPEZOID_VELOCITY_TOLERANCE        (max(2, bf->entry_velocity / 100))
+
+
+void mp_calculate_trapezoid(mpBuf_t *bf);
+float mp_get_target_length(const float Vi, const float Vf, const mpBuf_t *bf);
+float mp_get_target_velocity(const float Vi, const float L, const mpBuf_t *bf);
index 450374bf641bae9ea4c5e4d68fb4282ebbdbfd7e..07a21768031759a4a7ac8458814d3746bc2e533b 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "config.h"
 #include "canonical_machine.h"
-#include "plan/planner.h"
+#include "plan/exec.h"
 #include "plan/command.h"
 #include "motor.h"
 #include "hardware.h"