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