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" |
4cff3ded | 18 | |
5673fe39 MM |
19 | class Gcode; |
20 | class BaseSolution; | |
21 | class StepperMotor; | |
4cff3ded AW |
22 | |
23 | class Robot : public Module { | |
24 | public: | |
25 | Robot(); | |
26 | void on_module_loaded(); | |
da24d6ae | 27 | void on_config_reload(void* argument); |
4cff3ded | 28 | void on_gcode_received(void* argument); |
b55cfff1 JM |
29 | void on_get_public_data(void* argument); |
30 | void on_set_public_data(void* argument); | |
728477c4 | 31 | void on_halt(void *arg); |
5647f709 | 32 | |
1ad23cd3 | 33 | void reset_axis_position(float position, int axis); |
cef9acea | 34 | void reset_axis_position(float x, float y, float z); |
728477c4 | 35 | void reset_position_from_current_actuator_position(); |
1ad23cd3 MM |
36 | void get_axis_position(float position[]); |
37 | float to_millimeters(float value); | |
38 | float from_millimeters(float value); | |
dd0a7cfa | 39 | float get_seconds_per_minute() const { return seconds_per_minute; } |
76ddeb67 | 40 | float get_z_maxfeedrate() const { return this->max_speeds[2]; } |
02e4b295 JM |
41 | void setToolOffset(const float offset[3]); |
42 | float get_feed_rate() const { return feed_rate; } | |
a63da33c | 43 | |
6de8ab5b | 44 | BaseSolution* arm_solution; // Selected Arm solution ( millimeters to step calculation ) |
dd0a7cfa JM |
45 | |
46 | // gets accessed by Panel, Endstops, ZProbe | |
47 | std::vector<StepperMotor*> 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: |
d149c730 | 58 | void distance_in_gcode_is_known(Gcode* gcode); |
928467c0 | 59 | void append_milestone( Gcode *gcode, float target[], float rate_mm_s); |
da947c62 | 60 | void append_line( Gcode* gcode, float target[], float rate_mm_s); |
1ad23cd3 MM |
61 | //void append_arc(float theta_start, float angular_travel, float radius, float depth, float rate); |
62 | void append_arc( Gcode* gcode, float target[], float offset[], float radius, bool is_clockwise ); | |
aab6cbba AW |
63 | |
64 | ||
1ad23cd3 | 65 | void compute_arc(Gcode* gcode, float offset[], float target[]); |
6de8ab5b | 66 | |
1ad23cd3 | 67 | float theta(float x, float y); |
4cff3ded | 68 | void select_plane(uint8_t axis_0, uint8_t axis_1, uint8_t axis_2); |
dd0a7cfa JM |
69 | void clearToolOffset(); |
70 | void check_max_actuator_speeds(); | |
4cff3ded | 71 | |
562db364 JM |
72 | typedef std::tuple<float, float, bool> saved_state_t; // save current feedrate and absolute mode |
73 | std::stack<saved_state_t> state_stack; // saves state from M120 | |
1ad23cd3 | 74 | float last_milestone[3]; // Last position, in millimeters |
3632a517 | 75 | float transformed_last_milestone[3]; // Last transformed position |
3632a517 | 76 | int8_t motion_mode; // Motion mode for the current received Gcode |
728477c4 | 77 | uint8_t plane_axis_0, plane_axis_1, plane_axis_2; // Current plane ( XY, XZ, YZ ) |
1ad23cd3 MM |
78 | float seek_rate; // Current rate for seeking moves ( mm/s ) |
79 | float feed_rate; // Current rate for feeding moves ( mm/s ) | |
1ad23cd3 MM |
80 | float mm_per_line_segment; // Setting : Used to split lines into segments |
81 | float mm_per_arc_segment; // Setting : Used to split arcs into segmentrs | |
82 | float delta_segments_per_second; // Setting : Used to split lines into segments for delta based on speed | |
dd0a7cfa | 83 | float seconds_per_minute; // for realtime speed change |
7369629d | 84 | |
b66fb830 AW |
85 | // Number of arc generation iterations by small angle approximation before exact arc trajectory |
86 | // correction. This parameter maybe decreased if there are issues with the accuracy of the arc | |
87 | // generations. In general, the default value is more than enough for the intended CNC applications | |
88 | // of grbl, and should be on the order or greater than the size of the buffer to help with the | |
89 | // computational efficiency of generating arcs. | |
90 | int arc_correction; // Setting : how often to rectify arc computation | |
1ad23cd3 | 91 | float max_speeds[3]; // Setting : max allowable speed in mm/m for each axis |
b66fb830 | 92 | |
c7689006 | 93 | float toolOffset[3]; |
5966b7d0 | 94 | |
dd0a7cfa JM |
95 | // Used by Stepper, Planner |
96 | friend class Planner; | |
97 | friend class Stepper; | |
98 | ||
670fa10b L |
99 | StepperMotor* alpha_stepper_motor; |
100 | StepperMotor* beta_stepper_motor; | |
101 | StepperMotor* gamma_stepper_motor; | |
728477c4 JM |
102 | |
103 | struct { | |
104 | bool halted:1; | |
728477c4 | 105 | }; |
4cff3ded AW |
106 | }; |
107 | ||
6de8ab5b | 108 | // Convert from inches to millimeters ( our internal storage unit ) if needed |
1ad23cd3 | 109 | inline float Robot::to_millimeters( float value ){ |
6de8ab5b SK |
110 | return this->inch_mode ? value * 25.4 : value; |
111 | } | |
1ad23cd3 | 112 | inline float Robot::from_millimeters( float value){ |
6de8ab5b SK |
113 | return this->inch_mode ? value/25.4 : value; |
114 | } | |
1ad23cd3 | 115 | inline void Robot::get_axis_position(float position[]){ |
2ba859c9 | 116 | memcpy(position, this->last_milestone, sizeof(float)*3 ); |
6de8ab5b SK |
117 | } |
118 | ||
4cff3ded | 119 | #endif |