Welcome! Log In Create A New Profile

Advanced

OpenScad advice... required.

Posted by Treth 
OpenScad advice... required.
April 01, 2014 04:30PM
I'm really starting out today, having just downloaded OpenScad to see how it compares with 3D CAD programs (I'm also learning DesignSpark Mech).

I have a project that is using a small electret microphone which goes into the ultrasonic region. I want to experiment with various size parabolic reflectors to see how performance improves.

So I want a parabolic dish a few mm thick sitting on a round boss with a hole through the centre to pass the tube with wires to the mic which will be slid in and out to find the focal point.

I don't want anyone to produce a completed part, but what would your OpenScad steps be?

I guess it similar to a vase but with a mathematical defined curve?


Ormerod #007 (shaken but not stirred!)
Re: OpenScad advice... required.
April 01, 2014 06:29PM
EDIT : Read following posts for better method smiling smiley

regards
Andy

Edited 1 time(s). Last edit at 04/03/2014 04:15AM by kwikius.


Ormerod #318
www.zoomworks.org - Free and Open Source Stuff smiling smiley
Re: OpenScad advice... required.
April 02, 2014 01:28AM
paraboloid maybe a good starting point
Re: OpenScad advice... required.
April 02, 2014 05:49AM
Good find Bob (if I may call you that)
Generate a cone, then take a slice through it - giving: ellipse or parabola or hyperbola.
Greg


Ormerod #17
Re: OpenScad advice... required.
April 02, 2014 08:47AM
I had thought of using a Minkowski action, using a 2mm sphere rolled around the outside of the paraboloid - followed by subtracting the original paraboloid.
My reasonably fast machine just sat there for ages with the progress bar pretty stationary - I abandoned that.
Next attempt doesn't look too bad - generate a slightly larger paraboloid, and subtract the shape we actually want
difference(){
translate([0,0,-1])paraboloid (y=51,f=10.5,rfa= 0,fc=1,detail=120); // outer shell
paraboloid (y=50,f=10,rfa= 0,fc=1,detail=120); // cut out the required parabola
translate([0,0,-15])cylinder(20,5,5); // and the aperture for access
};



Ormerod #17
Re: OpenScad advice... required.
April 02, 2014 10:53AM
Yes, a very good find Bob. For 3D printing, it might be best to cut the parabolic shape out of a cube (to give a flat bottom for printing and a strong part for sanding smooth), though it obviously depends on the application. My simple mod. attached.

Dave
(#106)
Attachments:
open | download - Paraboloid.scad (2 KB)
Re: OpenScad advice... required.
April 02, 2014 01:27PM
@everyone, many thanks great advice!

OpenScad really does excel when you know how to use it!
Seems to suite certain tasks such as this very well with so few lines of code, but wow the details in that code. I need to get by brain thinking with the correct sequence.
Thanks.


Ormerod #007 (shaken but not stirred!)
Re: OpenScad advice... required.
April 02, 2014 02:42PM
I suspect that OpenSCAD might have some links back to an old AI language called Lisp - it too had a habit of doing things in reverse order.
Separate statements ( terminated by ';' or '}' ) are seemingly performed in a normal sequence - However inside the statement, where there are cascaded operations, it starts with the one at the terminator, and works its way backwards towards the beginning of the statement.
The difference operator takes the first statement as the initial blank, and then subtracts the shapes defined by each of the following statements.
Greg


Ormerod #17
Re: OpenScad advice... required.
April 03, 2014 05:31AM
Quote
GregL
I suspect that OpenSCAD might have some links back to an old AI language called Lisp - it too had a habit of doing things in reverse order.
Separate statements ( terminated by ';' or '}' ) are seemingly performed in a normal sequence - However inside the statement, where there are cascaded operations, it starts with the one at the terminator, and works its way backwards towards the beginning of the statement.
The difference operator takes the first statement as the initial blank, and then subtracts the shapes defined by each of the following statements.
Greg

I wish I could find a more definitive description of the execution order in OpenSCAD. It looks like almost anything goes from the examples in the User Manual (which seems to be all there is to go on). It obviously has a more proactive parser - which eliminates the need for header files, but I bet it's unsettling to most C programmers using it for the first time. I do like the programming approach but I never feel completely confident that I'm doing things correctly wit it.


RS Components Reprap Ormerod No. 481
Re: OpenScad advice... required.
April 03, 2014 06:20AM
Have you seen this PDF / presentation?

I don't know if this is of any help to you, but I found it useful,
it contains some good advice to keep a C programmer sane ;^)


