2. Computer Assisted Conception#
This week I started using application OpenSCAD and FreeCAD to design FlexLinks.
OpenSCAD#
I found that the most useful resource to understand how to use the OpenSCAD programming language is this cheat sheet shared to us in class. The other resource I used was a stack overflow page describing how to curve a rectangle in OpenSCAD.
Design#
The full code is available here, but I decided to present an explanation of the code below in the order that I wrote it.
Idea#
I wanted to make a simple 3 part piece such as this one:
Initial piece#
For my design, I wanted to be as general as possible and use variables instead of numbers so I could modify the utility of my code later on. The goal was to be able to build the final piece with only three commands:
n = 3; // number of slots
bar_r = 300; // length of the middle bar
make_lego(n, bar_r); // command to build the lego
This allowed me to limit the amount of values I had to calculate by hand to make the lego.
Length of the piece#
The first function that allows me to easily use the final program is the “length(n)” function, that calculates the length of the slotted piece with input n being the number of holes it will have:
function length(n) = edge_space*2 + n*r*2 + (n-1)*space;
with edge_space
being the space from the edge holes to the end of the piece, r
being the radius of holes, and space
being the sapce between the holes.
Creating a rectangle with rounded edges with equally spaced holes#
Next is a module that builds the slotted piece:
module piece(n, w, h, x0, y0, z0, a_x, a_y, a_z) {
l=length(n);
rotate([a_x, a_y, a_z]) translate([w/2, 0, 0]) {
difference(){
union(){
translate([x0, y0, z0]) cylinder(h, w/2., w/2.); // creates rounded edge
translate([x0, y0-w/2., z0]) cube([l-w,w,h]); // creates the rectangular body of the piece
translate([x0+l-w, y0, z0]) cylinder(h, w/2, w/2); // creates other rounded edge
}
for (i = [0:space+r*2:l]) {
translate([x0+i, y0, z0-1]) cylinder(h+2, r, r); // creates the equally spaced holes
}
}
}
}
with
w
and h
the width and height of the slotted piece, (x0, y0, z0)
the coordinates at which the piece will be placed, r
the radius of the holes, and (a_x, a_y, a_z)
the angle of the piece with respect to each axis. The for
loop in OpenSCAD works differently than what I’m used to with [start:step:stop]
. The step is defined as the space between two holes plus the diameter of the hole.
I could have used the hull function to achieve the same final curved edges effect, but I did not because at the time I thought this was simpler to define.
One minor modification was made to the code to facilitate the visualisation of the piece on OpenSCAD. As seen in the image above, the holes are not transparent but fuzzy as a result of the height of the holes being exactly the same as the height of the rectangle. So, I added a +2 to the height of the cylinders and translated the origin position of the cylinders by -1. This now allows the holes to be completely transparent and for there to be no confusion with the printing of the piece:
Flexible bar#
Next is the little bar between the two slotted pieces. When it is straight it is just a rectangle:
cube([bar_r, bar_w, h]); // bar_r is the length, just easier to use this within the final code
I decided to also make one where you could have a semi circle between the two pieces:
module half_circle(bar_r, bar_h, bar_w, x0, y0, z0) {
translate([x0, y0+bar_r, z0]) rotate(90) // choosing the location
rotate_extrude(angle = 180) // extruding the half circle
translate([bar_r, 0, 0]) // defines the diameter of the half circle
square(size = [bar_w, bar_h]); // square that defines the dimensions of the half circle
}
I did not understand how to use rotate_extrude() at first so I consulted the Stack Overflow page linked at the beginning of this page.
Putting it all together#
The module I defined as make_lego()
allows the final lego piece to be assembled with minor involvement from the user.
module make_lego(n, bar_r, angled) {
x0=0;
y0=0;
z0=0;
a_x=0;
a_y=0;
a_z=0;
if (angled==true) { // half circle FlexLink
union(){
piece(n, w, h, x0, y0, z0, a_x, a_y, a_z);
half_circle(bar_r, h, bar_w, x0, y0, z0);
piece(n, w, h, x0, y0+bar_r*2, z0, a_x, a_y, a_z);
}
}
else { // straight bar FlexLink
l=length(n);
union(){
piece(n, w, h, x0, y0, z0, a_x, a_y, a_z);
piece(n, w, h, x0+l+bar_r, y0, z0, a_x, a_y, a_z);
translate([x0+l, y0, z0])
cube([bar_r, bar_w, h]); // bar_r is the length, just easier to use this within the final code
}
}
}
CC License#
The Creative Commons license allowed me to set the terms on which I want to share my work. In my case, I want to have credit for my work, have non-commercial usages of it, and ensure that all other derivations of my work abide by these terms. This is the CC BY-NC-SA license.
Conclusion#
This all took a lot of effort but not too much time. The part that was the hardest was understanding the language and how each command worked. But, using my Python background and a little bit of Googling, I arrived at this solution.
The final code is flawed as we will see next week in the testing phase. It prints weak links, but by its own it is not completely incompetent. But it could be better. Further modifications will be made as I print more versions.