QT C++ code samples

More
25 Jun 2020 13:34 - 25 Jun 2020 13:38 #172729 by Grotius
Replied by Grotius on topic QT C++ code samples
Hi,

Reading online papers how to do a contour pocket offsets don't really tell how to do it in detail, step by step.
And they don't tell how the algoritme looks like. One solution that passes by is the Voronoi approach.
But it's not satisfying my needs.

So i started from scratch for this. Have made a document how to solve a pocket operation,
have tested the algoritme in several ways. It looks oke to me. And the input data is quite simple.

The calculation an sich takes some experience, this can be done by practice it several times.

I Hope it can help someone in the future to save time.

Later on the C++ header file for this pocket algoritme can be downloaded from my github channel.

The pdf document :

This browser does not support PDFs. Please download the PDF to view it: Download PDF



Have a nice day!
Attachments:
Last edit: 25 Jun 2020 13:38 by Grotius.
The following user(s) said Thank You: phillc54, tommylight, Clive S

Please Log in or Create an account to join the conversation.

More
25 Jun 2020 20:44 #172752 by Grotius
Replied by Grotius on topic QT C++ code samples
Hi,

Attached the tested header file "lib_pocket.h" for solving the pocket algoritme.

The terminal output is oke :


It is used for example 2 :


Today i did a hand calculation for example 2 :


So this is quite nice. After all, it's quite complicated stuff !
Attachments:
The following user(s) said Thank You: phillc54, tommylight

Please Log in or Create an account to join the conversation.

More
25 Jun 2020 21:12 #172756 by tommylight
Replied by tommylight on topic QT C++ code samples

.....After all, it's quite complicated stuff !

It sure is, but you are very good at it.
Regards,
Tom.
The following user(s) said Thank You: Grotius

Please Log in or Create an account to join the conversation.

More
25 Jun 2020 22:52 #172762 by Patrik T
Replied by Patrik T on topic QT C++ code samples
I peeked at some of the code. I like the straight forwardness of the coding style. Hope you don't mind a few suggestions. I am not pointing out errors, all these examples work fine as is, which you obviously know already.

1) I noticed this in a few places:
double y = radius * sinf(angle_start);
Why use sinf() when y, radius and angle_start are all doubles?

2) What are you trying to do here, with the function style int cast?
double theta = 2.0 * M_PI * int(j) / int(segments);
j and segments are already int and will be promoted to doubles anyway.

3) I noticed in display.h that you change the loop variable every loop. No harm but it is not necessary.

4) Have you considered using an enum for OBJECT::type, instead of a string?

5) std::vector::reserve() is a good idea here:
        std::vector<std::vector<double>> C; //2d array
	C.reserve(object.control.size() + 2); // This is a good idea here.
        C.push_back({object.start.x, object.start.y}); //spline startpoint
        for(int i=0; i<object.control.size(); i++){
            C.push_back({object.control.at(i).x, object.control.at(i).y}); //spline controlpoints
        }
        C.push_back({object.end.x, object.end.y}); //spline endpoint
        draw_spline(C);

I saw the pocket milling pattern, that looks advanced. Nice work all around.
The following user(s) said Thank You: Grotius

Please Log in or Create an account to join the conversation.

More
26 Jun 2020 11:32 #172794 by rodw
Replied by rodw on topic QT C++ code samples

Hi,

Updates
A big issue was the spline function. I used a Cubic bezier curve as spline. This was not good. Bezier curve's have startpoints cq endpoints that can not be used by dxf files. So i had to look for a Cubic spline like this : mathworld.wolfram.com/CubicSpline.html

The math was to heavy for me to solve. I did not find any plug an play solution that are dealing with a cubic spline in relation to elapsed time. But attached a minimal c++ QT project that does a cubic spline. A nice hollander helped me a lot !!
www.wiskundeforum.nl/viewtopic.php?f=37&t=12717