RS-Online Ormerod #263, Kossel mini with Minitronics, Prusa i3 MK2
Re: OpenScad advice... required.
April 03, 2014 06:23AM
This is only my understanding of what goes on

The key to the sequence of operations is to clearly focus on every semicolon and curly close bracket.
OpenScad will push each operation and its arguments on to a stack (when reading in normal left to right manner)
Only when OpenScad discovers a semicolon or curly close does it actually perform the operation on top of the stack - and produce a 2D or 3D entity.
OpenScad then pops the next operation (and its arguments) off the stack and performs that on the 2D/3D entity - it repeats this until the stack is empty.
It then moves on to the next statement - and new 2d?3D entity..

Any overlapping entities produced are automatically 'unioned'

I will have a go at annotating some OpenScad script to explain things - later.
Greg

Edited 1 time(s). Last edit at 04/03/2014 06:24AM by GregL.


Ormerod #17
Re: OpenScad advice... required.
April 04, 2014 04:11AM
Many thanks 3D-ES & GregL - I hadn't spotted that PDF presentation before. Just what I needed. thumbs up


RS Components Reprap Ormerod No. 481
Re: OpenScad advice... required.
April 04, 2014 10:31AM
I have annotated the code I used in my earlier post above.
It uses the Paraboloid code from elsewhere, with a bit of mycode to call it a couple of times.
I show the numbered steps in the order they are performed by OpenScad
Steps 1 and 3 call up the paraboloid module, so its numbered steps (.1 to .16) are performed inside the 1 or the 3

I do not pretend to understand what those squares are to do with the focus area - so don't ask me.
Greg
ScadExplanation.pdf


Ormerod #17
Re: OpenScad advice... required.
April 04, 2014 11:24AM
Quote
GregL
I have annotated the code I used in my earlier post above.
It uses the Paraboloid code from elsewhere, with a bit of mycode to call it a couple of times.
...
Greg
Many thanks for this, I'm far from understanding the sequence...., but I'm starting to visualise the code functions.

Quote
3D-ES
.......
Have you seen this PDF / presentation?
No I had not seen that before and it is very helpful, Thanks.

Quote
bobtidey
paraboloid maybe a good starting point
Thanks for this link, with that code and the subsequent discussions I should be able to produce what I require.

Thanks all for the great discussion and help (I kept quite until now to keep the flow going! as I could not contribute). smiling smiley
Feel free to discuss further.......

Regarding the execution sequence.
So the code is effectively all read in until a semi-colon is reached, hence .1 and .2 are executed.
Then all the lines are read in until another semi-colon (at 0.3) is found and code is execute back up the lines....

What happens with the jump from sequence at 0.8 and 0.9? and again with .11 and .12?

So as I gradually learn to read and modify code, that is one thing, but what's the thought process for creating from scratch?


Ormerod #007 (shaken but not stirred!)
Re: OpenScad advice... required.
April 04, 2014 12:19PM

I did this in about a minute in FreeCad..
Kim


Please send me a PM if you have suggestions, or problems with Big Blue 360.
I won't see comments in threads, as I move around to much.
Working Link to Big Blue 360 Complete
Re: OpenScad advice... required.
April 04, 2014 12:57PM
Quote
KimBrown
[attachment 29991 junk.jpg]
I did this in about a minute in FreeCad..
Kim
@Kim, thanks for the post, hmmm a minute, probably will be more than that per line for me in OpenScad!

So I'm new (very new) to FreeCad (in fact most mechanical CAD!) can you give a rough guide to the steps?

