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