Track spindle direction in set-spindle events
This commit is contained in:
@@ -8,6 +8,7 @@ void CanonEventSink::reset() {
|
||||
unit_scale_ = 1.0;
|
||||
feed_ = 0.0;
|
||||
spindle_ = 0.0;
|
||||
spindle_direction_ = 0;
|
||||
selected_tool_ = 0;
|
||||
callback_status_ = 0;
|
||||
kinematics_type_ = 1;
|
||||
@@ -114,6 +115,23 @@ void CanonEventSink::set_spindle_speed(double spindle, int line) {
|
||||
spindle_ = spindle;
|
||||
CncSimEvent event = base_event(CNC_SIM_EVENT_SET_SPINDLE, line);
|
||||
event.spindle = spindle_;
|
||||
event.reserved = spindle_direction_;
|
||||
emit(event);
|
||||
}
|
||||
|
||||
void CanonEventSink::start_spindle(int direction, int line) {
|
||||
spindle_direction_ = direction < 0 ? 2 : 1;
|
||||
CncSimEvent event = base_event(CNC_SIM_EVENT_SET_SPINDLE, line);
|
||||
event.spindle = spindle_;
|
||||
event.reserved = spindle_direction_;
|
||||
emit(event);
|
||||
}
|
||||
|
||||
void CanonEventSink::stop_spindle(int line) {
|
||||
spindle_direction_ = 0;
|
||||
CncSimEvent event = base_event(CNC_SIM_EVENT_SET_SPINDLE, line);
|
||||
event.spindle = 0.0;
|
||||
event.reserved = spindle_direction_;
|
||||
emit(event);
|
||||
}
|
||||
|
||||
@@ -201,6 +219,10 @@ double CanonEventSink::spindle_speed() const {
|
||||
return spindle_;
|
||||
}
|
||||
|
||||
int CanonEventSink::spindle_direction() const {
|
||||
return spindle_direction_;
|
||||
}
|
||||
|
||||
int CanonEventSink::selected_tool() const {
|
||||
return selected_tool_;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ public:
|
||||
void select_plane(int plane, int line);
|
||||
void set_feed_rate(double feed, int line);
|
||||
void set_spindle_speed(double spindle, int line);
|
||||
void start_spindle(int direction, int line);
|
||||
void stop_spindle(int line);
|
||||
void select_tool(int tool);
|
||||
void change_tool(int line);
|
||||
void straight_traverse(int line, const CncSimPose &end);
|
||||
@@ -37,6 +39,7 @@ public:
|
||||
double unit_scale() const;
|
||||
double feed_rate() const;
|
||||
double spindle_speed() const;
|
||||
int spindle_direction() const;
|
||||
int selected_tool() const;
|
||||
int kinematics_type() const;
|
||||
bool rtcp_enabled() const;
|
||||
@@ -55,6 +58,7 @@ private:
|
||||
double unit_scale_ = 1.0;
|
||||
double feed_ = 0.0;
|
||||
double spindle_ = 0.0;
|
||||
int spindle_direction_ = 0;
|
||||
int selected_tool_ = 0;
|
||||
bool rtcp_enabled_ = false;
|
||||
double default_rtcp_tool_length_ = 0.0;
|
||||
|
||||
@@ -355,14 +355,20 @@ void SPINDLE_RETRACT_TRAVERSE() {
|
||||
}
|
||||
|
||||
void START_SPINDLE_CLOCKWISE(int, int) {
|
||||
if (active_sink) {
|
||||
active_sink->start_spindle(1, event_line());
|
||||
}
|
||||
}
|
||||
|
||||
void START_SPINDLE_COUNTERCLOCKWISE(int, int) {
|
||||
if (active_sink) {
|
||||
active_sink->start_spindle(-1, event_line());
|
||||
}
|
||||
}
|
||||
|
||||
void STOP_SPINDLE_TURNING(int) {
|
||||
if (active_sink) {
|
||||
active_sink->set_spindle_speed(0.0, 0);
|
||||
active_sink->stop_spindle(event_line());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -621,7 +627,16 @@ double GET_EXTERNAL_SPEED(int) {
|
||||
}
|
||||
|
||||
CANON_DIRECTION GET_EXTERNAL_SPINDLE(int) {
|
||||
return active_sink && active_sink->spindle_speed() != 0.0 ? CANON_CLOCKWISE : CANON_STOPPED;
|
||||
if (!active_sink) {
|
||||
return CANON_STOPPED;
|
||||
}
|
||||
if (active_sink->spindle_direction() == 1) {
|
||||
return CANON_CLOCKWISE;
|
||||
}
|
||||
if (active_sink->spindle_direction() == 2) {
|
||||
return CANON_COUNTERCLOCKWISE;
|
||||
}
|
||||
return CANON_STOPPED;
|
||||
}
|
||||
|
||||
double GET_EXTERNAL_TOOL_LENGTH_XOFFSET() { return 0.0; }
|
||||
|
||||
@@ -336,8 +336,18 @@ int SmokeGcodeParser::parse(const char *program, size_t program_len, std::string
|
||||
|
||||
bool program_end = false;
|
||||
for (int m : m_codes) {
|
||||
if (m == 3 || m == 4 || m == 5) {
|
||||
sink_.set_spindle_speed(m == 5 ? 0.0 : sink_.spindle_speed(), line_number);
|
||||
if (m == 3) {
|
||||
sink_.start_spindle(1, line_number);
|
||||
if (stop_if_callback_aborted(sink_, error)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (m == 4) {
|
||||
sink_.start_spindle(-1, line_number);
|
||||
if (stop_if_callback_aborted(sink_, error)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (m == 5) {
|
||||
sink_.stop_spindle(line_number);
|
||||
if (stop_if_callback_aborted(sink_, error)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -73,6 +73,9 @@ int main() {
|
||||
bool saw_l20_end_line = false;
|
||||
bool saw_probe = false;
|
||||
bool saw_probe_as_feed = false;
|
||||
bool saw_spindle_cw = false;
|
||||
bool saw_spindle_ccw = false;
|
||||
bool saw_spindle_stop = false;
|
||||
for (const auto &event : events) {
|
||||
saw_tool = saw_tool || event.type == CNC_SIM_EVENT_TOOL_CHANGE;
|
||||
saw_rapid = saw_rapid || event.type == CNC_SIM_EVENT_RAPID;
|
||||
@@ -121,6 +124,36 @@ int main() {
|
||||
ok &= expect(saw_g49, "expected LinuxCNC G49 RTCP off state");
|
||||
ok &= expect(saw_g434, "expected LinuxCNC G43.4 RTCP on state with H code");
|
||||
|
||||
const char spindle_program[] =
|
||||
"G21 G90 G17\n"
|
||||
"S1200 M3\n"
|
||||
"M4\n"
|
||||
"M5\n"
|
||||
"M30\n";
|
||||
events.clear();
|
||||
ok &= expect(cnc_sim_parse_program(sim, spindle_program, sizeof(spindle_program) - 1) == 0,
|
||||
cnc_sim_last_error(sim));
|
||||
for (const auto &event : events) {
|
||||
saw_spindle_cw = saw_spindle_cw ||
|
||||
(event.type == CNC_SIM_EVENT_SET_SPINDLE &&
|
||||
event.line == 2 &&
|
||||
event.spindle == 1200.0 &&
|
||||
event.reserved == 1);
|
||||
saw_spindle_ccw = saw_spindle_ccw ||
|
||||
(event.type == CNC_SIM_EVENT_SET_SPINDLE &&
|
||||
event.line == 3 &&
|
||||
event.spindle == 1200.0 &&
|
||||
event.reserved == 2);
|
||||
saw_spindle_stop = saw_spindle_stop ||
|
||||
(event.type == CNC_SIM_EVENT_SET_SPINDLE &&
|
||||
event.line == 4 &&
|
||||
event.spindle == 0.0 &&
|
||||
event.reserved == 0);
|
||||
}
|
||||
ok &= expect(saw_spindle_cw, "expected LinuxCNC M3 clockwise spindle state");
|
||||
ok &= expect(saw_spindle_ccw, "expected LinuxCNC M4 counterclockwise spindle state");
|
||||
ok &= expect(saw_spindle_stop, "expected LinuxCNC M5 stopped spindle state");
|
||||
|
||||
const char probe_program[] =
|
||||
"G21 G90 G17\n"
|
||||
"G0 X0 Y0 Z5\n"
|
||||
|
||||
@@ -67,6 +67,9 @@ int main() {
|
||||
bool saw_m430 = false;
|
||||
bool saw_g49 = false;
|
||||
bool saw_g434 = false;
|
||||
bool saw_spindle_cw = false;
|
||||
bool saw_spindle_ccw = false;
|
||||
bool saw_spindle_stop = false;
|
||||
bool saw_incremental_move = false;
|
||||
bool saw_r_arc_center = false;
|
||||
for (const auto &event : events) {
|
||||
@@ -106,6 +109,11 @@ int main() {
|
||||
event.feed == 1.0 &&
|
||||
event.tool == 7 &&
|
||||
event.dwell_seconds == 125.0);
|
||||
saw_spindle_cw = saw_spindle_cw ||
|
||||
(event.type == CNC_SIM_EVENT_SET_SPINDLE &&
|
||||
event.line == 6 &&
|
||||
event.spindle == 8000.0 &&
|
||||
event.reserved == 1);
|
||||
saw_incremental_move = saw_incremental_move ||
|
||||
(event.type == CNC_SIM_EVENT_LINEAR_FEED &&
|
||||
event.start.x == 20.0 && event.end.x == 25.0);
|
||||
@@ -127,9 +135,33 @@ int main() {
|
||||
ok &= expect(saw_m430, "expected M430 five-axis BC kinematics switch");
|
||||
ok &= expect(saw_g49, "expected G49 RTCP off state");
|
||||
ok &= expect(saw_g434, "expected G43.4 RTCP on state with H code");
|
||||
ok &= expect(saw_spindle_cw, "expected M3 clockwise spindle state");
|
||||
ok &= expect(saw_incremental_move, "expected G91 incremental move");
|
||||
ok &= expect(saw_r_arc_center, "expected R arc center calculation");
|
||||
|
||||
const char spindle_program[] =
|
||||
"G21\n"
|
||||
"S1200 M3\n"
|
||||
"M4\n"
|
||||
"M5\n";
|
||||
events.clear();
|
||||
ok &= expect(cnc_sim_parse_program(sim, spindle_program, sizeof(spindle_program) - 1) == 0,
|
||||
cnc_sim_last_error(sim));
|
||||
for (const auto &event : events) {
|
||||
saw_spindle_ccw = saw_spindle_ccw ||
|
||||
(event.type == CNC_SIM_EVENT_SET_SPINDLE &&
|
||||
event.line == 3 &&
|
||||
event.spindle == 1200.0 &&
|
||||
event.reserved == 2);
|
||||
saw_spindle_stop = saw_spindle_stop ||
|
||||
(event.type == CNC_SIM_EVENT_SET_SPINDLE &&
|
||||
event.line == 4 &&
|
||||
event.spindle == 0.0 &&
|
||||
event.reserved == 0);
|
||||
}
|
||||
ok &= expect(saw_spindle_ccw, "expected M4 counterclockwise spindle state");
|
||||
ok &= expect(saw_spindle_stop, "expected M5 stopped spindle state");
|
||||
|
||||
const char linuxcnc_config[] = "{\"backend\":\"linuxcnc-rs274\"}";
|
||||
config_rc = cnc_sim_load_config_json(sim, linuxcnc_config, sizeof(linuxcnc_config) - 1);
|
||||
rc = cnc_sim_parse_program(sim, program, sizeof(program) - 1);
|
||||
|
||||
@@ -34,6 +34,10 @@ int main() {
|
||||
USE_LENGTH_UNITS(CANON_UNITS_MM);
|
||||
SELECT_PLANE(CANON_PLANE::XY);
|
||||
SET_FEED_RATE(500.0);
|
||||
SET_SPINDLE_SPEED(0, 1200.0);
|
||||
START_SPINDLE_CLOCKWISE(0, 0);
|
||||
START_SPINDLE_COUNTERCLOCKWISE(0, 0);
|
||||
STOP_SPINDLE_TURNING(0);
|
||||
SELECT_TOOL(7);
|
||||
CHANGE_TOOL();
|
||||
STRAIGHT_TRAVERSE(10, 0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
|
||||
@@ -53,6 +57,9 @@ int main() {
|
||||
bool saw_tool = false;
|
||||
bool saw_rapid = false;
|
||||
bool saw_feed = false;
|
||||
bool saw_spindle_cw = false;
|
||||
bool saw_spindle_ccw = false;
|
||||
bool saw_spindle_stop = false;
|
||||
bool saw_arc = false;
|
||||
bool saw_probe = false;
|
||||
bool saw_g5x = false;
|
||||
@@ -61,6 +68,15 @@ int main() {
|
||||
bool saw_end = false;
|
||||
for (const auto &event : events) {
|
||||
saw_tool = saw_tool || (event.type == CNC_SIM_EVENT_TOOL_CHANGE && event.tool == 7);
|
||||
saw_spindle_cw = saw_spindle_cw || (event.type == CNC_SIM_EVENT_SET_SPINDLE &&
|
||||
event.spindle == 1200.0 &&
|
||||
event.reserved == 1);
|
||||
saw_spindle_ccw = saw_spindle_ccw || (event.type == CNC_SIM_EVENT_SET_SPINDLE &&
|
||||
event.spindle == 1200.0 &&
|
||||
event.reserved == 2);
|
||||
saw_spindle_stop = saw_spindle_stop || (event.type == CNC_SIM_EVENT_SET_SPINDLE &&
|
||||
event.spindle == 0.0 &&
|
||||
event.reserved == 0);
|
||||
saw_rapid = saw_rapid || (event.type == CNC_SIM_EVENT_RAPID && event.end.z == 5.0);
|
||||
saw_feed = saw_feed || (event.type == CNC_SIM_EVENT_LINEAR_FEED && event.end.x == 10.0);
|
||||
saw_arc = saw_arc || (event.type == CNC_SIM_EVENT_ARC_FEED &&
|
||||
@@ -90,6 +106,9 @@ int main() {
|
||||
}
|
||||
|
||||
ok &= expect(saw_tool, "expected tool change");
|
||||
ok &= expect(saw_spindle_cw, "expected clockwise spindle state");
|
||||
ok &= expect(saw_spindle_ccw, "expected counterclockwise spindle state");
|
||||
ok &= expect(saw_spindle_stop, "expected stopped spindle state");
|
||||
ok &= expect(saw_rapid, "expected rapid move");
|
||||
ok &= expect(saw_feed, "expected linear feed");
|
||||
ok &= expect(saw_arc, "expected arc feed");
|
||||
|
||||
Reference in New Issue
Block a user