Presumably you defined the parabolic curve via an equation, gave it some thickness to produce an area and rotate around the centre line?

I must also launch DesignSpark Mechanical again as I did get on well with that program, but didn't know the step to define the parabolic curve! I just make a vase!!!
Perhaps I'll ask on their forum as well.


Ormerod #007 (shaken but not stirred!)
Re: OpenScad advice... required.
April 04, 2014 03:35PM
Quote
Treth

Regarding the execution sequence.
So the code is effectively all read in until a semi-colon is reached, hence .1 and .2 are executed.
Then all the lines are read in until another semi-colon (at 0.3) is found and code is execute back up the lines....

What happens with the jump from sequence at 0.8 and 0.9? and again with .11 and .12?

So as I gradually learn to read and modify code, that is one thing, but what's the thought process for creating from scratch?

The open and close curly brackets influence things here.
After the first two statements at .1 and .2, all the operations are put on a stack until the ; on the cylinder statement at .3
The operations are popped off the stack and computed until the open curly bracket at the union statement at .10

This is the bracket which will have to be matched later - just after .8 - so scad carries on stacking the .9 and .8 lines until the next semicolon. Again it will pop those off the stack and compute them until it hits that open curly again.
Next time it looks forward it finds the matchin close curly, so it can pop the union statement at .10 and obey it.
Can't pop any more as there is the open curly of the difference.

Keeps scanning forward and pushes the .12 and .11. Finds the semicolon so pops and operates .11 and .12
Finds that open curly of the difference, so scans forward, finding the close curly - pops and operates the difference.
Scans forward and finds the close curly of the module and exits.
--------------------
The basic thinking process is to picture the object you want as a collection of basic shapes which you can then machine away using other basic shapes (ie drill holes etc)
Your basic building blocks may need moving and rotating in various ways - in which case you precede the block with the relevant move or rotation.
Group together bits with the union statement, then you can move/rotate that group by precede the group with the relevant move or rotation.
Finally get your set of drills/ saws to hack away at the group - using the difference statement


Ormerod #17
Re: OpenScad advice... required.
April 04, 2014 04:09PM
@GregL,
Wow, what an amazingly clear explanation..... thank you smileys with beer

I followed that step by step, great! I shall now investigate the commands in a bit more detail and look at the instruction flow in other programs.

Way back in the 80's I did have and used Forth on a Sinclair Spectrum, that was fun and tricky at first, OK. But that was a long time ago!

Thanks for taking the time to explain this.


Ormerod #007 (shaken but not stirred!)
Re: OpenScad advice... required.
April 05, 2014 11:06AM
28 years teaching B.Sc. and M.Sc. Computer Science gave me some practice!

When looking at the paraboloid module, I copied and pasted the innermost operation (.3) and ran that - gradually adding the other operations one at a time
You have to make sure that any variables used eg hi had to be set up in a separate statement
Greg


Ormerod #17
Re: OpenScad advice... required.
April 06, 2014 05:11AM
In FreeCad I first click file, then New to start a new project.

I then placed a Sphere the size I wanted for the inside,
To alter the Spere sizes, first click on one of the Spheres...(If you right click it you can give it a name if you wish).
Then in the panel on the left, at the bottom, you will see a tab with Data....

Here I set Angle3 to 180' and the radius to 5mm for the inside Sphere.
Then another Sphere a fraction bigger (depending on how thick you want the dish, I used 5.5mm), and an angle of 180' for Angle 3.

(Now to show you the view of the two Spheres I pressed the middle and left mouse buttons to turn the view of the parts....If you let the left button go first, it will spin....
Cool yes....) hot smiley

Now we are nearly finished.... We need to subtract the Inner Sphere from the Outter Sphere.
This is simple...
First we select the Second Sphere (the outer) Sphere in the panel on the left of the screen, then holding down the CTRL key we select the second Sphere.
(When you subtract parts, the First selection is the item you want to keep, the second selection is the item you want to remove from it).
I've drawn an arrow for the icon you need to select.


I suggest you look around their Helpful Videos....
The Engine Block is a good one to try...
Kim..


