2#include <sys/_stdint.h>
8#include "interpolators.hpp"
18 void begin(
unsigned long) {}
21 int available()
override {
return 0; }
22 int read()
override {
return -1; }
23 int peek()
override {
return -1; }
26 size_t write(uint8_t)
override {
return 1; }
29 void flush()
override {}
31 operator bool()
const {
return true; }
45#define EBB_COMMAND_SIZE 2
46#define EBB_MAX_NUM_INPUT_PARAMETERS 10
47#define EBB_EXECUTE_IMMEDIATE 0
48#define EBB_EXECUTE_EMERGENCY 1
49#define EBB_EXECUTE_TO_QUEUE 2
50#define EBB_BLOCK_PENDING 1
52#define EBB_SERVO_MAX_POSITION_STEPS 500
53#define EBB_SERVO_MIN_POSITION_STEPS -500
54#define EBB_SERVO_MIDPOINT_PULSE_DURATION_US 1500
65class Eibotboard :
public Plugin{
76 void begin(usb_serial_class *target_usb_serial);
88 void set_ratio_z(
float output_units_mm,
float input_units_steps);
105 BlockPort& output_e = target_interpolator.output_e;
106 BlockPort& output_r = target_interpolator.output_r;
107 BlockPort& output_t = target_interpolator.output_t;
133 uint8_t debug_port_identified;
134 Stream *ebb_serial_port;
135 Stream *debug_serial_port;
138 float32_t xy_conversion_mm_per_step = 25.4 / 2874.0;
139 float32_t z_conversion_mm_per_step = 1.0 / 50.0;
142 void process_character(uint8_t character);
143 void reset_input_buffer();
144 void process_command(uint16_t command_value);
145 void process_string_int32();
146 static void initialize_all_commands_struct();
148 char command_string[EBB_COMMAND_SIZE + 1];
149 uint16_t command_value;
150 void (Eibotboard::*command_function)();
153 char input_buffer[255];
154 uint8_t input_buffer_write_index;
156 uint16_t input_command_value;
157 int32_t input_parameters[EBB_MAX_NUM_INPUT_PARAMETERS];
158 uint8_t num_input_parameters;
161 uint16_t block_id = 0;
162 TimeBasedInterpolator::motion_block pending_block;
163 uint8_t block_pending_flag = 0;
164 uint8_t debug_buffer_full_flag = 0;
168 int32_t servo_position_steps = 0;
169 int32_t servo_pen_up_position_steps = 0;
170 int32_t servo_pen_down_position_steps = 0;
171 float servo_rate_up_steps_per_sec = 100;
172 float servo_rate_down_steps_per_sec = 100;
175 static struct command all_commands[];
176 void command_query_current();
177 void command_query_button();
178 void command_query_variable();
179 void command_query_pen();
180 void command_stepper_servo_configure();
181 void command_stepper_move();
182 void command_set_pen();
183 void command_version();
184 void command_generic();
187 static void set_servo_position(uint16_t pulse_duration_83_3_ns, int32_t *servo_position_register);
188 static void set_servo_rate(uint16_t pulse_rate_us_per_ms,
float *servo_rate_register);
189 void debug_report_pending_block(
bool waiting_for_slot);
201class GCodeInterface :
public Plugin{
209 void begin(Stream *target_stream);
224 void begin(usb_serial_class *target_usb_serial);
225 void begin(HardwareSerialIMXRT *target_serial, uint32_t baud, uint16_t format = 0);
248 BlockPort& output_r = target_interpolator.output_r;
249 BlockPort& output_t = target_interpolator.output_t;
272 Stream *gcode_stream;
281 uint8_t receiver_state = RECEIVER_READY;
285 char input_line_buffer[255];
286 uint8_t input_line_buffer_index;
287 void reset_input_line_buffer();
288 bool process_character(uint8_t character);
291 const char *REALTIME_LETTERS =
"\x18?~!";
292 const char *TOKEN_LETTERS =
"GMXYZEABCSTHDFPN$=";
293 static const uint8_t MAX_NUM_TOKENS = 10;
294 static const uint8_t MAX_TOKEN_SIZE = 15;
296 char token_string[MAX_TOKEN_SIZE + 1];
301 struct token tokens[MAX_NUM_TOKENS];
303 int key_token_index = -1;
305 void (GCodeInterface::*code_function)();
308 struct block inbound_block;
309 bool tokenize_block();
315 EXECUTE_INTERPOLATOR,
319 char code_string[MAX_TOKEN_SIZE + 1];
320 void (GCodeInterface::*code_function)();
324 static struct code all_codes[];
326 bool preprocess_block();
327 int8_t find_code(
char *code_string);
330 bool dispatch_block();
333 static const uint8_t BLOCK_QUEUE_SIZE = 6;
334 uint8_t block_queue_read_index = 0;
335 uint8_t block_queue_write_index = 0;
336 uint8_t block_queue_slots_remaining = BLOCK_QUEUE_SIZE;
338 bool queue_is_empty();
339 struct block* pull_block();
340 struct block block_queue[BLOCK_QUEUE_SIZE];
341 void advance_head(uint8_t* target_head);
342 void reset_block_queue();
343 uint8_t next_block_execution();
346 std::map<String, DecimalPosition> execution_tokens;
347 void execute_block(block *target_block);
348 void load_tokens(block *target_block);
354 ERROR_UNSUPPORTED_CODE,
359 void send_error(uint8_t error_type);
368 void _report_parameters();
370 void _status_report();
373 void _parser_state();
376 void execute_realtime(
char command);
379 TimeBasedInterpolator target_interpolator;
382 struct TimeBasedInterpolator::position machine_position;
383 float64_t modal_feedrate_mm_per_min = 0;
BlockPorts provide a unified interface for mapping inputs and outputs of different StepDance componen...
Definition core.hpp:148
Enables using Axidraw commands from over serial as motion stream input.
Definition interfaces.hpp:65
BlockPort & output_parameter
Output BlockPort for the generated position signal of a parameter in [0, 1] range....
Definition interfaces.hpp:114
BlockPort & output_z
BlockPort for Z axis output. Use this to map to downstream components to drive position based on the ...
Definition interfaces.hpp:101
void begin()
Initialize the EiBotBoard interface. This must be called to set up the interface. Default communicati...
void begin(usb_serial_class *target_usb_serial)
Initialize the EiBotBoard interface with a specified communication interface.
BlockPort & output_x
BlockPort for X axis output. Use this to map to downstream components to drive position based on the ...
Definition interfaces.hpp:93
BlockPort & output_y
BlockPort for Y axis output. Use this to map to downstream components to drive position based on the ...
Definition interfaces.hpp:97
void set_ratio_xy(float output_units_mm, float input_units_steps)
Set the conversion ratio between XY steps and millimeters.
BlockPort & output_duration
Output BlockPort for the duration of the active move. Indicates the time the entire move is scheduled...
Definition interfaces.hpp:121
void set_ratio_z(float output_units_mm, float input_units_steps)
Set the conversion ratio between Z steps and millimeters.
BlockPort & output_parameter
Output BlockPort for the generated position signal of a parameter in [0, 1] range....
Definition interfaces.hpp:256
BlockPort & output_e
BlockPort for extruder output. Use this to map to downstream components to drive position based on G-...
Definition interfaces.hpp:243
BlockPort & output_z
BlockPort for Z axis output. Use this to map to downstream components to drive position based on G-co...
Definition interfaces.hpp:239
BlockPort & output_duration
Output BlockPort for the duration of the active move. Indicates the time the entire move is scheduled...
Definition interfaces.hpp:263
BlockPort & output_y
BlockPort for Y axis output. Use this to map to downstream components to drive position based on G-co...
Definition interfaces.hpp:235
BlockPort & output_x
Initialize the G-code interface with a USB serial port.
Definition interfaces.hpp:231
Definition interfaces.hpp:16
Enables scheduling a sequence of pre-planned motions towards given coordinate points,...
Definition interpolators.hpp:41