I have been doing some work in /src/emc/rs274ngc the folder. Now my copy of Linuxcnc knows the radius of any arcs and also the heading at any G1, G2, G3 move that could be used to orient a tangential knife and a few other things.

I don't think a new gcode would be hard to add.

I'd have to check while in front of a Linuxcnc box but gcodes are defined in interp_internal.h. So add your new code trhere. Gcodes are parsed andthen "converted" to tokenised motion segments in interp_convert.cc which inturn calls interp_arc.cc and a couple of others. So you'd need to work your way through the parsing code and create a new convert procedure to convert your spline.

Feel free to email me off forum and I'll try and explore this a bit further for you. All I Will say is that grep is your friend when you venture in to this code!
The following user(s) said Thank You: Grotius

Please Log in or Create an account to join the conversation.

More
26 Jun 2020 21:19 - 26 Jun 2020 21:52 #172819 by Grotius
Replied by Grotius on topic QT C++ code samples
@Hi Tom,

It sure is, but you are very good at it.
Thank you for compliment ! Step by step we go to finish the program.

@Hi Patrik,
I like the straight forwardness of the coding style.
Thank you.

Why use sinf() when y, radius and angle_start are all doubles?
That's correct. The sinf() to be changed to sind().

What are you trying to do here, with the function style int cast?
double theta = 2.0 * M_PI * int(j) / int(segments);
j and segments are already int and will be promoted to doubles anyway.

That's correct. It's quite a old piece of the code. I remember a problem with arc's that missed a short end piece.
Then i tried several things to solve it. It has to be corrected.

Have you considered using an enum for OBJECT::type, instead of a string?
No, but i tried it today. I miss some knowlegde to get it right. After one hour i stopped it,
because i was working on splitting up arc's between intersection points.
I you have a example, that would be nice.

Something like this would be perfect : it->type.line; or it->type.line=true;
But then all others must be off.
I use this sometime : it->type==""; For enum, we can choose a dummy name.

std::vector::reserve() is a good idea here:
An sich it is oke for me. If they are used.

But one thing to mention is :
When we reserve 2 empty controlpoints and they stay that way. Their both coordinates are 0,0,0. That coordinates are used in the eara calculation of the depth calculation. That calculation will not be correct.
So that's one thing to remember.


I saw the pocket milling pattern, that looks advanced.

It's a picture seen on the internet. The c++ header is available. But it can handle no splines, bezier, ellipse etc.
And i don't understand the readme file how to use the class for pocket offsetting.

@Hi Rod,
I don't think a new gcode would be hard to add.
I agree.
My idea is to make a linuxcnc copy, and edit the nurb class. Ivestegate some more code and see what happens.
After it works, writing it as a clean piece of code in new class. I am fan of header only.

Feel free to email me off forum and I'll try and explore this a bit further for you.

Thank you for your work ! At the moment i need all the time for coding the Cadcam software.
After that the plan is to dig into the linuxcnc code.

I have been doing some work in /src/emc/rs274ngc the folder. Now my copy of Linuxcnc knows the radius of any arcs and also the heading at any G1, G2, G3 move that could be used to orient a tangential knife and a few other things.
Perfect ! Making a tangential mode nice !

I am also interested in something i have never googled before, but where i think about often, i call it "true spline".
For me it's a very interesting fenomen. It's a spline that is the same in two directions. (played from left to right en visa versa)
It could be easely be realised to combine 2 spline algoritmes and take the difference as output.

Another interesting thing for linuxcnc is a c++ interface with full control. Or a c++ interface that has full control via component.

Yesterday i read on this forum that someone has bought a tiny machine with usb interface.
Why don't write some code that usb can be used for linuxcnc. If it works, it has not to be top speed always.
I thought about adding a usb mode to the stepgen file, adding a baud rate and another few things would make this work.

Okey have a nice day !
Last edit: 26 Jun 2020 21:52 by Grotius.
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

