Add endstops, light_sensor, test, many fixes
- Added endstop and light_sensor module - Improved configuration by splitting wiring configs to boards.h - Added a unit test for argument parsing - Fixed many smaller bugs
This commit is contained in:
parent
8f66bb7da9
commit
35d969aadd
16 changed files with 875 additions and 64 deletions
|
|
@ -2,11 +2,13 @@
|
|||
#include "config.h"
|
||||
#include <limits.h>
|
||||
#include <Arduino.h>
|
||||
#include <EEPROM.h>
|
||||
#ifdef SUPPORT_EEPROM
|
||||
#include <EEPROM.h>
|
||||
#else
|
||||
#include "dummyEEPROM.h"
|
||||
#endif
|
||||
#include "main.h"
|
||||
|
||||
#define EACH_MOTOR for (int i = 0; i < n_motors; i++)
|
||||
|
||||
// The array below has 3 stepper objects, for X,Y,Z respectively
|
||||
const int n_motors = 3;
|
||||
long min_step_delay;
|
||||
|
|
@ -18,22 +20,14 @@ Stepper *motors[n_motors];
|
|||
signed long current_pos[n_motors];
|
||||
long steps_remaining[n_motors];
|
||||
|
||||
bool test_mode = false;
|
||||
bool stage_moving = false;
|
||||
|
||||
void stage_setup()
|
||||
{
|
||||
// get the stepoper objects from the motor shield objects
|
||||
|
||||
#if defined(SANGABOARDv2)
|
||||
motors[0] = new Stepper(8, 13, 12, 11, 10);
|
||||
motors[1] = new Stepper(8, 9, 8, 7, 6);
|
||||
motors[2] = new Stepper(8, 5, 4, 3, 2);
|
||||
#elif defined(SANGABOARDv3)
|
||||
motors[0] = new Stepper(8, 8, 9, 10, 11);
|
||||
motors[1] = new Stepper(8, 5, 13, 4, 12);
|
||||
motors[2] = new Stepper(8, 6, 7, A5, A4);
|
||||
#endif
|
||||
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
|
||||
{
|
||||
motors[i]->setSpeed(10); // as a default set to 10 rpm, though this is ignored...
|
||||
|
|
@ -84,12 +78,12 @@ void print_position()
|
|||
|
||||
unsigned long move_start_time = 0;
|
||||
unsigned long distance_moved[n_motors];
|
||||
unsigned long displacement[n_motors];
|
||||
long displacement[n_motors];
|
||||
float final_scaled_t;
|
||||
float step_delay[n_motors];
|
||||
long move_directions[n_motors];
|
||||
int8_t move_directions[n_motors];
|
||||
|
||||
void start_move(unsigned long displ[n_motors])
|
||||
void start_move(long displ[n_motors])
|
||||
{
|
||||
// move all the axes in a nice move
|
||||
// split displacements into magnitude and direction, and find max. travel
|
||||
|
|
@ -103,7 +97,7 @@ void start_move(unsigned long displ[n_motors])
|
|||
}
|
||||
// scale the step delays so the move goes in a straight line, with >=1 motor
|
||||
// running at max. speed.
|
||||
EACH_MOTOR if (displacement[i] > 0)
|
||||
EACH_MOTOR {if (displacement[i] > 0)
|
||||
{
|
||||
step_delay[i] = float(max_steps) / float(displacement[i]) * float(min_step_delay);
|
||||
}
|
||||
|
|
@ -111,7 +105,7 @@ void start_move(unsigned long displ[n_motors])
|
|||
{
|
||||
step_delay[i] = 9999999999;
|
||||
}
|
||||
|
||||
}
|
||||
EACH_MOTOR distance_moved[i] = 0;
|
||||
move_start_time = micros();
|
||||
final_scaled_t = (float)max_steps * min_step_delay; //NB total time taken will be final_scaled_t + 2*ramp_time
|
||||
|
|
@ -157,7 +151,7 @@ void stage_loop()
|
|||
stage_moving = false;
|
||||
EACH_MOTOR
|
||||
{
|
||||
if (distance_moved[i] < displacement[i])
|
||||
if ((long) distance_moved[i] < displacement[i])
|
||||
{
|
||||
stage_moving = true; //only if all axes are done are we truly finished.
|
||||
|
||||
|
|
@ -173,12 +167,13 @@ void stage_loop()
|
|||
|
||||
void stage_move_single_axis(uint8_t axis, String command)
|
||||
{
|
||||
String args[1];
|
||||
char * args[1];
|
||||
parse_arguments(args, command, 1);
|
||||
int move = args[0].toInt();
|
||||
int move = atoi(args[0]);
|
||||
EACH_MOTOR displacement[i] = 0;
|
||||
displacement[axis] = move;
|
||||
start_move(displacement);
|
||||
free(args[0]);
|
||||
}
|
||||
|
||||
void stage_mrx(String command)
|
||||
|
|
@ -197,11 +192,12 @@ void stage_mrz(String command)
|
|||
|
||||
void stage_mr(String command)
|
||||
{
|
||||
String args[3];
|
||||
char * args[3];
|
||||
parse_arguments(args, command, 3);
|
||||
EACH_MOTOR
|
||||
{
|
||||
displacement[i] = args[i].toInt();
|
||||
displacement[i] = atol(args[i]);
|
||||
free(args[i]);
|
||||
}
|
||||
|
||||
start_move(displacement);
|
||||
|
|
@ -222,37 +218,40 @@ void stage_p(String command)
|
|||
|
||||
void stage_min_step_delay(String command)
|
||||
{
|
||||
String args[1];
|
||||
char * args[1];
|
||||
parse_arguments(args, command, 1);
|
||||
if (args[0].equals("?"))
|
||||
if (args[0][0] == '?')
|
||||
{
|
||||
Serial.print("minimum step delay ");
|
||||
Serial.println(min_step_delay);
|
||||
}
|
||||
else
|
||||
{
|
||||
min_step_delay = args[0].toInt();
|
||||
min_step_delay = atol(args[0]);
|
||||
EEPROM.put(min_step_delay_eeprom, min_step_delay);
|
||||
Serial.println("done.");
|
||||
}
|
||||
free(args[0]);
|
||||
}
|
||||
|
||||
void stage_ramp_time(String command)
|
||||
{
|
||||
String args[1];
|
||||
char * args[1];
|
||||
parse_arguments(args, command, 1);
|
||||
if (args[0].equals("?"))
|
||||
if (args[0][0] == '?')
|
||||
{
|
||||
Serial.print("ramp_time ");
|
||||
Serial.println(ramp_time);
|
||||
}
|
||||
else
|
||||
{
|
||||
ramp_time = args[0].toInt();
|
||||
ramp_time = atol(args[0]);
|
||||
EEPROM.put(ramp_time_eeprom, ramp_time);
|
||||
Serial.println("done.");
|
||||
}
|
||||
free(args[0]);
|
||||
}
|
||||
|
||||
void stage_zero(String command)
|
||||
{
|
||||
EACH_MOTOR current_pos[i] = 0;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
#ifndef STAGE_H
|
||||
#include "StepperF_alt.h"
|
||||
#include "main.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
#define EACH_MOTOR for (int i = 0; i < n_motors; i++)
|
||||
#define EACH_MOTOR for (int i = 0; i < STAGE_N_MOTORS; i++)
|
||||
#define VER_STRING "Sangaboard Firmware v0.6"
|
||||
|
||||
void stage_setup();
|
||||
|
|
@ -19,6 +20,17 @@ void stage_p(String command);
|
|||
void stage_min_step_delay(String command);
|
||||
void stage_ramp_time(String command);
|
||||
void stage_zero(String command);
|
||||
void start_move(long displ[]);
|
||||
void stage_stop(String command);
|
||||
|
||||
extern const Command stage_commands[];
|
||||
extern const Command stage_commands[];
|
||||
//we want to expose these for endstops (and potentially other modules)
|
||||
extern signed long current_pos[];
|
||||
extern long displacement[];
|
||||
extern bool stage_moving;
|
||||
extern int8_t move_directions[];
|
||||
extern unsigned long distance_moved[];
|
||||
extern long min_step_delay;
|
||||
|
||||
#define STAGE_H
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue