#include <math.h>
#include "mbed.h"
-// in steps/sec the default minimum speed (was 20steps/sec hardcoded)
-float StepperMotor::default_minimum_actuator_rate= 20.0F;
-
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;
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);
{
if(argument == nullptr) {
enable(false);
+ moving= false;
}
}
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);