├── LICENSE ├── QT_Lcnc_interface.pro ├── QT_Lcnc_interface.pro.user ├── README.md ├── display ├── display.h ├── opengl.cpp ├── opengl.h ├── structs.h ├── variable.cpp └── variable.h ├── gcode ├── parse_gcode.h └── read_in.h ├── gcode_output.ngc ├── github_screenshot.png ├── hal └── halsection.h ├── icons ├── icons.qrc └── pngegg.png ├── info.txt ├── keyboard ├── keyboard.h └── keypress.h ├── lcnc ├── halcommand │ ├── get_command.h │ ├── get_spindle_cw.h │ ├── send_command.h │ ├── set_adaptive_feed.h │ ├── set_feed_override.h │ ├── set_flood_off.h │ ├── set_flood_on.h │ ├── set_home_x.h │ ├── set_jog_speed.h │ ├── set_lube_off.h │ ├── set_lube_on.h │ ├── set_max_velocity.h │ ├── set_mode_joint.h │ ├── set_mode_teleop.h │ ├── set_rapid_override.h │ ├── set_scale_max_velocity.h │ ├── set_spindle_decrease.h │ ├── set_spindle_increase.h │ └── set_spindle_override.h ├── jog.h └── nml │ ├── config.h │ ├── disable_adaptive_feed.h │ ├── enable_adaptive_feed.h │ ├── estop.h │ ├── estop_reset.h │ ├── feed_override.h │ ├── get_position.h │ ├── hal_pin_test.h │ ├── home_all.h │ ├── home_x.h │ ├── jog.h │ ├── jog_speed.h │ ├── maxvel.h │ ├── mdi.h │ ├── mode_auto.h │ ├── mode_joint.h │ ├── mode_manual.h │ ├── mode_mdi.h │ ├── mode_teleop.h │ ├── open_file.h │ ├── pause.h │ ├── reload_file.h │ ├── reset_interpreter.h │ ├── resume.h │ ├── run_backward.h │ ├── run_forward.h │ ├── spindle_off.h │ ├── spindle_on.h │ ├── spindle_stop.h │ ├── state_off.h │ ├── state_on.h │ ├── status │ ├── error_message.h │ ├── get_message_status.h │ ├── get_position.h │ ├── get_program_line.h │ ├── home_x.h │ ├── message_status.h │ └── update_status.h │ ├── step.h │ ├── stop.h │ └── unhome.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── ngc ├── test.ngc └── test2.ngc └── run.h.autosave /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /QT_Lcnc_interface.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++17 console 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | display/opengl.cpp \ 20 | display/variable.cpp \ 21 | main.cpp \ 22 | mainwindow.cpp \ 23 | 24 | HEADERS += \ 25 | display/display.h \ 26 | display/opengl.h \ 27 | display/variable.h \ 28 | gcode/parse_gcode.h \ 29 | hal/halsection.h \ 30 | keyboard/keyboard.h \ 31 | lcnc/disable_adaptive_feed.h \ 32 | lcnc/enable_adaptive_feed.h \ 33 | lcnc/estop.h \ 34 | lcnc/estop_reset.h \ 35 | lcnc/get_position.h \ 36 | lcnc/halcommand/get_command.h \ 37 | lcnc/halcommand/send_command.h \ 38 | lcnc/halcommand/set_adaptive_feed.h \ 39 | lcnc/halcommand/set_feed_override.h \ 40 | lcnc/halcommand/set_flood_off.h \ 41 | lcnc/halcommand/set_flood_on.h \ 42 | lcnc/halcommand/set_home_x.h \ 43 | lcnc/halcommand/set_jog_speed.h \ 44 | lcnc/halcommand/set_lube_off.h \ 45 | lcnc/halcommand/set_lube_on.h \ 46 | lcnc/halcommand/set_max_velocity.h \ 47 | lcnc/halcommand/set_mode_joint.h \ 48 | lcnc/halcommand/set_mode_teleop.h \ 49 | lcnc/halcommand/set_rapid_override.h \ 50 | lcnc/halcommand/set_scale_max_velocity.h \ 51 | lcnc/halcommand/set_spindle_decrease.h \ 52 | lcnc/halcommand/set_spindle_increase.h \ 53 | lcnc/halcommand/set_spindle_override.h \ 54 | lcnc/home.h \ 55 | lcnc/estop.h \ 56 | lcnc/estop_reset.h \ 57 | lcnc/get_position.h \ 58 | lcnc/home.h \ 59 | lcnc/maxvel.h \ 60 | lcnc/mdi.h \ 61 | lcnc/mode_auto.h \ 62 | lcnc/mode_manual.h \ 63 | lcnc/mode_mdi.h \ 64 | lcnc/nml/config.h \ 65 | lcnc/nml/disable_adaptive_feed.h \ 66 | lcnc/nml/enable_adaptive_feed.h \ 67 | lcnc/nml/estop.h \ 68 | lcnc/nml/estop_reset.h \ 69 | lcnc/nml/feed_override.h \ 70 | lcnc/nml/hal_pin_test.h \ 71 | lcnc/nml/home_all.h \ 72 | lcnc/nml/home_x.h \ 73 | lcnc/nml/jog.h \ 74 | lcnc/nml/jog_speed.h \ 75 | lcnc/nml/maxvel.h \ 76 | lcnc/nml/mdi.h \ 77 | lcnc/nml/mode_auto.h \ 78 | lcnc/nml/mode_manual.h \ 79 | lcnc/nml/mode_mdi.h \ 80 | lcnc/nml/open_file.h \ 81 | lcnc/nml/pause.h \ 82 | lcnc/nml/reload_file.h \ 83 | lcnc/nml/reset_interpreter.h \ 84 | lcnc/nml/resume.h \ 85 | lcnc/nml/run_backward.h \ 86 | lcnc/nml/run_forward.h \ 87 | lcnc/nml/spindle_off.h \ 88 | lcnc/nml/spindle_on.h \ 89 | lcnc/nml/spindle_stop.h \ 90 | lcnc/nml/state_off.h \ 91 | lcnc/nml/state_on.h \ 92 | lcnc/nml/status/get_message_status.h \ 93 | lcnc/nml/status/get_position.h \ 94 | lcnc/nml/status/update_status.h \ 95 | lcnc/nml/step.h \ 96 | lcnc/nml/stop.h \ 97 | lcnc/nml/unhome.h \ 98 | lcnc/open_file.h \ 99 | lcnc/pause.h \ 100 | lcnc/reset_interpreter.h \ 101 | lcnc/resume.h \ 102 | lcnc/run_backward.h \ 103 | lcnc/run_forward.h \ 104 | lcnc/spindle_off.h \ 105 | lcnc/spindle_on.h \ 106 | lcnc/spindle_stop.h \ 107 | lcnc/state_off.h \ 108 | lcnc/state_on.h \ 109 | lcnc/step.h \ 110 | lcnc/stop.h \ 111 | lcnc/unhome.h \ 112 | mainwindow.h \ 113 | 114 | FORMS += \ 115 | mainwindow.ui 116 | 117 | INCLUDEPATH += /home/user/linuxcnc/include \ 118 | /home/user/linuxcnc/src/hal/utils 119 | 120 | LIBS += -Iinclude -Isrc/emc/rs274ngc -Llib -lnml -llinuxcnc -llinuxcnchal -llinuxcncini -DULAPI -lposemath 121 | LIBS += -lGLU 122 | 123 | 124 | # Default rules for deployment. 125 | qnx: target.path = /tmp/$${TARGET}/bin 126 | else: unix:!android: target.path = /opt/$${TARGET}/bin 127 | !isEmpty(target.path): INSTALLS += target 128 | 129 | DISTFILES += \ 130 | info.txt 131 | 132 | RESOURCES += \ 133 | icons/icons.qrc 134 | -------------------------------------------------------------------------------- /QT_Lcnc_interface.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {903da203-9a5f-4d82-bdfb-8eb9a3a17c00} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 1 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | true 60 | Builtin.Questionable 61 | 62 | true 63 | Builtin.DefaultTidyAndClazy 64 | 1 65 | 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | ProjectExplorer.Project.Target.0 74 | 75 | Desktop Qt 5.15.0 GCC 64bit 76 | Desktop Qt 5.15.0 GCC 64bit 77 | qt.qt5.5150.gcc_64_kit 78 | 0 79 | 0 80 | 0 81 | 82 | true 83 | 0 84 | /home/user/build-QT_Lcnc_interface-Desktop_Qt_5_15_0_GCC_64bit-Debug 85 | /home/user/build-QT_Lcnc_interface-Desktop_Qt_5_15_0_GCC_64bit-Debug 86 | 87 | 88 | true 89 | QtProjectManager.QMakeBuildStep 90 | 91 | false 92 | 93 | 94 | 95 | true 96 | Qt4ProjectManager.MakeStep 97 | 98 | false 99 | 100 | 101 | false 102 | 103 | 2 104 | Build 105 | Build 106 | ProjectExplorer.BuildSteps.Build 107 | 108 | 109 | 110 | true 111 | Qt4ProjectManager.MakeStep 112 | 113 | true 114 | clean 115 | 116 | false 117 | 118 | 1 119 | Clean 120 | Clean 121 | ProjectExplorer.BuildSteps.Clean 122 | 123 | 2 124 | false 125 | 126 | Debug 127 | Qt4ProjectManager.Qt4BuildConfiguration 128 | 2 129 | 2 130 | 2 131 | 132 | 133 | true 134 | 2 135 | /home/user/build-QT_Lcnc_interface-Desktop_Qt_5_15_0_GCC_64bit-Release 136 | /home/user/build-QT_Lcnc_interface-Desktop_Qt_5_15_0_GCC_64bit-Release 137 | 138 | 139 | true 140 | QtProjectManager.QMakeBuildStep 141 | 142 | true 143 | 144 | 145 | 146 | true 147 | Qt4ProjectManager.MakeStep 148 | 149 | false 150 | 151 | 152 | false 153 | 154 | 2 155 | Build 156 | Build 157 | ProjectExplorer.BuildSteps.Build 158 | 159 | 160 | 161 | true 162 | Qt4ProjectManager.MakeStep 163 | 164 | true 165 | clean 166 | 167 | false 168 | 169 | 1 170 | Clean 171 | Clean 172 | ProjectExplorer.BuildSteps.Clean 173 | 174 | 2 175 | false 176 | 177 | Release 178 | Qt4ProjectManager.Qt4BuildConfiguration 179 | 0 180 | 0 181 | 2 182 | 183 | 184 | true 185 | 0 186 | /home/user/build-QT_Lcnc_interface-Desktop_Qt_5_15_0_GCC_64bit-Profile 187 | /home/user/build-QT_Lcnc_interface-Desktop_Qt_5_15_0_GCC_64bit-Profile 188 | 189 | 190 | true 191 | QtProjectManager.QMakeBuildStep 192 | 193 | true 194 | 195 | 196 | 197 | true 198 | Qt4ProjectManager.MakeStep 199 | 200 | false 201 | 202 | 203 | false 204 | 205 | 2 206 | Build 207 | Build 208 | ProjectExplorer.BuildSteps.Build 209 | 210 | 211 | 212 | true 213 | Qt4ProjectManager.MakeStep 214 | 215 | true 216 | clean 217 | 218 | false 219 | 220 | 1 221 | Clean 222 | Clean 223 | ProjectExplorer.BuildSteps.Clean 224 | 225 | 2 226 | false 227 | 228 | Profile 229 | Qt4ProjectManager.Qt4BuildConfiguration 230 | 0 231 | 0 232 | 0 233 | 234 | 3 235 | 236 | 237 | 0 238 | Deploy 239 | Deploy 240 | ProjectExplorer.BuildSteps.Deploy 241 | 242 | 1 243 | 244 | false 245 | ProjectExplorer.DefaultDeployConfiguration 246 | 247 | 1 248 | 249 | 250 | dwarf 251 | 252 | cpu-cycles 253 | 254 | 255 | 250 256 | 257 | -e 258 | cpu-cycles 259 | --call-graph 260 | dwarf,4096 261 | -F 262 | 250 263 | 264 | -F 265 | true 266 | 4096 267 | false 268 | false 269 | 1000 270 | 271 | true 272 | 273 | false 274 | false 275 | false 276 | false 277 | true 278 | 0.01 279 | 10 280 | true 281 | kcachegrind 282 | 1 283 | 25 284 | 285 | 1 286 | true 287 | false 288 | true 289 | valgrind 290 | 291 | 0 292 | 1 293 | 2 294 | 3 295 | 4 296 | 5 297 | 6 298 | 7 299 | 8 300 | 9 301 | 10 302 | 11 303 | 12 304 | 13 305 | 14 306 | 307 | 2 308 | 309 | Qt4ProjectManager.Qt4RunConfiguration:/home/user/QT_Lcnc_interface/QT_Lcnc_interface.pro 310 | /home/user/QT_Lcnc_interface/QT_Lcnc_interface.pro 311 | 312 | false 313 | 314 | false 315 | true 316 | true 317 | false 318 | false 319 | true 320 | 321 | /home/user/build-QT_Lcnc_interface-Desktop_Qt_5_15_0_GCC_64bit-Debug 322 | 323 | 1 324 | 325 | 326 | 327 | ProjectExplorer.Project.TargetCount 328 | 1 329 | 330 | 331 | ProjectExplorer.Project.Updater.FileVersion 332 | 22 333 | 334 | 335 | Version 336 | 22 337 | 338 | 339 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QT_C++_Linuxcnc_interface_gui 2 | Linuxcnc interface gui based on halcommands and emc-nml messages, can read and visualise gcode 3 | For information only. Not ready to use in real time applications! 4 | 5 | Example : 6 | ![alt text](https://raw.githubusercontent.com/grotius-cnc/QT_C-_Linuxcnc_interface_gui/master/github_screenshot.png) 7 | 8 | To use : 9 | 10 | 1. clone and download linuxcnc. install as rip. how to install, follow this guide : 11 | https://forum.linuxcnc.org/27-driver-boards/35591-beckhoff-ethercat-64-with-bit-linuxcnc-how-to-install#121471 12 | 13 | 2. Start linuxcnc as rip. and select config axis_mm. select => create destop icon. 14 | 3. Copy the compiled qt executable file into the linux bin folder "../linuxcnc/bin/" or make a symbolic link. 15 | 16 | 4. Modify the axis_mm.ini file "../inuxcnc/configs/sim/axis/axis_mm.ini and replace in the file : 17 | 18 | Name of display program, e.g., axis 19 | DISPLAY = QT_Lcnc_interface 20 | 21 | Axes sections --------------- 22 | [AXIS_X] 23 | MIN_LIMIT = -10000 24 | MAX_LIMIT = 10000 25 | 26 | Joints sections ------------- 27 | [JOINT_0] 28 | MIN_LIMIT = -10000 29 | MAX_LIMIT = 10000 30 | 31 | 5. modify in the file ../QT_Lcnc_interface/display/variable.cpp 32 | 33 | std::string nmlfile="/home/user/linuxcnc/configs/common/linuxcnc.nml"; 34 | 35 | To your path : 36 | 37 | std::string nmlfile="/yourdirecory/linuxcnc/configs/common/linuxcnc.nml"; 38 | 39 | 6. start linuxcnc axis_mm config and start the qt application. 40 | 41 | Comments : 42 | 1. The program read's gcode with "G0" for reading "g0" you have to expand or modity ./QT_Lcnc_interface/gcode/parse_gcode.h 43 | 2. Some gui commands are emc-nml commands. It looks like linuxcnc has a overflow after some time trough the emc-nml calls. Solution may be free memory, 44 | deallocation etc. 45 | 3. Replacing emc-nml commands with halui read and write operations that are available, will solve this problem at tab 2 quickly, is what i suspect. 46 | 4. Have fun with playing around with the program !! 47 | 48 | Future goal : 49 | 50 | I think to write a new motion controller in c++ including a kernel module to acces ethercat hardware and do real time motion operations. 51 | Have looked into the linuxcnc source code for several day's now, and i am not happy how some things are done. 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /display/display.h: -------------------------------------------------------------------------------- 1 | #ifndef DISPLAY_H 2 | #define DISPLAY_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | bool trigger=0; 10 | double dist=0; 11 | POINT p={0,0,0}; 12 | void preview_toolpath(); 13 | void preview_parsed_gcode(); 14 | void draw_arc(int i); 15 | 16 | void display(){ 17 | 18 | //show current tool position 19 | get_position(); //get the tool coordinates etc. 20 | 21 | glLineWidth(1); 22 | glColor4d(255,0,0,255); 23 | glBegin(GL_LINES); 24 | glVertex3d(-5+toolpos.x,toolpos.y,toolpos.z); 25 | glVertex3d(5+toolpos.x,toolpos.y,toolpos.z); 26 | glVertex3d(toolpos.x,5+toolpos.y,toolpos.z); 27 | glVertex3d(toolpos.x,-5+toolpos.y,toolpos.z); 28 | glEnd(); 29 | 30 | dist=sqrt(pow(toolpos.x-p.x,2)+pow(toolpos.y-p.y,2)); 31 | //std::cout<<"dist: "<0.01){ 40 | if(toolpath.size()>1000000){ 41 | toolpath.clear(); 42 | } 43 | toolpath.push_back({toolpos.x,toolpos.y,toolpos.z}); 44 | //std::cout<<"toolpath pushed back"<0){ 91 | deg_angle_start = 180/M_PI*atan2(ye-y_center, xe-x_center); //start angle G2 92 | deg_angle_end = 180/M_PI*atan2(ys-y_center, xs-x_center); //end angle G2 93 | } 94 | if(objects.at(i).d<0){ 95 | deg_angle_start = 180/M_PI*atan2(ys-y_center, xs-x_center); //start angle G3 96 | deg_angle_end = 180/M_PI*atan2(ye-y_center, xe-x_center); //end angle G3 97 | } 98 | 99 | //draw arc.. 100 | double pi_angle_start = (deg_angle_start/360)*(2*M_PI); //start angle 101 | //if(end_angle==360) 102 | //{ 103 | // end_angle=0; //autocad degree problem.. 104 | //} 105 | double pi_angle_end = (deg_angle_end/360)*(2*M_PI); 106 | if (pi_angle_end 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | opengl::opengl(QWidget *parent) 11 | : QOpenGLWidget(parent) 12 | { 13 | QTimer *timer = new QTimer(this); 14 | connect(timer, SIGNAL(timeout()), this, SLOT(update())); 15 | timer->start(10); 16 | } 17 | 18 | opengl::~opengl() 19 | { 20 | //destructor 21 | } 22 | 23 | void opengl::initializeGL() 24 | { 25 | glEnable(GL_DEPTH_TEST); 26 | glEnable(GL_LINE_STIPPLE); 27 | setMouseTracking(true); 28 | zf=50; 29 | zl=-100; 30 | zr=100; 31 | zb=-100; 32 | zt=100; 33 | } 34 | 35 | void opengl::resizeGL(int w, int h) 36 | { 37 | glViewport(0, 0, w, h); 38 | aspect=double(w)/double(h); 39 | } 40 | 41 | void opengl::paintGL() 42 | { 43 | //gluPerspective(45,aspect,0,10); 44 | //gluLookAt(0,0,0,0,0,0,0,1,0); 45 | //glClearColor(1,1,1,1); //background color white 46 | glClearColor(0,0,0,1); //background color black 47 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 48 | 49 | glMatrixMode(GL_MODELVIEW); 50 | glLoadIdentity(); 51 | glOrtho(zl, zr, zb/aspect, zt/aspect, -10000.0, 10000.0); 52 | 53 | display(); 54 | } 55 | 56 | void opengl::wheelEvent(QWheelEvent *event) 57 | { 58 | if(zr-zl>5 && zr-zl<10){ //zoom accelerator.. 59 | zf=1; 60 | } else 61 | if(zr-zl>=10 && zr-zl<50){ 62 | zf=2; 63 | } else 64 | if(zr-zl>=50 && zr-zl<100){ 65 | zf=4; 66 | } else 67 | if(zr-zl>=100 && zr-zl<200){ 68 | zf=10; 69 | } else 70 | if(zr-zl>= 200 && zr-zl<300){ 71 | zf=25; 72 | } else 73 | if(zr-zl>= 300 && zr-zl<400){ 74 | zf=50; 75 | } else 76 | if(zr-zl>=400 && zr-zl<800){ 77 | zf=100; 78 | } else 79 | if(zr-zl>=800 && zr-zl<3000){ 80 | zf=200; 81 | } else 82 | if(zr-zl>=3000){ 83 | zf=1000; 84 | } 85 | 86 | if(event->delta()>0 && zr-zl>5 && zt-zb>5){ //zoom in to mouse direction 87 | if(xr<=0 && yr>=0){ //quadrant top left 88 | zl+=zf*(2-(xr*-1)); 89 | zr-=zf*(xr*-1); 90 | zt-=zf*(2-yr); 91 | zb+=zf*yr; 92 | }else if(xr>=0 && yr>=0){ //quadrant top right 93 | zl+=zf*xr; 94 | zr-=zf*(2-xr); 95 | zt-=zf*(2-yr); 96 | zb+=zf*yr; 97 | }else if(xr<=0 && yr<=0){ //quadrant bottom left 98 | zl+=zf*(2-(xr*-1)); 99 | zr-=zf*(xr*-1); 100 | zt-=zf*(yr*-1); 101 | zb+=zf*(2-(yr*-1)); 102 | }else if(xr>=0 && yr<=0){ //quadrant bottom right 103 | zl+=zf*xr; 104 | zr-=zf*(2-xr); 105 | zt-=zf*(yr*-1); 106 | zb+=zf*(2-(yr*-1)); 107 | } 108 | } 109 | if(event->delta()<0){ //zoom out 110 | zl-=zf; 111 | zr+=zf; 112 | zt+=zf; 113 | zb-=zf; 114 | } 115 | } 116 | 117 | void opengl::mouseMoveEvent(QMouseEvent *event) 118 | { 119 | pxw=this->width(); 120 | aspect=double(this->width())/double(this->height()); 121 | mx = ( (double(event->x())/ double(this->width())) * (zr-zl) ) + zl; 122 | my = ( ( ( double(this->height()) - double(event->y()) )/ double(this->height())) * ((zt-zb)/aspect) ) + zb/aspect; 123 | //std::cout<<"mx"<x()) / this->width() - 1.0f; 128 | if(xr>0){xr+=1;} else {xr-=1;} 129 | yr = (1.0f - (2.0f * event->y()) / this->height())/*/aspect*/; 130 | if(yr>0){yr+=1;} else {yr-=1;} 131 | 132 | if(event->buttons() == Qt::MiddleButton){ 133 | zl+= mx_snap - mx; 134 | zr+= mx_snap - mx; 135 | zt+= my_snap - my; 136 | zb+= my_snap - my; 137 | } 138 | 139 | if(event->buttons() == Qt::RightButton){ 140 | 141 | } 142 | } 143 | 144 | void opengl::mousePressEvent(QMouseEvent *event) 145 | { 146 | if(event->buttons() == Qt::LeftButton){ 147 | click++; 148 | } 149 | 150 | if(event->buttons() == Qt::MiddleButton){ 151 | mx_snap=mx; 152 | my_snap=my; 153 | } 154 | } 155 | 156 | void opengl::keyPressEvent(QKeyEvent *event) 157 | { 158 | //in the gui, give the opengl widget strong focus 159 | int_key=event->key(); 160 | } 161 | 162 | void opengl::keyReleaseEvent(QKeyEvent *event) 163 | { 164 | int dummy=event->key(); //done to prevent qt message 165 | dummy=-1; 166 | int_key=dummy; 167 | } 168 | 169 | -------------------------------------------------------------------------------- /display/opengl.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENGL_H 2 | #define OPENGL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | class opengl : public QOpenGLWidget 16 | { 17 | 18 | public: 19 | opengl(QWidget *parent = nullptr); 20 | ~opengl(); 21 | 22 | public: 23 | void initializeGL(); 24 | void resizeGL(int w, int h); 25 | void paintGL(); 26 | void wheelEvent(QWheelEvent *event); 27 | void mousePressEvent(QMouseEvent *event); 28 | void mouseMoveEvent(QMouseEvent *event); 29 | void keyPressEvent(QKeyEvent *); 30 | void keyReleaseEvent(QKeyEvent *); 31 | }; 32 | 33 | #endif // OPENGL_H 34 | -------------------------------------------------------------------------------- /display/structs.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECT_H 2 | #define OBJECT_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | #endif // OBJECT_H 10 | -------------------------------------------------------------------------------- /display/variable.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int click,int_key=0; 7 | double zl,zr,zt,zb,zf,xr,yr,pxw; 8 | double mx,my,mz; //mouse cad 9 | double mx_snap,my_snap,mz_snap; //mouse cad snap 10 | double aspect; 11 | double segments=25; 12 | 13 | //lcnc status channel 14 | double tx,ty,tz; 15 | int emcStatus_task_currentLine; 16 | int emcStatus_task_motionLine; 17 | int emcStatus_task_mode; 18 | int emcStatus_motion_status; 19 | int emcStatus_active_gcode_at0; 20 | char task_active_gcodes_string[256]; 21 | char task_active_mcodes_string[256]; 22 | char task_active_fcodes_string[256]; 23 | char task_active_scodes_string[256]; 24 | 25 | int emcStatus_motion_spindle_speed; 26 | int emcStatus_motion_traj_current_vel_mm_sec; 27 | int emcStatus_motion_traj_maxVelocity_mm_sec; 28 | 29 | int emcStatus_motion_spindle_direction; 30 | int emcStatus_motion_spindle_brake; 31 | int emcStatus_motion_spindle_increasing; 32 | int emcStatus_motion_spindle_enabled; 33 | int emcStatus_motion_spindle_homed; 34 | int emcStatus_motion_spindle_enabled_scale; 35 | 36 | std::string error_message; 37 | 38 | 39 | POINT toolpos; 40 | OBJECT object; 41 | std::vector objects; 42 | 43 | std::vector toolpath; 44 | 45 | std::string nmlfile="/home/user/linuxcnc/configs/common/linuxcnc.nml"; 46 | std::string filename; //gcode program filename 47 | 48 | variable::variable() 49 | { 50 | 51 | } 52 | -------------------------------------------------------------------------------- /display/variable.h: -------------------------------------------------------------------------------- 1 | #ifndef VARIABLE_H 2 | #define VARIABLE_H 3 | #include 4 | #include 5 | 6 | extern int click,int_key; 7 | extern double zl,zr,zt,zb,zf,xr,yr,pxw; 8 | extern double mx,my,mz; //mouse cad 9 | extern double mx_snap,my_snap,mz_snap; //mouse cad snap 10 | extern double aspect; 11 | extern double segments; 12 | 13 | //lcnc status channel 14 | extern double tx,ty,tz; 15 | extern int emcStatus_task_currentLine; 16 | extern int emcStatus_task_motionLine; 17 | extern int emcStatus_task_mode; 18 | extern int emcStatus_motion_status; 19 | extern int emcStatus_active_gcode_at0; 20 | extern char task_active_gcodes_string[256]; 21 | extern char task_active_mcodes_string[256]; 22 | extern char task_active_fcodes_string[256]; 23 | extern char task_active_scodes_string[256]; 24 | 25 | extern int emcStatus_motion_spindle_speed; 26 | extern int emcStatus_motion_traj_current_vel_mm_sec; 27 | extern int emcStatus_motion_traj_maxVelocity_mm_sec; 28 | 29 | extern int emcStatus_motion_spindle_direction; 30 | extern int emcStatus_motion_spindle_brake; 31 | extern int emcStatus_motion_spindle_increasing; 32 | extern int emcStatus_motion_spindle_enabled; 33 | extern int emcStatus_motion_spindle_homed; 34 | extern int emcStatus_motion_spindle_enabled_scale; 35 | 36 | extern std::string error_message; 37 | 38 | struct POINT { 39 | double x=0,y=0,z=0; 40 | }; 41 | extern POINT toolpos; 42 | 43 | struct OBJECT { //can be line or arc 44 | std::string type; 45 | double xs=0,ys=0,zs=0,xe=0,ye=0,ze=0; //xyz start, end 46 | double xcon=0,ycon=0,zcon=0; //xyz control 47 | double xc=0,yc=0,zc=0; //center xy 48 | double d=0; //determinant 49 | double red=0,green=0,blue=0,alpha=0; 50 | }; 51 | extern OBJECT object; 52 | extern std::vector objects; 53 | 54 | extern std::vector toolpath; 55 | 56 | extern std::string nmlfile; 57 | extern std::string filename; 58 | 59 | class variable 60 | { 61 | public: 62 | variable(); 63 | }; 64 | 65 | #endif // VARIABLE_H 66 | -------------------------------------------------------------------------------- /gcode/parse_gcode.h: -------------------------------------------------------------------------------- 1 | #ifndef PARSE_GCODE_H 2 | #define PARSE_GCODE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | std::vector split_line(std::string str); 11 | 12 | void parse_gcode(std::vector gcode){ 13 | 14 | //gcode letters 15 | std::string g0="G0"; //rapid 16 | std::string g1="G1"; //lineair 17 | std::string g2="G2"; //cw 18 | std::string g3="G3"; //ccw 19 | 20 | //axis letters 21 | std::string x="X"; 22 | std::string y="Y"; 23 | std::string z="Z"; 24 | std::string sci="I"; 25 | std::string scj="J"; 26 | double dci=0,dcj=0; 27 | 28 | //various letters 29 | std::string f="f"; 30 | 31 | object.type="g0"; 32 | object.d=0; 33 | object.xs=toolpos.x; //view rapid line from current toolpos to startpos. 34 | object.ys=toolpos.y; 35 | object.zs=toolpos.z; 36 | object.xe=toolpos.x; 37 | object.ye=toolpos.y; 38 | object.ze=toolpos.z; 39 | object.xc=0; 40 | object.yc=0; 41 | object.zc=0; 42 | object.xcon=0; 43 | object.ycon=0; 44 | object.zcon=0; 45 | objects.push_back(object); 46 | 47 | for(unsigned int i=0; i result=split_line(gcode.at(i)); 52 | for (auto str : result){ 53 | 54 | if(str.find(g0) != std::string::npos){ 55 | object.type="g0"; 56 | object.d=0; 57 | object.red=0; 58 | object.green=0; 59 | object.blue=255; 60 | object.alpha=255; 61 | } 62 | 63 | if(str.find(g1) != std::string::npos){ 64 | object.type="g1"; 65 | object.d=0; 66 | object.red=0; 67 | object.green=255; 68 | object.blue=0; 69 | object.alpha=255; 70 | } 71 | 72 | if(str.find(g2) != std::string::npos){ 73 | object.type="g2"; 74 | object.d=1; 75 | object.red=0; 76 | object.green=255; 77 | object.blue=0; 78 | object.alpha=255; 79 | } 80 | 81 | if(str.find(g3) != std::string::npos){ 82 | object.type="g3"; 83 | object.d=-1; 84 | object.red=0; 85 | object.green=255; 86 | object.blue=0; 87 | object.alpha=255; 88 | } 89 | 90 | if(str.find(x) != std::string::npos){ 91 | object.xs=objects.back().xe; 92 | object.xe=std::stod(str.assign(str.begin()+1,str.end())); 93 | } 94 | if(str.find(y) != std::string::npos){ 95 | object.ys=objects.back().ye; 96 | object.ye=std::stod(str.assign(str.begin()+1,str.end())); 97 | } 98 | if(str.find(z) != std::string::npos){ 99 | object.xs=objects.back().xe; 100 | object.ys=objects.back().ye; 101 | object.zs=objects.back().ze; 102 | object.ze=std::stod(str.assign(str.begin()+1,str.end())); 103 | } 104 | if(str.find(sci) != std::string::npos){ 105 | dci=std::stod(str.assign(str.begin()+1,str.end())); 106 | object.xc=dci+object.xs; std::cout<<"center_x: "< split_line(std::string string) 122 | { 123 | std::string word = ""; 124 | std::vector str; 125 | for (auto x : string){ 126 | if (x == ' '){ 127 | //std::cout << word << std::endl; 128 | str.push_back(word); 129 | word = ""; 130 | } 131 | else { 132 | word = word + x; 133 | } 134 | } 135 | //std::cout << word << std::endl; 136 | str.push_back(word); 137 | return str; 138 | } 139 | 140 | #endif // PARSE_GCODE_H 141 | -------------------------------------------------------------------------------- /gcode/read_in.h: -------------------------------------------------------------------------------- 1 | #ifndef READ_IN_H 2 | #define READ_IN_H 3 | 4 | 5 | 6 | #endif // READ_IN_H 7 | -------------------------------------------------------------------------------- /gcode_output.ngc: -------------------------------------------------------------------------------- 1 | N0 ( --intro --) 2 | N1 G21 (unit:mm) 3 | N2 G40 (cutter compensation off) 4 | N3 G80 (cancel canned cycle modal motion) 5 | N4 G90 (absolute distance, no offsets) 6 | N5 G64P0.01 (path following accuracy) 7 | N6 F1 (initialize feedrate) 8 | N7 S1 (initialize spindle speed/power) 9 | N8 ( --end intro --) 10 | N9 G0 X127.0000 Y50.0000 Z10.0000 11 | N10 G0 Z2.0000 (plunge-pierce height) 12 | N11 M3 S0.0000 (tool on) 13 | N12 G4 P0.5000 (delay) 14 | N13 G1 Z-5.0000 F250.0000 (cut depth) 15 | N14 F1250.0000 16 | N15 G3 X73.0000 Y50.0000 I-27.0000 J0.0000 17 | N16 G3 X127.0000 Y50.0000 I27.0000 J0.0000 18 | N17 M5 (tool off) 19 | N18 G0 Z10.0000 20 | N19 G0 X125.5000 Y50.0000 Z10.0000 21 | N20 G0 Z2.0000 (plunge-pierce height) 22 | N21 M3 S0.0000 (tool on) 23 | N22 G4 P0.5000 (delay) 24 | N23 G1 Z-5.0000 F250.0000 (cut depth) 25 | N24 F1250.0000 26 | N25 G3 X74.5000 Y50.0000 I-25.5000 J0.0000 27 | N26 G3 X125.5000 Y50.0000 I25.5000 J0.0000 28 | N27 M5 (tool off) 29 | N28 G0 Z10.0000 30 | N29 G0 X124.0000 Y50.0000 Z10.0000 31 | N30 G0 Z2.0000 (plunge-pierce height) 32 | N31 M3 S0.0000 (tool on) 33 | N32 G4 P0.5000 (delay) 34 | N33 G1 Z-5.0000 F250.0000 (cut depth) 35 | N34 F1250.0000 36 | N35 G3 X76.0000 Y50.0000 I-24.0000 J0.0000 37 | N36 G3 X124.0000 Y50.0000 I24.0000 J0.0000 38 | N37 M5 (tool off) 39 | N38 G0 Z10.0000 40 | N39 G0 X122.5000 Y50.0000 Z10.0000 41 | N40 G0 Z2.0000 (plunge-pierce height) 42 | N41 M3 S0.0000 (tool on) 43 | N42 G4 P0.5000 (delay) 44 | N43 G1 Z-5.0000 F250.0000 (cut depth) 45 | N44 F1250.0000 46 | N45 G3 X77.5000 Y50.0000 I-22.5000 J0.0000 47 | N46 G3 X122.5000 Y50.0000 I22.5000 J0.0000 48 | N47 M5 (tool off) 49 | N48 G0 Z10.0000 50 | N49 G0 X121.0000 Y50.0000 Z10.0000 51 | N50 G0 Z2.0000 (plunge-pierce height) 52 | N51 M3 S0.0000 (tool on) 53 | N52 G4 P0.5000 (delay) 54 | N53 G1 Z-5.0000 F250.0000 (cut depth) 55 | N54 F1250.0000 56 | N55 G3 X79.0000 Y50.0000 I-21.0000 J0.0000 57 | N56 G3 X121.0000 Y50.0000 I21.0000 J0.0000 58 | N57 M5 (tool off) 59 | N58 G0 Z10.0000 60 | N59 G0 X119.5000 Y50.0000 Z10.0000 61 | N60 G0 Z2.0000 (plunge-pierce height) 62 | N61 M3 S0.0000 (tool on) 63 | N62 G4 P0.5000 (delay) 64 | N63 G1 Z-5.0000 F250.0000 (cut depth) 65 | N64 F1250.0000 66 | N65 G3 X80.5000 Y50.0000 I-19.5000 J0.0000 67 | N66 G3 X119.5000 Y50.0000 I19.5000 J0.0000 68 | N67 M5 (tool off) 69 | N68 G0 Z10.0000 70 | N69 G0 X118.0000 Y50.0000 Z10.0000 71 | N70 G0 Z2.0000 (plunge-pierce height) 72 | N71 M3 S0.0000 (tool on) 73 | N72 G4 P0.5000 (delay) 74 | N73 G1 Z-5.0000 F250.0000 (cut depth) 75 | N74 F1250.0000 76 | N75 G3 X82.0000 Y50.0000 I-18.0000 J0.0000 77 | N76 G3 X118.0000 Y50.0000 I18.0000 J0.0000 78 | N77 M5 (tool off) 79 | N78 G0 Z10.0000 80 | N79 G0 X116.5000 Y50.0000 Z10.0000 81 | N80 G0 Z2.0000 (plunge-pierce height) 82 | N81 M3 S0.0000 (tool on) 83 | N82 G4 P0.5000 (delay) 84 | N83 G1 Z-5.0000 F250.0000 (cut depth) 85 | N84 F1250.0000 86 | N85 G3 X83.5000 Y50.0000 I-16.5000 J0.0000 87 | N86 G3 X116.5000 Y50.0000 I16.5000 J0.0000 88 | N87 M5 (tool off) 89 | N88 G0 Z10.0000 90 | N89 G0 X115.0000 Y50.0000 Z10.0000 91 | N90 G0 Z2.0000 (plunge-pierce height) 92 | N91 M3 S0.0000 (tool on) 93 | N92 G4 P0.5000 (delay) 94 | N93 G1 Z-5.0000 F250.0000 (cut depth) 95 | N94 F1250.0000 96 | N95 G3 X85.0000 Y50.0000 I-15.0000 J0.0000 97 | N96 G3 X115.0000 Y50.0000 I15.0000 J0.0000 98 | N97 M5 (tool off) 99 | N98 G0 Z10.0000 100 | N99 G0 X113.5000 Y50.0000 Z10.0000 101 | N100 G0 Z2.0000 (plunge-pierce height) 102 | N101 M3 S0.0000 (tool on) 103 | N102 G4 P0.5000 (delay) 104 | N103 G1 Z-5.0000 F250.0000 (cut depth) 105 | N104 F1250.0000 106 | N105 G3 X86.5000 Y50.0000 I-13.5000 J0.0000 107 | N106 G3 X113.5000 Y50.0000 I13.5000 J0.0000 108 | N107 M5 (tool off) 109 | N108 G0 Z10.0000 110 | N109 G0 X112.0000 Y50.0000 Z10.0000 111 | N110 G0 Z2.0000 (plunge-pierce height) 112 | N111 M3 S0.0000 (tool on) 113 | N112 G4 P0.5000 (delay) 114 | N113 G1 Z-5.0000 F250.0000 (cut depth) 115 | N114 F1250.0000 116 | N115 G3 X88.0000 Y50.0000 I-12.0000 J0.0000 117 | N116 G3 X112.0000 Y50.0000 I12.0000 J0.0000 118 | N117 M5 (tool off) 119 | N118 G0 Z10.0000 120 | N119 G0 X110.5000 Y50.0000 Z10.0000 121 | N120 G0 Z2.0000 (plunge-pierce height) 122 | N121 M3 S0.0000 (tool on) 123 | N122 G4 P0.5000 (delay) 124 | N123 G1 Z-5.0000 F250.0000 (cut depth) 125 | N124 F1250.0000 126 | N125 G3 X89.5000 Y50.0000 I-10.5000 J0.0000 127 | N126 G3 X110.5000 Y50.0000 I10.5000 J0.0000 128 | N127 M5 (tool off) 129 | N128 G0 Z10.0000 130 | N129 G0 X109.0000 Y50.0000 Z10.0000 131 | N130 G0 Z2.0000 (plunge-pierce height) 132 | N131 M3 S0.0000 (tool on) 133 | N132 G4 P0.5000 (delay) 134 | N133 G1 Z-5.0000 F250.0000 (cut depth) 135 | N134 F1250.0000 136 | N135 G3 X91.0000 Y50.0000 I-9.0000 J0.0000 137 | N136 G3 X109.0000 Y50.0000 I9.0000 J0.0000 138 | N137 M5 (tool off) 139 | N138 G0 Z10.0000 140 | N139 G0 X107.5000 Y50.0000 Z10.0000 141 | N140 G0 Z2.0000 (plunge-pierce height) 142 | N141 M3 S0.0000 (tool on) 143 | N142 G4 P0.5000 (delay) 144 | N143 G1 Z-5.0000 F250.0000 (cut depth) 145 | N144 F1250.0000 146 | N145 G3 X92.5000 Y50.0000 I-7.5000 J0.0000 147 | N146 G3 X107.5000 Y50.0000 I7.5000 J0.0000 148 | N147 M5 (tool off) 149 | N148 G0 Z10.0000 150 | N149 G0 X106.0000 Y50.0000 Z10.0000 151 | N150 G0 Z2.0000 (plunge-pierce height) 152 | N151 M3 S0.0000 (tool on) 153 | N152 G4 P0.5000 (delay) 154 | N153 G1 Z-5.0000 F250.0000 (cut depth) 155 | N154 F1250.0000 156 | N155 G3 X94.0000 Y50.0000 I-6.0000 J0.0000 157 | N156 G3 X106.0000 Y50.0000 I6.0000 J0.0000 158 | N157 M5 (tool off) 159 | N158 G0 Z10.0000 160 | N159 G0 X104.5000 Y50.0000 Z10.0000 161 | N160 G0 Z2.0000 (plunge-pierce height) 162 | N161 M3 S0.0000 (tool on) 163 | N162 G4 P0.5000 (delay) 164 | N163 G1 Z-5.0000 F250.0000 (cut depth) 165 | N164 F1250.0000 166 | N165 G3 X95.5000 Y50.0000 I-4.5000 J0.0000 167 | N166 G3 X104.5000 Y50.0000 I4.5000 J0.0000 168 | N167 M5 (tool off) 169 | N168 G0 Z10.0000 170 | N169 G0 X103.0000 Y50.0000 Z10.0000 171 | N170 G0 Z2.0000 (plunge-pierce height) 172 | N171 M3 S0.0000 (tool on) 173 | N172 G4 P0.5000 (delay) 174 | N173 G1 Z-5.0000 F250.0000 (cut depth) 175 | N174 F1250.0000 176 | N175 G3 X97.0000 Y50.0000 I-3.0000 J0.0000 177 | N176 G3 X103.0000 Y50.0000 I3.0000 J0.0000 178 | N177 M5 (tool off) 179 | N178 G0 Z10.0000 180 | N179 G0 X101.5000 Y50.0000 Z10.0000 181 | N180 G0 Z2.0000 (plunge-pierce height) 182 | N181 M3 S0.0000 (tool on) 183 | N182 G4 P0.5000 (delay) 184 | N183 G1 Z-5.0000 F250.0000 (cut depth) 185 | N184 F1250.0000 186 | N185 G3 X98.5000 Y50.0000 I-1.5000 J0.0000 187 | N186 G3 X101.5000 Y50.0000 I1.5000 J0.0000 188 | N187 M5 (tool off) 189 | N188 G0 Z10.0000 190 | N189 G0 X167.0000 Y50.0000 Z10.0000 191 | N190 G0 Z2.0000 (plunge-pierce height) 192 | N191 M3 S0.0000 (tool on) 193 | N192 G4 P0.5000 (delay) 194 | N193 G1 Z-5.0000 F250.0000 (cut depth) 195 | N194 F1250.0000 196 | N195 G3 X153.0000 Y50.0000 I-7.0000 J0.0000 197 | N196 G3 X167.0000 Y50.0000 I7.0000 J0.0000 198 | N197 M5 (tool off) 199 | N198 G0 Z10.0000 200 | N199 G0 X165.5000 Y50.0000 Z10.0000 201 | N200 G0 Z2.0000 (plunge-pierce height) 202 | N201 M3 S0.0000 (tool on) 203 | N202 G4 P0.5000 (delay) 204 | N203 G1 Z-5.0000 F250.0000 (cut depth) 205 | N204 F1250.0000 206 | N205 G3 X154.5000 Y50.0000 I-5.5000 J0.0000 207 | N206 G3 X165.5000 Y50.0000 I5.5000 J0.0000 208 | N207 M5 (tool off) 209 | N208 G0 Z10.0000 210 | N209 G0 X164.0000 Y50.0000 Z10.0000 211 | N210 G0 Z2.0000 (plunge-pierce height) 212 | N211 M3 S0.0000 (tool on) 213 | N212 G4 P0.5000 (delay) 214 | N213 G1 Z-5.0000 F250.0000 (cut depth) 215 | N214 F1250.0000 216 | N215 G3 X156.0000 Y50.0000 I-4.0000 J0.0000 217 | N216 G3 X164.0000 Y50.0000 I4.0000 J0.0000 218 | N217 M5 (tool off) 219 | N218 G0 Z10.0000 220 | N219 G0 X162.5000 Y50.0000 Z10.0000 221 | N220 G0 Z2.0000 (plunge-pierce height) 222 | N221 M3 S0.0000 (tool on) 223 | N222 G4 P0.5000 (delay) 224 | N223 G1 Z-5.0000 F250.0000 (cut depth) 225 | N224 F1250.0000 226 | N225 G3 X157.5000 Y50.0000 I-2.5000 J0.0000 227 | N226 G3 X162.5000 Y50.0000 I2.5000 J0.0000 228 | N227 M5 (tool off) 229 | N228 G0 Z10.0000 230 | N229 G0 X161.0000 Y50.0000 Z10.0000 231 | N230 G0 Z2.0000 (plunge-pierce height) 232 | N231 M3 S0.0000 (tool on) 233 | N232 G4 P0.5000 (delay) 234 | N233 G1 Z-5.0000 F250.0000 (cut depth) 235 | N234 F1250.0000 236 | N235 G3 X159.0000 Y50.0000 I-1.0000 J0.0000 237 | N236 G3 X161.0000 Y50.0000 I1.0000 J0.0000 238 | N237 M5 (tool off) 239 | N238 G0 Z10.0000 240 | N239 G0 X47.0000 Y50.0000 Z10.0000 241 | N240 G0 Z2.0000 (plunge-pierce height) 242 | N241 M3 S0.0000 (tool on) 243 | N242 G4 P0.5000 (delay) 244 | N243 G1 Z-5.0000 F250.0000 (cut depth) 245 | N244 F1250.0000 246 | N245 G3 X33.0000 Y50.0000 I-7.0000 J0.0000 247 | N246 G3 X47.0000 Y50.0000 I7.0000 J0.0000 248 | N247 M5 (tool off) 249 | N248 G0 Z10.0000 250 | N249 G0 X45.5000 Y50.0000 Z10.0000 251 | N250 G0 Z2.0000 (plunge-pierce height) 252 | N251 M3 S0.0000 (tool on) 253 | N252 G4 P0.5000 (delay) 254 | N253 G1 Z-5.0000 F250.0000 (cut depth) 255 | N254 F1250.0000 256 | N255 G3 X34.5000 Y50.0000 I-5.5000 J0.0000 257 | N256 G3 X45.5000 Y50.0000 I5.5000 J0.0000 258 | N257 M5 (tool off) 259 | N258 G0 Z10.0000 260 | N259 G0 X44.0000 Y50.0000 Z10.0000 261 | N260 G0 Z2.0000 (plunge-pierce height) 262 | N261 M3 S0.0000 (tool on) 263 | N262 G4 P0.5000 (delay) 264 | N263 G1 Z-5.0000 F250.0000 (cut depth) 265 | N264 F1250.0000 266 | N265 G3 X36.0000 Y50.0000 I-4.0000 J0.0000 267 | N266 G3 X44.0000 Y50.0000 I4.0000 J0.0000 268 | N267 M5 (tool off) 269 | N268 G0 Z10.0000 270 | N269 G0 X42.5000 Y50.0000 Z10.0000 271 | N270 G0 Z2.0000 (plunge-pierce height) 272 | N271 M3 S0.0000 (tool on) 273 | N272 G4 P0.5000 (delay) 274 | N273 G1 Z-5.0000 F250.0000 (cut depth) 275 | N274 F1250.0000 276 | N275 G3 X37.5000 Y50.0000 I-2.5000 J0.0000 277 | N276 G3 X42.5000 Y50.0000 I2.5000 J0.0000 278 | N277 M5 (tool off) 279 | N278 G0 Z10.0000 280 | N279 G0 X41.0000 Y50.0000 Z10.0000 281 | N280 G0 Z2.0000 (plunge-pierce height) 282 | N281 M3 S0.0000 (tool on) 283 | N282 G4 P0.5000 (delay) 284 | N283 G1 Z-5.0000 F250.0000 (cut depth) 285 | N284 F1250.0000 286 | N285 G3 X39.0000 Y50.0000 I-1.0000 J0.0000 287 | N286 G3 X41.0000 Y50.0000 I1.0000 J0.0000 288 | N287 M5 (tool off) 289 | N288 G0 Z10.0000 290 | N289 G0 X13.0000 Y240.0000 Z10.0000 291 | N290 G0 Z2.0000 (plunge-pierce height) 292 | N291 M3 S0.0000 (tool on) 293 | N292 G4 P0.5000 (delay) 294 | N293 G1 Z-5.0000 F250.0000 (cut depth) 295 | N294 F1250.0000 296 | N295 G1 X13.0000 Y180.0000 297 | N296 G3 X20.0000 Y173.0000 I7.0000 J0.0000 298 | N297 G1 X180.0000 Y173.0000 299 | N298 G3 X187.0000 Y180.0000 I0.0000 J7.0000 300 | N299 G1 X187.0000 Y240.0000 301 | N300 G3 X180.0000 Y247.0000 I-7.0000 J0.0000 302 | N301 G1 X20.0000 Y247.0000 303 | N302 G3 X13.0000 Y240.0000 I0.0000 J-7.0000 304 | N303 M5 (tool off) 305 | N304 G0 Z10.0000 306 | N305 G0 X14.5000 Y240.0000 Z10.0000 307 | N306 G0 Z2.0000 (plunge-pierce height) 308 | N307 M3 S0.0000 (tool on) 309 | N308 G4 P0.5000 (delay) 310 | N309 G1 Z-5.0000 F250.0000 (cut depth) 311 | N310 F1250.0000 312 | N311 G1 X14.5000 Y180.0000 313 | N312 G3 X20.0000 Y174.5000 I5.5000 J0.0000 314 | N313 G1 X180.0000 Y174.5000 315 | N314 G3 X185.5000 Y180.0000 I0.0000 J5.5000 316 | N315 G1 X185.5000 Y240.0000 317 | N316 G3 X180.0000 Y245.5000 I-5.5000 J0.0000 318 | N317 G1 X20.0000 Y245.5000 319 | N318 G3 X14.5000 Y240.0000 I-0.0000 J-5.5000 320 | N319 M5 (tool off) 321 | N320 G0 Z10.0000 322 | N321 G0 X16.0000 Y240.0000 Z10.0000 323 | N322 G0 Z2.0000 (plunge-pierce height) 324 | N323 M3 S0.0000 (tool on) 325 | N324 G4 P0.5000 (delay) 326 | N325 G1 Z-5.0000 F250.0000 (cut depth) 327 | N326 F1250.0000 328 | N327 G1 X16.0000 Y180.0000 329 | N328 G3 X20.0000 Y176.0000 I4.0000 J0.0000 330 | N329 G1 X180.0000 Y176.0000 331 | N330 G3 X184.0000 Y180.0000 I0.0000 J4.0000 332 | N331 G1 X184.0000 Y240.0000 333 | N332 G3 X180.0000 Y244.0000 I-4.0000 J0.0000 334 | N333 G1 X20.0000 Y244.0000 335 | N334 G3 X16.0000 Y240.0000 I0.0000 J-4.0000 336 | N335 M5 (tool off) 337 | N336 G0 Z10.0000 338 | N337 G0 X17.5000 Y240.0000 Z10.0000 339 | N338 G0 Z2.0000 (plunge-pierce height) 340 | N339 M3 S0.0000 (tool on) 341 | N340 G4 P0.5000 (delay) 342 | N341 G1 Z-5.0000 F250.0000 (cut depth) 343 | N342 F1250.0000 344 | N343 G1 X17.5000 Y180.0000 345 | N344 G3 X20.0000 Y177.5000 I2.5000 J0.0000 346 | N345 G1 X180.0000 Y177.5000 347 | N346 G3 X182.5000 Y180.0000 I0.0000 J2.5000 348 | N347 G1 X182.5000 Y240.0000 349 | N348 G3 X180.0000 Y242.5000 I-2.5000 J0.0000 350 | N349 G1 X20.0000 Y242.5000 351 | N350 G3 X17.5000 Y240.0000 I-0.0000 J-2.5000 352 | N351 M5 (tool off) 353 | N352 G0 Z10.0000 354 | N353 G0 X19.0000 Y240.0000 Z10.0000 355 | N354 G0 Z2.0000 (plunge-pierce height) 356 | N355 M3 S0.0000 (tool on) 357 | N356 G4 P0.5000 (delay) 358 | N357 G1 Z-5.0000 F250.0000 (cut depth) 359 | N358 F1250.0000 360 | N359 G1 X19.0000 Y180.0000 361 | N360 G3 X20.0000 Y179.0000 I1.0000 J0.0000 362 | N361 G1 X180.0000 Y179.0000 363 | N362 G3 X181.0000 Y180.0000 I0.0000 J1.0000 364 | N363 G1 X181.0000 Y240.0000 365 | N364 G3 X180.0000 Y241.0000 I-1.0000 J0.0000 366 | N365 G1 X20.0000 Y241.0000 367 | N366 G3 X19.0000 Y240.0000 I-0.0000 J-1.0000 368 | N367 M5 (tool off) 369 | N368 G0 Z10.0000 370 | N369 G0 X179.5000 Y180.5000 Z10.0000 371 | N370 G0 Z2.0000 (plunge-pierce height) 372 | N371 M3 S0.0000 (tool on) 373 | N372 G4 P0.5000 (delay) 374 | N373 G1 Z-5.0000 F250.0000 (cut depth) 375 | N374 F1250.0000 376 | N375 G1 X179.5000 Y239.5000 377 | N376 G1 X20.5000 Y239.5000 378 | N377 G1 X20.5000 Y180.5000 379 | N378 G1 X179.5000 Y180.5000 380 | N379 M5 (tool off) 381 | N380 G0 Z10.0000 382 | N381 G0 X178.0000 Y182.0000 Z10.0000 383 | N382 G0 Z2.0000 (plunge-pierce height) 384 | N383 M3 S0.0000 (tool on) 385 | N384 G4 P0.5000 (delay) 386 | N385 G1 Z-5.0000 F250.0000 (cut depth) 387 | N386 F1250.0000 388 | N387 G1 X178.0000 Y238.0000 389 | N388 G1 X22.0000 Y238.0000 390 | N389 G1 X22.0000 Y182.0000 391 | N390 G1 X178.0000 Y182.0000 392 | N391 M5 (tool off) 393 | N392 G0 Z10.0000 394 | N393 G0 X176.5000 Y183.5000 Z10.0000 395 | N394 G0 Z2.0000 (plunge-pierce height) 396 | N395 M3 S0.0000 (tool on) 397 | N396 G4 P0.5000 (delay) 398 | N397 G1 Z-5.0000 F250.0000 (cut depth) 399 | N398 F1250.0000 400 | N399 G1 X176.5000 Y236.5000 401 | N400 G1 X23.5000 Y236.5000 402 | N401 G1 X23.5000 Y183.5000 403 | N402 G1 X176.5000 Y183.5000 404 | N403 M5 (tool off) 405 | N404 G0 Z10.0000 406 | N405 G0 X175.0000 Y185.0000 Z10.0000 407 | N406 G0 Z2.0000 (plunge-pierce height) 408 | N407 M3 S0.0000 (tool on) 409 | N408 G4 P0.5000 (delay) 410 | N409 G1 Z-5.0000 F250.0000 (cut depth) 411 | N410 F1250.0000 412 | N411 G1 X175.0000 Y235.0000 413 | N412 G1 X25.0000 Y235.0000 414 | N413 G1 X25.0000 Y185.0000 415 | N414 G1 X175.0000 Y185.0000 416 | N415 M5 (tool off) 417 | N416 G0 Z10.0000 418 | N417 G0 X173.5000 Y186.5000 Z10.0000 419 | N418 G0 Z2.0000 (plunge-pierce height) 420 | N419 M3 S0.0000 (tool on) 421 | N420 G4 P0.5000 (delay) 422 | N421 G1 Z-5.0000 F250.0000 (cut depth) 423 | N422 F1250.0000 424 | N423 G1 X173.5000 Y233.5000 425 | N424 G1 X26.5000 Y233.5000 426 | N425 G1 X26.5000 Y186.5000 427 | N426 G1 X173.5000 Y186.5000 428 | N427 M5 (tool off) 429 | N428 G0 Z10.0000 430 | N429 G0 X172.0000 Y188.0000 Z10.0000 431 | N430 G0 Z2.0000 (plunge-pierce height) 432 | N431 M3 S0.0000 (tool on) 433 | N432 G4 P0.5000 (delay) 434 | N433 G1 Z-5.0000 F250.0000 (cut depth) 435 | N434 F1250.0000 436 | N435 G1 X172.0000 Y232.0000 437 | N436 G1 X28.0000 Y232.0000 438 | N437 G1 X28.0000 Y188.0000 439 | N438 G1 X172.0000 Y188.0000 440 | N439 M5 (tool off) 441 | N440 G0 Z10.0000 442 | N441 G0 X170.5000 Y189.5000 Z10.0000 443 | N442 G0 Z2.0000 (plunge-pierce height) 444 | N443 M3 S0.0000 (tool on) 445 | N444 G4 P0.5000 (delay) 446 | N445 G1 Z-5.0000 F250.0000 (cut depth) 447 | N446 F1250.0000 448 | N447 G1 X170.5000 Y230.5000 449 | N448 G1 X29.5000 Y230.5000 450 | N449 G1 X29.5000 Y189.5000 451 | N450 G1 X170.5000 Y189.5000 452 | N451 M5 (tool off) 453 | N452 G0 Z10.0000 454 | N453 G0 X169.0000 Y191.0000 Z10.0000 455 | N454 G0 Z2.0000 (plunge-pierce height) 456 | N455 M3 S0.0000 (tool on) 457 | N456 G4 P0.5000 (delay) 458 | N457 G1 Z-5.0000 F250.0000 (cut depth) 459 | N458 F1250.0000 460 | N459 G1 X169.0000 Y229.0000 461 | N460 G1 X31.0000 Y229.0000 462 | N461 G1 X31.0000 Y191.0000 463 | N462 G1 X169.0000 Y191.0000 464 | N463 M5 (tool off) 465 | N464 G0 Z10.0000 466 | N465 G0 X167.5000 Y192.5000 Z10.0000 467 | N466 G0 Z2.0000 (plunge-pierce height) 468 | N467 M3 S0.0000 (tool on) 469 | N468 G4 P0.5000 (delay) 470 | N469 G1 Z-5.0000 F250.0000 (cut depth) 471 | N470 F1250.0000 472 | N471 G1 X167.5000 Y227.5000 473 | N472 G1 X32.5000 Y227.5000 474 | N473 G1 X32.5000 Y192.5000 475 | N474 G1 X167.5000 Y192.5000 476 | N475 M5 (tool off) 477 | N476 G0 Z10.0000 478 | N477 G0 X166.0000 Y194.0000 Z10.0000 479 | N478 G0 Z2.0000 (plunge-pierce height) 480 | N479 M3 S0.0000 (tool on) 481 | N480 G4 P0.5000 (delay) 482 | N481 G1 Z-5.0000 F250.0000 (cut depth) 483 | N482 F1250.0000 484 | N483 G1 X166.0000 Y226.0000 485 | N484 G1 X34.0000 Y226.0000 486 | N485 G1 X34.0000 Y194.0000 487 | N486 G1 X166.0000 Y194.0000 488 | N487 M5 (tool off) 489 | N488 G0 Z10.0000 490 | N489 G0 X164.5000 Y195.5000 Z10.0000 491 | N490 G0 Z2.0000 (plunge-pierce height) 492 | N491 M3 S0.0000 (tool on) 493 | N492 G4 P0.5000 (delay) 494 | N493 G1 Z-5.0000 F250.0000 (cut depth) 495 | N494 F1250.0000 496 | N495 G1 X164.5000 Y224.5000 497 | N496 G1 X35.5000 Y224.5000 498 | N497 G1 X35.5000 Y195.5000 499 | N498 G1 X164.5000 Y195.5000 500 | N499 M5 (tool off) 501 | N500 G0 Z10.0000 502 | N501 G0 X163.0000 Y197.0000 Z10.0000 503 | N502 G0 Z2.0000 (plunge-pierce height) 504 | N503 M3 S0.0000 (tool on) 505 | N504 G4 P0.5000 (delay) 506 | N505 G1 Z-5.0000 F250.0000 (cut depth) 507 | N506 F1250.0000 508 | N507 G1 X163.0000 Y223.0000 509 | N508 G1 X37.0000 Y223.0000 510 | N509 G1 X37.0000 Y197.0000 511 | N510 G1 X163.0000 Y197.0000 512 | N511 M5 (tool off) 513 | N512 G0 Z10.0000 514 | N513 G0 X161.5000 Y198.5000 Z10.0000 515 | N514 G0 Z2.0000 (plunge-pierce height) 516 | N515 M3 S0.0000 (tool on) 517 | N516 G4 P0.5000 (delay) 518 | N517 G1 Z-5.0000 F250.0000 (cut depth) 519 | N518 F1250.0000 520 | N519 G1 X161.5000 Y221.5000 521 | N520 G1 X38.5000 Y221.5000 522 | N521 G1 X38.5000 Y198.5000 523 | N522 G1 X161.5000 Y198.5000 524 | N523 M5 (tool off) 525 | N524 G0 Z10.0000 526 | N525 G0 X160.0000 Y200.0000 Z10.0000 527 | N526 G0 Z2.0000 (plunge-pierce height) 528 | N527 M3 S0.0000 (tool on) 529 | N528 G4 P0.5000 (delay) 530 | N529 G1 Z-5.0000 F250.0000 (cut depth) 531 | N530 F1250.0000 532 | N531 G1 X160.0000 Y220.0000 533 | N532 G1 X40.0000 Y220.0000 534 | N533 G1 X40.0000 Y200.0000 535 | N534 G1 X160.0000 Y200.0000 536 | N535 M5 (tool off) 537 | N536 G0 Z10.0000 538 | N537 G0 X158.5000 Y201.5000 Z10.0000 539 | N538 G0 Z2.0000 (plunge-pierce height) 540 | N539 M3 S0.0000 (tool on) 541 | N540 G4 P0.5000 (delay) 542 | N541 G1 Z-5.0000 F250.0000 (cut depth) 543 | N542 F1250.0000 544 | N543 G1 X158.5000 Y218.5000 545 | N544 G1 X41.5000 Y218.5000 546 | N545 G1 X41.5000 Y201.5000 547 | N546 G1 X158.5000 Y201.5000 548 | N547 M5 (tool off) 549 | N548 G0 Z10.0000 550 | N549 G0 X157.0000 Y203.0000 Z10.0000 551 | N550 G0 Z2.0000 (plunge-pierce height) 552 | N551 M3 S0.0000 (tool on) 553 | N552 G4 P0.5000 (delay) 554 | N553 G1 Z-5.0000 F250.0000 (cut depth) 555 | N554 F1250.0000 556 | N555 G1 X157.0000 Y217.0000 557 | N556 G1 X43.0000 Y217.0000 558 | N557 G1 X43.0000 Y203.0000 559 | N558 G1 X157.0000 Y203.0000 560 | N559 M5 (tool off) 561 | N560 G0 Z10.0000 562 | N561 G0 X155.5000 Y204.5000 Z10.0000 563 | N562 G0 Z2.0000 (plunge-pierce height) 564 | N563 M3 S0.0000 (tool on) 565 | N564 G4 P0.5000 (delay) 566 | N565 G1 Z-5.0000 F250.0000 (cut depth) 567 | N566 F1250.0000 568 | N567 G1 X155.5000 Y215.5000 569 | N568 G1 X44.5000 Y215.5000 570 | N569 G1 X44.5000 Y204.5000 571 | N570 G1 X155.5000 Y204.5000 572 | N571 M5 (tool off) 573 | N572 G0 Z10.0000 574 | N573 G0 X154.0000 Y206.0000 Z10.0000 575 | N574 G0 Z2.0000 (plunge-pierce height) 576 | N575 M3 S0.0000 (tool on) 577 | N576 G4 P0.5000 (delay) 578 | N577 G1 Z-5.0000 F250.0000 (cut depth) 579 | N578 F1250.0000 580 | N579 G1 X154.0000 Y214.0000 581 | N580 G1 X46.0000 Y214.0000 582 | N581 G1 X46.0000 Y206.0000 583 | N582 G1 X154.0000 Y206.0000 584 | N583 M5 (tool off) 585 | N584 G0 Z10.0000 586 | N585 G0 X152.5000 Y207.5000 Z10.0000 587 | N586 G0 Z2.0000 (plunge-pierce height) 588 | N587 M3 S0.0000 (tool on) 589 | N588 G4 P0.5000 (delay) 590 | N589 G1 Z-5.0000 F250.0000 (cut depth) 591 | N590 F1250.0000 592 | N591 G1 X152.5000 Y212.5000 593 | N592 G1 X47.5000 Y212.5000 594 | N593 G1 X47.5000 Y207.5000 595 | N594 G1 X152.5000 Y207.5000 596 | N595 M5 (tool off) 597 | N596 G0 Z10.0000 598 | N597 G0 X151.0000 Y209.0000 Z10.0000 599 | N598 G0 Z2.0000 (plunge-pierce height) 600 | N599 M3 S0.0000 (tool on) 601 | N600 G4 P0.5000 (delay) 602 | N601 G1 Z-5.0000 F250.0000 (cut depth) 603 | N602 F1250.0000 604 | N603 G1 X151.0000 Y211.0000 605 | N604 G1 X49.0000 Y211.0000 606 | N605 G1 X49.0000 Y209.0000 607 | N606 G1 X151.0000 Y209.0000 608 | N607 M5 (tool off) 609 | N608 G0 Z10.0000 610 | N609 M30 611 | N610 (--end outtro--) 612 | -------------------------------------------------------------------------------- /github_screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grotius-cnc/qt_c_linuxcnc_interface_gui/b9ced9ce1571be9af99bfc730a76008945b55e38/github_screenshot.png -------------------------------------------------------------------------------- /hal/halsection.h: -------------------------------------------------------------------------------- 1 | #ifndef HALSECTION_H 2 | #define HALSECTION_H 3 | 4 | 5 | 6 | #endif // HALSECTION_H 7 | -------------------------------------------------------------------------------- /icons/icons.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | pngegg.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /icons/pngegg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grotius-cnc/qt_c_linuxcnc_interface_gui/b9ced9ce1571be9af99bfc730a76008945b55e38/icons/pngegg.png -------------------------------------------------------------------------------- /info.txt: -------------------------------------------------------------------------------- 1 | xemc.cc is a C++ program that uses the relevant APIs. It is far from 2 | being tutorial documentation, but at present we don't *have* any 3 | tutorial documentation about using these APIs. 4 | 5 | (such documentation would be a great contribution to LinuxCNC. You 6 | could start with a new page on the wiki and later work with someone like 7 | John Thornton to get it integrated into the offical documentation. if 8 | you are so inclined) 9 | 10 | Anyway, here's a complete program that uses the C++ interface to log the 11 | position at about 10Hz: 12 | 13 | #include "emc.hh" 14 | #include "emc_nml.hh" 15 | #include 16 | #include 17 | #include 18 | 19 | int main(int argc, char **argv) { 20 | if(argc < 2) { std::cerr << "Usage: " << argv[0] << " NMLFILE\n"; abort(); } 21 | const char *nmlfile = argv[1]; 22 | RCS_STAT_CHANNEL *stat = new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "xemc", nmlfile); 23 | while(1) { 24 | usleep(100*1000); 25 | if(!stat->valid()) continue; 26 | if(stat->peek() != EMC_STAT_TYPE) continue; 27 | EMC_STAT *emcStatus = static_cast(stat->get_address()); 28 | std::cout << emcStatus->motion.traj.position.tran.x << " " 29 | << emcStatus->motion.traj.position.tran.y << " " 30 | << emcStatus->motion.traj.position.tran.z << "\n"; 31 | } 32 | return 0; 33 | } 34 | 35 | In a run-in-place version of v2.5_branch it builds with this commandline: 36 | g++ -o nml-position-logger nml-position-logger.cc -Iinclude -Llib -lnml -llinuxcnc 37 | (and probably it will build from the package version if you have the -dev 38 | package installed, but I didn't test this) 39 | 40 | in master branch it looks like we have a regression so the commandline required is: 41 | g++ -o nml-position-logger nml-position-logger.cc -Iinclude -Isrc/emc/rs274ngc -Llib -lnml -llinuxcnc 42 | and a -dev package will not include at least one of the required headers. 43 | 44 | To use this program you would start linuxcnc with a traditional UI and 45 | then execute the program with the path to linuxcnc.nml. For example 46 | if you're at the top dirctory of a run-in-place linuxcnc: 47 | ./nml-position-logger configs/common/linuxcnc.nml 48 | .. press ctrl-c to exit. 49 | 50 | To send commands you will use an RCS_CMD_CHANNEL: 51 | // command channel 52 | RCS_CMD_CHANNEL *cmd = 53 | new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", file); 54 | int emcCommandSerialNumber = 0; 55 | and sending a command consists of something like 56 | EMC_TASK_ABORT m; 57 | m.serial_number = ++emcCommandSerialNumber; 58 | // most commands have other fields that must be initialized 59 | // such as EMC_TASK_SET_MODE::mode 60 | cmd->write(m); 61 | // at this point, many UIs have logic to "wait for task to receive 62 | // the command", though xemc does not 63 | 64 | To recieve error notices create an error connection 65 | // error channel 66 | NML *error = new NML(emcFormat, "emcError", "xemc", file); 67 | and poll it like yo usee in xemc.cc:updateError(). Note that when 68 | multiple UIs exist which poll for errors, only one of them will receive 69 | the error. 70 | 71 | The string "xemc" which occurs in several places is a magic string; you 72 | will just want to leave it unchanged. 73 | 74 | Jeff 75 | 76 | 77 | // 78 | 79 | const char *cstr = nmlfile.c_str(); 80 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 81 | if(!c) { 82 | std::cout<<"command channel failed"<write(&m); 96 | 97 | 98 | 99 | // 100 | 101 | void MainWindow::on_actionopen_triggered() 102 | { 103 | #define NGC_FILES "Linuxcnc files(*.ngc)" 104 | 105 | QFileDialog *dialog = new QFileDialog; 106 | dialog->resize(500,250); 107 | QString selectedFilter; 108 | 109 | QString filename_open = QFileDialog::getOpenFileName( 110 | dialog, 111 | "Open", 112 | QDir::currentPath(), 113 | NGC_FILES, 114 | &selectedFilter, 115 | QFileDialog::DontUseNativeDialog); //this solves a dxf multiload problem 116 | 117 | if(selectedFilter == NGC_FILES){ 118 | 119 | //first convert Qstring to standard string 120 | std::string filename=filename_open.toStdString(); 121 | //convert standard string to char 122 | const char *char_filename = filename.c_str(); 123 | 124 | const char *cstr = nmlfile.c_str(); 125 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 126 | 127 | //first close current loaded ngc file 128 | EMC_TASK_PLAN_CLOSE close; 129 | c->write(&close); 130 | 131 | //load new ngc file 132 | EMC_TASK_PLAN_OPEN open; 133 | strcpy(open.file, char_filename); 134 | c->write(&open); 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /keyboard/keyboard.h: -------------------------------------------------------------------------------- 1 | #ifndef KEYBOARD_H 2 | #define KEYBOARD_H 3 | 4 | #include 5 | #include 6 | 7 | 8 | void keypress(int key){ 9 | std::cout<<"int key: "< 5 | 6 | void keypress(int key){ 7 | 8 | 9 | } 10 | 11 | void keyrelease(){ 12 | 13 | 14 | } 15 | 16 | 17 | #endif // KEYPRESS_H 18 | -------------------------------------------------------------------------------- /lcnc/halcommand/get_command.h: -------------------------------------------------------------------------------- 1 | #ifndef GET_COMMAND_H 2 | #define GET_COMMAND_H 3 | 4 | // For user space HAL RTAPI 5 | #ifdef RTAPI 6 | #undef RTAPI 7 | #endif 8 | #ifndef ULAPI 9 | #define ULAPI 10 | #endif 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | #include "hal.h" 20 | #include "rtapi.h" /* RTAPI realtime OS API */ 21 | #include "rtapi_string.h" 22 | #include "rtapi_errno.h" 23 | 24 | #include "config.h" 25 | #include "rtapi.h" /* RTAPI realtime OS API */ 26 | #include "hal.h" /* HAL public API decls */ 27 | #include 28 | #include 29 | 30 | #include "config.h" 31 | #include "rtapi.h" /* RTAPI realtime OS API */ 32 | #include "hal.h" /* HAL public API decls */ 33 | #include "../hal_priv.h" /* private HAL decls */ 34 | #include "halcmd_commands.h" 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | 52 | float get_command(std::string name); 53 | static char *data_value2(int type, void *valptr); 54 | 55 | //void hal_command_test(){ 56 | 57 | // std::string name= "ini.traj_default_velocity"; 58 | // float result=get_command(name); 59 | // std::cout<<"result: "<mutex)); 76 | /* search param list for name */ 77 | param = halpr_find_param_by_name(text); 78 | if (param) { 79 | /* found it */ 80 | type = param->type; 81 | d_ptr = SHMPTR(param->data_ptr); 82 | 83 | rtapi_mutex_give(&(hal_data->mutex)); 84 | 85 | char *data= data_value2((int) type, d_ptr); 86 | std::string str(data); 87 | float value=std::stof(str); 88 | return value; 89 | } 90 | 91 | /* not found, search pin list for name */ 92 | pin = halpr_find_pin_by_name(text); 93 | if(pin) { 94 | /* found it */ 95 | type = pin->type; 96 | if (pin->signal != 0) { 97 | //sig = SHMPTR(pin->signal); 98 | d_ptr = SHMPTR(sig->data_ptr); 99 | } else { 100 | sig = 0; 101 | d_ptr = &(pin->dummysig); 102 | } 103 | 104 | rtapi_mutex_give(&(hal_data->mutex)); 105 | 106 | char *data= data_value2((int) type, d_ptr); 107 | std::string str(data); 108 | float value=std::stof(str); 109 | return value; 110 | } 111 | 112 | rtapi_mutex_give(&(hal_data->mutex)); 113 | //halcmd_error("pin or parameter '%s' not found\n", name); 114 | //return -EINVAL; 115 | return -1; 116 | } 117 | 118 | bool get_bool_command(std::string name){ ///../linuxcnc/src/hal/utils/halcmd_commands.c 119 | 120 | char text[1]; 121 | sprintf(text,"%s",name.c_str()); //copy float value to char container 122 | 123 | hal_param_t *param; 124 | hal_pin_t *pin; 125 | hal_sig_t *sig = nullptr; 126 | hal_type_t type; 127 | void *d_ptr; 128 | 129 | rtapi_print_msg(RTAPI_MSG_DBG, "getting parameter '%s'\n", text); 130 | /* get mutex before accessing shared data */ 131 | rtapi_mutex_get(&(hal_data->mutex)); 132 | /* search param list for name */ 133 | param = halpr_find_param_by_name(text); 134 | if (param) { 135 | /* found it */ 136 | type = param->type; 137 | d_ptr = SHMPTR(param->data_ptr); 138 | 139 | rtapi_mutex_give(&(hal_data->mutex)); 140 | 141 | char *data= data_value2((int) type, d_ptr); 142 | 143 | if(strcmp(data,"TRUE")!=0){ 144 | return 0; 145 | } else return 1; 146 | } 147 | 148 | /* not found, search pin list for name */ 149 | pin = halpr_find_pin_by_name(text); 150 | if(pin) { 151 | /* found it */ 152 | type = pin->type; 153 | if (pin->signal != 0) { 154 | //sig = SHMPTR(pin->signal); 155 | d_ptr = SHMPTR(sig->data_ptr); 156 | } else { 157 | sig = 0; 158 | d_ptr = &(pin->dummysig); 159 | } 160 | 161 | rtapi_mutex_give(&(hal_data->mutex)); 162 | 163 | char *data= data_value2((int) type, d_ptr); 164 | 165 | if(strcmp(data,"TRUE")!=0){ 166 | return 0; 167 | } else return 1; 168 | } 169 | 170 | rtapi_mutex_give(&(hal_data->mutex)); 171 | //halcmd_error("pin or parameter '%s' not found\n", name); 172 | //return -EINVAL; 173 | return -1; 174 | } 175 | 176 | /* Switch function to return var value in string form */ 177 | /* the value is printed as a packed string (no whitespace */ 178 | static char *data_value2(int type, void *valptr) 179 | { 180 | char *value_str; 181 | static char buf[15]; 182 | 183 | switch (type) { 184 | case HAL_BIT: 185 | if (*((char *) valptr) == 0) 186 | value_str = "FALSE"; 187 | else 188 | value_str = "TRUE"; 189 | break; 190 | case HAL_FLOAT: 191 | snprintf(buf, 14, "%.7g", (double)*((hal_float_t *) valptr)); 192 | value_str = buf; 193 | break; 194 | case HAL_S32: 195 | snprintf(buf, 14, "%ld", (long)*((hal_s32_t *) valptr)); 196 | value_str = buf; 197 | break; 198 | case HAL_U32: 199 | snprintf(buf, 14, "%ld", (unsigned long)*((hal_u32_t *) valptr)); 200 | value_str = buf; 201 | break; 202 | // case HAL_PORT: 203 | // //snprintf(buf, 14, "%u", hal_port_buffer_size(*((hal_port_t*) valptr))); 204 | // value_str = buf; 205 | // break; 206 | 207 | default: 208 | /* Shouldn't get here, but just in case... */ 209 | value_str = "unknown_type"; 210 | } 211 | return value_str; 212 | } 213 | 214 | #endif // GET_COMMAND_H 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | -------------------------------------------------------------------------------- /lcnc/halcommand/get_spindle_cw.h: -------------------------------------------------------------------------------- 1 | #ifndef GET_SPINDLE_CW_H 2 | #define GET_SPINDLE_CW_H 3 | 4 | #endif // GET_SPINDLE_CW_H 5 | -------------------------------------------------------------------------------- /lcnc/halcommand/send_command.h: -------------------------------------------------------------------------------- 1 | #ifndef SEND_COMMAND_H 2 | #define SEND_COMMAND_H 3 | 4 | // For user space HAL RTAPI 5 | #ifdef RTAPI 6 | #undef RTAPI 7 | #endif 8 | #ifndef ULAPI 9 | #define ULAPI 10 | #endif 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | #include "hal.h" 20 | #include "rtapi.h" /* RTAPI realtime OS API */ 21 | #include "rtapi_string.h" 22 | #include "rtapi_errno.h" 23 | 24 | #include "config.h" 25 | #include "rtapi.h" /* RTAPI realtime OS API */ 26 | #include "hal.h" /* HAL public API decls */ 27 | #include 28 | #include 29 | 30 | #include "config.h" 31 | #include "rtapi.h" /* RTAPI realtime OS API */ 32 | #include "hal.h" /* HAL public API decls */ 33 | #include "../hal_priv.h" /* private HAL decls */ 34 | #include "halcmd_commands.h" 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | 52 | static int set_common(hal_type_t type, void *d_ptr, char *value); 53 | 54 | void hal_connection(){ 55 | //somehow we need this at the startup of lcnc, otherwise we get segmentation fault. 56 | int comp_id = hal_init("QT_C++_Interface"); 57 | hal_comp_name(comp_id); 58 | hal_malloc(200); 59 | //int sigml= hal_signal_new("xxx", HAL_FLOAT ); 60 | hal_ready(comp_id); 61 | } 62 | 63 | //void hal_command_test(){ 64 | // //to test various hal commands quite easy. 65 | // char value[] = "12"; 66 | // char name[] = "halui.feed-override.counts"; 67 | // do_setp_cmd(name,value); 68 | //} 69 | 70 | int do_sets_cmd(char *name, char *value) ///../linuxcnc/src/hal/utils/halcmd_commands.c 71 | { 72 | int retval; 73 | hal_sig_t *sig; 74 | hal_type_t type; 75 | void *d_ptr; 76 | 77 | rtapi_print_msg(RTAPI_MSG_DBG, "setting signal '%s'\n", name); 78 | /* get mutex before accessing shared data */ 79 | rtapi_mutex_get(&(hal_data->mutex)); 80 | /* search signal list for name */ 81 | sig = halpr_find_sig_by_name(name); 82 | if (sig == 0) { 83 | rtapi_mutex_give(&(hal_data->mutex)); 84 | //halcmd_error("signal '%s' not found\n", name); 85 | return -EINVAL; 86 | } 87 | /* found it - it have a writer? if it is a port we can set its buffer size */ 88 | if ((sig->type != HAL_PORT) && (sig->writers > 0)) { 89 | rtapi_mutex_give(&(hal_data->mutex)); 90 | //halcmd_error("signal '%s' already has writer(s)\n", name); 91 | return -EINVAL; 92 | } 93 | /* no writer, so we can safely set it */ 94 | type = sig->type; 95 | d_ptr = SHMPTR(sig->data_ptr); 96 | retval = set_common(type, d_ptr, value); 97 | rtapi_mutex_give(&(hal_data->mutex)); 98 | if (retval == 0) { 99 | /* print success message */ 100 | // halcmd_info("Signal '%s' set to %s\n", name, value); 101 | } else { 102 | //halcmd_error("sets failed\n"); 103 | } 104 | return retval; 105 | } 106 | 107 | int do_setp_cmd(char *name, char *value) 108 | { 109 | int retval; 110 | hal_param_t *param; 111 | hal_pin_t *pin; 112 | hal_type_t type; 113 | void *d_ptr; 114 | 115 | //halcmd_info("setting parameter '%s' to '%s'\n", name, value); 116 | /* get mutex before accessing shared data */ 117 | rtapi_mutex_get(&(hal_data->mutex)); 118 | /* search param list for name */ 119 | param = halpr_find_param_by_name(name); 120 | if (param == 0) { 121 | pin = halpr_find_pin_by_name(name); 122 | if(pin == 0) { 123 | rtapi_mutex_give(&(hal_data->mutex)); 124 | //halcmd_error("parameter or pin '%s' not found\n", name); 125 | return -EINVAL; 126 | } else { 127 | /* found it */ 128 | type = pin->type; 129 | if(pin->dir == HAL_OUT) { 130 | rtapi_mutex_give(&(hal_data->mutex)); 131 | //halcmd_error("pin '%s' is not writable\n", name); 132 | return -EINVAL; 133 | } 134 | if(pin->signal != 0) { 135 | rtapi_mutex_give(&(hal_data->mutex)); 136 | //halcmd_error("pin '%s' is connected to a signal\n", name); 137 | return -EINVAL; 138 | } 139 | // d_ptr = (void*)SHMPTR(pin->dummysig); 140 | d_ptr = (void*)&pin->dummysig; 141 | } 142 | } else { 143 | /* found it */ 144 | type = param->type; 145 | /* is it read only? */ 146 | if (param->dir == HAL_RO) { 147 | rtapi_mutex_give(&(hal_data->mutex)); 148 | //halcmd_error("param '%s' is not writable\n", name); 149 | return -EINVAL; 150 | } 151 | d_ptr = SHMPTR(param->data_ptr); 152 | } 153 | 154 | retval = set_common(type, d_ptr, value); 155 | 156 | rtapi_mutex_give(&(hal_data->mutex)); 157 | if (retval == 0) { 158 | /* print success message */ 159 | if(param) { 160 | //halcmd_info("Parameter '%s' set to %s\n", name, value); 161 | } else { 162 | //halcmd_info("Pin '%s' set to %s\n", name, value); 163 | } 164 | } else { 165 | //halcmd_error("setp failed\n"); 166 | } 167 | return retval; 168 | 169 | } 170 | 171 | static int set_common(hal_type_t type, void *d_ptr, char *value) { 172 | // This function assumes that the mutex is held 173 | int retval = 0; 174 | double fval; 175 | long lval; 176 | unsigned long ulval; 177 | unsigned uval; 178 | char *cp = value; 179 | 180 | switch (type) { 181 | case HAL_BIT: 182 | if ((strcmp("1", value) == 0) || (strcasecmp("TRUE", value) == 0)) { 183 | *(hal_bit_t *) (d_ptr) = 1; 184 | } else if ((strcmp("0", value) == 0) 185 | || (strcasecmp("FALSE", value)) == 0) { 186 | *(hal_bit_t *) (d_ptr) = 0; 187 | } else { 188 | //halcmd_error("value '%s' invalid for bit\n", value); 189 | retval = -EINVAL; 190 | } 191 | break; 192 | case HAL_FLOAT: 193 | fval = strtod ( value, &cp ); 194 | if ((*cp != '\0') && (!isspace(*cp))) { 195 | /* invalid character(s) in string */ 196 | //halcmd_error("value '%s' invalid for float\n", value); 197 | retval = -EINVAL; 198 | } else { 199 | *((hal_float_t *) (d_ptr)) = fval; 200 | } 201 | break; 202 | case HAL_S32: 203 | lval = strtol(value, &cp, 0); 204 | if ((*cp != '\0') && (!isspace(*cp))) { 205 | /* invalid chars in string */ 206 | //halcmd_error("value '%s' invalid for S32\n", value); 207 | retval = -EINVAL; 208 | } else { 209 | *((hal_s32_t *) (d_ptr)) = lval; 210 | } 211 | break; 212 | case HAL_U32: 213 | ulval = strtoul(value, &cp, 0); 214 | if ((*cp != '\0') && (!isspace(*cp))) { 215 | /* invalid chars in string */ 216 | //halcmd_error("value '%s' invalid for U32\n", value); 217 | retval = -EINVAL; 218 | } else { 219 | *((hal_u32_t *) (d_ptr)) = ulval; 220 | } 221 | break; 222 | // case HAL_PORT: 223 | // uval = strtoul(value, &cp, 0); 224 | // if ((*cp != '\0') && (!isspace(*cp))) { 225 | // //halcmd_error("value '%s' invalid for PORT\n", value); 226 | // retval = -EINVAL; 227 | // } //else { 228 | // // if((*((hal_port_t*)d_ptr) != 0) && (hal_port_buffer_size(*((hal_port_t*)d_ptr)) > 0)) { 229 | // //halcmd_error("port is already allocated with %u bytes.\n", hal_port_buffer_size(*((hal_port_t*)d_ptr))); 230 | // // retval = -EINVAL; 231 | // // } else { 232 | // //*((hal_port_t*) (d_ptr)) = hal_port_alloc(uval); 233 | // // } 234 | // } 235 | // break; 236 | default: 237 | /* Shouldn't get here, but just in case... */ 238 | //halcmd_error("bad type %d\n", type); 239 | retval = -EINVAL; 240 | } 241 | return retval; 242 | } 243 | 244 | #endif // SEND_COMMAND_H 245 | -------------------------------------------------------------------------------- /lcnc/halcommand/set_adaptive_feed.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_ADAPTIVE_FEED_H 2 | #define SET_ADAPTIVE_FEED_H 3 | 4 | #include 5 | #include 6 | 7 | void set_adaptive_feed(float value){ //value = -1 to 1 8 | char sz[101]; //101 data places is for float value 9 | sprintf(sz,"%G",value); //copy float value to char container 10 | char name[] = "motion.adaptive-feed"; //name of halui pin 11 | do_setp_cmd(name,sz); //cal send_command.h 12 | } 13 | 14 | #endif // SET_ADAPTIVE_FEED_H 15 | -------------------------------------------------------------------------------- /lcnc/halcommand/set_feed_override.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_FEED_OVERRIDE_H 2 | #define SET_FEED_OVERRIDE_H 3 | 4 | #include 5 | #include 6 | 7 | void set_feed_override(int value){ 8 | char sz[32]; //lcnc input is format:U32, this is a int. 9 | sprintf(sz,"%i",value); //convert value to char. 10 | char name[] = "halui.feed-override.counts"; 11 | do_setp_cmd(name,sz); 12 | } 13 | 14 | #endif // SET_FEED_OVERRIDE_H 15 | -------------------------------------------------------------------------------- /lcnc/halcommand/set_flood_off.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_FLOOD_OFF_H 2 | #define SET_FLOOD_OFF_H 3 | 4 | #include 5 | #include 6 | 7 | void set_flood_off(){ 8 | char value[] = "0"; 9 | char name[] = "halui.flood.on"; 10 | do_setp_cmd(name,value); 11 | 12 | char value1[] = "1"; 13 | char name1[] = "halui.flood.off"; 14 | do_setp_cmd(name1,value1); 15 | } 16 | 17 | #endif // SET_FLOOD_OFF_H 18 | -------------------------------------------------------------------------------- /lcnc/halcommand/set_flood_on.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_FLOOD_ON_H 2 | #define SET_FLOOD_ON_H 3 | 4 | #include 5 | #include 6 | 7 | void set_flood_on(){ 8 | char value[] = "1"; 9 | char name[] = "halui.flood.on"; 10 | do_setp_cmd(name,value); 11 | 12 | char value1[] = "0"; 13 | char name1[] = "halui.flood.off"; 14 | do_setp_cmd(name1,value1); 15 | } 16 | 17 | #endif // SET_FLOOD_ON_H 18 | -------------------------------------------------------------------------------- /lcnc/halcommand/set_home_x.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_HOME_X_H 2 | #define SET_HOME_X_H 3 | 4 | #include 5 | #include 6 | 7 | void set_home_x(){ 8 | char value[] = "1"; 9 | char name[] = "halui.joint.0.home"; 10 | do_setp_cmd(name,value); 11 | } 12 | 13 | #endif // SET_HOME_X_H 14 | -------------------------------------------------------------------------------- /lcnc/halcommand/set_jog_speed.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_JOG_SPEED_H 2 | #define SET_JOG_SPEED_H 3 | 4 | #include 5 | #include 6 | 7 | void set_jog_speed(float value){ 8 | char sz[101]; //101 char data places is a float 9 | sprintf(sz,"%G",value); //copy float value into char container 10 | char name[] = "halui.jog-speed"; //pin to send command to 11 | do_setp_cmd(name,sz); //call send_command.h 12 | } 13 | 14 | #endif // SET_JOG_SPEED_H 15 | -------------------------------------------------------------------------------- /lcnc/halcommand/set_lube_off.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_LUBE_OFF_H 2 | #define SET_LUBE_OFF_H 3 | 4 | #include 5 | #include 6 | 7 | void set_lube_off(){ 8 | char value[] = "0"; 9 | char name[] = "halui.lube.on"; 10 | do_setp_cmd(name,value); 11 | 12 | char value1[] = "1"; 13 | char name1[] = "halui.lube.off"; 14 | do_setp_cmd(name1,value1); 15 | } 16 | 17 | #endif // SET_LUBE_OFF_H 18 | -------------------------------------------------------------------------------- /lcnc/halcommand/set_lube_on.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_LUBE_ON_H 2 | #define SET_LUBE_ON_H 3 | 4 | #include 5 | #include 6 | 7 | void set_lube_on(){ 8 | char value[] = "1"; 9 | char name[] = "halui.lube.on"; 10 | do_setp_cmd(name,value); 11 | 12 | char value1[] = "0"; 13 | char name1[] = "halui.lube.off"; 14 | do_setp_cmd(name1,value1); 15 | } 16 | 17 | #endif // SET_LUBE_ON_H 18 | -------------------------------------------------------------------------------- /lcnc/halcommand/set_max_velocity.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_MAX_VELOCITY_H 2 | #define SET_MAX_VELOCITY_H 3 | 4 | #include 5 | #include 6 | 7 | void set_max_velocity(int value){ 8 | char sz[32]; //lcnc input is format:U32, this is a int. 9 | sprintf(sz,"%i",value/60); //convert value to char, convert units from mm/min to mm/sec lcnc input 10 | char name1[] = "halui.max-velocity.counts"; //lcnc pin to sent message to 11 | do_setp_cmd(name1,sz); //call send_command.h 12 | } 13 | 14 | #endif // SET_MAX_VELOCITY_H 15 | -------------------------------------------------------------------------------- /lcnc/halcommand/set_mode_joint.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_MODE_JOINT_H 2 | #define SET_MODE_JOINT_H 3 | 4 | #include 5 | #include 6 | 7 | void set_mode_joint(){ 8 | char value[] = "1"; 9 | char name[] = "halui.mode.joint"; 10 | do_setp_cmd(name,value); 11 | } 12 | 13 | #endif // SET_MODE_JOINT_H 14 | -------------------------------------------------------------------------------- /lcnc/halcommand/set_mode_teleop.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_MODE_TELEOP_H 2 | #define SET_MODE_TELEOP_H 3 | 4 | #include 5 | #include 6 | 7 | void set_mode_teleop(){ 8 | char value[] = "1"; 9 | char name[] = "halui.mode.teleop"; 10 | do_setp_cmd(name,value); 11 | } 12 | 13 | #endif // SET_MODE_TELEOP_H 14 | -------------------------------------------------------------------------------- /lcnc/halcommand/set_rapid_override.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_RAPID_OVERRIDE_H 2 | #define SET_RAPID_OVERRIDE_H 3 | 4 | #include 5 | #include 6 | 7 | void set_rapid_override(int value){ 8 | char sz[32]; //lcnc input is format:U32, this is a int. 9 | sprintf(sz,"%i",value); //copy int to char container 10 | char name[] = "halui.rapid-override.counts"; //pin to send command to 11 | do_setp_cmd(name,sz); //call send_command.h 12 | } 13 | 14 | #endif // SET_RAPID_OVERRIDE_H 15 | -------------------------------------------------------------------------------- /lcnc/halcommand/set_scale_max_velocity.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_SCALE_MAX_VELOCITY_H 2 | #define SET_SCALE_MAX_VELOCITY_H 3 | 4 | #include 5 | #include 6 | 7 | void set_scale_max_velocity(float value){ 8 | char sz1[101]; //lcnc input is format:float 9 | sprintf(sz1,"%G",value); //copy float value to char container 10 | char name[] = "halui.max-velocity.scale"; //the pin to send the message to 11 | do_setp_cmd(name,sz1); //cal send_command.h 12 | } 13 | 14 | #endif // SET_SCALE_MAX_VELOCITY_H 15 | -------------------------------------------------------------------------------- /lcnc/halcommand/set_spindle_decrease.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_SPINDLE_DECREASE_H 2 | #define SET_SPINDLE_DECREASE_H 3 | 4 | #include 5 | #include 6 | 7 | void set_spindle_decrease(int value){ 8 | char sz[32]; //lcnc input is format:U32, this is a int. 9 | sprintf(sz,"%i",value); //convert value to char. 10 | char name[] = "halui.spindle.0.decrease"; 11 | do_setp_cmd(name,sz); 12 | } 13 | 14 | #endif // SET_SPINDLE_DECREASE_H 15 | -------------------------------------------------------------------------------- /lcnc/halcommand/set_spindle_increase.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_SPINDLE_INCREASE_H 2 | #define SET_SPINDLE_INCREASE_H 3 | 4 | #include 5 | #include 6 | 7 | void set_spindle_increase(int value){ 8 | char sz[32]; //lcnc input is format:U32, this is a int. 9 | sprintf(sz,"%i",value); //convert value to char. 10 | char name[] = "halui.spindle.0.increase"; 11 | do_setp_cmd(name,sz); 12 | } 13 | 14 | #endif // SET_SPINDLE_INCREASE_H 15 | 16 | -------------------------------------------------------------------------------- /lcnc/halcommand/set_spindle_override.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_SPINDLE_OVERRIDE_H 2 | #define SET_SPINDLE_OVERRIDE_H 3 | 4 | #include 5 | #include 6 | 7 | void set_spindle_override(int value){ 8 | char sz[32]; //lcnc input is format:U32, this is a int. 9 | sprintf(sz,"%i",value); //copy int to char container 10 | char name[] = "halui.spindle.0.override.counts"; //pin to send command to 11 | do_setp_cmd(name,sz); //call send_command.h 12 | } 13 | 14 | #endif // SET_SPINDLE_OVERRIDE_H 15 | -------------------------------------------------------------------------------- /lcnc/jog.h: -------------------------------------------------------------------------------- 1 | #ifndef JOG_H 2 | #define JOG_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void jog(int axis, double velocity, int jogmode){ 10 | 11 | const char *cstr = nmlfile.c_str(); 12 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 13 | 14 | EMC_JOG_CONT cont; 15 | cont.joint_or_axis = axis; 16 | cont.vel = velocity; 17 | cont.jjogmode = 0; //1=teleop 18 | c->write(&cont); 19 | } 20 | 21 | #endif // JOG_H 22 | -------------------------------------------------------------------------------- /lcnc/nml/config.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_H 2 | #define CONFIG_H 3 | 4 | 5 | 6 | #endif // CONFIG_H 7 | -------------------------------------------------------------------------------- /lcnc/nml/disable_adaptive_feed.h: -------------------------------------------------------------------------------- 1 | #ifndef DISABLE_ADAPTIVE_FEED_H 2 | #define DISABLE_ADAPTIVE_FEED_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include //system 9 | 10 | void disable_adaptive_feed(){ 11 | 12 | const char *cstr = nmlfile.c_str(); 13 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 14 | EMC_TASK_SET_STATE state; 15 | state.state=EMC_TASK_STATE_ENUM(EMC_TASK_STATE_ESTOP); 16 | c->write(&state); 17 | 18 | EMC_MOTION_ADAPTIVE m; 19 | m.status=0; 20 | c->write(&m); 21 | } 22 | 23 | #endif // DISABLE_ADAPTIVE_FEED_H 24 | -------------------------------------------------------------------------------- /lcnc/nml/enable_adaptive_feed.h: -------------------------------------------------------------------------------- 1 | #ifndef ENABLE_ADAPTIVE_FEED_H 2 | #define ENABLE_ADAPTIVE_FEED_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include //system 9 | 10 | void enable_adaptive_feed(){ 11 | 12 | const char *cstr = nmlfile.c_str(); 13 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 14 | EMC_TASK_SET_STATE state; 15 | state.state=EMC_TASK_STATE_ENUM(EMC_TASK_STATE_ESTOP); 16 | c->write(&state); 17 | 18 | EMC_MOTION_ADAPTIVE m; 19 | m.status=1; 20 | c->write(&m); 21 | } 22 | 23 | #endif // ENABLE_ADAPTIVE_FEED_H 24 | -------------------------------------------------------------------------------- /lcnc/nml/estop.h: -------------------------------------------------------------------------------- 1 | #ifndef ESTOP_H 2 | #define ESTOP_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void estop(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | EMC_TASK_SET_STATE state; 13 | state.state=EMC_TASK_STATE_ENUM(EMC_TASK_STATE_ESTOP); 14 | c->write(&state); 15 | } 16 | 17 | #endif // ESTOP_H 18 | -------------------------------------------------------------------------------- /lcnc/nml/estop_reset.h: -------------------------------------------------------------------------------- 1 | #ifndef ESTOP_RESET_H 2 | #define ESTOP_RESET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void estop_reset(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | EMC_TASK_SET_STATE state; 13 | state.state=EMC_TASK_STATE_ENUM(EMC_TASK_STATE_ESTOP_RESET); 14 | c->write(&state); 15 | } 16 | 17 | #endif // ESTOP_RESET_H 18 | -------------------------------------------------------------------------------- /lcnc/nml/feed_override.h: -------------------------------------------------------------------------------- 1 | #ifndef FEED_OVERRIDE_H 2 | #define FEED_OVERRIDE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void feed_override(int procent){ 10 | 11 | // const char *cstr = nmlfile.c_str(); 12 | // RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 13 | // EMC_TRAJ_SET_FO_ENABLE m; 14 | // m.mode=1; 15 | // c->write(&m); 16 | } 17 | 18 | #endif // FEED_OVERRIDE_H 19 | 20 | 21 | -------------------------------------------------------------------------------- /lcnc/nml/get_position.h: -------------------------------------------------------------------------------- 1 | #ifndef GET_POSITION_H 2 | #define GET_POSITION_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | POINT get_position(){ 10 | std::string nmlfile="/home/user/linuxcnc/configs/common/linuxcnc.nml"; 11 | const char *cstr = nmlfile.c_str(); 12 | POINT t; 13 | RCS_STAT_CHANNEL *stat = new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "xemc", cstr); 14 | 15 | for(int i=0; i<1; i++){ 16 | usleep(100); 17 | if(!stat->valid()) continue; 18 | if(stat->peek() != EMC_STAT_TYPE) continue; 19 | EMC_STAT *emcStatus = static_cast(stat->get_address()); 20 | 21 | t.x=emcStatus->motion.traj.position.tran.x; 22 | t.y=emcStatus->motion.traj.position.tran.y; 23 | t.z=emcStatus->motion.traj.position.tran.z; 24 | 25 | emcStatus_task_currentLine=emcStatus->task.currentLine; 26 | emcStatus_task_motionLine=emcStatus->task.motionLine; 27 | emcStatus_task_mode=emcStatus->task.mode; //1=manual 2=auto 3=mdi 28 | emcStatus_motion_status=emcStatus->motion.status; //2=auto running 29 | 30 | //std::cout<<"motion status: "<task.activeGCodes; 33 | //int d=emcStatus->task.activeGCodes; 34 | 35 | 36 | 37 | 38 | } 39 | return t; 40 | } 41 | 42 | #endif // GET_POSITION_H 43 | -------------------------------------------------------------------------------- /lcnc/nml/hal_pin_test.h: -------------------------------------------------------------------------------- 1 | #ifndef HAL_PIN_TEST_H 2 | #define HAL_PIN_TEST_H 3 | 4 | 5 | 6 | #endif // HAL_PIN_TEST_H 7 | 8 | -------------------------------------------------------------------------------- /lcnc/nml/home_all.h: -------------------------------------------------------------------------------- 1 | #ifndef HOME_H 2 | #define HOME_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void home_all(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | 13 | //EMC_TRAJ_SET_MODE x; 14 | //x. 15 | //x.mode=EMC_TRAJ_MODE_TELEOP; 16 | //c->write(&x); 17 | 18 | EMC_JOINT_HOME m; 19 | m.joint=0; //x 20 | c->write(&m); 21 | 22 | m.joint=1; //y 23 | c->write(&m); 24 | 25 | m.joint=2; //z 26 | c->write(&m); 27 | 28 | } 29 | 30 | #endif // HOME_H 31 | -------------------------------------------------------------------------------- /lcnc/nml/home_x.h: -------------------------------------------------------------------------------- 1 | #ifndef HOME_X_H 2 | #define HOME_X_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void home_x(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | 13 | //EMC_TRAJ_SET_MODE x; 14 | //x. 15 | //x.mode=EMC_TRAJ_MODE_TELEOP; 16 | //c->write(&x); 17 | 18 | EMC_JOINT_HOME m; 19 | m.joint=0; //x 20 | c->write(&m); 21 | } 22 | 23 | #endif // HOME_X_H 24 | -------------------------------------------------------------------------------- /lcnc/nml/jog.h: -------------------------------------------------------------------------------- 1 | #ifndef JOG_H 2 | #define JOG_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void jog(int axis, double velocity, int jogmode){ 10 | 11 | const char *cstr = nmlfile.c_str(); 12 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 13 | 14 | EMC_JOG_CONT cont; 15 | cont.joint_or_axis = axis; 16 | cont.vel = velocity; 17 | cont.jjogmode = 0; //1=teleop 18 | c->write(&cont); 19 | } 20 | 21 | #endif // JOG_H 22 | -------------------------------------------------------------------------------- /lcnc/nml/jog_speed.h: -------------------------------------------------------------------------------- 1 | #ifndef JOG_SPEED_H 2 | #define JOG_SPEED_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void jog_speed(int speed){ 10 | 11 | //const char *cstr = nmlfile.c_str(); 12 | //RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 13 | 14 | 15 | } 16 | 17 | #endif // JOG_SPEED_H 18 | -------------------------------------------------------------------------------- /lcnc/nml/maxvel.h: -------------------------------------------------------------------------------- 1 | #ifndef MAXVEL_H 2 | #define MAXVEL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void maxvel(double velocity){ 10 | //const char *cstr = nmlfile.c_str(); 11 | //RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | 13 | //finish later on 14 | //EMC_TRAJ_SET_MAX_VELOCITY ss; 15 | 16 | //m.tag.flags.reset(); 17 | //m.tag.is_valid(); 18 | //m.tag.get_state_tag(); 19 | 20 | // void update(CMS * cms); 21 | 22 | //m.velocity=velocity; 23 | //c->write(&m); 24 | } 25 | 26 | #endif // MAXVEL_H 27 | -------------------------------------------------------------------------------- /lcnc/nml/mdi.h: -------------------------------------------------------------------------------- 1 | #ifndef MDI_H 2 | #define MDI_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | void mdi(std::string mdi_command){ 11 | const char *cstr = nmlfile.c_str(); 12 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 13 | 14 | //set mode mdi 15 | EMC_TASK_SET_MODE m; 16 | m.mode=EMC_TASK_MODE_MDI; 17 | c->write(&m); 18 | 19 | //write mdi 20 | std::cout<<"mdi command: "<write(&mdi); 26 | } 27 | 28 | #endif // MDI_H 29 | -------------------------------------------------------------------------------- /lcnc/nml/mode_auto.h: -------------------------------------------------------------------------------- 1 | #ifndef MODE_AUTO_H 2 | #define MODE_AUTO_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void mode_auto(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | EMC_TASK_SET_MODE m; 13 | m.mode=EMC_TASK_MODE_AUTO; 14 | c->write(&m); 15 | } 16 | 17 | #endif // MODE_AUTO_H 18 | -------------------------------------------------------------------------------- /lcnc/nml/mode_joint.h: -------------------------------------------------------------------------------- 1 | #ifndef MODE_JOINT_H 2 | #define MODE_JOINT_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void mode_joint(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | EMC_TRAJ_MODE_FREE 13 | c->write(&m); 14 | } 15 | 16 | #endif // MODE_JOINT_H 17 | -------------------------------------------------------------------------------- /lcnc/nml/mode_manual.h: -------------------------------------------------------------------------------- 1 | #ifndef MODE_MANUAL_H 2 | #define MODE_MANUAL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void mode_manual(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | EMC_TASK_SET_MODE m; 13 | m.mode=EMC_TASK_MODE_MANUAL; 14 | c->write(&m); 15 | } 16 | 17 | #endif // MODE_MANUAL_H 18 | -------------------------------------------------------------------------------- /lcnc/nml/mode_mdi.h: -------------------------------------------------------------------------------- 1 | #ifndef MODE_MDI_H 2 | #define MODE_MDI_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void mode_mdi(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | EMC_TASK_SET_MODE m; 13 | m.mode=EMC_TASK_MODE_MDI; 14 | c->write(&m); 15 | } 16 | 17 | #endif // MODE_MDI_H 18 | -------------------------------------------------------------------------------- /lcnc/nml/mode_teleop.h: -------------------------------------------------------------------------------- 1 | #ifndef MODE_TELEOP_H 2 | #define MODE_TELEOP_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void mode_teleop(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | //EMC_TRAJ_SET_TELEOP_ENABLE m; 13 | //c->write(&m); 14 | } 15 | 16 | #endif // MODE_TELEOP_H 17 | -------------------------------------------------------------------------------- /lcnc/nml/open_file.h: -------------------------------------------------------------------------------- 1 | #ifndef OPEN_FILE_H 2 | #define OPEN_FILE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | std::string open_file(){ 14 | 15 | objects.clear(); 16 | 17 | const char *char_filename; 18 | 19 | #define NGC_FILES "Linuxcnc files(*.ngc)" 20 | 21 | QFileDialog *dialog = new QFileDialog; 22 | dialog->resize(500,250); 23 | QString selectedFilter; 24 | 25 | QString filename_open = QFileDialog::getOpenFileName( 26 | dialog, 27 | "Open", 28 | QDir::currentPath(), 29 | NGC_FILES, 30 | &selectedFilter, 31 | QFileDialog::DontUseNativeDialog); //this solves a dxf multiload problem 32 | 33 | if(selectedFilter == NGC_FILES){ 34 | 35 | //first convert Qstring to standard string 36 | filename=filename_open.toStdString(); 37 | char_filename = filename.c_str(); 38 | 39 | const char *cstr = nmlfile.c_str(); 40 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 41 | 42 | EMC_TASK_SET_MODE a; 43 | a.mode=EMC_TASK_MODE_AUTO; 44 | c->write(&a); 45 | 46 | //first close current loaded ngc file 47 | EMC_TASK_PLAN_CLOSE close; 48 | c->write(&close); 49 | 50 | //load new ngc file 51 | EMC_TASK_PLAN_OPEN open; 52 | strcpy(open.file, char_filename); 53 | c->write(&open); 54 | } 55 | 56 | //load file line by line to display in gui preview 57 | std::string text; 58 | std::vector gcode; 59 | char count[200]; 60 | FILE *file=fopen(char_filename, "r"); //convert std::string to std::char 61 | while(file && fgets(count, sizeof(count), file)){ 62 | text+=count; 63 | gcode.push_back(count); 64 | } 65 | fcloseall(); 66 | parse_gcode(gcode); 67 | return text; 68 | } 69 | 70 | #endif // OPEN_FILE_H 71 | 72 | //working: 73 | //const char *cstr = nmlfile.c_str(); 74 | //RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 75 | 76 | //EMC_TASK_SET_MODE a; 77 | //a.mode=EMC_TASK_MODE_AUTO; 78 | //c->write(&a); 79 | 80 | //EMC_TASK_PLAN_CLOSE m; 81 | //c->write(&m); 82 | 83 | //EMC_TASK_PLAN_OPEN x; 84 | //strcpy(x.file, "/home/user/QT_Lcnc_interface/ngc/test.ngc"); 85 | //c->write(&x); 86 | -------------------------------------------------------------------------------- /lcnc/nml/pause.h: -------------------------------------------------------------------------------- 1 | #ifndef PAUSE_H 2 | #define PAUSE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void pause_(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | EMC_TASK_PLAN_PAUSE pause; 13 | c->write(&pause); 14 | } 15 | 16 | #endif // PAUSE_H 17 | -------------------------------------------------------------------------------- /lcnc/nml/reload_file.h: -------------------------------------------------------------------------------- 1 | #ifndef RELOAD_FILE_H 2 | #define RELOAD_FILE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | std::string reload_file(){ 14 | 15 | objects.clear(); 16 | 17 | const char *char_filename; 18 | char_filename = filename.c_str(); //filename in orange is already in memory as external variable, so no magic happens over here. 19 | 20 | const char *cstr = nmlfile.c_str(); 21 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 22 | 23 | EMC_TASK_SET_MODE a; 24 | a.mode=EMC_TASK_MODE_AUTO; 25 | c->write(&a); 26 | 27 | //first close current loaded ngc file 28 | EMC_TASK_PLAN_CLOSE close; 29 | c->write(&close); 30 | 31 | //load new ngc file 32 | EMC_TASK_PLAN_OPEN open; 33 | strcpy(open.file, char_filename); 34 | c->write(&open); 35 | 36 | //load file line by line to display in gui preview 37 | std::string text; 38 | std::vector gcode; 39 | char count[200]; 40 | FILE *file=fopen(char_filename, "r"); //convert std::string to std::char 41 | while(file && fgets(count, sizeof(count), file)){ 42 | text+=count; 43 | gcode.push_back(count); 44 | } 45 | fcloseall(); 46 | parse_gcode(gcode); 47 | return text; 48 | } 49 | 50 | #endif // RELOAD_FILE_H 51 | -------------------------------------------------------------------------------- /lcnc/nml/reset_interpreter.h: -------------------------------------------------------------------------------- 1 | #ifndef RESET_INTEPRETER_H 2 | #define RESET_INTEPRETER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void reset_interpreter(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | 13 | EMC_TASK_PLAN_INIT m; 14 | c->write(&m); 15 | } 16 | 17 | #endif // RESET_INTEPRETER_H 18 | -------------------------------------------------------------------------------- /lcnc/nml/resume.h: -------------------------------------------------------------------------------- 1 | #ifndef RESUME_H 2 | #define RESUME_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void resume(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | EMC_TASK_PLAN_RESUME resume; 13 | c->write(&resume); 14 | } 15 | 16 | #endif // RESUME_H 17 | -------------------------------------------------------------------------------- /lcnc/nml/run_backward.h: -------------------------------------------------------------------------------- 1 | #ifndef RUN_BACKWARD_H 2 | #define RUN_BACKWARD_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void run_backward(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | 13 | EMC_TASK_PLAN_REVERSE reverse_run; 14 | c->write(&reverse_run); 15 | } 16 | 17 | #endif // RUN_BACKWARD_H 18 | -------------------------------------------------------------------------------- /lcnc/nml/run_forward.h: -------------------------------------------------------------------------------- 1 | #ifndef RUN_H 2 | #define RUN_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void run_forward(int linenumber){ //not working yet 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | 13 | //EMC_TASK_PLAN_FORWARD 14 | 15 | EMC_TASK_PLAN_RUN run; 16 | run.line=linenumber; 17 | 18 | c->write(&run); 19 | } 20 | 21 | #endif // RUN_H 22 | -------------------------------------------------------------------------------- /lcnc/nml/spindle_off.h: -------------------------------------------------------------------------------- 1 | #ifndef SPINDLE_OFF_H 2 | #define SPINDLE_OFF_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void spindle_off(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | EMC_SPINDLE_OFF m; 13 | c->write(&m); 14 | } 15 | 16 | #endif // SPINDLE_OFF_H 17 | -------------------------------------------------------------------------------- /lcnc/nml/spindle_on.h: -------------------------------------------------------------------------------- 1 | #ifndef SPINDLE_ON_H 2 | #define SPINDLE_ON_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void spindle_on(int direction, double rpm){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | 13 | EMC_SPINDLE_ON m; 14 | m.speed=rpm; 15 | m.spindle=direction; 16 | c->write(&m); 17 | } 18 | 19 | #endif // SPINDLE_ON_H 20 | -------------------------------------------------------------------------------- /lcnc/nml/spindle_stop.h: -------------------------------------------------------------------------------- 1 | #ifndef SPINDLE_STOP_H 2 | #define SPINDLE_STOP_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void spindle_stop(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | 13 | EMC_SPINDLE_OFF m; 14 | c->write(&m); 15 | } 16 | 17 | #endif // SPINDLE_STOP_H 18 | -------------------------------------------------------------------------------- /lcnc/nml/state_off.h: -------------------------------------------------------------------------------- 1 | #ifndef STATE_OFF_H 2 | #define STATE_OFF_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void state_off(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | EMC_TASK_SET_STATE state; 13 | state.state=EMC_TASK_STATE_ENUM(EMC_TASK_STATE_OFF); 14 | c->write(&state); 15 | } 16 | 17 | #endif // STATE_OFF_H 18 | -------------------------------------------------------------------------------- /lcnc/nml/state_on.h: -------------------------------------------------------------------------------- 1 | #ifndef STATE_ON_H 2 | #define STATE_ON_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void state_on(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | EMC_TASK_SET_STATE state; 13 | state.state=EMC_TASK_STATE_ENUM(EMC_TASK_STATE_ON); 14 | c->write(&state); 15 | } 16 | 17 | #endif // STATE_ON_H 18 | -------------------------------------------------------------------------------- /lcnc/nml/status/error_message.h: -------------------------------------------------------------------------------- 1 | #ifndef ERROR_MESSAGE_H 2 | #define ERROR_MESSAGE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include "linklist.hh" 14 | 15 | 16 | void error_message(){ ///for more into look at../linuxcnc/include/emc_nml.hh 17 | 18 | // const char *cstr = nmlfile.c_str(); 19 | // RCS_STAT_CHANNEL *stat = new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "xemc", cstr); 20 | 21 | // for(int i=0; i<1; i++){ 22 | // usleep(1); 23 | // if(!stat->valid()) continue; 24 | // if(stat->peek() != EMC_STAT_TYPE) continue; 25 | // EMC_STAT *emcStatus = static_cast(stat->get_address()); 26 | 27 | // //problably this is not working at the moment : 28 | 29 | 30 | 31 | // EMC_OPERATOR_ERROR e; 32 | // char *error=e.error; 33 | 34 | // EMC_OPERATOR_TEXT t; 35 | // char *text=t.text; 36 | 37 | // EMC_OPERATOR_DISPLAY d; 38 | // char *display=d.display; 39 | 40 | // std::vector str; 41 | // str.push_back(error); 42 | // str.push_back(text); 43 | // str.push_back(display); 44 | 45 | // return str; 46 | // } 47 | 48 | 49 | 50 | 51 | } 52 | 53 | void hal_command_test(){ 54 | 55 | 56 | } 57 | 58 | #endif // ERROR_MESSAGE_H 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /lcnc/nml/status/get_message_status.h: -------------------------------------------------------------------------------- 1 | #ifndef GET_MESSAGE_STATUS_H 2 | #define GET_MESSAGE_STATUS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | void get_message_status(){ //function used in display/display.h 13 | 14 | 15 | 16 | } 17 | 18 | #endif // GET_MESSAGE_STATUS_H 19 | 20 | -------------------------------------------------------------------------------- /lcnc/nml/status/get_position.h: -------------------------------------------------------------------------------- 1 | #ifndef GET_POSITION_H 2 | #define GET_POSITION_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "nml_oi.hh" // nmlErrorFormat, NML_ERROR, etc 13 | 14 | void get_position(){ //function used in display/display.h 15 | 16 | const char *cstr = nmlfile.c_str(); 17 | RCS_STAT_CHANNEL *stat = new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "xemc", cstr); 18 | 19 | for(int i=0; i<1; i++){ 20 | usleep(1); 21 | if(!stat->valid()) continue; 22 | if(stat->peek() != EMC_STAT_TYPE) continue; 23 | EMC_STAT *emcStatus = static_cast(stat->get_address()); 24 | 25 | toolpos.x=emcStatus->motion.traj.position.tran.x; 26 | toolpos.y=emcStatus->motion.traj.position.tran.y; 27 | toolpos.z=emcStatus->motion.traj.position.tran.z; 28 | } 29 | 30 | 31 | RCS_STAT_CHANNEL *stat1 = new RCS_STAT_CHANNEL(emcFormat, "emcError", "xemc", cstr); 32 | 33 | for(int i=0; i<1; i++){ 34 | usleep(1); 35 | if(!stat1->valid()) continue; 36 | if(stat1->peek() != EMC_STAT_TYPE) continue; 37 | NML *emcErrorBuffer = new NML(nmlErrorFormat, "emcError", "xemc", cstr); 38 | 39 | for(int i=0; i<1; i++){ 40 | usleep(1); 41 | if(!emcErrorBuffer->valid()) continue; 42 | if(emcErrorBuffer->peek() != EMC_STAT_TYPE) continue; 43 | 44 | NMLTYPE type; 45 | 46 | if (0 == emcErrorBuffer || !emcErrorBuffer->valid()) { 47 | //return -1; 48 | } 49 | 50 | switch (type = emcErrorBuffer->read()) { 51 | case -1: 52 | std::cout<<"error reading channel"< 5 | #include 6 | #include 7 | #include 8 | #include //system 9 | 10 | #include 11 | 12 | void get_program_line(){ 13 | 14 | std::string nmlfile="/home/user/linuxcnc/configs/common/linuxcnc.nml"; 15 | const char *cstr = nmlfile.c_str(); 16 | 17 | RCS_STAT_CHANNEL *stat = new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "xemc", cstr); 18 | 19 | for(int i=0; i<1; i++){ 20 | usleep(100); 21 | if(!stat->valid()) continue; 22 | if(stat->peek() != EMC_STAT_TYPE) continue; 23 | EMC_STAT *emcStatus = static_cast(stat->get_address()); 24 | 25 | int programline=emcStatus->motion.line; 26 | std::cout<<"program line: "< 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | void update_m(){ //function used in display/display.h 13 | 14 | const char *cstr = nmlfile.c_str(); 15 | RCS_STAT_CHANNEL *stat = new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "xemc", cstr); 16 | 17 | for(int i=0; i<1; i++){ 18 | usleep(100*1000); 19 | if(!stat->valid()) continue; 20 | if(stat->peek() != EMC_STAT_TYPE) continue; 21 | EMC_STAT *emcStatus = static_cast(stat->get_address()); 22 | 23 | EMC_OPERATOR_ERROR e; 24 | char *x=e.error; 25 | 26 | std::cout<<"error message: "< 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | void update_status(){ //function used in display/display.h 13 | 14 | const char *cstr = nmlfile.c_str(); 15 | RCS_STAT_CHANNEL *stat = new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "xemc", cstr); 16 | 17 | for(int i=0; i<1; i++){ 18 | usleep(1); 19 | if(!stat->valid()) continue; 20 | if(stat->peek() != EMC_STAT_TYPE) continue; 21 | EMC_STAT *emcStatus = static_cast(stat->get_address()); 22 | 23 | emcStatus_task_currentLine=emcStatus->task.currentLine; 24 | emcStatus_task_motionLine=emcStatus->task.motionLine; //current executed gcode line 25 | emcStatus_task_mode=emcStatus->task.mode; //1=manual 2=auto 3=mdi 26 | emcStatus_motion_status=emcStatus->motion.status; //2=auto running 27 | 28 | 29 | emcStatus_motion_spindle_speed=emcStatus->motion.spindle->speed; //current rpm 30 | emcStatus_motion_traj_current_vel_mm_sec=emcStatus->motion.traj.current_vel; //current velocity 31 | emcStatus_motion_traj_maxVelocity_mm_sec=emcStatus->motion.traj.maxVelocity; //value in units/sec, from ini. 32 | 33 | //so far unused 34 | emcStatus_motion_spindle_direction=emcStatus->motion.spindle->direction; 35 | emcStatus_motion_spindle_brake=emcStatus->motion.spindle->brake; 36 | emcStatus_motion_spindle_increasing=emcStatus->motion.spindle->increasing; 37 | emcStatus_motion_spindle_enabled=emcStatus->motion.spindle->enabled; 38 | emcStatus_motion_spindle_homed=emcStatus->motion.spindle->homed; 39 | emcStatus_motion_spindle_enabled_scale=emcStatus->motion.spindle->spindle_scale; 40 | //int state = emcStatus->task.state; 41 | //int emcStatus_lube_level=emcStatus->io.lube.level; 42 | //int emcStatus_coolant.flood=emcStatus->io.coolant.flood; 43 | //int emcStatus_auz_estop=emcStatus->io.aux.estop; 44 | //int emcStatus_mist=emcStatus->io.coolant.mist; 45 | //int emcStatus_lube=emcStatus->io.lube.on; 46 | 47 | //from file emcsh.cc we get the active gcode and mcode, feedrate and spindlespeed values. 48 | char string[256]; 49 | int t; 50 | int code; 51 | 52 | // fill in the active G codes 53 | task_active_gcodes_string[0] = 0; 54 | for (t = 1; t < ACTIVE_G_CODES; t++) { 55 | code = emcStatus->task.activeGCodes[t]; 56 | if (code == -1) { 57 | continue; 58 | } 59 | if (code % 10) { 60 | sprintf(string, "G%.1f ", (double) code / 10.0); 61 | } else { 62 | sprintf(string, "G%d ", code / 10); 63 | } 64 | strcat(task_active_gcodes_string, string); 65 | } 66 | 67 | // fill in the active M codes, settings too 68 | task_active_mcodes_string[0] = 0; 69 | for (t = 1; t < ACTIVE_M_CODES; t++) { 70 | code = emcStatus->task.activeMCodes[t]; 71 | if (code == -1) { 72 | continue; 73 | } 74 | sprintf(string, "M%d ", code); 75 | strcat(task_active_mcodes_string, string); 76 | } 77 | 78 | // fill in F and S codes also 79 | sprintf(string, "F%.0f ", emcStatus->task.activeSettings[1]); 80 | task_active_fcodes_string[0] = 0; 81 | strcat(task_active_fcodes_string, string); 82 | sprintf(string, "S%.0f", fabs(emcStatus->task.activeSettings[2])); 83 | task_active_scodes_string[0] = 0; 84 | strcat(task_active_scodes_string, string); 85 | 86 | } 87 | } 88 | 89 | #endif // UPDATE_STATUS_H 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /lcnc/nml/step.h: -------------------------------------------------------------------------------- 1 | #ifndef STEP_H 2 | #define STEP_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void step(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | EMC_TASK_PLAN_STEP step; 13 | c->write(&step); 14 | } 15 | 16 | #endif // STEP_H 17 | -------------------------------------------------------------------------------- /lcnc/nml/stop.h: -------------------------------------------------------------------------------- 1 | #ifndef STOP_H 2 | #define STOP_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void stop(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | EMC_TASK_ABORT stop; 13 | c->write(&stop); 14 | } 15 | 16 | #endif // STOP_H 17 | -------------------------------------------------------------------------------- /lcnc/nml/unhome.h: -------------------------------------------------------------------------------- 1 | #ifndef UNHOME_H 2 | #define UNHOME_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void unhome(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | 13 | EMC_JOINT_UNHOME m; 14 | m.joint=0; //x 15 | c->write(&m); 16 | 17 | m.joint=1; //y 18 | c->write(&m); 19 | 20 | m.joint=2; //z 21 | c->write(&m); 22 | } 23 | 24 | #endif // UNHOME_H 25 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | MainWindow w; 9 | w.show(); 10 | return a.exec(); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | //// nml set commands 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | //// nml get commands 45 | #include 46 | #include 47 | 48 | //// halcommand set commands 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | 65 | //// halcommand get commands 66 | #include 67 | 68 | //test 69 | //#include 70 | 71 | int oldline=0; 72 | int init=0; 73 | 74 | //setup a stylesheet to colorize buttons and labels later on. 75 | QString grey="background-color: rgb(242, 242, 242)"; 76 | QString darkgrey="background-color: rgb(149, 149, 149)"; 77 | QString green="background-color: rgb(170, 255, 0);"; 78 | QString red="background-color: rgb(242, 0, 0);"; 79 | QString orange="background-color: rgb(255, 170, 0)"; 80 | 81 | //////// START SETUP APP SECTION ///////// 82 | MainWindow::MainWindow(QWidget *parent) 83 | : QMainWindow(parent) 84 | , ui(new Ui::MainWindow) 85 | { 86 | ui->setupUi(this); 87 | timerId = startTimer(100); 88 | 89 | ui->toolButton_estop->setChecked(true); 90 | estop(); 91 | 92 | ui->pushButton_spindle_cw->setEnabled(0); 93 | ui->pushButton_spindle_ccw->setEnabled(0); 94 | 95 | //startup sequence, set some parameters. 96 | hal_connection(); //set some hal memory for this app. 97 | enable_adaptive_feed(); //set active at nml level, without using mdi command: "M52 P1" 98 | 99 | //set halui max velocity scale to 1, without initialisation the scale is set at 0; 100 | set_scale_max_velocity(1); 101 | } 102 | //////// END SETUP APP SECTION ///////// 103 | 104 | MainWindow::~MainWindow() //destructor for closing app 105 | { 106 | system("exit"); //exit log 107 | killTimer(timerId); 108 | delete ui; 109 | } 110 | 111 | 112 | //////// START POLL EVENT SECTION ///////// 113 | void MainWindow::timerEvent(QTimerEvent *) 114 | { 115 | update_status(); //get the current status via emc nml channel by lcnc/nml/status/update_status.h 116 | 117 | if(emcStatus_motion_traj_maxVelocity_mm_sec>0 && init==0){ //to do once at program startup, but after the first opengl loop, we look if one of the ini values is updated. 118 | init_once(); 119 | init=1; 120 | } 121 | 122 | ///update machine e-stop and machine-on status 123 | //halui.estop.is-activated, bit out. must be off to move. 124 | bool estop_active=get_bool_command("halui.estop.is-activated"); 125 | if(!estop_active){ 126 | ui->toolButton_estop->setStyleSheet(grey); 127 | } else { 128 | ui->toolButton_estop->setStyleSheet(red); 129 | //reset focus for home xyz button. 130 | ui->pushButton_home->setStyleSheet(grey); 131 | } 132 | 133 | bool machine_on=get_bool_command("halui.machine.is-on"); 134 | if(!machine_on){ 135 | ui->toolButton_state->setStyleSheet(grey); 136 | } else { 137 | ui->toolButton_state->setStyleSheet(green); 138 | //if machine is on. give home button focus 139 | ui->pushButton_home->setStyleSheet(darkgrey); 140 | } 141 | 142 | get_message_status(); 143 | ui->label_system_message->setText(QString::fromStdString(error_message)); 144 | 145 | ///update labels if joints are homed. 146 | bool x_homed = get_bool_command("joint.0.homed"); 147 | bool y_homed = get_bool_command("joint.1.homed"); 148 | bool z_homed = get_bool_command("joint.2.homed"); 149 | 150 | //colorize home labels 151 | if(!x_homed){ 152 | ui->label_status_homed_x->setStyleSheet(grey); 153 | } else { 154 | ui->label_status_homed_x->setStyleSheet(green); 155 | } 156 | if(!y_homed){ 157 | ui->label_status_homed_y->setStyleSheet(grey); 158 | } else { 159 | ui->label_status_homed_y->setStyleSheet(green); 160 | } 161 | if(!z_homed){ 162 | ui->label_status_homed_z->setStyleSheet(grey); 163 | } else { 164 | ui->label_status_homed_z->setStyleSheet(green); 165 | } 166 | 167 | if(x_homed && y_homed && z_homed){ 168 | ui->pushButton_home->setStyleSheet(grey); 169 | //give open file button focus. 170 | } 171 | 172 | ///update program status, pause, run 173 | bool program_running=get_bool_command("halui.program.is-running"); 174 | bool program_paused=get_bool_command("halui.program.is-paused"); 175 | bool program_idle=get_bool_command("halui.program.is-idle"); 176 | if(program_running){ 177 | ui->pushButton_run_forward->setStyleSheet(green); 178 | } else {ui->pushButton_run_forward->setStyleSheet(grey);} 179 | 180 | if(program_paused){ 181 | ui->pushButton_pause->setStyleSheet(orange); 182 | //when paused, user has to push resume button. give resume button more focus 183 | ui->pushButton_resume->setStyleSheet(darkgrey); 184 | } else {ui->pushButton_pause->setStyleSheet(grey);} 185 | 186 | if(program_idle){ 187 | ui->label_status_program_idle->setStyleSheet(green); 188 | } else {ui->label_status_program_idle->setStyleSheet(grey);} 189 | 190 | 191 | ///set dro 192 | ui->lineEdit_x_pos->setText(QString::number(toolpos.x,'f',4)); 193 | ui->lineEdit_y_pos->setText(QString::number(toolpos.y,'f',4)); 194 | ui->lineEdit_z_pos->setText(QString::number(toolpos.z,'f',4)); 195 | 196 | //set current executed program line number in gcode text editor when program is running. 197 | if(emcStatus_motion_status==2){ //lcnc program is running 198 | 199 | //colorize old line back into white. 200 | QTextBlockFormat format_white; 201 | format_white.setBackground(Qt::white); 202 | QTextCursor cursor_0(ui->textBrowser_gcode->document()->findBlockByLineNumber(oldline)); 203 | cursor_0.select(QTextCursor::LineUnderCursor); 204 | cursor_0.setBlockFormat(format_white); 205 | 206 | //highlight current program line 207 | if(emcStatus_task_motionLine>0){ //don't colorize when homing is active. 208 | QTextCursor cursor_1(ui->textBrowser_gcode->document()->findBlockByLineNumber(emcStatus_task_motionLine-1)); 209 | QTextBlockFormat format; 210 | format.setBackground(Qt::lightGray); 211 | cursor_1.select(QTextCursor::LineUnderCursor); 212 | cursor_1.setBlockFormat(format); 213 | } 214 | 215 | //update gui label 216 | ui->label_program_line_number->setText(QString::number(emcStatus_task_motionLine-1)); 217 | 218 | oldline=emcStatus_task_motionLine-1; 219 | 220 | //set cursor a few lines further 221 | QTextCursor cursor_2(ui->textBrowser_gcode->document()->findBlockByLineNumber(emcStatus_task_motionLine+5)); 222 | ui->textBrowser_gcode->setTextCursor(cursor_2); 223 | } 224 | 225 | ///update status for current gcode, mcode, feedrate and spindlespeed. 226 | ui->label_status_active_Gcode->setText(task_active_gcodes_string); 227 | ui->label_status_active_Mcode->setText(task_active_mcodes_string); 228 | ui->label_status_active_Fcode->setText(task_active_fcodes_string); 229 | ui->label_status_active_Scode->setText(task_active_scodes_string); 230 | 231 | 232 | ///update spindle speed status 233 | ui->label_status_spindlespeed->setText("status rpm-power "+ QString::number(emcStatus_motion_spindle_speed)); 234 | 235 | 236 | ///update current velocity status, lcnc gives a value units/sec. This is mm/sec if ini file is set to mm. We translate this value to mm/min by *60sec. 237 | ui->label_status_current_velocity->setText("status current velocity [mm/min] "+ QString::number(emcStatus_motion_traj_current_vel_mm_sec*60)); 238 | 239 | 240 | ///check status mode manual, auto or mdi etc. 241 | bool mode_is_auto = get_bool_command("halui.mode.is-auto"); //halui.mode.is-auto, bit out 242 | bool mode_is_joint = get_bool_command("halui.mode.is-joint"); //halui.mode.is-joint, bit out 243 | bool mode_is_manual = get_bool_command("halui.mode.is-manual"); //halui.mode.is-manual, bit out 244 | bool mode_is_mdi = get_bool_command("halui.mode.is-mdi"); //halui.mode.is-mdi, bit out 245 | bool mode_is_teleop = get_bool_command("halui.mode.is-teleop"); //halui.mode.is-teleop, bit out 246 | 247 | if(mode_is_auto){ 248 | ui->pushButton_mode_auto->setStyleSheet(green); 249 | } else {ui->pushButton_mode_auto->setStyleSheet(grey);} 250 | if(mode_is_joint){ 251 | ui->pushButton_mode_joint->setStyleSheet(green); 252 | } else {ui->pushButton_mode_joint->setStyleSheet(grey);} 253 | if(mode_is_manual){ 254 | ui->pushButton_mode_manual->setStyleSheet(green); 255 | } else {ui->pushButton_mode_manual->setStyleSheet(grey);} 256 | if(mode_is_mdi){ 257 | ui->pushButton_mode_mdi->setStyleSheet(green); 258 | } else {ui->pushButton_mode_mdi->setStyleSheet(grey);} 259 | if(mode_is_teleop){ 260 | ui->pushButton_mode_teleop->setStyleSheet(green); 261 | } else {ui->pushButton_mode_teleop->setStyleSheet(grey);} 262 | 263 | 264 | ///check spindle status 265 | bool spindle_cw = get_bool_command("halui.spindle.0.runs-forward"); 266 | bool spindle_ccw = get_bool_command("halui.spindle.0.runs-backward"); 267 | if(spindle_cw){ 268 | ui->pushButton_spindle_cw->setStyleSheet(green); 269 | } else {ui->pushButton_spindle_cw->setStyleSheet(grey);} 270 | if(spindle_ccw){ 271 | ui->pushButton_spindle_ccw->setStyleSheet(green); 272 | } else {ui->pushButton_spindle_ccw->setStyleSheet(grey);} 273 | 274 | 275 | ///poll keyboard key events. key events are triggerd in the opengl class. 276 | if(int_key==16777234){ //left arrow 277 | on_pushButton_x_min_pressed(); //simulate a screen button if keyboard button is pressed 278 | } 279 | 280 | if(int_key==16777235){ //top arrow 281 | on_pushButton_y_plus_pressed(); 282 | } 283 | 284 | if(int_key==16777236){ //right arrow 285 | on_pushButton_x_plus_pressed(); 286 | } 287 | 288 | if(int_key==16777237){ //down arrow 289 | on_pushButton_y_min_pressed(); 290 | } 291 | 292 | if(int_key==16777238){ //page up 293 | on_pushButton_z_plus_pressed(); 294 | } 295 | 296 | if(int_key==16777239){ //page down 297 | on_pushButton_z_min_pressed(); 298 | } 299 | 300 | if(int_key==16777232){ //home 301 | //a plus pressed 302 | } 303 | 304 | if(int_key==16777233){ //end 305 | //a min pressed 306 | } 307 | 308 | if(int_key==16777222){ //insert 309 | //b plus pressed 310 | } 311 | 312 | if(int_key==16777223){ //delete 313 | //b min pressed 314 | } 315 | 316 | if(int_key==-1){ 317 | stop(); 318 | int_key=0; //reset to do nothing. 319 | } 320 | } 321 | 322 | 323 | void MainWindow::init_once(){ 324 | 325 | //Some ini parameters to show where parameters stands for. 326 | //[TRAJ] MAX_LINEAIR_VELOCITY : 327 | //note: MAXV max: 53.340 units/sec 3200.400 units/min 328 | 329 | //[TRAJ] DEFAULT_LINEAR_VELOCITY : 330 | //note: LJOG max: 53.340 units/sec 3200.400 units/min 331 | //note: LJOG default: 30.480 units/sec 1828.800 units/min 332 | 333 | //initialisation that need to be done after opengl has done the update_status function to retrieve ini file values. 334 | 335 | //set default jog speed from ini file. 336 | int default_jog_speed=int(get_command("ini.traj_default_velocity"));//in mm/sec 337 | ui->horizontalScrollBar_jog_speed->setValue(default_jog_speed*60); //to mm/min 338 | ui->label_jog_speed_value->setText(QString::number(default_jog_speed*60)); 339 | 340 | ////here we read in max velocity. We can get the data in multiple ways. 341 | /// 1 - hal 342 | /// 2 - emc nml status channel 343 | 344 | //set max velocity speed from ini file. 345 | int max_velocity=int(get_command("ini.traj_max_velocity"));//in mm/sec 346 | ui->horizontalScrollBar_max_velocity->setMaximum(max_velocity*60); //to mm/min 347 | ui->label_max_velocity_value->setText(QString::number(max_velocity*60)); 348 | 349 | //set max velocity value from status channel 350 | //ui->horizontalScrollBar_max_velocity->setMaximum(emcStatus_motion_traj_maxVelocity_mm_sec*60); 351 | //ui->label_max_velocity_value->setText(QString::number(emcStatus_motion_traj_maxVelocity_mm_sec*60)); 352 | 353 | ////get_command is a function in : lcnc/halcommand/get_command.h it returns a float value. 354 | } 355 | 356 | //////// END POLL EVENT SECTION ///////// 357 | 358 | void MainWindow::on_toolButton_estop_toggled(bool checked) 359 | { 360 | if(checked){ 361 | estop(); 362 | ui->toolButton_state->setChecked(false); 363 | state_off(); 364 | //here the lube goes off automaticly by lcnc 365 | ui->pushButton_lube_on_off->setChecked(0); 366 | //release spindle buttons and disable spindle buttons 367 | ui->pushButton_spindle_cw->setChecked(0); 368 | ui->pushButton_spindle_ccw->setChecked(0); 369 | ui->pushButton_spindle_cw->setEnabled(0); 370 | ui->pushButton_spindle_ccw->setEnabled(0); 371 | 372 | } else { 373 | estop_reset(); 374 | 375 | } 376 | } 377 | 378 | void MainWindow::on_toolButton_state_toggled(bool checked) 379 | { 380 | if(checked){ 381 | ui->toolButton_estop->setChecked(false); 382 | estop_reset(); 383 | state_on(); 384 | //here the lube goes on automaticly by lcnc 385 | ui->pushButton_lube_on_off->setChecked(1); 386 | //enable spindle buttons 387 | ui->pushButton_spindle_cw->setEnabled(1); 388 | ui->pushButton_spindle_ccw->setEnabled(1); 389 | } else { 390 | state_off(); 391 | //release spindle buttons and disable spindle buttons 392 | ui->pushButton_spindle_cw->setChecked(0); 393 | ui->pushButton_spindle_ccw->setChecked(0); 394 | ui->pushButton_spindle_cw->setEnabled(0); 395 | ui->pushButton_spindle_ccw->setEnabled(0); 396 | } 397 | } 398 | 399 | void MainWindow::on_pushButton_home_pressed() //home all 400 | { 401 | mode_manual(); 402 | home_all(); 403 | } 404 | 405 | //////// START KEY EVENT SECTION ///////// 406 | void MainWindow::on_pushButton_x_min_pressed() 407 | { 408 | mode_manual(); 409 | jog(0,-ui->horizontalScrollBar_jog_speed->value()/60,0); 410 | } 411 | 412 | void MainWindow::on_pushButton_x_min_released() 413 | { 414 | jog(0,0,0); 415 | } 416 | 417 | void MainWindow::on_pushButton_x_plus_pressed() 418 | { 419 | mode_manual(); 420 | jog(0,ui->horizontalScrollBar_jog_speed->value()/60,0); 421 | } 422 | 423 | void MainWindow::on_pushButton_x_plus_released() 424 | { 425 | jog(0,0,0); 426 | } 427 | 428 | void MainWindow::on_pushButton_y_plus_pressed() 429 | { 430 | mode_manual(); 431 | jog(1,ui->horizontalScrollBar_jog_speed->value()/60,0); 432 | } 433 | 434 | void MainWindow::on_pushButton_y_plus_released() 435 | { 436 | jog(1,0,0); 437 | } 438 | 439 | void MainWindow::on_pushButton_y_min_pressed() 440 | { 441 | mode_manual(); 442 | jog(1,-ui->horizontalScrollBar_jog_speed->value()/60,0); 443 | } 444 | 445 | void MainWindow::on_pushButton_y_min_released() 446 | { 447 | jog(1,0,0); 448 | } 449 | 450 | void MainWindow::on_pushButton_z_plus_pressed() 451 | { 452 | mode_manual(); 453 | jog(2,ui->horizontalScrollBar_jog_speed->value()/60,0); 454 | } 455 | 456 | void MainWindow::on_pushButton_z_plus_released() 457 | { 458 | jog(2,0,0); 459 | } 460 | 461 | void MainWindow::on_pushButton_z_min_pressed() 462 | { 463 | mode_manual(); 464 | jog(2,-ui->horizontalScrollBar_jog_speed->value()/60,0); 465 | } 466 | 467 | void MainWindow::on_pushButton_z_min_released() 468 | { 469 | jog(2,0,0); 470 | } 471 | //////// END KEY EVENT SECTION ///////// 472 | 473 | //////// START PROGRAM CONTROL SECTION ///////// 474 | void MainWindow::on_pushButton_run_forward_pressed() 475 | { 476 | mode_auto(); 477 | run_forward(ui->lineEdit_run_from_line->text().toInt()); 478 | //reset focus open file button to normal. 479 | ui->pushButton_open_file->setStyleSheet(grey); 480 | } 481 | 482 | void MainWindow::on_pushButton_backward_pressed() 483 | { 484 | mode_auto(); 485 | run_backward(); 486 | } 487 | 488 | void MainWindow::on_pushButton_pause_pressed() 489 | { 490 | pause_(); 491 | } 492 | 493 | void MainWindow::on_pushButton_resume_pressed() 494 | { 495 | resume(); 496 | ui->pushButton_resume->setStyleSheet(grey); 497 | } 498 | 499 | void MainWindow::on_pushButton_step_pressed() 500 | { 501 | step(); 502 | //focus resume button. 503 | ui->pushButton_resume->setStyleSheet(darkgrey); 504 | } 505 | 506 | void MainWindow::on_pushButton_stop_pressed() 507 | { 508 | stop(); 509 | } 510 | 511 | void MainWindow::on_pushButton_mode_auto_pressed() 512 | { 513 | mode_auto(); 514 | } 515 | 516 | void MainWindow::on_pushButton_mode_manual_pressed() 517 | { 518 | mode_manual(); 519 | } 520 | 521 | void MainWindow::on_pushButton_mode_mdi_pressed() 522 | { 523 | mode_mdi(); 524 | } 525 | 526 | void MainWindow::on_pushButton_mode_joint_pressed() 527 | { 528 | set_mode_joint(); 529 | } 530 | 531 | void MainWindow::on_pushButton_mode_teleop_pressed() 532 | { 533 | set_mode_teleop(); 534 | } 535 | 536 | 537 | void MainWindow::on_pushButton_mdi_go_pressed() 538 | { 539 | mdi(ui->lineEdit_mdi->text().toStdString()); 540 | } 541 | 542 | void MainWindow::on_pushButton_open_file_pressed() 543 | { 544 | std::string gcode_read_in=open_file(); 545 | ui->textBrowser_gcode->clear(); 546 | ui->textBrowser_gcode->setText(QString::fromStdString(gcode_read_in)); 547 | ui->label_gcode_filename->setText(QString::fromStdString("gcode file:"+filename)); 548 | } 549 | 550 | void MainWindow::on_pushButton_reload_file_pressed() 551 | { 552 | std::string gcode_read_in=reload_file(); 553 | ui->textBrowser_gcode->clear(); 554 | ui->textBrowser_gcode->setText(QString::fromStdString(gcode_read_in)); 555 | ui->label_gcode_filename->setText(QString::fromStdString("gcode file reloaded:"+filename)); 556 | on_pushButton_clear_toolpath_pressed(); 557 | } 558 | 559 | void MainWindow::on_pushButton_unhome_pressed() 560 | { 561 | state_off(); 562 | unhome(); 563 | } 564 | 565 | void MainWindow::on_pushButton_clear_toolpath_pressed() 566 | { 567 | toolpath.clear(); //clear screen gui toolpath 568 | } 569 | 570 | void MainWindow::on_pushButton_halshow_pressed() 571 | { 572 | system("halshow &"); //& sign is for not freezing the app if subprogram is loaded 573 | } 574 | 575 | //////// END PROGRAM CONTROL SECTION ///////// 576 | 577 | //////// START SPINDLE SECTION ///////// 578 | void MainWindow::on_pushButton_spindle_cw_toggled(bool checked) 579 | { 580 | int rpm = abs(ui->lineEdit_rpm->text().toInt()); //abs is positive 581 | if(checked){ 582 | ui->pushButton_spindle_ccw->setChecked(false); 583 | spindle_on(0,rpm); 584 | } else { 585 | spindle_off(); 586 | } 587 | } 588 | 589 | void MainWindow::on_pushButton_spindle_ccw_toggled(bool checked) 590 | { 591 | int rpm_neg = -abs(ui->lineEdit_rpm->text().toInt()); //-abs is negative 592 | if(checked){ 593 | ui->pushButton_spindle_cw->setChecked(false); 594 | spindle_on(0,rpm_neg); 595 | } else { 596 | spindle_off(); 597 | } 598 | } 599 | 600 | void MainWindow::on_pushButton_spindle_decrease_pressed() 601 | { 602 | set_spindle_decrease(1); 603 | } 604 | 605 | void MainWindow::on_pushButton_spindle_decrease_released() 606 | { 607 | set_spindle_decrease(0); 608 | } 609 | 610 | 611 | void MainWindow::on_pushButton_spindle_increase_pressed() 612 | { 613 | set_spindle_increase(1); 614 | } 615 | 616 | void MainWindow::on_pushButton_spindle_increase_released() 617 | { 618 | set_spindle_increase(0); 619 | } 620 | 621 | 622 | void MainWindow::on_pushButton_spindle_stop_pressed() 623 | { 624 | spindle_stop(); 625 | ui->pushButton_spindle_cw->setChecked(false); 626 | ui->pushButton_spindle_ccw->setChecked(false); 627 | } 628 | //////// END SPINDLE SECTION ///////// 629 | 630 | //////// START IO SECTION ///////// 631 | void MainWindow::on_pushButton_flood_on_off_toggled(bool checked) 632 | { 633 | //flood is not involved by e-stop state or machine state. 634 | if(checked){ 635 | set_flood_on(); 636 | } 637 | if(!checked){ 638 | set_flood_off(); 639 | } 640 | } 641 | 642 | void MainWindow::on_pushButton_lube_on_off_toggled(bool checked) 643 | { 644 | if(checked){ 645 | set_lube_on(); 646 | } 647 | if(!checked){ 648 | set_lube_off(); 649 | } 650 | } 651 | 652 | void MainWindow::on_horizontalScrollBar_spindle_override_sliderMoved(int position) 653 | { 654 | // the max spindle override value is setted in the ini file. lcnc input value is scaled back /10 655 | // [DISPLAY] MAX_SPINDLE_OVERRIDE = 1.2 656 | int value=position/10; 657 | set_spindle_override(value); 658 | ui->label_spindle_override_value->setText(QString::number(position)); 659 | } 660 | 661 | void MainWindow::on_horizontalScrollBar_rapid_override_sliderMoved(int position) 662 | { 663 | set_rapid_override(position); 664 | ui->label_rapid_override_value->setText(QString::number(position)); 665 | } 666 | 667 | void MainWindow::on_horizontalScrollBar_feed_override_sliderMoved(int position) 668 | { 669 | // the max feed override value is set in the ini file. slider value is scaled back /10 670 | // [DISPLAY] MAX_FEED_OVERRIDE = 1.2 671 | int value=position/10; 672 | set_feed_override(value); 673 | ui->label_feed_override_value->setText(QString::number(value*10)); 674 | } 675 | 676 | void MainWindow::on_horizontalScrollBar_jog_speed_sliderMoved(int position) 677 | { 678 | //signal : halui.axis.jog-speed, float in, value mm/min 679 | float float_position=float(position); //convert int position to float position. 680 | set_jog_speed(float_position); 681 | ui->label_jog_speed_value->setText(QString::number(position)); 682 | } 683 | 684 | void MainWindow::on_horizontalScrollBar_max_velocity_sliderMoved(int position) 685 | { 686 | set_max_velocity(position); 687 | ui->label_max_velocity_value->setText(QString::number(position)); 688 | } 689 | 690 | void MainWindow::on_horizontalScrollBar_adaptive_feed_sliderMoved(int position) 691 | { 692 | //the adaptive feed value is between -1 and 1, the scrollbar resolution is factor 100. 693 | float value=float(position)/100; 694 | set_adaptive_feed(value); 695 | ui->label_adaptive_feed_value->setText(QString::number(value)); 696 | } 697 | //////// END IO SECTION ///////// 698 | 699 | 700 | void MainWindow::on_pushButton_start_debug_pressed() 701 | { 702 | 703 | 704 | } 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class MainWindow; } 8 | QT_END_NAMESPACE 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | MainWindow(QWidget *parent = nullptr); 16 | ~MainWindow(); 17 | 18 | void init_once(); 19 | 20 | private slots: 21 | 22 | void on_toolButton_estop_toggled(bool checked); 23 | 24 | void on_toolButton_state_toggled(bool checked); 25 | 26 | void on_pushButton_home_pressed(); 27 | 28 | void on_pushButton_x_min_pressed(); 29 | 30 | void on_pushButton_x_plus_pressed(); 31 | 32 | void on_pushButton_x_min_released(); 33 | 34 | void on_pushButton_x_plus_released(); 35 | 36 | void on_pushButton_y_plus_pressed(); 37 | 38 | void on_pushButton_y_plus_released(); 39 | 40 | void on_pushButton_y_min_pressed(); 41 | 42 | void on_pushButton_y_min_released(); 43 | 44 | void on_pushButton_z_plus_pressed(); 45 | 46 | void on_pushButton_z_plus_released(); 47 | 48 | void on_pushButton_z_min_pressed(); 49 | 50 | void on_pushButton_z_min_released(); 51 | 52 | void on_pushButton_run_forward_pressed(); 53 | 54 | void on_pushButton_backward_pressed(); 55 | 56 | void on_pushButton_pause_pressed(); 57 | 58 | void on_pushButton_resume_pressed(); 59 | 60 | void on_pushButton_step_pressed(); 61 | 62 | void on_pushButton_stop_pressed(); 63 | 64 | void on_pushButton_mode_auto_pressed(); 65 | 66 | void on_pushButton_mode_manual_pressed(); 67 | 68 | void on_pushButton_mode_mdi_pressed(); 69 | 70 | void on_pushButton_mdi_go_pressed(); 71 | 72 | void on_pushButton_spindle_ccw_toggled(bool checked); 73 | 74 | void on_pushButton_spindle_cw_toggled(bool checked); 75 | 76 | void on_pushButton_open_file_pressed(); 77 | 78 | void on_pushButton_unhome_pressed(); 79 | 80 | void on_pushButton_spindle_stop_pressed(); 81 | 82 | void on_pushButton_clear_toolpath_pressed(); 83 | 84 | void on_pushButton_halshow_pressed(); 85 | 86 | void on_pushButton_flood_on_off_toggled(bool checked); 87 | 88 | void on_pushButton_lube_on_off_toggled(bool checked); 89 | 90 | void on_horizontalScrollBar_rapid_override_sliderMoved(int position); 91 | 92 | void on_horizontalScrollBar_spindle_override_sliderMoved(int position); 93 | 94 | void on_horizontalScrollBar_feed_override_sliderMoved(int position); 95 | 96 | void on_horizontalScrollBar_jog_speed_sliderMoved(int position); 97 | 98 | void on_horizontalScrollBar_max_velocity_sliderMoved(int position); 99 | 100 | void on_horizontalScrollBar_adaptive_feed_sliderMoved(int position); 101 | 102 | void on_pushButton_spindle_decrease_pressed(); 103 | 104 | void on_pushButton_spindle_increase_pressed(); 105 | 106 | void on_pushButton_spindle_decrease_released(); 107 | 108 | void on_pushButton_spindle_increase_released(); 109 | 110 | void on_pushButton_mode_joint_pressed(); 111 | 112 | void on_pushButton_mode_teleop_pressed(); 113 | 114 | void on_pushButton_reload_file_pressed(); 115 | 116 | void on_pushButton_start_debug_pressed(); 117 | 118 | private: 119 | Ui::MainWindow *ui; 120 | int timerId; 121 | 122 | protected: 123 | 124 | void timerEvent(QTimerEvent *); 125 | 126 | }; 127 | #endif // MAINWINDOW_H 128 | -------------------------------------------------------------------------------- /ngc/test.ngc: -------------------------------------------------------------------------------- 1 | g20 2 | g64 p0.01 3 | g0 x0 y0 f30 4 | g0 x0 y5 5 | g0 x5 y5 6 | g0 x5 y0 7 | g0 x0 y0 8 | m30 9 | -------------------------------------------------------------------------------- /ngc/test2.ngc: -------------------------------------------------------------------------------- 1 | g20 2 | g0 x0 y0 3 | g1 x0 y0 f2500 4 | g1 x0 y2.5 5 | g1 x2.5 y2.5 6 | g1 x2.5 y0 7 | g1 x0 y0 8 | m30 9 | -------------------------------------------------------------------------------- /run.h.autosave: -------------------------------------------------------------------------------- 1 | #ifndef RUN_H 2 | #define RUN_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void run(){ 10 | const char *cstr = nmlfile.c_str(); 11 | RCS_CMD_CHANNEL *c = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", cstr); 12 | EMC_TASK_PLAN_RESUME resume; 13 | c->write(&resume); 14 | } 15 | 16 | #endif // RUN_H 17 | --------------------------------------------------------------------------------