setting for an actuator to be an extruder
authorJim Morris <morris@wolfman.com>
Sun, 16 Oct 2016 22:05:05 +0000 (15:05 -0700)
committerJim Morris <morris@wolfman.com>
Sun, 16 Oct 2016 22:05:05 +0000 (15:05 -0700)
check the actuator is an extruder before applying or using e_scale()

src/libs/StepperMotor.cpp
src/libs/StepperMotor.h
src/modules/robot/Robot.cpp
src/modules/tools/extruder/Extruder.cpp

index 65b0248..c54a502 100644 (file)
@@ -26,6 +26,7 @@ StepperMotor::StepperMotor(Pin &step, Pin &dir, Pin &en) : step_pin(step), dir_p
     moving= false;
     acceleration= NAN;
     selected= true;
+    extruder= false;
 
     enable(false);
     unstep(); // initialize step pin
index 1673a36..0f356af 100644 (file)
@@ -51,6 +51,8 @@ class StepperMotor  : public Module {
         float get_acceleration() const { return acceleration; }
         bool is_selected() const { return selected; }
         void set_selected(bool b) { selected= b; }
+        bool is_extruder() const { return extruder; }
+        void set_extruder(bool b) { extruder= b; }
 
         int32_t steps_to_target(float);
 
@@ -77,6 +79,7 @@ class StepperMotor  : public Module {
             volatile bool direction:1;
             volatile bool moving:1;
             bool selected:1;
+            bool extruder:1;
         };
 };
 
index afe98a6..0b0023d 100644 (file)
@@ -789,7 +789,7 @@ int Robot::get_active_extruder() const
 {
     for (int i = E_AXIS; i < n_motors; ++i) {
         // find first selected extruder
-        if(actuators[i]->is_selected()) return i;
+        if(actuators[i]->is_extruder() && actuators[i]->is_selected()) return i;
     }
     return 0;
 }
@@ -987,7 +987,7 @@ void Robot::reset_position_from_current_actuator_position()
     for (int i = A_AXIS; i <= n_motors; i++) {
         // ABC and/or extruders just need to set machine_position and compensated_machine_position
         float ap= actuator_pos[i];
-        if(get_e_scale_fnc && i == get_active_extruder()) ap /= get_e_scale_fnc(); // inverse E scale if there is one and this is the active extruder
+        if(actuators[i]->is_extruder() && get_e_scale_fnc) ap /= get_e_scale_fnc(); // inverse E scale if there is one and this is an extruder
         machine_position[i]= compensated_machine_position[i]= ap;
         actuators[i]->change_last_milestone(ap);
     }
@@ -1072,7 +1072,7 @@ bool Robot::append_milestone(const float target[], float rate_mm_s)
     // for the extruders just copy the position, and possibly scale it from mm³ to mm
     for (size_t i = E_AXIS; i < n_motors; i++) {
         actuator_pos[i]= transformed_target[i];
-        if(get_e_scale_fnc) {
+        if(actuators[i]->is_extruder() && get_e_scale_fnc) {
             // NOTE this relies on the fact only one extruder is active at a time
             // scale for volumetric or flow rate
             // TODO is this correct? scaling the absolute target? what if the scale changes?
index 5659761..80580fb 100644 (file)
@@ -133,6 +133,7 @@ void Extruder::config_load()
     stepper_motor->set_acceleration(acceleration);
     stepper_motor->change_steps_per_mm(steps_per_millimeter);
     stepper_motor->set_selected(false); // not selected by default
+    stepper_motor->set_extruder(true);  // indicates it is an extruder
 }
 
 void Extruder::select()