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