temperaturecontrol: allow setting background tool without activating
[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 <bitset>
11 #include "ActuatorCoordinates.h"
12
13 class Block {
14 public:
15 Block();
16
17 static void init(uint8_t);
18
19 void calculate_trapezoid( float entry_speed, float exit_speed );
20
21 float reverse_pass(float exit_speed);
22 float forward_pass(float next_entry_speed);
23 float max_exit_speed();
24 void debug() const;
25 void ready() { is_ready= true; }
26 void clear();
27 float get_trapezoid_rate(int i) const;
28
29 private:
30 float max_allowable_speed( float acceleration, float target_velocity, float distance);
31 void prepare(float acceleration_in_steps, float deceleration_in_steps);
32
33 static double fp_scale; // optimize to store this as it does not change
34
35 public:
36 std::array<uint32_t, k_max_actuators> steps; // Number of steps for each axis for this block
37 uint32_t steps_event_count; // Steps for the longest axis
38 float nominal_rate; // Nominal rate in steps per second
39 float nominal_speed; // Nominal speed in mm per second
40 float millimeters; // Distance for this move
41 float entry_speed;
42 float exit_speed;
43 float acceleration; // the acceleration for this block
44 float initial_rate; // Initial rate in steps per second
45 float maximum_rate;
46
47 float max_entry_speed;
48
49 // this is tick info needed for this block. applies to all motors
50 uint32_t accelerate_until;
51 uint32_t decelerate_after;
52 uint32_t total_move_ticks;
53 std::bitset<k_max_actuators> direction_bits; // Direction for each axis in bit form, relative to the direction port's mask
54
55 // this is the data needed to determine when each motor needs to be issued a step
56 using tickinfo_t= struct {
57 int64_t steps_per_tick; // 2.62 fixed point
58 int64_t counter; // 2.62 fixed point
59 int64_t acceleration_change; // 2.62 fixed point signed
60 int64_t deceleration_change; // 2.62 fixed point
61 int64_t plateau_rate; // 2.62 fixed point
62 uint32_t steps_to_move;
63 uint32_t step_count;
64 uint32_t next_accel_event;
65 };
66
67 // need info for each active motor
68 tickinfo_t *tick_info;
69
70 static uint8_t n_actuators;
71
72 struct {
73 bool recalculate_flag:1; // Planner flag to recalculate trapezoids on entry junction
74 bool nominal_length_flag:1; // Planner flag for nominal speed always reached
75 bool is_ready:1;
76 bool primary_axis:1; // set if this move is a primary axis
77 bool is_g123:1; // set if this is a G1, G2 or G3
78 volatile bool is_ticking:1; // set when this block is being actively ticked by the stepticker
79 volatile bool locked:1; // set to true when the critical data is being updated, stepticker will have to skip if this is set
80 uint16_t s_value:12; // for laser 1.11 Fixed point
81 };
82 };