Implement Johanns method of specifying segments for delta bots in segments per second.
[clinton/Smoothieware.git] / src / modules / robot / Robot.h
1 /*
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/>.
6 */
7
8 #ifndef ROBOT_H
9 #define ROBOT_H
10
11 #include <string>
12 using std::string;
13 #include "libs/Module.h"
14 #include "libs/Kernel.h"
15 #include "../communication/utils/Gcode.h"
16 #include "arm_solutions/BaseSolution.h"
17 #include "Planner.h"
18 #include "libs/Pin.h"
19 #include "libs/StepperMotor.h"
20
21
22 #define default_seek_rate_checksum CHECKSUM("default_seek_rate")
23 #define default_feed_rate_checksum CHECKSUM("default_feed_rate")
24 #define mm_per_line_segment_checksum CHECKSUM("mm_per_line_segment")
25 #define delta_segments_per_second_checksum CHECKSUM("delta_segments_per_second")
26 #define mm_per_arc_segment_checksum CHECKSUM("mm_per_arc_segment")
27 #define arc_correction_checksum CHECKSUM("arc_correction")
28 #define x_axis_max_speed_checksum CHECKSUM("x_axis_max_speed")
29 #define y_axis_max_speed_checksum CHECKSUM("y_axis_max_speed")
30 #define z_axis_max_speed_checksum CHECKSUM("z_axis_max_speed")
31 #define arm_solution_checksum CHECKSUM("arm_solution")
32 #define cartesian_checksum CHECKSUM("cartesian")
33 #define rotatable_cartesian_checksum CHECKSUM("rotatable_cartesian")
34 #define rostock_checksum CHECKSUM("rostock")
35 #define delta_checksum CHECKSUM("delta")
36
37 #define NEXT_ACTION_DEFAULT 0
38 #define NEXT_ACTION_DWELL 1
39 #define NEXT_ACTION_GO_HOME 2
40
41 #define MOTION_MODE_SEEK 0 // G0
42 #define MOTION_MODE_LINEAR 1 // G1
43 #define MOTION_MODE_CW_ARC 2 // G2
44 #define MOTION_MODE_CCW_ARC 3 // G3
45 #define MOTION_MODE_CANCEL 4 // G80
46
47 #define PATH_CONTROL_MODE_EXACT_PATH 0
48 #define PATH_CONTROL_MODE_EXACT_STOP 1
49 #define PATH_CONTROL_MODE_CONTINOUS 2
50
51 #define PROGRAM_FLOW_RUNNING 0
52 #define PROGRAM_FLOW_PAUSED 1
53 #define PROGRAM_FLOW_COMPLETED 2
54
55 #define SPINDLE_DIRECTION_CW 0
56 #define SPINDLE_DIRECTION_CCW 1
57
58
59
60 class Robot : public Module {
61 public:
62 Robot();
63 void on_module_loaded();
64 void on_config_reload(void* argument);
65 void on_gcode_received(void* argument);
66 void reset_axis_position(double position, int axis);
67
68 private:
69 void execute_gcode(Gcode* gcode);
70 void append_milestone( double target[], double feed_rate);
71 void append_line( Gcode* gcode, double target[], double feed_rate);
72 //void append_arc(double theta_start, double angular_travel, double radius, double depth, double rate);
73 void append_arc( Gcode* gcode, double target[], double offset[], double radius, bool is_clockwise );
74
75
76 void compute_arc(Gcode* gcode, double offset[], double target[]);
77 double to_millimeters(double value);
78 double theta(double x, double y);
79 void select_plane(uint8_t axis_0, uint8_t axis_1, uint8_t axis_2);
80
81 double current_position[3]; // Current position, in millimeters
82 double last_milestone[3]; // Last position, in millimeters
83 bool inch_mode; // true for inch mode, false for millimeter mode ( default )
84 bool absolute_mode; // true for absolute mode ( default ), false for relative mode
85 int8_t motion_mode; // Motion mode for the current received Gcode
86 double seek_rate; // Current rate for seeking moves ( mm/s )
87 double feed_rate; // Current rate for feeding moves ( mm/s )
88 uint8_t plane_axis_0, plane_axis_1, plane_axis_2; // Current plane ( XY, XZ, YZ )
89 BaseSolution* arm_solution; // Selected Arm solution ( millimeters to step calculation )
90 double mm_per_line_segment; // Setting : Used to split lines into segments
91 double mm_per_arc_segment; // Setting : Used to split arcs into segmentrs
92 double delta_segments_per_second; // Setting : Used to split lines into segments for delta based on speed
93
94 // Number of arc generation iterations by small angle approximation before exact arc trajectory
95 // correction. This parameter maybe decreased if there are issues with the accuracy of the arc
96 // generations. In general, the default value is more than enough for the intended CNC applications
97 // of grbl, and should be on the order or greater than the size of the buffer to help with the
98 // computational efficiency of generating arcs.
99 int arc_correction; // Setting : how often to rectify arc computation
100 double max_speeds[3]; // Setting : max allowable speed in mm/m for each axis
101
102 // Used by Stepper
103 public:
104 Pin alpha_step_pin;
105 Pin alpha_dir_pin;
106 Pin alpha_en_pin;
107 Pin beta_step_pin;
108 Pin beta_dir_pin;
109 Pin beta_en_pin;
110 Pin gamma_step_pin;
111 Pin gamma_dir_pin;
112 Pin gamma_en_pin;
113
114 StepperMotor* alpha_stepper_motor;
115 StepperMotor* beta_stepper_motor;
116 StepperMotor* gamma_stepper_motor;
117
118 double seconds_per_minute; // for realtime speed change
119 };
120
121 #endif