Added position reset at homing end; Added min and max axis positions.
[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;
4cff3ded
AW
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"
feb204be
AW
18#include "libs/Pin.h"
19#include "libs/StepperMotor.h"
20
4cff3ded 21
d4f93cf4
AG
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 mm_per_arc_segment_checksum CHECKSUM("mm_per_arc_segment")
26#define arc_correction_checksum CHECKSUM("arc_correction")
27#define x_axis_max_speed_checksum CHECKSUM("x_axis_max_speed")
28#define y_axis_max_speed_checksum CHECKSUM("y_axis_max_speed")
29#define z_axis_max_speed_checksum CHECKSUM("z_axis_max_speed")
4cff3ded
AW
30
31#define NEXT_ACTION_DEFAULT 0
32#define NEXT_ACTION_DWELL 1
33#define NEXT_ACTION_GO_HOME 2
34
35#define MOTION_MODE_SEEK 0 // G0
36#define MOTION_MODE_LINEAR 1 // G1
37#define MOTION_MODE_CW_ARC 2 // G2
38#define MOTION_MODE_CCW_ARC 3 // G3
39#define MOTION_MODE_CANCEL 4 // G80
40
41#define PATH_CONTROL_MODE_EXACT_PATH 0
42#define PATH_CONTROL_MODE_EXACT_STOP 1
43#define PATH_CONTROL_MODE_CONTINOUS 2
44
45#define PROGRAM_FLOW_RUNNING 0
46#define PROGRAM_FLOW_PAUSED 1
47#define PROGRAM_FLOW_COMPLETED 2
48
49#define SPINDLE_DIRECTION_CW 0
50#define SPINDLE_DIRECTION_CCW 1
51
52
53
54class Robot : public Module {
55 public:
56 Robot();
57 void on_module_loaded();
da24d6ae 58 void on_config_reload(void* argument);
4cff3ded 59 void on_gcode_received(void* argument);
3ffe27fb 60 void reset_axis_position(double position, int axis);
a974cd04
BG
61
62 private:
4cff3ded
AW
63 void execute_gcode(Gcode* gcode);
64 void append_milestone( double target[], double feed_rate);
436a2cd1 65 void append_line( Gcode* gcode, double target[], double feed_rate);
aab6cbba 66 //void append_arc(double theta_start, double angular_travel, double radius, double depth, double rate);
436a2cd1 67 void append_arc( Gcode* gcode, double target[], double offset[], double radius, bool is_clockwise );
aab6cbba
AW
68
69
436a2cd1 70 void compute_arc(Gcode* gcode, double offset[], double target[]);
4cff3ded
AW
71 double to_millimeters(double value);
72 double theta(double x, double y);
73 void select_plane(uint8_t axis_0, uint8_t axis_1, uint8_t axis_2);
74
75 double current_position[3]; // Current position, in millimeters
76 double last_milestone[3]; // Last position, in millimeters
77 bool inch_mode; // true for inch mode, false for millimeter mode ( default )
78 bool absolute_mode; // true for absolute mode ( default ), false for relative mode
c83887ea 79 int8_t motion_mode; // Motion mode for the current received Gcode
4cff3ded
AW
80 double seek_rate; // Current rate for seeking moves ( mm/s )
81 double feed_rate; // Current rate for feeding moves ( mm/s )
82 uint8_t plane_axis_0, plane_axis_1, plane_axis_2; // Current plane ( XY, XZ, YZ )
83 BaseSolution* arm_solution; // Selected Arm solution ( millimeters to step calculation )
7b49793d
MM
84 double mm_per_line_segment; // Setting : Used to split lines into segments
85 double mm_per_arc_segment; // Setting : Used to split arcs into segmentrs
7369629d 86
b66fb830
AW
87 // Number of arc generation iterations by small angle approximation before exact arc trajectory
88 // correction. This parameter maybe decreased if there are issues with the accuracy of the arc
89 // generations. In general, the default value is more than enough for the intended CNC applications
90 // of grbl, and should be on the order or greater than the size of the buffer to help with the
91 // computational efficiency of generating arcs.
92 int arc_correction; // Setting : how often to rectify arc computation
7b470506 93 double max_speeds[3]; // Setting : max allowable speed in mm/m for each axis
b66fb830 94
a974cd04
BG
95 // Used by Stepper
96 public:
e4fe5194
MM
97 Pin alpha_step_pin;
98 Pin alpha_dir_pin;
99 Pin alpha_en_pin;
100 Pin beta_step_pin;
101 Pin beta_dir_pin;
102 Pin beta_en_pin;
103 Pin gamma_step_pin;
104 Pin gamma_dir_pin;
105 Pin gamma_en_pin;
7369629d 106
feb204be
AW
107 StepperMotor* alpha_stepper_motor;
108 StepperMotor* beta_stepper_motor;
109 StepperMotor* gamma_stepper_motor;
110
7369629d 111 double seconds_per_minute; // for realtime speed change
4cff3ded
AW
112};
113
114#endif