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> |
4cff3ded | 15 | |
38bf9a1c | 16 | #include "libs/Module.h" |
4cff3ded | 17 | |
5673fe39 MM |
18 | class Gcode; |
19 | class BaseSolution; | |
20 | class StepperMotor; | |
4cff3ded AW |
21 | |
22 | class Robot : public Module { | |
23 | public: | |
24 | Robot(); | |
25 | void on_module_loaded(); | |
da24d6ae | 26 | void on_config_reload(void* argument); |
4cff3ded | 27 | void on_gcode_received(void* argument); |
b55cfff1 JM |
28 | void on_get_public_data(void* argument); |
29 | void on_set_public_data(void* argument); | |
5647f709 | 30 | |
1ad23cd3 | 31 | void reset_axis_position(float position, int axis); |
cef9acea | 32 | void reset_axis_position(float x, float y, float z); |
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]; } |
a63da33c | 38 | |
6de8ab5b | 39 | BaseSolution* arm_solution; // Selected Arm solution ( millimeters to step calculation ) |
a63da33c | 40 | bool absolute_mode; // true for absolute mode ( default ), false for relative mode |
dd0a7cfa JM |
41 | void setToolOffset(const float offset[3]); |
42 | ||
43 | // gets accessed by Panel, Endstops, ZProbe | |
44 | std::vector<StepperMotor*> actuators; | |
a974cd04 | 45 | |
3632a517 JM |
46 | // set by a leveling strategy to transform the target of a move according to the current plan |
47 | std::function<void(float[3])> compensationTransform; | |
33742399 | 48 | |
a974cd04 | 49 | private: |
d149c730 | 50 | void distance_in_gcode_is_known(Gcode* gcode); |
da947c62 MM |
51 | void append_milestone( float target[], float rate_mm_s); |
52 | void append_line( Gcode* gcode, float target[], float rate_mm_s); | |
1ad23cd3 MM |
53 | //void append_arc(float theta_start, float angular_travel, float radius, float depth, float rate); |
54 | void append_arc( Gcode* gcode, float target[], float offset[], float radius, bool is_clockwise ); | |
aab6cbba AW |
55 | |
56 | ||
1ad23cd3 | 57 | void compute_arc(Gcode* gcode, float offset[], float target[]); |
6de8ab5b | 58 | |
1ad23cd3 | 59 | float theta(float x, float y); |
4cff3ded | 60 | void select_plane(uint8_t axis_0, uint8_t axis_1, uint8_t axis_2); |
dd0a7cfa JM |
61 | void clearToolOffset(); |
62 | void check_max_actuator_speeds(); | |
4cff3ded | 63 | |
1ad23cd3 | 64 | float last_milestone[3]; // Last position, in millimeters |
3632a517 JM |
65 | float transformed_last_milestone[3]; // Last transformed position |
66 | bool inch_mode; // true for inch mode, false for millimeter mode ( default ) | |
67 | int8_t motion_mode; // Motion mode for the current received Gcode | |
1ad23cd3 MM |
68 | float seek_rate; // Current rate for seeking moves ( mm/s ) |
69 | float feed_rate; // Current rate for feeding moves ( mm/s ) | |
3632a517 | 70 | uint8_t plane_axis_0, plane_axis_1, plane_axis_2; // Current plane ( XY, XZ, YZ ) |
1ad23cd3 MM |
71 | float mm_per_line_segment; // Setting : Used to split lines into segments |
72 | float mm_per_arc_segment; // Setting : Used to split arcs into segmentrs | |
73 | float delta_segments_per_second; // Setting : Used to split lines into segments for delta based on speed | |
dd0a7cfa | 74 | float seconds_per_minute; // for realtime speed change |
7369629d | 75 | |
b66fb830 AW |
76 | // Number of arc generation iterations by small angle approximation before exact arc trajectory |
77 | // correction. This parameter maybe decreased if there are issues with the accuracy of the arc | |
78 | // generations. In general, the default value is more than enough for the intended CNC applications | |
79 | // of grbl, and should be on the order or greater than the size of the buffer to help with the | |
80 | // computational efficiency of generating arcs. | |
81 | int arc_correction; // Setting : how often to rectify arc computation | |
1ad23cd3 | 82 | float max_speeds[3]; // Setting : max allowable speed in mm/m for each axis |
b66fb830 | 83 | |
c7689006 | 84 | float toolOffset[3]; |
5966b7d0 | 85 | |
dd0a7cfa JM |
86 | // Used by Stepper, Planner |
87 | friend class Planner; | |
88 | friend class Stepper; | |
89 | ||
670fa10b L |
90 | StepperMotor* alpha_stepper_motor; |
91 | StepperMotor* beta_stepper_motor; | |
92 | StepperMotor* gamma_stepper_motor; | |
4cff3ded AW |
93 | }; |
94 | ||
6de8ab5b | 95 | // Convert from inches to millimeters ( our internal storage unit ) if needed |
1ad23cd3 | 96 | inline float Robot::to_millimeters( float value ){ |
6de8ab5b SK |
97 | return this->inch_mode ? value * 25.4 : value; |
98 | } | |
1ad23cd3 | 99 | inline float Robot::from_millimeters( float value){ |
6de8ab5b SK |
100 | return this->inch_mode ? value/25.4 : value; |
101 | } | |
1ad23cd3 | 102 | inline void Robot::get_axis_position(float position[]){ |
2ba859c9 | 103 | memcpy(position, this->last_milestone, sizeof(float)*3 ); |
6de8ab5b SK |
104 | } |
105 | ||
4cff3ded | 106 | #endif |