-
-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathMachineState.cpp
More file actions
133 lines (89 loc) · 3.32 KB
/
MachineState.cpp
File metadata and controls
133 lines (89 loc) · 3.32 KB
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
/******************************************************************************\
CAMotics is an Open-Source simulation and CAM software.
Copyright (C) 2011-2019 Joseph Coffland <joseph@cauldrondevelopment.com>
This program 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 2 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
\******************************************************************************/
#include "MachineState.h"
#include <cbang/Exception.h>
#include <cbang/log/Logger.h>
#include <cbang/debug/Debugger.h>
#include <cstring> // For memset()
using namespace std;
using namespace cb;
using namespace GCode;
MachineState::MachineState() :
started(false), feed(0), feedMode(UNITS_PER_MINUTE), speed(0),
spinMode(REVOLUTIONS_PER_MINUTE), maxSpeed(0) {
// Coordinate system
set(CURRENT_COORD_SYSTEM, 1, NO_UNITS);
// Tool
set("_selected_tool", -1, NO_UNITS);
set(TOOL_NUMBER, -1, NO_UNITS);
// Units
set("_metric", 1, NO_UNITS);
set("_imperial", 0, NO_UNITS);
// Arc error
set("_max_arc_error", 0.01, METRIC);
}
void MachineState::start() {started = true;}
void MachineState::end() {
if (!started) THROW("Machine not started");
started = false;
}
void MachineState::setFeed(double feed) {
this->feed = feed;
set("_feed", feed, METRIC);
}
void MachineState::setSpeed(double speed) {
this->speed = speed;
set("_speed", speed, NO_UNITS);
}
void MachineState::setPathMode(path_mode_t mode, double motionBlending,
double naiveCAM) {
set("_path_mode", (unsigned)mode, NO_UNITS);
if (mode == CONTINUOUS_MODE) {
set("_motion_blending_tolerance", motionBlending, METRIC);
set("_naive_cam_tolerance", naiveCAM, METRIC);
}
}
void MachineState::changeTool(unsigned tool) {
set(TOOL_NUMBER, tool, NO_UNITS);
set("_tool", tool, NO_UNITS);
}
Vector3D MachineState::getPosition(axes_t axes) const {
switch (axes) {
case XYZ: return position.getXYZ();
case ABC: return position.getABC();
case UVW: return position.getUVW();
default: THROW("Invalid axes " << axes);
}
}
void MachineState::setPosition(const Axes &position) {
this->position.setFrom(position);
}
double MachineState::get(address_t addr, Units units) const {
return MAX_ADDRESS <= addr ? 0 : params[addr].get(units);
}
void MachineState::set(address_t addr, double value, Units units) {
if (addr < MAX_ADDRESS) params[addr].set(value, units);
}
bool MachineState::has(const string &name) const {
return named.find(name) != named.end();
}
double MachineState::get(const string &name, Units units) const {
auto it = named.find(name);
return it == named.end() ? 0 : it->second.get(units);
}
void MachineState::set(const string &name, double value, Units units) {
named[name] = Parameter(value, units);
}
void MachineState::clear(const string &name) {named.erase(name);}