only check max speeds for 3 axis
[clinton/Smoothieware.git] / src / modules / robot / Block.h
1 /*
2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
3 Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4 Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
6 */
7
8 #pragma once
9
10 #include <vector>
11 #include <bitset>
12 #include "ActuatorCoordinates.h"
13
14 class Block {
15 public:
16 Block();
17
18 static void init(uint8_t);
19
20 void calculate_trapezoid( float entry_speed, float exit_speed );
21
22 float reverse_pass(float exit_speed);
23 float forward_pass(float next_entry_speed);
24 float max_exit_speed();
25 void debug() const;
26 void ready() { is_ready= true; }
27 void clear();
28 float get_trapezoid_rate(int i) const;
29
30 private:
31 float max_allowable_speed( float acceleration, float target_velocity, float distance);
32 void prepare(float acceleration_in_steps, float deceleration_in_steps);
33
34 static double fp_scale; // optimize to store this as it does not change
35
36 public:
37 std::array<uint32_t, k_max_actuators> steps; // Number of steps for each axis for this block
38 uint32_t steps_event_count; // Steps for the longest axis
39 float nominal_rate; // Nominal rate in steps per second
40 float nominal_speed; // Nominal speed in mm per second
41 float millimeters; // Distance for this move
42 float entry_speed;
43 float exit_speed;
44 float acceleration; // the acceleration for this block
45 float initial_rate; // Initial rate in steps per second
46 float maximum_rate;
47
48 float max_entry_speed;
49
50 // this is tick info needed for this block. applies to all motors
51 uint32_t accelerate_until;
52 uint32_t decelerate_after;
53 uint32_t total_move_ticks;
54 std::bitset<k_max_actuators> direction_bits; // Direction for each axis in bit form, relative to the direction port's mask
55
56 // this is the data needed to determine when each motor needs to be issued a step
57 using tickinfo_t= struct {
58 int64_t steps_per_tick; // 2.62 fixed point
59 int64_t counter; // 2.62 fixed point
60 int64_t acceleration_change; // 2.62 fixed point signed
61 int64_t deceleration_change; // 2.62 fixed point
62 int64_t plateau_rate; // 2.62 fixed point
63 uint32_t steps_to_move;
64 uint32_t step_count;
65 uint32_t next_accel_event;
66 };
67
68 // need info for each active motor
69 tickinfo_t *tick_info;
70
71 static uint8_t n_actuators;
72
73 struct {
74 bool recalculate_flag:1; // Planner flag to recalculate trapezoids on entry junction
75 bool nominal_length_flag:1; // Planner flag for nominal speed always reached
76 bool is_ready:1;
77 bool primary_axis:1; // set if this move is a primary axis
78 bool is_g123:1; // set if this is a G1, G2 or G3
79 volatile bool is_ticking:1; // set when this block is being actively ticked by the stepticker
80 volatile bool locked:1; // set to true when the critical data is being updated, stepticker will have to skip if this is set
81 uint16_t s_value:12; // for laser 1.11 Fixed point
82 };
83 };