Commit | Line | Data |
---|---|---|
df27a6a3 | 1 | /* |
4cff3ded AW |
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. | |
df27a6a3 | 5 | You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>. |
4cff3ded AW |
6 | */ |
7 | ||
8 | #ifndef ROBOT_H | |
9 | #define ROBOT_H | |
10 | ||
11 | #include <string> | |
12 | using std::string; | |
66383b80 | 13 | #include <string.h> |
33742399 | 14 | #include <functional> |
562db364 | 15 | #include <stack> |
89288956 | 16 | #include <vector> |
4cff3ded | 17 | |
38bf9a1c | 18 | #include "libs/Module.h" |
807b9b57 | 19 | #include "ActuatorCoordinates.h" |
29e809e0 | 20 | #include "nuts_bolts.h" |
4cff3ded | 21 | |
5673fe39 MM |
22 | class Gcode; |
23 | class BaseSolution; | |
24 | class StepperMotor; | |
4cff3ded | 25 | |
0b8b81b6 JM |
26 | // 9 WCS offsets |
27 | #define MAX_WCS 9UL | |
28 | ||
4cff3ded AW |
29 | class Robot : public Module { |
30 | public: | |
aaf0c0ee | 31 | using wcs_t= std::tuple<float, float, float>; |
4cff3ded AW |
32 | Robot(); |
33 | void on_module_loaded(); | |
34 | void on_gcode_received(void* argument); | |
5647f709 | 35 | |
1ad23cd3 | 36 | void reset_axis_position(float position, int axis); |
cef9acea | 37 | void reset_axis_position(float x, float y, float z); |
93f20a8c | 38 | void reset_actuator_position(const ActuatorCoordinates &ac); |
728477c4 | 39 | void reset_position_from_current_actuator_position(); |
dd0a7cfa | 40 | float get_seconds_per_minute() const { return seconds_per_minute; } |
29e809e0 JM |
41 | float get_z_maxfeedrate() const { return this->max_speeds[Z_AXIS]; } |
42 | float get_default_acceleration() const { return default_acceleration; } | |
43 | void setToolOffset(const float offset[N_PRIMARY_AXIS]); | |
0ec2f63a | 44 | float get_feed_rate() const; |
73cc27d2 | 45 | float get_s_value() const { return s_value; } |
b5008339 | 46 | void set_s_value(float s) { s_value= s; } |
212caccd JM |
47 | void push_state(); |
48 | void pop_state(); | |
3c9fee28 | 49 | void check_max_actuator_speeds(); |
2791c829 JM |
50 | float to_millimeters( float value ) const { return this->inch_mode ? value * 25.4F : value; } |
51 | float from_millimeters( float value) const { return this->inch_mode ? value/25.4F : value; } | |
45ca77ec | 52 | float get_axis_position(int axis) const { return(this->machine_position[axis]); } |
6ab92d32 | 53 | void get_axis_position(float position[], size_t n= 3) const { memcpy(position, this->machine_position, n*sizeof(float)); } |
45ca77ec | 54 | wcs_t get_axis_position() const { return wcs_t(machine_position[X_AXIS], machine_position[Y_AXIS], machine_position[Z_AXIS]); } |
fdfa00d2 | 55 | void get_current_machine_position(float *pos) const; |
e03f2747 | 56 | int print_position(uint8_t subcode, char *buf, size_t bufsize) const; |
40843ebc | 57 | uint8_t get_current_wcs() const { return current_wcs; } |
34210908 | 58 | std::vector<wcs_t> get_wcs_state() const; |
4440e123 JM |
59 | std::tuple<float, float, float, uint8_t> get_last_probe_position() const { return last_probe_position; } |
60 | void set_last_probe_position(std::tuple<float, float, float, uint8_t> p) { last_probe_position = p; } | |
121094a5 | 61 | bool delta_move(const float delta[], float rate_mm_s, uint8_t naxis); |
29e809e0 | 62 | uint8_t register_motor(StepperMotor*); |
8a9f9313 | 63 | uint8_t get_number_registered_motors() const {return n_motors; } |
34210908 | 64 | |
6de8ab5b | 65 | BaseSolution* arm_solution; // Selected Arm solution ( millimeters to step calculation ) |
dd0a7cfa JM |
66 | |
67 | // gets accessed by Panel, Endstops, ZProbe | |
2cd32d70 | 68 | std::vector<StepperMotor*> actuators; |
a974cd04 | 69 | |
3632a517 | 70 | // set by a leveling strategy to transform the target of a move according to the current plan |
8fe38353 | 71 | std::function<void(float*, bool)> compensationTransform; |
325ed08b | 72 | // set by an active extruder, returns the amount to scale the E parameter by (to convert mm³ to mm) |
121094a5 | 73 | std::function<float(void)> get_e_scale_fnc; |
33742399 | 74 | |
a395f085 | 75 | // Workspace coordinate systems |
31c6c2c2 | 76 | wcs_t mcs2wcs(const wcs_t &pos) const; |
29e809e0 | 77 | wcs_t mcs2wcs(const float *pos) const { return mcs2wcs(wcs_t(pos[X_AXIS], pos[Y_AXIS], pos[Z_AXIS])); } |
a395f085 | 78 | |
02e4b295 JM |
79 | struct { |
80 | bool inch_mode:1; // true for inch mode, false for millimeter mode ( default ) | |
81 | bool absolute_mode:1; // true for absolute mode ( default ), false for relative mode | |
29e809e0 | 82 | bool e_absolute_mode:1; // true for absolute mode for E ( default ), false for relative mode |
00e607c7 | 83 | bool next_command_is_MCS:1; // set by G53 |
778093ce | 84 | bool disable_segmentation:1; // set to disable segmentation |
84cf4071 | 85 | bool disable_arm_solution:1; // set to disable the arm solution |
a3e1326a | 86 | bool segment_z_moves:1; |
3aad33c7 | 87 | bool save_g92:1; // save g92 on M500 if set |
e560f057 | 88 | bool is_g123:1; |
40843ebc JM |
89 | uint8_t plane_axis_0:2; // Current plane ( XY, XZ, YZ ) |
90 | uint8_t plane_axis_1:2; | |
91 | uint8_t plane_axis_2:2; | |
02e4b295 JM |
92 | }; |
93 | ||
a974cd04 | 94 | private: |
29e809e0 JM |
95 | enum MOTION_MODE_T { |
96 | NONE, | |
97 | SEEK, // G0 | |
98 | LINEAR, // G1 | |
99 | CW_ARC, // G2 | |
100 | CCW_ARC // G3 | |
101 | }; | |
102 | ||
807b9b57 | 103 | void load_config(); |
c1ebb1fe | 104 | bool append_milestone(const float target[], float rate_mm_s); |
29e809e0 | 105 | bool append_line( Gcode* gcode, const float target[], float rate_mm_s, float delta_e); |
350c8a60 | 106 | bool append_arc( Gcode* gcode, const float target[], const float offset[], float radius, bool is_clockwise ); |
29e809e0 JM |
107 | bool compute_arc(Gcode* gcode, const float offset[], const float target[], enum MOTION_MODE_T motion_mode); |
108 | void process_move(Gcode *gcode, enum MOTION_MODE_T); | |
6de8ab5b | 109 | |
1ad23cd3 | 110 | float theta(float x, float y); |
4cff3ded | 111 | void select_plane(uint8_t axis_0, uint8_t axis_1, uint8_t axis_2); |
dd0a7cfa | 112 | void clearToolOffset(); |
325ed08b | 113 | int get_active_extruder() const; |
c2f7c261 | 114 | |
0b8b81b6 | 115 | std::array<wcs_t, MAX_WCS> wcs_offsets; // these are persistent once saved with M500 |
34210908 | 116 | uint8_t current_wcs{0}; // 0 means G54 is enabled this is persistent once saved with M500 |
807b9b57 | 117 | wcs_t g92_offset; |
c2f7c261 | 118 | wcs_t tool_offset; // used for multiple extruders, sets the tool offset for the current extruder applied first |
078f76e0 | 119 | std::tuple<float, float, float, uint8_t> last_probe_position{0,0,0,0}; |
807b9b57 | 120 | |
29e809e0 | 121 | using saved_state_t= std::tuple<float, float, bool, bool, bool, uint8_t>; // save current feedrate and absolute mode, e absolute mode, inch mode, current_wcs |
562db364 | 122 | std::stack<saved_state_t> state_stack; // saves state from M120 |
807b9b57 | 123 | |
45ca77ec JM |
124 | float machine_position[k_max_actuators]; // Last requested position, in millimeters, which is what we were requested to move to in the gcode after offsets applied but before compensation transform |
125 | float compensated_machine_position[k_max_actuators]; // Last machine position, which is the position before converting to actuator coordinates (includes compensation transform) | |
29e809e0 | 126 | |
788e5809 JM |
127 | float seek_rate; // Current rate for seeking moves ( mm/min ) |
128 | float feed_rate; // Current rate for feeding moves ( mm/min ) | |
1ad23cd3 | 129 | float mm_per_line_segment; // Setting : Used to split lines into segments |
a3be54e3 | 130 | float mm_per_arc_segment; // Setting : Used to split arcs into segments |
83c6e067 | 131 | float mm_max_arc_error; // Setting : Used to limit total arc segments to max error |
1ad23cd3 | 132 | float delta_segments_per_second; // Setting : Used to split lines into segments for delta based on speed |
dd0a7cfa | 133 | float seconds_per_minute; // for realtime speed change |
29e809e0 | 134 | float default_acceleration; // the defualt accleration if not set for each axis |
e560f057 | 135 | float s_value; // modal S value |
7369629d | 136 | |
b66fb830 | 137 | // Number of arc generation iterations by small angle approximation before exact arc trajectory |
a3be54e3 | 138 | // correction. This parameter may be decreased if there are issues with the accuracy of the arc |
b66fb830 AW |
139 | // generations. In general, the default value is more than enough for the intended CNC applications |
140 | // of grbl, and should be on the order or greater than the size of the buffer to help with the | |
141 | // computational efficiency of generating arcs. | |
29e809e0 JM |
142 | int arc_correction; // Setting : how often to rectify arc computation |
143 | float max_speeds[3]; // Setting : max allowable speed in mm/s for each axis | |
29e809e0 | 144 | |
29e809e0 | 145 | uint8_t n_motors; //count of the motors/axis registered |
b66fb830 | 146 | |
8a9f9313 | 147 | // Used by Planner |
dd0a7cfa | 148 | friend class Planner; |
4cff3ded AW |
149 | }; |
150 | ||
6de8ab5b | 151 | |
4cff3ded | 152 | #endif |