More
27 Jun 2020 03:52 #172833 by Patrik T
Replied by Patrik T on topic QT C++ code samples
#include <iostream>

	enum Type { // Use "enum Class Type" to avoid warning 26812.
		empty,
		line,
		circle,
		arc,
	};

	struct Object {
		Type type{ empty };
	};

	void Print_Shape(Object* object) {
		switch (object->type) {
			case empty:
				std::cout << "Type is empty.\n\n";
				break;
			case line:
				std::cout << "Type is line.\n\n";
				break;
			case circle:
				std::cout << "Type is circle.\n\n";
				break;
			case arc:
				std::cout << "Type is arc.\n\n";
				break;
			default:
				std::cout << "Type is unknown.\n\n";
				break;
		}
	}

	int main(int argc, char** argv) {
		Object object_1;
		Print_Shape(&object_1);

		object_1.type = circle;
		Print_Shape(&object_1);

		Object line_object{ line };
		Print_Shape(&line_object);
		
		Object object_2{ object_1 };
		Print_Shape(&object_2);
		
		Object object_3{ (Type)5 };
		Print_Shape(&object_3);

		if (line_object.type != empty)
			std::cout << "Type is not empty.\n\n";

		return 0;
	}

And I think you are mixing up vector::reserve() with vector::resize().
The following user(s) said Thank You: tommylight, Grotius

Please Log in or Create an account to join the conversation.

More
28 Jun 2020 18:23 - 28 Jun 2020 18:36 #173014 by Grotius
Replied by Grotius on topic QT C++ code samples
Hi,

Thank you Patrik for the code sample. Yes i mixed them up, excuse for that.

This is interesting for me:
Object* object (i guess a pointer)
&object_1 (I guess by reference)

Today i tested some more with the pocket algoritme. To keep it simple i started with lines only. There was much work to do to get
it like the preview. There where some offset difficulties when value's became Nan. Some intersection problems that had to be solved.
A whole list of difficulties to get trhough.

This contour preview is based on a contour offset from farest outside to offset distance.

Next step is do a repeated offset from old offset to new offset and then stop offsetting at some point.

For today i am satisfied. :laugh:



Here you can see how the algortime works at offset distance -12mm
The purple lines are area's with positve area, these will be removed. It is showing how the algoritme works behind the screen.


At offset -21mm, there is almost no positive area left (positive area is color green)
Attachments:
Last edit: 28 Jun 2020 18:36 by Grotius.
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

More
28 Jun 2020 21:31 #173038 by Patrik T
Replied by Patrik T on topic QT C++ code samples

This is interesting for me:
Object* object (i guess a pointer) Yes, pointer.
&object_1 (I guess by reference) No, "address of" operator to get a pointer to object_1.


You wrote:

I use this sometime : it->type=="";

Where you dereference a pointer so I also used a pointer to show code similar to what you asked about.
The following user(s) said Thank You: Grotius

Please Log in or Create an account to join the conversation.

More
29 Jun 2020 23:28 #173153 by Grotius
Replied by Grotius on topic QT C++ code samples
Hi,

I had an idea about a new type of spline. Tonight i did a "true spline" test for the fun !

The picture is showing a normal natural cubic spline.
When you draw the spline from left to right, and then you draw it from right to left, there is a difference.
The picture is showing the difference. The algoritme that is used : mathworld.wolfram.com/CubicSpline.html


Okey for robot's it's not handy to interpolate in a different path when moving in reverse.
And in the CadCam program i spotted "this not really problem" several times during swapping a spline.

The idea is to produce a spline that is always the same in every direction. The picture below is showing a True spline.
I call it that way. Just a name.


The C++ code is attached.

If you use this for stock market. Maybe you can get rich ! :laugh:
Attachments:
The following user(s) said Thank You: phillc54, tommylight

Please Log in or Create an account to join the conversation.

Time to create page: 0.483 seconds
Powered by Kunena Forum