Please send me a PM if you have suggestions, or problems with Big Blue 360.
I won't see comments in threads, as I move around to much.
Working Link to Big Blue 360 Complete
Re: OpenScad advice... required.
April 06, 2014 01:19PM
Quote
bobtidey
paraboloid maybe a good starting point

I found a much more concise method of generating the parabolic section, though it requires you to enable OpenSCAD's concat function in preferences, but then you can create your polygon inline... Here is a view of the result:



The code is a few lines only :

/*
parabolic reflector
n.b need to enable concat in preferences
*/

/*
 parabolic curve
 x:integer  is number of points 
 xscale: float is expansion of x in x dir
*/
function parabola_pts(x, xscale) 
= (x == 0)
?[[0,0]]
:concat(parabola_pts(x-1,xscale),[[xscale *x, x*x]]);

basic_curve  = parabola_pts(20, 50);

rotate_extrude(){
  polygon (points = concat([[basic_curve[20][0],0]], basic_curve));
}

parabolic_reflector.scad

regards
Andy

Edited 1 time(s). Last edit at 04/06/2014 01:31PM by kwikius.


Ormerod #318
www.zoomworks.org - Free and Open Source Stuff smiling smiley
Re: OpenScad advice... required.
April 07, 2014 03:22AM
Quote
KimBrown
In FreeCad I first click file, then New to start a new project.
I then placed a Sphere the size I wanted for the inside,
To alter the Sphere sizes, first click on one of the Spheres...(If you right click it you can give it a name if you wish).
Then in the panel on the left, at the bottom, you will see a tab with Data......

I suggest you look around their Helpful Videos....
The Engine Block is a good one to try...
Kim..
Hi Kim, good instructions and screen shots, thanks. I will have a look FreeCad.
I actually want a parabola not a hemisphere, so the question would be can you put an equation to the surface or the cross section?
No need to answer that one as I will probably use OpenScad as I have been given a solution I can work with.

Thanks for detailed instructions


Ormerod #007 (shaken but not stirred!)
Re: OpenScad advice... required.
April 07, 2014 03:25AM
Quote
kwikius
Quote
bobtidey
paraboloid maybe a good starting point

I found a much more concise method of generating the parabolic section, though it requires you to enable OpenSCAD's concat function in preferences, but then you can create your polygon inline... Here is a view of the result:

The code is a few lines only :

/*
parabolic reflector
n.b need to enable concat in preferences
*/

/*
 parabolic curve
 x:integer  is number of points 
 xscale: float is expansion of x in x dir
*/
function parabola_pts(x, xscale) 
= (x == 0)
?[[0,0]]
:concat(parabola_pts(x-1,xscale),[[xscale *x, x*x]]);

basic_curve  = parabola_pts(20, 50);

rotate_extrude(){
  polygon (points = concat([[basic_curve[20][0],0]], basic_curve));
}
Thanks Andy, this has helped also. I'll study the code in more detail, but have to have a week break now with family here enjoying the wet and windy weather in Cornwall UK.


Ormerod #007 (shaken but not stirred!)
Re: OpenScad advice... required.
April 07, 2014 08:04AM
Cornwall Superb! Even if its wet!

I was happy to do a bit of work on this since the ability to create parametric sequences of arbitrary length in OpenSCAD makes it much more powerful. I only just found out about it! The concept of recursive function can be hard to grasp but once grasped is very useful.

I found the original source code barfs if you try the CGAL compile and render, though works OK in quick and dirty render. rotate _extrude doesnt like the [0,0] coordinate for some reason. So I modified the source to sort that and so that you can create the reflector from a required diameter and its focus. The object is then drawn with the focus at the origin Ive also added comments to hopefully explain what is going on.

Here is a view of the basic module followed by some othere examples in the file which you can enable with some flags defined half way down the file.

Thin wall version

A cool looking offset reflector, to reduce masking by the detector on a small reflector and add some bling smiling smiley

Finally here is the source with the module and examples.
parabolic_reflector1.scad

regards
Andy


