Support 4 motors

Partial support for > 4 motors, needs a clean way of defining wiring.
This commit is contained in:
Filip Ayazi 2023-03-09 00:05:12 +00:00
parent 51b5b670e6
commit 1b3e251783
6 changed files with 57 additions and 28 deletions

View file

@ -11,8 +11,8 @@
unsigned long retreat_steps = 5000;
unsigned long home_move_steps = 100000;
unsigned long axis_max[STAGE_N_MOTORS];
const uint8_t axis_max_eeprom = sizeof(long)*(STAGE_N_MOTORS+2);
unsigned long axis_max[STAGE_MAX_MOTORS];
const uint8_t axis_max_eeprom = 200+sizeof(long)*(STAGE_MAX_MOTORS+2);
#ifdef ENDSTOPS_MIN
const uint8_t endstops_min_pins[] = WIRING_ENDSTOPS_MIN;
#endif

View file

@ -10,18 +10,22 @@
#include "main.h"
#include <ComPort.h>
#if MAX_STEPPERS > 3 && !defined(WIRING_ADDITIONAL_STEPPER)
#error "Define WIRING_ADDITIONAL_STEPPER to support 4th stepper"
#endif
// The array below has 3 stepper objects, for X,Y,Z respectively
const uint8_t n_motors = STAGE_N_MOTORS;
uint8_t n_motors = 3;
const uint8_t stage_position_eeprom = 0;
long min_step_delay = -1;
const uint8_t min_step_delay_eeprom = stage_position_eeprom + sizeof(long) * n_motors;
const uint8_t min_step_delay_eeprom = stage_position_eeprom + sizeof(long) * STAGE_MAX_MOTORS;
long ramp_time = -1;
const uint8_t ramp_time_eeprom = min_step_delay_eeprom + sizeof(long);
const uint8_t axis_max_eeprom = ramp_time_eeprom + sizeof(long);
const uint8_t non_blocking_moves_eeprom = axis_max_eeprom + sizeof(long);
Stepper *motors[n_motors];
signed long current_pos[n_motors];
long steps_remaining[n_motors];
Stepper *motors[STAGE_MAX_MOTORS];
signed long current_pos[STAGE_MAX_MOTORS];
long steps_remaining[STAGE_MAX_MOTORS];
bool stage_moving = false;
bool notify_on_stop = false;
@ -33,7 +37,15 @@ void stage_setup()
motors[0] = new Stepper(8, WIRING_MOTOR_X);
motors[1] = new Stepper(8, WIRING_MOTOR_Y);
motors[2] = new Stepper(8, WIRING_MOTOR_Z);
EACH_MOTOR
#if STAGE_MAX_MOTORS > 3
//TODO: support >4 stepppers
for (int i = 0; i < STAGE_MAX_MOTORS - 3; i++)
{
motors[i+3] = new Stepper(8, WIRING_ADDITIONAL_STEPPER);
}
#endif
EACH_MAX_MOTOR
{
motors[i]->setSpeed(10); // as a default set to 10 rpm, though this is ignored...
steps_remaining[i] = 0;
@ -85,13 +97,13 @@ void print_position()
}
unsigned long move_start_time = 0;
unsigned long distance_moved[n_motors];
long displacement[n_motors];
unsigned long distance_moved[STAGE_MAX_MOTORS];
long displacement[STAGE_MAX_MOTORS];
float final_scaled_t;
float step_delay[n_motors];
int8_t move_directions[n_motors];
float step_delay[STAGE_MAX_MOTORS];
int8_t move_directions[STAGE_MAX_MOTORS];
void start_move(long displ[n_motors])
void start_move(long displ[STAGE_MAX_MOTORS])
{
// move all the axes in a nice move
// split displacements into magnitude and direction, and find max. travel
@ -219,13 +231,10 @@ void stage_mrz(String command)
void stage_mr(String command)
{
char *args[3];
parse_arguments(args, command, 3);
char *args[STAGE_MAX_MOTORS];
parse_arguments(args, command, n_motors);
EACH_MOTOR
{
if (i>3)
continue;
displacement[i] = atol(args[i]);
free(args[i]);
}
@ -300,6 +309,19 @@ void update_blocking_moves(String command)
}
}
void stage_n_motors(String command)
{
char *args[1];
parse_arguments(args, command, 1);
if (args[0][0] != '?')
n_motors = atoi(args[0]);
comPort->print("n_motors ");
comPort->println(n_motors);
free(args[0]);
}
void stage_zero(String command)
{
EACH_MOTOR current_pos[i] = 0;
@ -348,4 +370,5 @@ extern const Command stage_commands[] = {
{"moving", is_stage_moving},
{"notify_on_stop", activate_notify_on_stop},
{"blocking_moves", update_blocking_moves},
{"n_motors", stage_n_motors},
END_COMMAND};

View file

@ -3,7 +3,9 @@
#include "main.h"
#include <Arduino.h>
#define EACH_MOTOR for (int i = 0; i < STAGE_N_MOTORS; i++)
#define EACH_MOTOR for (int i = 0; i < n_motors; i++)
#define EACH_MAX_MOTOR for (int i = 0; i < STAGE_MAX_MOTORS; i++)
void stage_setup();
void stage_loop();
@ -21,6 +23,7 @@ void stage_ramp_time(String command);
void stage_zero(String command);
void start_move(long displ[]);
void stage_stop(String command);
void stage_n_motors(String command);
extern const Command stage_commands[];
//we want to expose these for endstops (and potentially other modules)