Michael Spencer / Smoothie

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

Committer:
Michael J. Spencer
Date:
Fri Feb 28 18:52:52 2014 -0800
Revision:
2:1df0b61d3b5a
Parent:
0:31e91bb0ef3c
Update to latest Smoothie.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Michael J. Spencer 2:1df0b61d3b5a 1 /*
scachat 0:31e91bb0ef3c 2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
scachat 0:31e91bb0ef3c 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.
scachat 0:31e91bb0ef3c 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.
Michael J. Spencer 2:1df0b61d3b5a 5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
scachat 0:31e91bb0ef3c 6 */
scachat 0:31e91bb0ef3c 7
scachat 0:31e91bb0ef3c 8 #ifndef ROBOT_H
scachat 0:31e91bb0ef3c 9 #define ROBOT_H
scachat 0:31e91bb0ef3c 10
scachat 0:31e91bb0ef3c 11 #include <string>
scachat 0:31e91bb0ef3c 12 using std::string;
scachat 0:31e91bb0ef3c 13 #include "libs/Module.h"
Michael J. Spencer 2:1df0b61d3b5a 14 #include "RobotPublicAccess.h"
scachat 0:31e91bb0ef3c 15
scachat 0:31e91bb0ef3c 16 #define NEXT_ACTION_DEFAULT 0
scachat 0:31e91bb0ef3c 17 #define NEXT_ACTION_DWELL 1
scachat 0:31e91bb0ef3c 18 #define NEXT_ACTION_GO_HOME 2
scachat 0:31e91bb0ef3c 19
scachat 0:31e91bb0ef3c 20 #define MOTION_MODE_SEEK 0 // G0
scachat 0:31e91bb0ef3c 21 #define MOTION_MODE_LINEAR 1 // G1
scachat 0:31e91bb0ef3c 22 #define MOTION_MODE_CW_ARC 2 // G2
scachat 0:31e91bb0ef3c 23 #define MOTION_MODE_CCW_ARC 3 // G3
scachat 0:31e91bb0ef3c 24 #define MOTION_MODE_CANCEL 4 // G80
scachat 0:31e91bb0ef3c 25
scachat 0:31e91bb0ef3c 26 #define PATH_CONTROL_MODE_EXACT_PATH 0
scachat 0:31e91bb0ef3c 27 #define PATH_CONTROL_MODE_EXACT_STOP 1
scachat 0:31e91bb0ef3c 28 #define PATH_CONTROL_MODE_CONTINOUS 2
scachat 0:31e91bb0ef3c 29
scachat 0:31e91bb0ef3c 30 #define PROGRAM_FLOW_RUNNING 0
scachat 0:31e91bb0ef3c 31 #define PROGRAM_FLOW_PAUSED 1
scachat 0:31e91bb0ef3c 32 #define PROGRAM_FLOW_COMPLETED 2
scachat 0:31e91bb0ef3c 33
scachat 0:31e91bb0ef3c 34 #define SPINDLE_DIRECTION_CW 0
scachat 0:31e91bb0ef3c 35 #define SPINDLE_DIRECTION_CCW 1
scachat 0:31e91bb0ef3c 36
Michael J. Spencer 2:1df0b61d3b5a 37 class Gcode;
Michael J. Spencer 2:1df0b61d3b5a 38 class BaseSolution;
Michael J. Spencer 2:1df0b61d3b5a 39 class StepperMotor;
scachat 0:31e91bb0ef3c 40
scachat 0:31e91bb0ef3c 41 class Robot : public Module {
scachat 0:31e91bb0ef3c 42 public:
scachat 0:31e91bb0ef3c 43 Robot();
Michael J. Spencer 2:1df0b61d3b5a 44 void on_module_loaded();
Michael J. Spencer 2:1df0b61d3b5a 45 void on_config_reload(void* argument);
Michael J. Spencer 2:1df0b61d3b5a 46 void on_gcode_received(void* argument);
Michael J. Spencer 2:1df0b61d3b5a 47 void on_get_public_data(void* argument);
Michael J. Spencer 2:1df0b61d3b5a 48 void on_set_public_data(void* argument);
Michael J. Spencer 2:1df0b61d3b5a 49
Michael J. Spencer 2:1df0b61d3b5a 50 void reset_axis_position(float position, int axis);
Michael J. Spencer 2:1df0b61d3b5a 51 void get_axis_position(float position[]);
Michael J. Spencer 2:1df0b61d3b5a 52 float to_millimeters(float value);
Michael J. Spencer 2:1df0b61d3b5a 53 float from_millimeters(float value);
Michael J. Spencer 2:1df0b61d3b5a 54
Michael J. Spencer 2:1df0b61d3b5a 55 BaseSolution* arm_solution; // Selected Arm solution ( millimeters to step calculation )
Michael J. Spencer 2:1df0b61d3b5a 56 bool absolute_mode; // true for absolute mode ( default ), false for relative mode
Michael J. Spencer 2:1df0b61d3b5a 57
Michael J. Spencer 2:1df0b61d3b5a 58 private:
Michael J. Spencer 2:1df0b61d3b5a 59 void distance_in_gcode_is_known(Gcode* gcode);
Michael J. Spencer 2:1df0b61d3b5a 60 void append_milestone( float target[], float rate_mm_s);
Michael J. Spencer 2:1df0b61d3b5a 61 void append_line( Gcode* gcode, float target[], float rate_mm_s);
Michael J. Spencer 2:1df0b61d3b5a 62 //void append_arc(float theta_start, float angular_travel, float radius, float depth, float rate);
Michael J. Spencer 2:1df0b61d3b5a 63 void append_arc( Gcode* gcode, float target[], float offset[], float radius, bool is_clockwise );
scachat 0:31e91bb0ef3c 64
scachat 0:31e91bb0ef3c 65
Michael J. Spencer 2:1df0b61d3b5a 66 void compute_arc(Gcode* gcode, float offset[], float target[]);
Michael J. Spencer 2:1df0b61d3b5a 67
Michael J. Spencer 2:1df0b61d3b5a 68 float theta(float x, float y);
scachat 0:31e91bb0ef3c 69 void select_plane(uint8_t axis_0, uint8_t axis_1, uint8_t axis_2);
scachat 0:31e91bb0ef3c 70
Michael J. Spencer 2:1df0b61d3b5a 71 float last_milestone[3]; // Last position, in millimeters
Michael J. Spencer 2:1df0b61d3b5a 72 bool inch_mode; // true for inch mode, false for millimeter mode ( default )
Michael J. Spencer 2:1df0b61d3b5a 73 int8_t motion_mode; // Motion mode for the current received Gcode
Michael J. Spencer 2:1df0b61d3b5a 74 float seek_rate; // Current rate for seeking moves ( mm/s )
Michael J. Spencer 2:1df0b61d3b5a 75 float feed_rate; // Current rate for feeding moves ( mm/s )
scachat 0:31e91bb0ef3c 76 uint8_t plane_axis_0, plane_axis_1, plane_axis_2; // Current plane ( XY, XZ, YZ )
Michael J. Spencer 2:1df0b61d3b5a 77 float mm_per_line_segment; // Setting : Used to split lines into segments
Michael J. Spencer 2:1df0b61d3b5a 78 float mm_per_arc_segment; // Setting : Used to split arcs into segmentrs
Michael J. Spencer 2:1df0b61d3b5a 79 float delta_segments_per_second; // Setting : Used to split lines into segments for delta based on speed
Michael J. Spencer 2:1df0b61d3b5a 80
scachat 0:31e91bb0ef3c 81 // Number of arc generation iterations by small angle approximation before exact arc trajectory
scachat 0:31e91bb0ef3c 82 // correction. This parameter maybe decreased if there are issues with the accuracy of the arc
scachat 0:31e91bb0ef3c 83 // generations. In general, the default value is more than enough for the intended CNC applications
scachat 0:31e91bb0ef3c 84 // of grbl, and should be on the order or greater than the size of the buffer to help with the
scachat 0:31e91bb0ef3c 85 // computational efficiency of generating arcs.
scachat 0:31e91bb0ef3c 86 int arc_correction; // Setting : how often to rectify arc computation
Michael J. Spencer 2:1df0b61d3b5a 87 float max_speeds[3]; // Setting : max allowable speed in mm/m for each axis
scachat 0:31e91bb0ef3c 88
Michael J. Spencer 2:1df0b61d3b5a 89 // Used by Stepper
Michael J. Spencer 2:1df0b61d3b5a 90 public:
Michael J. Spencer 2:1df0b61d3b5a 91 StepperMotor* alpha_stepper_motor;
Michael J. Spencer 2:1df0b61d3b5a 92 StepperMotor* beta_stepper_motor;
Michael J. Spencer 2:1df0b61d3b5a 93 StepperMotor* gamma_stepper_motor;
Michael J. Spencer 2:1df0b61d3b5a 94
Michael J. Spencer 2:1df0b61d3b5a 95 std::vector<StepperMotor*> actuators;
Michael J. Spencer 2:1df0b61d3b5a 96
Michael J. Spencer 2:1df0b61d3b5a 97 float seconds_per_minute; // for realtime speed change
scachat 0:31e91bb0ef3c 98 };
scachat 0:31e91bb0ef3c 99
Michael J. Spencer 2:1df0b61d3b5a 100 // Convert from inches to millimeters ( our internal storage unit ) if needed
Michael J. Spencer 2:1df0b61d3b5a 101 inline float Robot::to_millimeters( float value ){
Michael J. Spencer 2:1df0b61d3b5a 102 return this->inch_mode ? value * 25.4 : value;
Michael J. Spencer 2:1df0b61d3b5a 103 }
Michael J. Spencer 2:1df0b61d3b5a 104 inline float Robot::from_millimeters( float value){
Michael J. Spencer 2:1df0b61d3b5a 105 return this->inch_mode ? value/25.4 : value;
Michael J. Spencer 2:1df0b61d3b5a 106 }
Michael J. Spencer 2:1df0b61d3b5a 107 inline void Robot::get_axis_position(float position[]){
Michael J. Spencer 2:1df0b61d3b5a 108 memcpy(position, this->last_milestone, sizeof(float)*3 );
Michael J. Spencer 2:1df0b61d3b5a 109 }
Michael J. Spencer 2:1df0b61d3b5a 110
scachat 0:31e91bb0ef3c 111 #endif