Homing direction #114

Merged
merged 3 commits into from Feb 15, 2013
@@ -92,10 +92,19 @@ switch.spindle.enable false #
# Endstops
alpha_min_endstop 1.24 #
alpha_max_endstop 1.25 #
+alpha_homing_direction -1 #
+alpha_min 0 #
+alpha_max 200 #
beta_min_endstop 1.26 #
beta_max_endstop 1.27 #
+beta_homing_direction -1 #
+beta_min 0 #
+beta_max 200 #
gamma_min_endstop 1.28 #
gamma_max_endstop 1.29 #
+gamma_homing_direction 1 #
+gamma_min 0 #
+gamma_max 200 #
# Panel
panel.enable false #
@@ -92,6 +92,12 @@ void Robot::on_gcode_received(void * argument){
}
+void Robot::reset_axis_position(double position, int axis) {
+ this->last_milestone[axis] = this->current_position[axis] = position;
+ this->arm_solution->millimeters_to_steps(this->current_position, this->kernel->planner->position);
+}
+
+
//See if the current Gcode line has some orders for us
void Robot::execute_gcode(Gcode* gcode){
@@ -57,6 +57,7 @@ class Robot : public Module {
void on_module_loaded();
void on_config_reload(void* argument);
void on_gcode_received(void* argument);
+ void reset_axis_position(double position, int axis);
private:
void execute_gcode(Gcode* gcode);
@@ -41,16 +41,22 @@ void Endstops::on_config_reload(void* argument){
this->pins[3].from_string( this->kernel->config->value(alpha_max_endstop_checksum )->by_default("nc" )->as_string())->as_input()->pull_up();
this->pins[4].from_string( this->kernel->config->value(beta_max_endstop_checksum )->by_default("nc" )->as_string())->as_input()->pull_up();
this->pins[5].from_string( this->kernel->config->value(gamma_max_endstop_checksum )->by_default("nc" )->as_string())->as_input()->pull_up();
- this->fast_rates[0] = this->kernel->config->value(alpha_fast_homing_rate_checksum )->by_default("500" )->as_number();
- this->fast_rates[1] = this->kernel->config->value(beta_fast_homing_rate_checksum )->by_default("500" )->as_number();
- this->fast_rates[2] = this->kernel->config->value(gamma_fast_homing_rate_checksum )->by_default("5" )->as_number();
- this->slow_rates[0] = this->kernel->config->value(alpha_slow_homing_rate_checksum )->by_default("100" )->as_number();
- this->slow_rates[1] = this->kernel->config->value(beta_slow_homing_rate_checksum )->by_default("100" )->as_number();
- this->slow_rates[2] = this->kernel->config->value(gamma_slow_homing_rate_checksum )->by_default("5" )->as_number();
- this->retract_steps[0] = this->kernel->config->value(alpha_homing_retract_checksum )->by_default("30" )->as_number();
- this->retract_steps[1] = this->kernel->config->value(beta_homing_retract_checksum )->by_default("30" )->as_number();
- this->retract_steps[2] = this->kernel->config->value(gamma_homing_retract_checksum )->by_default("10" )->as_number();
- this->debounce_count = this->kernel->config->value(endstop_debounce_count_checksum )->by_default("100" )->as_number();
+ this->fast_rates[0] = this->kernel->config->value(alpha_fast_homing_rate_checksum )->by_default("500" )->as_number();
+ this->fast_rates[1] = this->kernel->config->value(beta_fast_homing_rate_checksum )->by_default("500" )->as_number();
+ this->fast_rates[2] = this->kernel->config->value(gamma_fast_homing_rate_checksum )->by_default("5" )->as_number();
+ this->slow_rates[0] = this->kernel->config->value(alpha_slow_homing_rate_checksum )->by_default("100" )->as_number();
+ this->slow_rates[1] = this->kernel->config->value(beta_slow_homing_rate_checksum )->by_default("100" )->as_number();
+ this->slow_rates[2] = this->kernel->config->value(gamma_slow_homing_rate_checksum )->by_default("5" )->as_number();
+ this->retract_steps[0] = this->kernel->config->value(alpha_homing_retract_checksum )->by_default("30" )->as_number();
+ this->retract_steps[1] = this->kernel->config->value(beta_homing_retract_checksum )->by_default("30" )->as_number();
+ this->retract_steps[2] = this->kernel->config->value(gamma_homing_retract_checksum )->by_default("10" )->as_number();
+ this->debounce_count = this->kernel->config->value(endstop_debounce_count_checksum )->by_default("100" )->as_number();
+ this->direction[0] =((-this->kernel->config->value(alpha_homing_direction_checksum )->by_default("-1" )->as_number()) / 2.0) + 0.5;
+ this->direction[1] =((-this->kernel->config->value(beta_homing_direction_checksum )->by_default("-1" )->as_number()) / 2.0) + 0.5;
+ this->direction[2] =((-this->kernel->config->value(gamma_homing_direction_checksum )->by_default("1" )->as_number()) / 2.0) + 0.5;
+ this->homing_position[0] = this->direction[0]?this->kernel->config->value(alpha_min_checksum)->by_default("0")->as_number():this->kernel->config->value(alpha_max_checksum)->by_default("200")->as_number();
+ this->homing_position[1] = this->direction[1]?this->kernel->config->value(beta_min_checksum)->by_default("0")->as_number():this->kernel->config->value(beta_max_checksum)->by_default("200")->as_number();;
+ this->homing_position[2] = this->direction[2]?this->kernel->config->value(gamma_min_checksum)->by_default("0")->as_number():this->kernel->config->value(gamma_max_checksum)->by_default("200")->as_number();;
}
void Endstops::wait_for_homed(char axes_to_move)
@@ -61,7 +67,7 @@ void Endstops::wait_for_homed(char axes_to_move)
running = false;
for( char c = 'X'; c <= 'Z'; c++ ){
if( ( axes_to_move >> ( c - 'X' ) ) & 1 ){
- if( this->pins[c - 'X'].get() ){
+ if( this->pins[c - 'X' + (this->direction[c - 'X']?0:3)].get() ){
if( debounce[c - 'X'] < debounce_count ) {
debounce[c - 'X'] ++;
running = true;
@@ -105,8 +111,8 @@ void Endstops::on_gcode_received(void* argument)
this->status = MOVING_TO_ORIGIN_FAST;
for( char c = 'X'; c <= 'Z'; c++ ){
if( ( axes_to_move >> ( c - 'X' ) ) & 1 ){
- this->steppers[c - 'X']->set_speed(this->fast_rates[c -'X']);
- this->steppers[c - 'X']->move(1,10000000);
+ this->steppers[c - 'X']->set_speed(this->fast_rates[c - 'X']);
+ this->steppers[c - 'X']->move(this->direction[c - 'X'],10000000);
}
}
@@ -116,10 +122,12 @@ void Endstops::on_gcode_received(void* argument)
printf("test a\r\n");
// Move back a small distance
this->status = MOVING_BACK;
+ int inverted_dir;
for( char c = 'X'; c <= 'Z'; c++ ){
if( ( axes_to_move >> ( c - 'X' ) ) & 1 ){
+ inverted_dir = -(this->direction[c - 'X'] - 1);
this->steppers[c - 'X']->set_speed(this->slow_rates[c - 'X']);
- this->steppers[c - 'X']->move(0,this->retract_steps[c - 'X']);
+ this->steppers[c - 'X']->move(inverted_dir,this->retract_steps[c - 'X']);
}
}
@@ -139,7 +147,7 @@ void Endstops::on_gcode_received(void* argument)
for( char c = 'X'; c <= 'Z'; c++ ){
if( ( axes_to_move >> ( c - 'X' ) ) & 1 ){
this->steppers[c - 'X']->set_speed(this->slow_rates[c -'X']);
- this->steppers[c - 'X']->move(1,10000000);
+ this->steppers[c - 'X']->move(this->direction[c - 'X'],10000000);
}
}
@@ -148,6 +156,15 @@ void Endstops::on_gcode_received(void* argument)
// Homing is done
this->status = NOT_HOMING;
+
+ // Zero the ax(i/e)s position
+ for( char c = 'X'; c <= 'Z'; c++ ){
+ if( ( axes_to_move >> ( c - 'X' ) ) & 1 ){
+
+ this->kernel->robot->reset_axis_position(this->homing_position[c - 'X'], c - 'X');
+ }
+ }
+
}
}
else if (gcode->has_m)
@@ -44,6 +44,18 @@
#define gamma_homing_retract_checksum CHECKSUM("gamma_homing_retract")
#define endstop_debounce_count_checksum CHECKSUM("endstop_debounce_count")
+#define alpha_homing_direction_checksum CHECKSUM("alpha_homing_direction")
+#define beta_homing_direction_checksum CHECKSUM("beta_homing_direction")
+#define gamma_homing_direction_checksum CHECKSUM("gamma_homing_direction")
+
+#define alpha_min_checksum CHECKSUM("alpha_min")
+#define beta_min_checksum CHECKSUM("beta_min")
+#define gamma_min_checksum CHECKSUM("gamma_min")
+
+#define alpha_max_checksum CHECKSUM("alpha_max")
+#define beta_max_checksum CHECKSUM("beta_max")
+#define gamma_max_checksum CHECKSUM("gamma_max")
+
class Endstops : public Module{
private:
@@ -61,6 +73,8 @@ class Endstops : public Module{
double fast_rates[3];
unsigned int retract_steps[3];
unsigned int debounce_count;
+ int direction[3];
+ double homing_position[3];
char status;
};