How to read the source of the LinuxCNC?
- wuxiaoke
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
03 Mar 2024 13:49 #295042
by wuxiaoke
How to read the source of the LinuxCNC? was created by wuxiaoke
Hi every one:
I'm new to the linuxCNC and I'm interested in is.I want to know its code architecture. Especially how to communicate with Ethercat. My current progress is that I can compile this code through the console on Debian. But I am still confused about the architecture of the source code.
Here is my specific question:
1. Which IDE do you use? Cause I was used to be a windows developer, I am just familiar with Visual Studio.
2. Is there any docs for developer guide? Although here is some docs in package, but they seems like told us how to use linuxCNC.
3. How to debug the source code? I want to debug the code, make the break point to know how the data circle around the system.
Thanks a lot!
I'm new to the linuxCNC and I'm interested in is.I want to know its code architecture. Especially how to communicate with Ethercat. My current progress is that I can compile this code through the console on Debian. But I am still confused about the architecture of the source code.
Here is my specific question:
1. Which IDE do you use? Cause I was used to be a windows developer, I am just familiar with Visual Studio.
2. Is there any docs for developer guide? Although here is some docs in package, but they seems like told us how to use linuxCNC.
3. How to debug the source code? I want to debug the code, make the break point to know how the data circle around the system.
Thanks a lot!
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
Less
More
- Posts: 23162
- Thank you received: 4860
03 Mar 2024 14:36 #295051
by andypugh
Replied by andypugh on topic How to read the source of the LinuxCNC?
Different developers use different things.
Some use vi.
I use Geany.
Others do use actual IDE's.
Breakpoints would probably be achieved with gdb, and some IDEs can automate that.
Note that you can't typically breakpoint realtime code.
linuxcnc.org/docs/stable/html/code/code-notes.html might help (but is a bit out of date)
The system is complicated, with two process running in tandem, realtime and non-realtime. The G-code interpreter runs non-realtime and creates a queue of commands to be processed by the realtime code.
Some use vi.
I use Geany.
Others do use actual IDE's.
Breakpoints would probably be achieved with gdb, and some IDEs can automate that.
Note that you can't typically breakpoint realtime code.
linuxcnc.org/docs/stable/html/code/code-notes.html might help (but is a bit out of date)
The system is complicated, with two process running in tandem, realtime and non-realtime. The G-code interpreter runs non-realtime and creates a queue of commands to be processed by the realtime code.
The following user(s) said Thank You: ErrickW, wuxiaoke
Please Log in or Create an account to join the conversation.
- zz912
- Offline
- Platinum Member
Less
More
- Posts: 509
- Thank you received: 81
03 Mar 2024 18:00 #295068
by zz912
Replied by zz912 on topic How to read the source of the LinuxCNC?
If you are a complete beginner in LCNC, I recommend studying HAL:
linuxcnc.org/docs/stable/html/hal/intro.html
If you don't understand HAL, there is no point in studying LCNC source codes.
If you are mainly interested in EtherCAT, then the HAL issue will be enough for you. A deeper study of LCNC is only necessary if you want to make your own GUI or if you want to fix a bug or making some individual stuff.
To understand CORE LCNC you must study:
www.nist.gov/system/files/documents/el/isd/cs/nml-tutorial.pdf
I can recommend not to start the first application with EtherCAT. Buy a parallel port and do your first LCNC configuration using the Wizard
linuxcnc.org/docs/stable/html/config/stepconf.html
Explore the configuration files that this Wizard created and understand how they work.
You don't have to build the machine on the LPT port, just make a stand like this:
https://4d9e891bef.cbaul-cdnwnd.com/c49e4d7c1be57530867b65b896f0c71a/200000231-36adb36ade/700/LPT-port.webp?ph=4d9e891bef
It will save you a lot of time.
If you don't want to waste time with the parallel port, at least go through the configuration:
github.com/LinuxCNC/linuxcnc/tree/2.9/configs
The *.ini file is always important. This file then refers to other files, especially *.hal.
linuxcnc.org/docs/stable/html/hal/intro.html
If you don't understand HAL, there is no point in studying LCNC source codes.
If you are mainly interested in EtherCAT, then the HAL issue will be enough for you. A deeper study of LCNC is only necessary if you want to make your own GUI or if you want to fix a bug or making some individual stuff.
To understand CORE LCNC you must study:
www.nist.gov/system/files/documents/el/isd/cs/nml-tutorial.pdf
I can recommend not to start the first application with EtherCAT. Buy a parallel port and do your first LCNC configuration using the Wizard
linuxcnc.org/docs/stable/html/config/stepconf.html
Explore the configuration files that this Wizard created and understand how they work.
You don't have to build the machine on the LPT port, just make a stand like this:
https://4d9e891bef.cbaul-cdnwnd.com/c49e4d7c1be57530867b65b896f0c71a/200000231-36adb36ade/700/LPT-port.webp?ph=4d9e891bef
It will save you a lot of time.
If you don't want to waste time with the parallel port, at least go through the configuration:
github.com/LinuxCNC/linuxcnc/tree/2.9/configs
The *.ini file is always important. This file then refers to other files, especially *.hal.
The following user(s) said Thank You: ErrickW, wuxiaoke
Please Log in or Create an account to join the conversation.
- rodw
- Away
- Platinum Member
Less
More
- Posts: 10777
- Thank you received: 3548
03 Mar 2024 20:09 #295080
by rodw
Replied by rodw on topic How to read the source of the LinuxCNC?
There is a linux version of visual studio. I use Geany which is similar to notepad++ on windows
Study up on halcomp linuxcnc.org/docs/stable/html/hal/comp.html
and also study code for existing components in /src/hal/components on github.
As Andy says the realtime side is hard to debug.
The beauty of hal architecture is that you don't need to know much about the core code as you can write your own component which once installed is treated exactly as if it was a standard hal component included in the base system. these can be compiled and installed with one command
halcompile --install mycomp.comp
Think of the servo thread as a timer interrupt that is called 1000 times a second. components need to be short and sharp so as not to overload this thread. You should not do loops but there is no need as the timer thread does this for you. Just wait for the next cycle. Use state machines to keep track of where you are.
Ethercat adds another layer of complexity to development as the linuxcnc ethercat driver simply connect to the ethercat system. This was bloody hard but it has got easier now ethercat can be installed from its own repository (now supported in the 2.9.2 installer I built) and the work of scottlaird who has added a lot of new functionality to the linuxcnc driver.
At least having a play to ge thte basics with a parallel port might be helpful.
With ethercat, a custom homing component would be very useful.
Ref: linuxcnc.org/docs/stable/html/man/man9/homecomp.9.html
This will require you study homing.c because many of the homing steps can be bypassed if you let the ethercat drive home internally.
Good luck!
Study up on halcomp linuxcnc.org/docs/stable/html/hal/comp.html
and also study code for existing components in /src/hal/components on github.
As Andy says the realtime side is hard to debug.
The beauty of hal architecture is that you don't need to know much about the core code as you can write your own component which once installed is treated exactly as if it was a standard hal component included in the base system. these can be compiled and installed with one command
halcompile --install mycomp.comp
Think of the servo thread as a timer interrupt that is called 1000 times a second. components need to be short and sharp so as not to overload this thread. You should not do loops but there is no need as the timer thread does this for you. Just wait for the next cycle. Use state machines to keep track of where you are.
Ethercat adds another layer of complexity to development as the linuxcnc ethercat driver simply connect to the ethercat system. This was bloody hard but it has got easier now ethercat can be installed from its own repository (now supported in the 2.9.2 installer I built) and the work of scottlaird who has added a lot of new functionality to the linuxcnc driver.
At least having a play to ge thte basics with a parallel port might be helpful.
With ethercat, a custom homing component would be very useful.
Ref: linuxcnc.org/docs/stable/html/man/man9/homecomp.9.html
This will require you study homing.c because many of the homing steps can be bypassed if you let the ethercat drive home internally.
Good luck!
The following user(s) said Thank You: ErrickW, wuxiaoke
Please Log in or Create an account to join the conversation.
- Mecanix
- Offline
- Platinum Member
Less
More
- Posts: 446
- Thank you received: 216
03 Mar 2024 21:45 #295092
by Mecanix
1. Eclipse CDT (projects.eclipse.org/projects/tools.cdt)
2. Yes, quite a few in fact. One out of many (linuxcnc.org/docs/html/config/python-interface.html)
3. Eclipse CDT (sudo apt install gdbserver) & PyDev server (marketplace.eclipse.org/content/pydev-python-ide-eclipse)
Hope this helps.
Eclipse >> Import >> C/C++ >> Existing Code as Makefile Project >> Select "Linux GCC"
Replied by Mecanix on topic How to read the source of the LinuxCNC?
Here is my specific question:
1. Which IDE do you use? Cause I was used to be a windows developer, I am just familiar with Visual Studio.
2. Is there any docs for developer guide? Although here is some docs in package, but they seems like told us how to use linuxCNC.
3. How to debug the source code? I want to debug the code, make the break point to know how the data circle around the system.
1. Eclipse CDT (projects.eclipse.org/projects/tools.cdt)
2. Yes, quite a few in fact. One out of many (linuxcnc.org/docs/html/config/python-interface.html)
3. Eclipse CDT (sudo apt install gdbserver) & PyDev server (marketplace.eclipse.org/content/pydev-python-ide-eclipse)
Hope this helps.
$ git clone https://github.com/LinuxCNC/linuxcnc.git
$ cd linuxcnc
$ ./debian/configure
$ sudo apt-get build-dep .
$ dpkg-checkbuilddeps (<--should retun null if all good)
$ cd src
$ ./autogen.sh
$ ./configure --with-realtime=uspace --disable-build-documentation-translation
(do not make. Import in eclipse at this stage and dev all you need)
Eclipse >> Import >> C/C++ >> Existing Code as Makefile Project >> Select "Linux GCC"
The following user(s) said Thank You: ErrickW, Aciera, Unlogic, wuxiaoke
Please Log in or Create an account to join the conversation.
- Aciera
- Away
- Administrator
Less
More
- Posts: 3998
- Thank you received: 1726
04 Mar 2024 08:48 #295117
by Aciera
Replied by Aciera on topic How to read the source of the LinuxCNC?
You may need to use:
$ ./configure --with-realtime=uspace --disable-build-documentation-translation --enable-non-distributable=yes
Would be great if somebody could do a tutorial on how to use eclipse for linuxCNC development. Things like how to setup the python path for the project, how to get both python and C/C++ co-development setup. I'm struggling with it and given the shortage of people familiar with the linuxcnc code base it may get the odd person interested in getting involved.
$ ./configure --with-realtime=uspace --disable-build-documentation-translation --enable-non-distributable=yes
Would be great if somebody could do a tutorial on how to use eclipse for linuxCNC development. Things like how to setup the python path for the project, how to get both python and C/C++ co-development setup. I'm struggling with it and given the shortage of people familiar with the linuxcnc code base it may get the odd person interested in getting involved.
The following user(s) said Thank You: tommylight, ErrickW, zz912, ContinenteCNC, wuxiaoke
Please Log in or Create an account to join the conversation.
Time to create page: 0.130 seconds