#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);
+ if(en.connected()) {
+ set_high_on_debug(en.port_number, en.pin);
+ }
steps_per_mm = 1.0F;
max_rate = 50.0F;
last_milestone_steps = 0;
last_milestone_mm = 0.0F;
current_position_steps= 0;
- enable(false);
moving= false;
+ acceleration= NAN;
+ selected= true;
+ extruder= false;
+
+ enable(false);
+ unstep(); // initialize step pin
+ set_direction(false); // initialize dir pin
this->register_for_event(ON_HALT);
this->register_for_event(ON_ENABLE);
{
if(argument == nullptr) {
enable(false);
+ moving= false;
}
}
void StepperMotor::on_enable(void *argument)
{
- enable(argument != nullptr);
+ // argument is a uin32_t where bit0 is on or off, and bit 1:X, 2:Y, 3:Z, 4:A, 5:B, 6:C etc
+ // for now if bit0 is 1 we turn all on, if 0 we turn all off otherwise we turn selected axis off
+ uint32_t bm= (uint32_t)argument;
+ if(bm == 0x01) {
+ enable(true);
+
+ }else if(bm == 0 || ((bm&0x01) == 0 && ((bm&(0x02<<motor_id)) != 0)) ) {
+ enable(false);
+ }
}
void StepperMotor::change_steps_per_mm(float new_steps)
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);