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.
5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
17 #include "libs/Module.h"
18 #include "ActuatorCoordinates.h"
27 class Robot
: public Module
{
29 using wcs_t
= std::tuple
<float, float, float>;
31 void on_module_loaded();
32 void on_gcode_received(void* argument
);
34 void reset_axis_position(float position
, int axis
);
35 void reset_axis_position(float x
, float y
, float z
);
36 void reset_position_from_current_actuator_position();
37 float get_seconds_per_minute() const { return seconds_per_minute
; }
38 float get_z_maxfeedrate() const { return this->max_speeds
[2]; }
39 void setToolOffset(const float offset
[3]);
40 float get_feed_rate() const;
43 void check_max_actuator_speeds();
44 float to_millimeters( float value
) const { return this->inch_mode
? value
* 25.4F
: value
; }
45 float from_millimeters( float value
) const { return this->inch_mode
? value
/25.4F
: value
; }
46 void get_axis_position(float position
[]) const { memcpy(position
, this->last_milestone
, sizeof this->last_milestone
); }
47 wcs_t
get_axis_position() const { return wcs_t(last_milestone
[0], last_milestone
[1], last_milestone
[2]); }
48 int print_position(uint8_t subcode
, char *buf
, size_t bufsize
) const;
49 uint8_t get_current_wcs() const { return current_wcs
; }
51 std::vector
<wcs_t
> get_wcs_state() const;
53 BaseSolution
* arm_solution
; // Selected Arm solution ( millimeters to step calculation )
55 // gets accessed by Panel, Endstops, ZProbe
56 std::array
<StepperMotor
*, k_max_actuators
> actuators
;
58 // set by a leveling strategy to transform the target of a move according to the current plan
59 std::function
<void(float[3])> compensationTransform
;
62 bool inch_mode
:1; // true for inch mode, false for millimeter mode ( default )
63 bool absolute_mode
:1; // true for absolute mode ( default ), false for relative mode
64 bool next_command_is_MCS
:1; // set by G53
65 uint8_t plane_axis_0
:2; // Current plane ( XY, XZ, YZ )
66 uint8_t plane_axis_1
:2;
67 uint8_t plane_axis_2
:2;
72 void distance_in_gcode_is_known(Gcode
* gcode
);
73 bool append_milestone( Gcode
*gcode
, const float target
[], float rate_mm_s
);
74 bool append_line( Gcode
* gcode
, const float target
[], float rate_mm_s
);
75 bool append_arc( Gcode
* gcode
, const float target
[], const float offset
[], float radius
, bool is_clockwise
);
76 bool compute_arc(Gcode
* gcode
, const float offset
[], const float target
[]);
77 void process_move(Gcode
*gcode
);
79 float theta(float x
, float y
);
80 void select_plane(uint8_t axis_0
, uint8_t axis_1
, uint8_t axis_2
);
81 void clearToolOffset();
83 // Workspace coordinate systems
84 wcs_t
mcs2wcs(const float *pos
) const;
86 std::array
<wcs_t
, MAX_WCS
> wcs_offsets
; // these are persistent once saved with M500
87 uint8_t current_wcs
{0}; // 0 means G54 is enabled thisĀ is persistent once saved with M500
89 wcs_t tool_offset
; // used for multiple extruders, sets the tool offset for the current extruder applied first
91 using saved_state_t
= std::tuple
<float, float, bool, bool, uint8_t>; // save current feedrate and absolute mode, inch mode, current_wcs
92 std::stack
<saved_state_t
> state_stack
; // saves state from M120
94 float last_milestone
[3]; // Last requested position, in millimeters, which is what we were requested to move to in the gcode after offsets applied but before compensation transform
95 float last_machine_position
[3]; // Last machine position, which is the position before converting to actuator coordinates (includes compensation transform)
96 int8_t motion_mode
; // Motion mode for the current received Gcode
97 float seek_rate
; // Current rate for seeking moves ( mm/s )
98 float feed_rate
; // Current rate for feeding moves ( mm/s )
99 float mm_per_line_segment
; // Setting : Used to split lines into segments
100 float mm_per_arc_segment
; // Setting : Used to split arcs into segmentrs
101 float delta_segments_per_second
; // Setting : Used to split lines into segments for delta based on speed
102 float seconds_per_minute
; // for realtime speed change
104 // Number of arc generation iterations by small angle approximation before exact arc trajectory
105 // correction. This parameter maybe decreased if there are issues with the accuracy of the arc
106 // generations. In general, the default value is more than enough for the intended CNC applications
107 // of grbl, and should be on the order or greater than the size of the buffer to help with the
108 // computational efficiency of generating arcs.
109 int arc_correction
; // Setting : how often to rectify arc computation
110 float max_speeds
[3]; // Setting : max allowable speed in mm/m for each axis
112 // Used by Stepper, Planner
113 friend class Planner
;
114 friend class Stepper
;