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
307
src/modules/endstops/endstops.cpp
Normal file
307
src/modules/endstops/endstops.cpp
Normal file
|
|
@ -0,0 +1,307 @@
|
|||
#include "config.h"
|
||||
#ifdef ENDSTOPS
|
||||
#include "endstops.h"
|
||||
#include "../stage/stage.h"
|
||||
#ifdef SUPPORT_EEPROM
|
||||
#include <EEPROM.h>
|
||||
#else
|
||||
#include "dummyEEPROM.h"
|
||||
#endif
|
||||
|
||||
unsigned long retreat_steps = 5000;
|
||||
unsigned long home_move_steps = 100000;
|
||||
unsigned long axis_max[STAGE_N_MOTORS];
|
||||
const int axis_max_eeprom = sizeof(long)*(STAGE_N_MOTORS+2);
|
||||
#ifdef ENDSTOPS_MIN
|
||||
const int endstops_min_pins[] = WIRING_ENDSTOPS_MIN;
|
||||
#endif
|
||||
#ifdef ENDSTOPS_MAX
|
||||
const int endstops_max_pins[] = WIRING_ENDSTOPS_MAX;
|
||||
#endif
|
||||
bool endstops_enabled = true;
|
||||
|
||||
//we want to be able to abort homing, so all calls are non-blocking
|
||||
//we start with a very long move towards the endstops
|
||||
//when this is finished we start a move away from the endstops
|
||||
//when this is finished we set a very slow speed and start a move
|
||||
//back towards the endstops, after which we move away a few thousands
|
||||
//steps (the switch has some hysteresis)
|
||||
bool homing_initial_move = false;
|
||||
bool homing_moving_away = false;
|
||||
bool homing_final = false;
|
||||
uint8_t homing_axes = 0;
|
||||
int8_t homing_direction = 0;
|
||||
long previous_step_delay = 0;
|
||||
|
||||
boolean endstop_triggered(uint8_t axis, int8_t direction)
|
||||
{
|
||||
#if defined(ENDSTOPS_MIN)
|
||||
if (direction < 0)
|
||||
{
|
||||
int value = analogRead(endstops_min_pins[axis]);
|
||||
if (ENDSTOPS_INVERT != (value < 100))
|
||||
return true;
|
||||
}
|
||||
#elif defined(ENDSTOPS_SOFT)
|
||||
if (direction < 0 && current_pos[axis] < 1)
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#if defined(ENDSTOPS_MAX)
|
||||
if (direction > 0)
|
||||
{
|
||||
int value = analogRead(endstops_max_pins[axis]);
|
||||
if (ENDSTOPS_INVERT != (value < 100))
|
||||
return true;
|
||||
}
|
||||
#elif defined(ENDSTOPS_SOFT)
|
||||
if (direction > 0 && current_pos[axis] >= (signed long) axis_max[axis])
|
||||
return true;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
void endstops_loop()
|
||||
{
|
||||
if (!endstops_enabled)
|
||||
return;
|
||||
|
||||
endstops_check();
|
||||
|
||||
if (homing_initial_move)
|
||||
{
|
||||
if (stage_moving)
|
||||
return;
|
||||
D(F("Homing initial move complete"));
|
||||
homing_initial_move = false;
|
||||
homing_moving_away = true;
|
||||
home_retreat();
|
||||
return;
|
||||
}
|
||||
|
||||
if (homing_moving_away)
|
||||
{
|
||||
if (stage_moving)
|
||||
return;
|
||||
D(F("Homing retreat complete"));
|
||||
|
||||
homing_moving_away = false;
|
||||
homing_final = true;
|
||||
home_final();
|
||||
return;
|
||||
}
|
||||
|
||||
if (homing_final)
|
||||
{
|
||||
if (stage_moving)
|
||||
return;
|
||||
D(F("Homing complete complete"));
|
||||
homing_final = false;
|
||||
min_step_delay = previous_step_delay;
|
||||
home_retreat();
|
||||
Serial.println("done.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int8_t endstops_check()
|
||||
{
|
||||
int8_t endstop_break = 0;
|
||||
#if defined(ENDSTOPS_MIN) || defined(ENDSTOPS_MAX)
|
||||
EACH_MOTOR
|
||||
{
|
||||
//TODO: why the second part? isn't move direction enough?
|
||||
if (endstop_triggered(i, move_directions[i]))
|
||||
{
|
||||
endstop_break = move_directions[i] * (i + 1);
|
||||
D(endstop_break);
|
||||
D(move_directions[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (endstop_break != 0 && stage_moving)
|
||||
{
|
||||
Serial.print(F("Endstop hit:"));
|
||||
Serial.println(endstop_break);
|
||||
//if we have both min/max endstops, axis_max is adjusted to the correct value
|
||||
//if we only have min, we go from 0 -> predefined axis_max
|
||||
//if we only have max, we go from 0 -> predefined axis_max
|
||||
//the predefined axis_max are the travel distances in steps
|
||||
if (endstop_break < 0)
|
||||
{
|
||||
current_pos[-endstop_break - 1] = 0;
|
||||
//abort move in this direction
|
||||
displacement[-endstop_break - 1] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
displacement[endstop_break - 1] = 0;
|
||||
#if defined(ENDSTOPS_MIN) && defined(ENDSTOPS_MAX)
|
||||
axis_max[endstop_break - 1] = current_pos[endstop_break - 1];
|
||||
#elif defined(ENDSTOP_MAX) //we do not do this for ENDSTOPS_SOFT
|
||||
current_pos[endstop_break - 1] = axis_max[endstop_break - 1];
|
||||
#else
|
||||
;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif //ENDSTOPS_MIN || ENDSTOPS_MAX
|
||||
return endstop_break;
|
||||
}
|
||||
|
||||
void endstops_status(String command)
|
||||
{
|
||||
EACH_MOTOR
|
||||
{
|
||||
if (i > 0)
|
||||
Serial.print(" ");
|
||||
if (endstop_triggered(i, -1))
|
||||
Serial.print("-1");
|
||||
else if (endstop_triggered(i, 1))
|
||||
Serial.print("1");
|
||||
else
|
||||
Serial.print("0");
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void print_axes_max(String command)
|
||||
{
|
||||
EACH_MOTOR
|
||||
{
|
||||
if (i > 0)
|
||||
Serial.print(" ");
|
||||
Serial.print(axis_max[i]);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void home_start(uint8_t axes, int8_t direction)
|
||||
{
|
||||
homing_axes = axes;
|
||||
homing_direction = direction;
|
||||
homing_initial_move = true;
|
||||
long displacement[3];
|
||||
EACH_MOTOR
|
||||
{
|
||||
if (((homing_axes >> i) & 1) == 1)
|
||||
displacement[i] = homing_direction * home_move_steps;
|
||||
else
|
||||
displacement[i] = 0;
|
||||
}
|
||||
|
||||
start_move(displacement);
|
||||
}
|
||||
|
||||
void home_retreat()
|
||||
{
|
||||
long displacement[3];
|
||||
EACH_MOTOR
|
||||
{
|
||||
if (((homing_axes >> i) & 1) == 1)
|
||||
displacement[i] = -homing_direction * retreat_steps;
|
||||
else
|
||||
displacement[i] = 0;
|
||||
}
|
||||
start_move(displacement);
|
||||
}
|
||||
|
||||
void home_final()
|
||||
{
|
||||
long displacement[3];
|
||||
EACH_MOTOR
|
||||
{
|
||||
if (((homing_axes >> i) & 1) == 1)
|
||||
displacement[i] = 2 * homing_direction * retreat_steps;
|
||||
else
|
||||
displacement[i] = 0;
|
||||
}
|
||||
|
||||
previous_step_delay = min_step_delay;
|
||||
min_step_delay = 4000;
|
||||
start_move(displacement);
|
||||
}
|
||||
|
||||
void endstops_home_min(String command)
|
||||
{
|
||||
#ifndef ENDSTOPS_MIN
|
||||
Serial.println(F("Min endstops not installed"));
|
||||
return;
|
||||
#endif
|
||||
if (command.equals("home_min"))
|
||||
return home_start(7, -1);
|
||||
char * arg[1];
|
||||
parse_arguments(arg, command, 1);
|
||||
uint8_t axes = atoi(arg[0]);
|
||||
free(arg[0]);
|
||||
home_start(axes, -1);
|
||||
}
|
||||
|
||||
void endstops_home_max(String command)
|
||||
{
|
||||
#ifndef ENDSTOPS_MAX
|
||||
Serial.println(F("Max endstops not installed"));
|
||||
return;
|
||||
#endif
|
||||
if (command.equals("home_max"))
|
||||
return home_start(7, 1);
|
||||
char * arg[1];
|
||||
parse_arguments(arg, command, 1);
|
||||
uint8_t axes = atoi(arg[0]);
|
||||
free(arg[0]);
|
||||
home_start(axes, 1);
|
||||
}
|
||||
|
||||
void endstops_set_max(String command)
|
||||
{
|
||||
char * args[3];
|
||||
parse_arguments(args, command, 3);
|
||||
EACH_MOTOR
|
||||
{
|
||||
axis_max[i] = atol(args[i]);
|
||||
free(args[i]);
|
||||
}
|
||||
EEPROM.put(axis_max_eeprom, axis_max);
|
||||
|
||||
}
|
||||
|
||||
void endstops_setup()
|
||||
{
|
||||
#ifdef ENDSTOPS_MIN
|
||||
EACH_MOTOR{
|
||||
if(ENDSTOPS_PULLUPS)
|
||||
pinMode(endstops_min_pins[i], INPUT_PULLUP);
|
||||
else
|
||||
pinMode(endstops_min_pins[i], INPUT);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENDSTOPS_MAX
|
||||
EACH_MOTOR{
|
||||
if(ENDSTOPS_PULLUPS)
|
||||
pinMode(endstops_max_pins[i], INPUT_PULLUP);
|
||||
else
|
||||
pinMode(endstops_max_pins[i], INPUT);
|
||||
}
|
||||
#endif
|
||||
EACH_MOTOR
|
||||
{
|
||||
EEPROM.get(axis_max_eeprom+i*sizeof(long), axis_max[i]);
|
||||
}
|
||||
register_module(endstops_commands, endstops_loop);
|
||||
}
|
||||
|
||||
//endstops? - get triggered endstops in (1,0,-1) format for max, none, min"));
|
||||
// Serial.println(F("home_min <axes?> - home given (00000zyx byte, e.g. 1 for x) or all axes to their min position"));
|
||||
// Serial.println(F("home_max <axes?> - home given (00000zyx byte, e.g. 3 for x and y) or all axes to their max position"));
|
||||
// Serial.println(F("max_p? - return positions of max endstops"));
|
||||
// Serial.println(F("max <d> <d> <d>
|
||||
extern const Command endstops_commands[] = {
|
||||
{"endstops?", endstops_status},
|
||||
{"home_min", endstops_home_min},
|
||||
{"home_max", endstops_home_max},
|
||||
{"max_p?", print_axes_max},
|
||||
{"max", endstops_set_max},
|
||||
END_COMMAND};
|
||||
#endif
|
||||
32
src/modules/endstops/endstops.h
Normal file
32
src/modules/endstops/endstops.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include "config.h"
|
||||
#ifdef ENDSTOPS
|
||||
#ifndef ENDSTOPS_H
|
||||
#include "config.h"
|
||||
#ifndef STAGE
|
||||
#error "Endstops module depends on the stage module"
|
||||
#endif
|
||||
|
||||
#include "main.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
void endstops_setup();
|
||||
void endstops_loop();
|
||||
|
||||
void endstops_home_min(String command);
|
||||
void endstops_home_max(String command);
|
||||
void endstops_max(String command);
|
||||
void endstops_status(String command);
|
||||
extern void stage_stop(String command);
|
||||
|
||||
void home_min(uint8_t axes);
|
||||
void home_max(uint8_t axes);
|
||||
|
||||
void home_start(uint8_t, int8_t);
|
||||
void home_retreat();
|
||||
void home_final();
|
||||
int8_t endstops_check();
|
||||
|
||||
extern const Command endstops_commands[];
|
||||
#define ENDSTOPS_H
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
#include "config.h"
|
||||
#ifdef HELP
|
||||
#include "help.h"
|
||||
|
||||
void help_setup()
|
||||
|
|
@ -68,4 +70,5 @@ void help(String command)
|
|||
Serial.println(F("<d> - a decimal integer."));
|
||||
Serial.println("");
|
||||
Serial.println("--END--");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
#include "config.h"
|
||||
#ifdef HELP
|
||||
#ifndef HELP_H
|
||||
#include <Arduino.h>
|
||||
#include "main.h"
|
||||
|
|
@ -9,4 +11,5 @@ const struct Command help_commands[] = {
|
|||
END_COMMAND
|
||||
};
|
||||
#define HELP_H
|
||||
#endif
|
||||
#endif
|
||||
214
src/modules/light_sensor/light_sensor.cpp
Normal file
214
src/modules/light_sensor/light_sensor.cpp
Normal file
|
|
@ -0,0 +1,214 @@
|
|||
#include "config.h"
|
||||
#ifdef LIGHT_SENSOR
|
||||
#include "light_sensor.h"
|
||||
#include "config.h"
|
||||
#include "main.h"
|
||||
#ifdef LIGHT_SENSOR_ADAFRUIT_TSL2591
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Adafruit_TSL2591.h>
|
||||
#endif
|
||||
#ifdef LIGHT_SENSOR_ADAFRUIT_ADS1115
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_ADS1015.h>
|
||||
#endif
|
||||
|
||||
const struct Command light_sensor_commands[] = {
|
||||
{"light_sensor_gain", light_sensor_gain},
|
||||
{"light_sensor_gain_values?", light_sensor_gain_values},
|
||||
{"light_sensor_integration_time?", light_sensor_integration_time},
|
||||
{"light_sensor_intensity", light_sensor_intensity},
|
||||
END_COMMAND};
|
||||
|
||||
void light_sensor_integration_time(String);
|
||||
|
||||
void light_sensor_setup()
|
||||
{
|
||||
setup_light_sensor_device();
|
||||
register_module(light_sensor_commands, NULL);
|
||||
}
|
||||
|
||||
void light_sensor_gain(String command)
|
||||
{
|
||||
char *args[1];
|
||||
parse_arguments(args, command, 1);
|
||||
if (args[0][0] != '?')
|
||||
{
|
||||
int gain = atoi(args[0]);
|
||||
free(args[0]);
|
||||
return set_light_sensor_gain(gain);
|
||||
}
|
||||
free(args[0]);
|
||||
return print_light_sensor_gain();
|
||||
}
|
||||
|
||||
#ifdef LIGHT_SENSOR_ADAFRUIT_TSL2591
|
||||
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // pass in a number for the sensor identifier (for your use later)
|
||||
|
||||
void setup_light_sensor_device()
|
||||
{
|
||||
if (tsl.begin())
|
||||
{
|
||||
tsl.setGain(TSL2591_GAIN_MED);
|
||||
tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS); // shortest integration time (bright light)
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println(F("No light sensor found. NB your board will start up faster if you recompile without light sensor support."));
|
||||
}
|
||||
}
|
||||
|
||||
void print_light_sensor_gain()
|
||||
{
|
||||
// Print the current gain value of the light sensor
|
||||
Serial.print(F("light sensor gain "));
|
||||
tsl2591Gain_t gain = tsl.getGain();
|
||||
switch (gain)
|
||||
{
|
||||
case TSL2591_GAIN_LOW:
|
||||
Serial.println(F("1x (Low)"));
|
||||
break;
|
||||
case TSL2591_GAIN_MED:
|
||||
Serial.println(F("25x (Medium)"));
|
||||
break;
|
||||
case TSL2591_GAIN_HIGH:
|
||||
Serial.println(F("428x (High)"));
|
||||
break;
|
||||
case TSL2591_GAIN_MAX:
|
||||
Serial.println(F("9876x (Max)"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
void light_sensor_gain_values(String command)
|
||||
{
|
||||
// Print the allowable gain values of the light sensor
|
||||
Serial.println(F("light sensor gains: 1x, 25x, 428x, 9876x"));
|
||||
}
|
||||
|
||||
void set_light_sensor_gain(int newgain)
|
||||
{
|
||||
// Set the current gain value of the light sensor, and print a confirmation.
|
||||
switch (newgain)
|
||||
{
|
||||
case 1:
|
||||
tsl.setGain(TSL2591_GAIN_LOW);
|
||||
break;
|
||||
case 25:
|
||||
tsl.setGain(TSL2591_GAIN_MED);
|
||||
break;
|
||||
case 428:
|
||||
tsl.setGain(TSL2591_GAIN_HIGH);
|
||||
break;
|
||||
case 9876:
|
||||
tsl.setGain(TSL2591_GAIN_MAX);
|
||||
break;
|
||||
default:
|
||||
Serial.println(F("Error: gain may only be 1, 25, 428, or 9876."));
|
||||
return;
|
||||
}
|
||||
print_light_sensor_gain();
|
||||
}
|
||||
|
||||
void light_sensor_integration_time(String command)
|
||||
{
|
||||
// Print the current integration time in milliseconds.
|
||||
Serial.print(F("light sensor integration time "));
|
||||
Serial.print((tsl.getTiming() + 1) * 100, DEC);
|
||||
Serial.println(F(" ms"));
|
||||
}
|
||||
|
||||
void light_sensor_intensity(String command)
|
||||
{
|
||||
// Print the current light value
|
||||
uint16_t x = tsl.getLuminosity(TSL2591_FULLSPECTRUM);
|
||||
Serial.println(x, DEC);
|
||||
}
|
||||
#endif // ADAFRUIT_TSL2591
|
||||
|
||||
#ifdef LIGHT_SENSOR_ADAFRUIT_ADS1115
|
||||
Adafruit_ADS1115 ads; // pass in a number for the sensor identifier (for your use later)
|
||||
|
||||
void setup_light_sensor_device()
|
||||
{
|
||||
ads.begin();
|
||||
ads.setGain(GAIN_ONE);
|
||||
}
|
||||
|
||||
void print_light_sensor_gain()
|
||||
{
|
||||
// Print the current gain value of the light sensor
|
||||
Serial.print(F("light sensor gain "));
|
||||
adsGain_t gain = ads.getGain() M;
|
||||
switch (gain)
|
||||
{
|
||||
case GAIN_TWOTHIRDS:
|
||||
Serial.println(F("0.66x (specify 0)"));
|
||||
break;
|
||||
case GAIN_ONE:
|
||||
Serial.println(F("1x"));
|
||||
break;
|
||||
case GAIN_TWO:
|
||||
Serial.println(F("2x"));
|
||||
break;
|
||||
case GAIN_FOUR:
|
||||
Serial.println(F("4x"));
|
||||
break;
|
||||
case GAIN_EIGHT:
|
||||
Serial.println(F("8x"));
|
||||
break;
|
||||
case GAIN_SIXTEEN:
|
||||
Serial.println(F("16x"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
void light_sensor_gain_values(String command)
|
||||
{
|
||||
// Print the allowable gain values of the light sensor
|
||||
Serial.println(F("light sensor gains: 0.66x (specify 0), 1x, 2x, 4x, 8x, 16x"));
|
||||
}
|
||||
|
||||
void set_light_sensor_gain(int newgain)
|
||||
{
|
||||
// Set the current gain value of the light sensor, and print a confirmation.
|
||||
switch (newgain)
|
||||
{
|
||||
case 0:
|
||||
ads.setGain(GAIN_TWOTHIRDS);
|
||||
break;
|
||||
case 1:
|
||||
ads.setGain(GAIN_ONE);
|
||||
break;
|
||||
case 2:
|
||||
ads.setGain(GAIN_TWO);
|
||||
break;
|
||||
case 4:
|
||||
ads.setGain(GAIN_FOUR);
|
||||
break;
|
||||
case 8:
|
||||
ads.setGain(GAIN_EIGHT);
|
||||
break;
|
||||
case 16:
|
||||
ads.setGain(GAIN_SIXTEEN);
|
||||
break;
|
||||
default:
|
||||
Serial.println(F("Error: gain may only be 0, 1, 2, 4, 8, 16 (0 means 2/3)."));
|
||||
return;
|
||||
}
|
||||
print_light_sensor_gain();
|
||||
}
|
||||
|
||||
void light_sensor_integration_time(String command)
|
||||
{
|
||||
// Print the current integration time in milliseconds.
|
||||
Serial.println(F("integration time not supported for ADS1115"));
|
||||
}
|
||||
|
||||
void light_sensor_intensity(String command)
|
||||
{
|
||||
// Print the current light value
|
||||
// uint16_t x = ads.readADC_SingleEnded(0); //single ended measurement on pin 0
|
||||
uint16_t x = ads.readADC_Differential_0_1(); //differential measurement on pins 0,1
|
||||
Serial.println(x, DEC);
|
||||
}
|
||||
#endif // ADAFRUIT_ADS1115
|
||||
#endif
|
||||
18
src/modules/light_sensor/light_sensor.h
Normal file
18
src/modules/light_sensor/light_sensor.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#include "config.h"
|
||||
#ifdef LIGHT_SENSOR
|
||||
#ifndef LIGHT_SENSOR_H
|
||||
#include <Arduino.h>
|
||||
|
||||
void light_sensor_gain(String);
|
||||
void light_sensor_gain_values(String);
|
||||
void light_sensor_integration_time(String);
|
||||
void light_sensor_intensity(String);
|
||||
|
||||
void light_sensor_setup();
|
||||
void setup_light_sensor_device();
|
||||
|
||||
void print_light_sensor_gain();
|
||||
void set_light_sensor_gain(int);
|
||||
#define LIGHT_SENSOR_H
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -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