Fix the proportional laser power during acceleration and deceleration to be based...
authorJim Morris <morris@wolfman.com>
Fri, 2 Sep 2016 18:56:49 +0000 (11:56 -0700)
committerJim Morris <morris@wolfman.com>
Fri, 2 Sep 2016 18:56:49 +0000 (11:56 -0700)
src/modules/robot/Block.cpp
src/modules/robot/Block.h
src/modules/tools/laser/Laser.cpp

index 1fc51db..58c6658 100644 (file)
@@ -331,3 +331,11 @@ void Block::prepare()
         this->tick_info[m].plateau_rate= STEPTICKER_TOFP((this->maximum_rate * aratio) / STEP_TICKER_FREQUENCY);
     }
 }
+
+// returns current rate (steps/sec) for the given actuator
+float Block::get_trapezoid_rate(int i) const
+{
+    // convert steps per tick from fixed point to float and convert to steps/sec
+    // FIXME steps_per_tick can change at any time, potential race condition if it changes while being read here
+    return STEPTICKER_FROMFP(tick_info[i].steps_per_tick) * STEP_TICKER_FREQUENCY;
+}
index 5888447..3df796c 100644 (file)
@@ -25,6 +25,8 @@ class Block {
         void clear();
         void prepare();
 
+        float get_trapezoid_rate(int i) const;
+
         std::array<uint32_t, k_max_actuators> steps; // Number of steps for each axis for this block
         uint32_t steps_event_count;  // Steps for the longest axis
         float nominal_rate;       // Nominal rate in steps per second
index 3891d08..2bcb9d4 100644 (file)
@@ -198,9 +198,9 @@ float Laser::current_speed_ratio(const Block *block) const
         }
     }
 
-    // figure out the ratio of its speed, from 0 to 1 based on where it is on the trapezoid
-    // FIXME steps_per_tick can change at any time, potential race condition if it changes while being read here
-    float ratio= (float)block->tick_info[pm].steps_per_tick / block->tick_info[pm].plateau_rate;
+    // figure out the ratio of its speed, from 0 to 1 based on where it is on the trapezoid,
+    // this is based on the fraction it is of the requested rate (nominal rate)
+    float ratio= block->get_trapezoid_rate(pm) / block->nominal_rate;
 
     return ratio;
 }