-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathgcode-machine-control.h
148 lines (118 loc) · 5.73 KB
/
gcode-machine-control.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
* (c) 2013, 2014 Henner Zeller <[email protected]>
*
* This file is part of BeagleG. http://github.com/hzeller/beagleg
*
* BeagleG 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.
*
* BeagleG 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.
*
* You should have received a copy of the GNU General Public License
* along with BeagleG. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _BEAGLEG_GCODE_MACHINE_CONTROL_H_
#define _BEAGLEG_GCODE_MACHINE_CONTROL_H_
#include <string>
#include "common/container.h"
#include "gcode-parser/gcode-parser.h"
#include "hardware-mapping.h"
class SegmentQueue;
class ConfigParser;
class Spindle;
typedef AxesRegister FloatAxisConfig;
/* Configuration constants for the controller.
* Parameters in the arrays are always indexed by logical axes, e.g. AXIS_X.
* The output mapping to the physical driver is controlled by output_mapping
*/
struct MachineControlConfig {
MachineControlConfig();
// Read values from configuration file.
bool ConfigureFromFile(const ConfigParser &parser);
// Arrays with values for each axis
FloatAxisConfig steps_per_mm; // Steps per mm for each logical axis.
FloatAxisConfig
move_range_mm; // Range of axes in mm (0..range[axis]). -1: no limit
FloatAxisConfig max_feedrate; // Max feedrate for axis (mm/s)
FloatAxisConfig acceleration; // Max acceleration for axis (mm/s^2)
FloatAxisConfig max_probe_feedrate; // Max probe feedrate for axis (mm/s)
float speed_factor; // Multiply feed with. Should be 1.0 by default.
float threshold_angle; // Threshold angle to ignore speed changes
float speed_tune_angle; // Angle added to the angle between vectors for speed
// tuning
std::string home_order; // Order in which axes are homed.
FixedArray<HardwareMapping::AxisTrigger, GCODE_NUM_AXES> homing_trigger;
int auto_motor_disable_seconds; // disable motors automatically after these
// seconds.
int auto_fan_disable_seconds; // Disable fan automatically after these
// seconds.
int auto_fan_pwm; // PWM value to automatically enable fan with.
bool acknowledge_lines; // Respond w/ 'ok' on each command on msg_stream.
bool require_homing; // Require homing before any moves.
bool range_check; // Do machine limit checks. Default 1.
std::string clamp_to_range; // Clamp these axes to machine range before
// range check. Dangerous.
// Support only "" or "Z" right now.
bool debug_print; // Print step-tuples to output_fd if 1.
bool synchronous; // Don't queue, wait for command to finish if 1.
bool enable_pause; // Enable pause switch detection. Default 0.
};
// A class that controls a machine via gcode.
class GCodeMachineControl {
public:
enum class EStopState { NONE, SOFT, HARD };
// The three levels of homing confidence. If we ever switch off
// power to the motors after homing, we can't be sure.
enum class HomingState { NEVER_HOMED, HOMED_BUT_MOTORS_UNPOWERED, HOMED };
// Factor to create a GCodeMachineControl.
// The SegmentQueue provide the low-level motor control ops.
// msg_stream, if non-NULL, sends back return messages on the GCode channel.
// Returns NULL on failure.
static GCodeMachineControl *Create(const MachineControlConfig &config,
SegmentQueue *segment_queue,
HardwareMapping *hardware_mapping,
Spindle *spindle, FILE *msg_stream);
~GCodeMachineControl();
// Set where messages should go.
void SetMsgOut(FILE *msg_stream);
// Get the physical home position of this machine which depend
// on the position of the endstops configured for homing.
// return in *pos register.
void GetHomePos(AxesRegister *pos);
// Return the receiver for parse events. The caller must not assume ownership
// of the returned pointer.
GCodeParser::EventReceiver *ParseEventReceiver();
// Return the E-Stop status.
// Can only be called in the same thread that also handles gcode updates.
EStopState GetEStopStatus();
// Return the Homing status.
// Can only be called in the same thread that also handles gcode updates.
HomingState GetHomeStatus();
// Return the motors enabled status.
// Can only be called in the same thread that also handles gcode updates.
bool GetMotorsEnabled();
// Return current position relative to origin.
// Can only be called in the same thread that also handles gcode updates.
void GetCurrentPosition(AxesRegister *pos);
// Set the internal planner queue size.
// Used to trade-off between command sent - executed motion latency
// and maximum achievable speed.
// Requires 0 < size <= GetMaxLookahead(), returns true on success.
bool SetLookahead(int size);
// Retrieve the internal planning queue size.
int Lookahead() const;
// Get the maximum allowed lookahead size.
int GetMaxLookahead() const;
private:
class Impl;
// The SegmentQueue struct provide the low-level motor control ops.
// msg_stream, if non-NULL, sends back return messages on the GCode channel.
explicit GCodeMachineControl(Impl *Impl);
Impl *const impl_; // opaque state.
};
#endif // _BEAGLEG_GCODE_MACHINE_CONTROL_H_