reset position after test raw.
[clinton/Smoothieware.git] / src / libs / StepperMotor.cpp
index fa70732..236ce25 100644 (file)
@@ -16,8 +16,6 @@
 StepperMotor::StepperMotor(Pin &step, Pin &dir, Pin &en) : step_pin(step), dir_pin(dir), en_pin(en)
 {
     set_high_on_debug(en.port_number, en.pin);
-    // register this motor with the step ticker, and get its index in that array and bit position
-    this->index= THEKERNEL->step_ticker->register_motor(this);
 
     steps_per_mm         = 1.0F;
     max_rate             = 50.0F;
@@ -27,6 +25,10 @@ StepperMotor::StepperMotor(Pin &step, Pin &dir, Pin &en) : step_pin(step), dir_p
     current_position_steps= 0;
     enable(false);
     moving= false;
+    acceleration= NAN;
+    selected= true;
+
+    this->set_direction(false);
 
     this->register_for_event(ON_HALT);
     this->register_for_event(ON_ENABLE);
@@ -42,6 +44,7 @@ void StepperMotor::on_halt(void *argument)
 {
     if(argument == nullptr) {
         enable(false);
+        moving= false;
     }
 }
 
@@ -64,13 +67,28 @@ void StepperMotor::change_last_milestone(float new_milestone)
     current_position_steps = last_milestone_steps;
 }
 
-int  StepperMotor::steps_to_target(float target)
+void StepperMotor::set_last_milestones(float mm, int32_t steps)
+{
+    last_milestone_mm= mm;
+    last_milestone_steps= steps;
+    current_position_steps= last_milestone_steps;
+}
+
+void StepperMotor::update_last_milestones(float mm, int32_t steps)
+{
+    last_milestone_steps += steps;
+    last_milestone_mm = mm;
+}
+
+int32_t StepperMotor::steps_to_target(float target)
 {
-    int target_steps = lroundf(target * steps_per_mm);
+    int32_t target_steps = lroundf(target * steps_per_mm);
     return target_steps - last_milestone_steps;
 }
 
 // Does a manual step pulse, used for direct encoder control of a stepper
+// NOTE this is experimental and may change and/or be reomved in the future, it is an unsupported feature.
+// use at your own risk
 void StepperMotor::manual_step(bool dir)
 {
     if(!is_enabled()) enable(true);