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> |
4cff3ded | 16 | |
38bf9a1c | 17 | #include "libs/Module.h" |
807b9b57 | 18 | #include "ActuatorCoordinates.h" |
4cff3ded | 19 | |
5673fe39 MM |
20 | class Gcode; |
21 | class BaseSolution; | |
22 | class StepperMotor; | |
4cff3ded AW |
23 | |
24 | class Robot : public Module { | |
25 | public: | |
26 | Robot(); | |
27 | void on_module_loaded(); | |
28 | void on_gcode_received(void* argument); | |
5647f709 | 29 | |
1ad23cd3 | 30 | void reset_axis_position(float position, int axis); |
cef9acea | 31 | void reset_axis_position(float x, float y, float z); |
728477c4 | 32 | void reset_position_from_current_actuator_position(); |
1ad23cd3 MM |
33 | void get_axis_position(float position[]); |
34 | float to_millimeters(float value); | |
35 | float from_millimeters(float value); | |
dd0a7cfa | 36 | float get_seconds_per_minute() const { return seconds_per_minute; } |
76ddeb67 | 37 | float get_z_maxfeedrate() const { return this->max_speeds[2]; } |
02e4b295 JM |
38 | void setToolOffset(const float offset[3]); |
39 | float get_feed_rate() const { return feed_rate; } | |
212caccd JM |
40 | void push_state(); |
41 | void pop_state(); | |
3c9fee28 | 42 | void check_max_actuator_speeds(); |
a63da33c | 43 | |
6de8ab5b | 44 | BaseSolution* arm_solution; // Selected Arm solution ( millimeters to step calculation ) |
dd0a7cfa JM |
45 | |
46 | // gets accessed by Panel, Endstops, ZProbe | |
807b9b57 | 47 | std::array<StepperMotor*, k_max_actuators> actuators; |
a974cd04 | 48 | |
3632a517 JM |
49 | // set by a leveling strategy to transform the target of a move according to the current plan |
50 | std::function<void(float[3])> compensationTransform; | |
33742399 | 51 | |
02e4b295 JM |
52 | struct { |
53 | bool inch_mode:1; // true for inch mode, false for millimeter mode ( default ) | |
54 | bool absolute_mode:1; // true for absolute mode ( default ), false for relative mode | |
55 | }; | |
56 | ||
a974cd04 | 57 | private: |
807b9b57 | 58 | void load_config(); |
d149c730 | 59 | void distance_in_gcode_is_known(Gcode* gcode); |
928467c0 | 60 | void append_milestone( Gcode *gcode, float target[], float rate_mm_s); |
da947c62 | 61 | void append_line( Gcode* gcode, float target[], float rate_mm_s); |
1ad23cd3 | 62 | void append_arc( Gcode* gcode, float target[], float offset[], float radius, bool is_clockwise ); |
1ad23cd3 | 63 | void compute_arc(Gcode* gcode, float offset[], float target[]); |
6de8ab5b | 64 | |
1ad23cd3 | 65 | float theta(float x, float y); |
4cff3ded | 66 | void select_plane(uint8_t axis_0, uint8_t axis_1, uint8_t axis_2); |
dd0a7cfa | 67 | void clearToolOffset(); |
4cff3ded | 68 | |
807b9b57 JM |
69 | // Workspace coordinate systems |
70 | using wcs_t= std::tuple<float, float, float>; | |
71 | static const size_t k_max_wcs= 9; // setup 9 WCS offsets | |
72 | std::array<wcs_t, k_max_wcs> wcs_offsets; // these are persistent once set | |
73 | uint8_t current_wcs{0}; // 0 means G54 in enabled thisĀ is persistent | |
74 | wcs_t g92_offset; | |
75 | ||
76 | using saved_state_t= std::tuple<float, float, bool, bool>; // save current feedrate and absolute mode, inch mode | |
562db364 | 77 | std::stack<saved_state_t> state_stack; // saves state from M120 |
807b9b57 | 78 | |
1ad23cd3 | 79 | float last_milestone[3]; // Last position, in millimeters |
3632a517 | 80 | float transformed_last_milestone[3]; // Last transformed position |
3632a517 | 81 | int8_t motion_mode; // Motion mode for the current received Gcode |
728477c4 | 82 | uint8_t plane_axis_0, plane_axis_1, plane_axis_2; // Current plane ( XY, XZ, YZ ) |
1ad23cd3 MM |
83 | float seek_rate; // Current rate for seeking moves ( mm/s ) |
84 | float feed_rate; // Current rate for feeding moves ( mm/s ) | |
1ad23cd3 MM |
85 | float mm_per_line_segment; // Setting : Used to split lines into segments |
86 | float mm_per_arc_segment; // Setting : Used to split arcs into segmentrs | |
87 | float delta_segments_per_second; // Setting : Used to split lines into segments for delta based on speed | |
dd0a7cfa | 88 | float seconds_per_minute; // for realtime speed change |
7369629d | 89 | |
b66fb830 AW |
90 | // Number of arc generation iterations by small angle approximation before exact arc trajectory |
91 | // correction. This parameter maybe decreased if there are issues with the accuracy of the arc | |
92 | // generations. In general, the default value is more than enough for the intended CNC applications | |
93 | // of grbl, and should be on the order or greater than the size of the buffer to help with the | |
94 | // computational efficiency of generating arcs. | |
95 | int arc_correction; // Setting : how often to rectify arc computation | |
1ad23cd3 | 96 | float max_speeds[3]; // Setting : max allowable speed in mm/m for each axis |
b66fb830 | 97 | |
c7689006 | 98 | float toolOffset[3]; |
5966b7d0 | 99 | |
dd0a7cfa JM |
100 | // Used by Stepper, Planner |
101 | friend class Planner; | |
102 | friend class Stepper; | |
4cff3ded AW |
103 | }; |
104 | ||
6de8ab5b | 105 | // Convert from inches to millimeters ( our internal storage unit ) if needed |
1ad23cd3 | 106 | inline float Robot::to_millimeters( float value ){ |
03b01bac | 107 | return this->inch_mode ? value * 25.4F : value; |
6de8ab5b | 108 | } |
1ad23cd3 | 109 | inline float Robot::from_millimeters( float value){ |
03b01bac | 110 | return this->inch_mode ? value/25.4F : value; |
6de8ab5b | 111 | } |
1ad23cd3 | 112 | inline void Robot::get_axis_position(float position[]){ |
2ba859c9 | 113 | memcpy(position, this->last_milestone, sizeof(float)*3 ); |
6de8ab5b SK |
114 | } |
115 | ||
4cff3ded | 116 | #endif |