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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user