Ormerod #318
www.zoomworks.org - Free and Open Source Stuff smiling smiley
Re: OpenScad advice... required.
April 07, 2014 12:06PM
Quote
KimBrown
In FreeCad I first click file, then New to start a new project.
I then placed a Sphere the size I wanted for the inside,
To alter the Spere sizes, first click on one of the Spheres...(If you right click it you can give it a name if you wish).
Kim..

A spherical reflector does work after a fashion, but to get the sharpest focus (and hence best gain) you need to use a parabolic reflector rather than a spherical reflector.

The solution offered reminded me that a section of a cone is a parabola, which I had forgotten. If memories from my school days are correct, the equation for plotting a parabola is a trinomial i.e. Y = aX^2 + bX + c, where a and b are positive or negative constants that affect the shape & focal distance of the parabola in ways that I have long forgotten, and c is a constant that will simply provide an offset above or below the X axis. The simplest is when a=1, b=0 and c=0 when the equation becomes Y = X^2 (you need to use negative and positive values of X to get the complete shape) . If a=0 the graph will be a straight line, which I suppose can be considered to be a parabola with an infinite focal distance.

Dave
(#106)
Re: OpenScad advice... required.
April 07, 2014 12:48PM
I agree with you Dave, but I thought he wanted a small dish (a few mm in diameter) in which case he would then have to polish the surface to get rid of the laminations from printing. Maybe I read it wrong, but I thought a simple spherical dish would do.
Kim eye rolling smiley


Please send me a PM if you have suggestions, or problems with Big Blue 360.
I won't see comments in threads, as I move around to much.
Working Link to Big Blue 360 Complete
Re: OpenScad advice... required.
April 07, 2014 03:35PM
@Andy, Dave and Kim,

Thanks again for your help.

@Kim sorry for any confusion, I want a parabolic dish to amplify ultrasound, I haven't yet defined the size, I expect it to be about 3cm diameter up to 10cm. I shall print off some and see what offers the required sensitivity. The mic insert I have selected is only 3mm diameter and with an even smaller aperture, so I require the parabolic shape for the best focus.

Regarding print quality, I am assuming the printed ridges are insignificant to the ~1cm wavelength (35kHz) but will be more significant at the higher frequencies, so I was going to try gentle fine 'wet or dry' to smooth and observe any improvements. This in itself may be the reason for going to the larger diameters!

@Andy, yes I love Cornwall, the coasts and weather! It does cause some problems with the number of times our power has gone for a fraction of second which resets so many electronic bits, especially the Ormerod. I'm looking for a 12V battery backup charger supply for my Ormerod! But that might be a new post......
But we have great broadband speeds now where I live, 70Mbps with FTTC, compared to 0.75Mbps 2 years ago.

I like the latests sample designs and the explanations, so thanks. It certainly shows the power of OpenScad with mathematical equations which I have found tricky in conventional CAD. I hope this thread is proving useful to others learning OpenScad.


Ormerod #007 (shaken but not stirred!)
Re: OpenScad advice... required.
April 07, 2014 05:03PM
I'm greatly enjoying this thread - it's really switched me on to OpenSCAD and I'm also dreaming up ideas for projects involving parabolas. Treth, have you thought about printing in ABS and using the Acetone polishing method: [hackaday.com] ?


RS Components Reprap Ormerod No. 481
Re: OpenScad advice... required.
April 12, 2014 04:06AM
Quote
Radian
I'm greatly enjoying this thread - it's really switched me on to OpenSCAD and I'm also dreaming up ideas for projects involving parabolas. Treth, have you thought about printing in ABS and using the Acetone polishing method: [hackaday.com] ?
Great idea about the acetone and ABS, I have seen this used with models and ornaments etc., but yes there could be a good 'engineering' use as well.

At the moment I am steering clear of ABS due to my printing being indoors and I don't want to introduce any fumes!
I also need to ruggedise my printer for the higher temperatures, probably a summer job.
But excellent idea for using the acetone method.

Anyone else using this for and 'engineering' purpose?


Ormerod #007 (shaken but not stirred!)
Sorry, only registered users may post in this forum.

Click here to login