refactor
[clinton/Smoothieware.git] / src / modules / robot / Robot.h
CommitLineData
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>
12using std::string;
66383b80 13#include <string.h>
33742399 14#include <functional>
562db364 15#include <stack>
4cff3ded 16
38bf9a1c 17#include "libs/Module.h"
807b9b57 18#include "ActuatorCoordinates.h"
4cff3ded 19
5673fe39
MM
20class Gcode;
21class BaseSolution;
22class StepperMotor;
4cff3ded
AW
23
24class Robot : public Module {
25 public:
26 Robot();
27 void on_module_loaded();
28 void on_gcode_received(void* argument);
5647f709 29
1ad23cd3 30 void reset_axis_position(float position, int axis);
cef9acea 31 void reset_axis_position(float x, float y, float z);
728477c4 32 void reset_position_from_current_actuator_position();
dd0a7cfa 33 float get_seconds_per_minute() const { return seconds_per_minute; }
76ddeb67 34 float get_z_maxfeedrate() const { return this->max_speeds[2]; }
02e4b295
JM
35 void setToolOffset(const float offset[3]);
36 float get_feed_rate() const { return feed_rate; }
212caccd
JM
37 void push_state();
38 void pop_state();
3c9fee28 39 void check_max_actuator_speeds();
2791c829
JM
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); }
e03f2747 43 int print_position(uint8_t subcode, char *buf, size_t bufsize) const;
40843ebc 44 uint8_t get_current_wcs() const { return current_wcs; }
a63da33c 45
34210908
JM
46 using wcs_t= std::tuple<float, float, float>;
47 std::vector<wcs_t> get_wcs_state() const;
48
6de8ab5b 49 BaseSolution* arm_solution; // Selected Arm solution ( millimeters to step calculation )
dd0a7cfa
JM
50
51 // gets accessed by Panel, Endstops, ZProbe
807b9b57 52 std::array<StepperMotor*, k_max_actuators> actuators;
a974cd04 53
3632a517
JM
54 // set by a leveling strategy to transform the target of a move according to the current plan
55 std::function<void(float[3])> compensationTransform;
33742399 56
02e4b295
JM
57 struct {
58 bool inch_mode:1; // true for inch mode, false for millimeter mode ( default )
59 bool absolute_mode:1; // true for absolute mode ( default ), false for relative mode
00e607c7 60 bool next_command_is_MCS:1; // set by G53
40843ebc
JM
61 uint8_t plane_axis_0:2; // Current plane ( XY, XZ, YZ )
62 uint8_t plane_axis_1:2;
63 uint8_t plane_axis_2:2;
02e4b295
JM
64 };
65
a974cd04 66 private:
807b9b57 67 void load_config();
d149c730 68 void distance_in_gcode_is_known(Gcode* gcode);
350c8a60
JM
69 bool append_milestone( Gcode *gcode, const float target[], float rate_mm_s);
70 bool append_line( Gcode* gcode, const float target[], float rate_mm_s);
71 bool append_arc( Gcode* gcode, const float target[], const float offset[], float radius, bool is_clockwise );
72 bool compute_arc(Gcode* gcode, const float offset[], const float target[]);
c2f7c261 73 void process_move(Gcode *gcode);
6de8ab5b 74
1ad23cd3 75 float theta(float x, float y);
4cff3ded 76 void select_plane(uint8_t axis_0, uint8_t axis_1, uint8_t axis_2);
dd0a7cfa 77 void clearToolOffset();
4cff3ded 78
807b9b57 79 // Workspace coordinate systems
c2f7c261 80 wcs_t mcs2wcs(const float *pos) const;
c2f7c261 81
807b9b57 82 static const size_t k_max_wcs= 9; // setup 9 WCS offsets
34210908
JM
83 std::array<wcs_t, k_max_wcs> wcs_offsets; // these are persistent once saved with M500
84 uint8_t current_wcs{0}; // 0 means G54 is enabled thisĀ is persistent once saved with M500
807b9b57 85 wcs_t g92_offset;
c2f7c261 86 wcs_t tool_offset; // used for multiple extruders, sets the tool offset for the current extruder applied first
807b9b57 87
a6bbe768 88 using saved_state_t= std::tuple<float, float, bool, bool, uint8_t>; // save current feedrate and absolute mode, inch mode, current_wcs
562db364 89 std::stack<saved_state_t> state_stack; // saves state from M120
807b9b57 90
c2f7c261
JM
91 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
92 float last_machine_position[3]; // Last machine position, which is the position before converting to actuator coordinates (includes compensation transform)
3632a517 93 int8_t motion_mode; // Motion mode for the current received Gcode
1ad23cd3
MM
94 float seek_rate; // Current rate for seeking moves ( mm/s )
95 float feed_rate; // Current rate for feeding moves ( mm/s )
1ad23cd3
MM
96 float mm_per_line_segment; // Setting : Used to split lines into segments
97 float mm_per_arc_segment; // Setting : Used to split arcs into segmentrs
98 float delta_segments_per_second; // Setting : Used to split lines into segments for delta based on speed
dd0a7cfa 99 float seconds_per_minute; // for realtime speed change
7369629d 100
b66fb830
AW
101 // Number of arc generation iterations by small angle approximation before exact arc trajectory
102 // correction. This parameter maybe decreased if there are issues with the accuracy of the arc
103 // generations. In general, the default value is more than enough for the intended CNC applications
104 // of grbl, and should be on the order or greater than the size of the buffer to help with the
105 // computational efficiency of generating arcs.
106 int arc_correction; // Setting : how often to rectify arc computation
1ad23cd3 107 float max_speeds[3]; // Setting : max allowable speed in mm/m for each axis
b66fb830 108
dd0a7cfa
JM
109 // Used by Stepper, Planner
110 friend class Planner;
111 friend class Stepper;
4cff3ded
AW
112};
113
6de8ab5b 114
4cff3ded 115#endif