Stepdance Software Library
Loading...
Searching...
No Matches
interpolators.hpp
1#include <sys/_stdint.h>
2#include "arm_math.h"
3/*
4Interpolator Module of the StepDance Control System
5
6This module provides buffered motion interpretation.
7
8[More Details to be Added]
9
10A part of the Mixing Metaphors Project
11(c) 2025 Ilan Moyer, Jennifer Jacobs, Devon Frost
12*/
13
14#include "core.hpp"
15
16#ifndef interpolators_h //prevent importing twice
17#define interpolators_h
18
19// TBI stands for "TIME_BASED_INTERPRETER"
20#define TBI_BLOCK_QUEUE_SIZE 100 //we'll start here. Each block currently requires 33 bytes of RAM
21#define TBI_NUM_AXES 7 //number of axes to support in the interpolator
22
23#define TBI_AXIS_INACTIVE 0
24#define TBI_AXIS_ACTIVE 1
25
26#define TBI_AXIS_X 0
27#define TBI_AXIS_Y 1
28#define TBI_AXIS_Z 2
29#define TBI_AXIS_E 3
30#define TBI_AXIS_R 4
31#define TBI_AXIS_T 5
32#define TBI_AXIS_V 6 //virtual axis. we use this for detecting the end of a move
33
34class TimeBasedInterpolator : public Plugin{
35 public:
36 TimeBasedInterpolator();
37
38 struct position{
39 float64_t x_mm; // X
40 float64_t y_mm; // Y
41 float64_t z_mm; // Z
42 float64_t e_mm; // Extruder
43 float64_t r_mm; // Radial
44 float64_t t_rad; // Theta
45 };
46
48 uint8_t block_type; //specifies which type of block this is (e.g. delay, absolute, relative, set position, etc...). We don't currently use this.
49 uint32_t block_id; //an ID # for the motion block
50 float32_t block_time_s; //total time for the block, in seconds. We'll later convert this to frames, but keep it in seconds here for legibility.
51 float32_t block_velocity_per_s;
52 struct position block_position;
53 };
54
55 int16_t add_block(struct motion_block* block_to_add); //adds a block to the queue
56 int16_t add_move(uint8_t mode, float32_t velocity_per_s, DecimalPosition x, DecimalPosition y, DecimalPosition z, DecimalPosition e, DecimalPosition r, DecimalPosition t);
57 int16_t add_timed_move(uint8_t mode, float32_t time_s, DecimalPosition x, DecimalPosition y, DecimalPosition z, DecimalPosition e, DecimalPosition r, DecimalPosition t);
58 volatile ControlParameter speed_overide = 1; //modifier for the interpolator speed.
59 void begin();
60 volatile uint16_t slots_remaining; //number of slots remaining in block queue
61 bool is_idle(); //returns true if the interpolator is idle
62 bool queue_is_full();
63 void enroll(RPC *rpc, const String& instance_name);
64
65 // BlockPorts
66 BlockPort output_x;
67 BlockPort output_y;
68 BlockPort output_z;
69 BlockPort output_e;
70 BlockPort output_r;
71 BlockPort output_t;
72
73 private:
74 // BlockPort State Variables
75 DecimalPosition output_position_x;
76 DecimalPosition output_position_y;
77 DecimalPosition output_position_z;
78 DecimalPosition output_position_e;
79 DecimalPosition output_position_r;
80 DecimalPosition output_position_t;
81
82 struct motion_block block_queue[TBI_BLOCK_QUEUE_SIZE]; // stores all pending motion blocks
83 volatile uint16_t next_write_index; //next write index in the block queue
84 volatile uint16_t next_read_index; //next read index in the block queue
85
86 void advance_head(volatile uint16_t* target_head); //handles roll-overs etc
87 void reset_block_queue();
88 void pull_block(); //pulls a block from the queue and into the active buffer
89 volatile uint8_t in_block = 0; //1 if actively reading a block
90 volatile uint16_t active_block_id; //stores the current active block
91 volatile uint8_t active_block_type; //we don't use this for now
92 volatile uint8_t active_axes[TBI_NUM_AXES]; //indexed by axis #, 0 if axis inactive, 1 if active
93 volatile float64_t active_axes_remaining_distance_mm[TBI_NUM_AXES];
94 volatile float32_t active_axes_velocity_mm_per_frame[TBI_NUM_AXES];
95 BlockPort* output_BlockPorts[TBI_NUM_AXES - 1] = {&output_x, &output_y, &output_z, &output_e, &output_r, &output_t};
96 void run_frame_on_active_block(); //run a frame of the currently active block
97 int16_t _add_move(uint8_t mode, float32_t move_time_s, float32_t velocity_per_s, DecimalPosition x, DecimalPosition y, DecimalPosition z, DecimalPosition e, DecimalPosition r, DecimalPosition t);
98
99 enum{
100 BLOCK_TYPE_INCREMENTAL,
101 BLOCK_TYPE_ABSOLUTE,
102 BLOCK_TYPE_GLOBAL
103 };
104
105 protected:
106 void run();
107};
108
109#endif
BlockPorts provide a unified interface for mapping inputs and outputs of different StepDance componen...
Definition core.hpp:148
RPC class for handling remote procedure calls over serial streams.
Definition rpc.hpp:35
Definition interpolators.hpp:47
Definition interpolators.hpp:38