linuxcnc trajectory planner
09 Oct 2024 14:03 #311646
by Grotius
linuxcnc trajectory planner was created by Grotius
Hi all,
In this topic i want to discuss and keep updated development related to new linuxcnc trajectory planners.
For this there is a fresh repository : codeberg.org/skynet/linuxcnc_trajectory_planner
This repository include the latest source of the original linuxcnc repository hosted at github.
To start coding your own planner, you could use the template branch to get started.
This branch is a clean project.
In the source dir, there is a cmake directory producing 2 libraries (motmod.so & tpmod.so) , involving the trajectory planners code.
These 2 libs, can be compiled and installed to replace (overwrite) the original libs.
Short briefing
Why do we need 2 libraries involving the trajectory planners code:
The motion controller component "motmod.so" wich handles a few things like jogging,
but also call's the trajectory component to add fresh gcode lines trough functions like : tpAddline();
~/cmake/motion
The trajectory planner component "tpmod" wich run's the gcode recieved by the motmod.so component.
The tpmod.so calculates the trajectory and does things like "look ahead", create path's, updates tool position etc.
~/cmake/planner
Repository cmake compile & install rtlib test
Repository linuxcnc run test
Ok so far we are on the right track. Above run's at my pc.
My investegation start's at the motion controller component motmod.so, the related file command.c
~/cmake/motion/command.c
In command.c, the function emcmotCommandHandler is runned every cycle. And check's what needs to be done.
It is responsible for adding lines & arc's to the trajectory planners tpmod.so component.
The emcmotCommandHandler function calls adding lines and arc's several times in the source file at different locations :
- Line 1027 tpAddLine
- Line 1437 tpAddLine
- Line 1088 tpAddCircle
Now i think a good strategy is to change a few tiny things to the current linuxcnc motion command flow:
1. Dont send tpAddLine and or tpAddCircle every cycle. Buffer this info into shared memory.
2. When the emcmotCommandHandler recieves a "run: command to execute the program,
then *optimize the path given the buffer, also optimize the **look ahead for the path.
3. Send only optimized path's, including ***vo's & ve's to the trajectory component tpmod.so
4. The trajectory planners component tpmod.so is now very simple to code. As is no longer is required to do
complex calculations. It only has to have a scurve motion algo under the hood.
*optimize = G64 P.. Q.. remove tiny segments, add fillets, etc.
**look ahead = Run a forward & backward algo over the trajectory to optimize speeds based on curvature extrema, maxvel, maxacc, maxjerk.
***vo's & ve's = velocity begin, velocity end for a line or arc.
Todo coming time related to the scurve library:
Review the scurve library, some things can be cleaned up, and create a test environment to test millions of iterations.
In this topic i want to discuss and keep updated development related to new linuxcnc trajectory planners.
For this there is a fresh repository : codeberg.org/skynet/linuxcnc_trajectory_planner
This repository include the latest source of the original linuxcnc repository hosted at github.
To start coding your own planner, you could use the template branch to get started.
This branch is a clean project.
In the source dir, there is a cmake directory producing 2 libraries (motmod.so & tpmod.so) , involving the trajectory planners code.
These 2 libs, can be compiled and installed to replace (overwrite) the original libs.
Short briefing
Why do we need 2 libraries involving the trajectory planners code:
The motion controller component "motmod.so" wich handles a few things like jogging,
but also call's the trajectory component to add fresh gcode lines trough functions like : tpAddline();
~/cmake/motion
The trajectory planner component "tpmod" wich run's the gcode recieved by the motmod.so component.
The tpmod.so calculates the trajectory and does things like "look ahead", create path's, updates tool position etc.
~/cmake/planner
Repository cmake compile & install rtlib test
~/cmake mkdir build
~/cmake cd build
~/cmake cmake ..
~/cmake make
~/cmake make install
Repository linuxcnc run test
~/scripts . ./rip-environment
~/scripts linuxcnc
Ok so far we are on the right track. Above run's at my pc.
My investegation start's at the motion controller component motmod.so, the related file command.c
~/cmake/motion/command.c
In command.c, the function emcmotCommandHandler is runned every cycle. And check's what needs to be done.
It is responsible for adding lines & arc's to the trajectory planners tpmod.so component.
The emcmotCommandHandler function calls adding lines and arc's several times in the source file at different locations :
- Line 1027 tpAddLine
- Line 1437 tpAddLine
- Line 1088 tpAddCircle
Now i think a good strategy is to change a few tiny things to the current linuxcnc motion command flow:
1. Dont send tpAddLine and or tpAddCircle every cycle. Buffer this info into shared memory.
2. When the emcmotCommandHandler recieves a "run: command to execute the program,
then *optimize the path given the buffer, also optimize the **look ahead for the path.
3. Send only optimized path's, including ***vo's & ve's to the trajectory component tpmod.so
4. The trajectory planners component tpmod.so is now very simple to code. As is no longer is required to do
complex calculations. It only has to have a scurve motion algo under the hood.
*optimize = G64 P.. Q.. remove tiny segments, add fillets, etc.
**look ahead = Run a forward & backward algo over the trajectory to optimize speeds based on curvature extrema, maxvel, maxacc, maxjerk.
***vo's & ve's = velocity begin, velocity end for a line or arc.
Todo coming time related to the scurve library:
Review the scurve library, some things can be cleaned up, and create a test environment to test millions of iterations.
Please Log in or Create an account to join the conversation.
10 Oct 2024 06:34 #311699
by Aciera
Replied by Aciera on topic linuxcnc trajectory planner
Does not seem to work for me (missing 'config.h'):
user@user-iMac:~$ cd linuxcnc_trajectory_planner/
user@user-iMac:~/linuxcnc_trajectory_planner$ cd cmake/
user@user-iMac:~/linuxcnc_trajectory_planner/cmake$ cd build/
user@user-iMac:~/linuxcnc_trajectory_planner/cmake/build$ cmake ..
-- The CXX compiler identification is GNU 11.4.0
-- The C compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/linuxcnc_trajectory_planner/cmake/build
user@user-iMac:~/linuxcnc_trajectory_planner/cmake/build$ make
Consolidate compiler generated dependencies of target motmod
[ 5%] Building C object motion/CMakeFiles/motmod.dir/home/user/linuxcnc_trajectory_planner/src/emc/kinematics/cubic.c.o
[ 10%] Building C object motion/CMakeFiles/motmod.dir/home/user/linuxcnc_trajectory_planner/src/emc/motion/axis.c.o
[ 15%] Building C object motion/CMakeFiles/motmod.dir/home/user/linuxcnc_trajectory_planner/src/emc/motion/motion.c.o
[ 20%] Building C object motion/CMakeFiles/motmod.dir/command.c.o
[ 25%] Building C object motion/CMakeFiles/motmod.dir/home/user/linuxcnc_trajectory_planner/src/emc/motion/control.c.o
/home/user/linuxcnc_trajectory_planner/src/emc/motion/control.c:31:10: fatal error: config.h: No such file or directory
31 | #include "config.h"
| ^~~~~~~~~~
compilation terminated.
make[2]: *** [motion/CMakeFiles/motmod.dir/build.make:132: motion/CMakeFiles/motmod.dir/home/user/linuxcnc_trajectory_planner/src/emc/motion/control.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:116: motion/CMakeFiles/motmod.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
The following user(s) said Thank You: Grotius
Please Log in or Create an account to join the conversation.
10 Oct 2024 06:47 #311700
by Aciera
Replied by Aciera on topic linuxcnc trajectory planner
Disregard the above. I was not aware that I needed to go through the usual linuxcnc build process before running the cmake build:
You now need to run 'sudo make setuid' in order to run in place with access to hardware.
user@user-iMac:~/linuxcnc_trajectory_planner/src$ cd ..
user@user-iMac:~/linuxcnc_trajectory_planner$ cd cmake/build/
user@user-iMac:~/linuxcnc_trajectory_planner/cmake/build$ make
Consolidate compiler generated dependencies of target motmod
[ 5%] Linking C shared library motmod.so
[ 50%] Built target motmod
Consolidate compiler generated dependencies of target tpmod
[ 55%] Building C object planner/CMakeFiles/tpmod.dir/tpmod.c.o
[ 60%] Building C object planner/CMakeFiles/tpmod.dir/home/user/linuxcnc_trajectory_planner/src/emc/tp/tc.c.o
[ 65%] Building C object planner/CMakeFiles/tpmod.dir/home/user/linuxcnc_trajectory_planner/src/emc/tp/tcq.c.o
[ 70%] Building C object planner/CMakeFiles/tpmod.dir/tp.c.o
[ 75%] Building C object planner/CMakeFiles/tpmod.dir/home/user/linuxcnc_trajectory_planner/src/emc/tp/spherical_arc.c.o
[ 80%] Building C object planner/CMakeFiles/tpmod.dir/home/user/linuxcnc_trajectory_planner/src/emc/tp/blendmath.c.o
[ 85%] Building C object planner/CMakeFiles/tpmod.dir/home/user/linuxcnc_trajectory_planner/src/emc/nml_intf/emcpose.c.o
[ 90%] Building C object planner/CMakeFiles/tpmod.dir/home/user/linuxcnc_trajectory_planner/src/libnml/posemath/_posemath.c.o
[ 95%] Building C object planner/CMakeFiles/tpmod.dir/home/user/linuxcnc_trajectory_planner/src/libnml/posemath/sincos.c.o
[100%] Linking C shared library tpmod.so
[100%] Built target tpmod
user@user-iMac:~/linuxcnc_trajectory_planner/cmake/build$
The following user(s) said Thank You: Grotius
Please Log in or Create an account to join the conversation.
10 Oct 2024 07:16 #311704
by Aciera
sounds like a good starting point.
Replied by Aciera on topic linuxcnc trajectory planner
Now i think a good strategy is to change a few tiny things to the current linuxcnc motion command flow:
sounds like a good starting point.
The following user(s) said Thank You: Grotius
Please Log in or Create an account to join the conversation.
10 Oct 2024 14:13 - 10 Oct 2024 14:15 #311728
by Grotius
Replied by Grotius on topic linuxcnc trajectory planner
Hi Arciera,
Yes, first build the linuxcnc as usual. Then overwrite it with the cmake build.
Another option, this i am using myself now :
When editing the cmake project in Qt, save your changes. "Cntr+s"
Then in terminal run the usual lcnc's make command $ ~linuxcnc_trajectory_planner/src/make then $ sudo make setuid
As i am editing the original source file's directly now. **Repository is updated with this change in used source files.
Ok i did some coding today.
There is now a new function added to the planner tpmod.so component.
I's called by the motion controller motmod.so.
When the entire gcode is loaded, the motion controller signals the trajectory planner
it can start processing the G64 P.. Q.. stuff for the trajectory.
Above function is now empty, but should start a new thread. This means heavy calculations
will not influence the current program cycle.
Yes, first build the linuxcnc as usual. Then overwrite it with the cmake build.
Another option, this i am using myself now :
When editing the cmake project in Qt, save your changes. "Cntr+s"
Then in terminal run the usual lcnc's make command $ ~linuxcnc_trajectory_planner/src/make then $ sudo make setuid
As i am editing the original source file's directly now. **Repository is updated with this change in used source files.
Ok i did some coding today.
There is now a new function added to the planner tpmod.so component.
I's called by the motion controller motmod.so.
When the entire gcode is loaded, the motion controller signals the trajectory planner
it can start processing the G64 P.. Q.. stuff for the trajectory.
int tpGcodeLoaded(TP_STRUCT * tp, int count);
Above function is now empty, but should start a new thread. This means heavy calculations
will not influence the current program cycle.
Last edit: 10 Oct 2024 14:15 by Grotius.
Please Log in or Create an account to join the conversation.
10 Oct 2024 20:15 #311769
by Lcvette
Replied by Lcvette on topic linuxcnc trajectory planner
Hurray!! \o/ great news to see this in motion once more! so excited!Ok i did some coding today.
The following user(s) said Thank You: Grotius
Please Log in or Create an account to join the conversation.
- ihavenofish
- Offline
- Platinum Member
Less
More
- Posts: 680
- Thank you received: 123
11 Oct 2024 18:06 #311826
by ihavenofish
Replied by ihavenofish on topic linuxcnc trajectory planner
Yay!
Take you time...
... Is it done yet?
Take you time...
... Is it done yet?
The following user(s) said Thank You: Grotius
Please Log in or Create an account to join the conversation.
12 Oct 2024 13:22 #311859
by Grotius
Replied by Grotius on topic linuxcnc trajectory planner
Hi,
Hurray!! \o/ great news to see this in motion once more! so excited!
Take you time...
... Is it done yet?
Did some coding today.
Now at the point, the gcode file loads into a vector.
Then it calls the optimizer to optimize the path respecting the gcode G64 P.. & Q.. values.
For the Q value, this is interpreted for removing tiny segments.
For the P value, this is interpreted for path deviation.
For creating the fillets, i will use 3d splines. As the clothoid lib is currently only 2d.
This code is running in the motmod.so, motion control component.
This is not involving the tpmod.so trajectory planners code so far,
the original trajectory planner is still running and functional now.
repository link
vector
optimizer
Hurray!! \o/ great news to see this in motion once more! so excited!
Take you time...
... Is it done yet?
Did some coding today.
Now at the point, the gcode file loads into a vector.
Then it calls the optimizer to optimize the path respecting the gcode G64 P.. & Q.. values.
For the Q value, this is interpreted for removing tiny segments.
For the P value, this is interpreted for path deviation.
For creating the fillets, i will use 3d splines. As the clothoid lib is currently only 2d.
This code is running in the motmod.so, motion control component.
This is not involving the tpmod.so trajectory planners code so far,
the original trajectory planner is still running and functional now.
repository link
vector
optimizer
Please Log in or Create an account to join the conversation.
12 Oct 2024 22:18 #311902
by Grotius
Replied by Grotius on topic linuxcnc trajectory planner
Hi,
Now given the G64 P.. Q.. value's for a gcode line, this is hiding : emcmotInternal->coord_tp.execTag.fields_float[3 & 4];
This can differ along the file. As the file may have multiple of these commands using different values.
1. The motmod.so (motion controller) component loads the file into a vector.
2. It initializes the lines & arc's inside the vector, just as the tpmod.so does written by Rob Ellenberg. Same struct's are used.
3. It trim's the segments given the G64 P.. value for that gcode line. The trim logic is there to produce a nice trim if it can.
4. Interpolation for arc's is used from original lcnc functions. and tested ok.
5. Interpolation for line's i added a new function wich make more sence.
The picture is a print result after loading the entire gcode, simulating a 5 second delay,
and after trimming is done to connect the spline fillets later on.
Next step is to add the spline fillets. But not too fast now.
First create the G64 Q.. (naive cam) filter function. We want to filter out tiny segments first.
How important is rigid tapping for the planner?
Now given the G64 P.. Q.. value's for a gcode line, this is hiding : emcmotInternal->coord_tp.execTag.fields_float[3 & 4];
This can differ along the file. As the file may have multiple of these commands using different values.
1. The motmod.so (motion controller) component loads the file into a vector.
2. It initializes the lines & arc's inside the vector, just as the tpmod.so does written by Rob Ellenberg. Same struct's are used.
3. It trim's the segments given the G64 P.. value for that gcode line. The trim logic is there to produce a nice trim if it can.
4. Interpolation for arc's is used from original lcnc functions. and tested ok.
5. Interpolation for line's i added a new function wich make more sence.
The picture is a print result after loading the entire gcode, simulating a 5 second delay,
and after trimming is done to connect the spline fillets later on.
Next step is to add the spline fillets. But not too fast now.
First create the G64 Q.. (naive cam) filter function. We want to filter out tiny segments first.
How important is rigid tapping for the planner?
Attachments:
Please Log in or Create an account to join the conversation.
- tiagounderground
- Offline
- New Member
Less
More
- Posts: 7
- Thank you received: 6
12 Oct 2024 23:52 #311905
by tiagounderground
Replied by tiagounderground on topic linuxcnc trajectory planner
At this stage scurve algorithm is already working?
Please Log in or Create an account to join the conversation.
Time to create page: 0.145 seconds