Commit b7d68e38 authored by Jan Koniarik's avatar Jan Koniarik
Browse files

finished abillity to export to print

parent 92afa954
......@@ -108,7 +108,7 @@ leg leg_pos conf_type = Leg
, min_angle = 0 *~ radian
, default_angle = case conf_type of
Folded -> 0 *~ degree
_ -> 45 *~ degree
_ -> 0 *~ degree
, max_angle = 90 *~ degree
, vel_lim = 0.5 *~ (radian D./ second)
, effor_lim = 100
......
......@@ -30,6 +30,7 @@ import Walker
import Data.Hashable ( hash )
import Debug.Trace (traceShowId)
import System.Directory
data ExprRes = RNum Double | RString String | RBool Bool | RVec [ExprRes] | RUndef deriving (Show, Eq)
type Arg = (String, ExprRes)
......@@ -38,6 +39,12 @@ data ObjectRes = RUnion [ObjectRes] | RTranslate [Arg] (Maybe ObjectRes) | RRot
rp_model :: SCADModel,
rp_printed :: Bool } deriving (Show, Eq)
data ExtrPart = ExtrPart {
ex_name :: String,
ex_model :: SCADModel,
ex_print_file :: Maybe Filename
} deriving (Show, Eq, Ord)
-- [args] ... [body]
type ModuleDefContent = ([(LS.Ident, Maybe LS.Expr)], [LS.Object])
data Scope = Scope
......@@ -151,7 +158,7 @@ exprResToLS v = case v of
RBool b -> LS.EBool b
RVec n -> LS.EVec (exprResToLS <$> n)
evalUntilParts :: Filename -> LS.Object -> [LS.TopLevel] -> [SimplePart]
evalUntilParts :: Filename -> LS.Object -> [LS.TopLevel] -> [ExtrPart]
evalUntilParts root_file obj cmap = case res of
Left err -> error err
Right child -> extract child
......@@ -159,17 +166,22 @@ evalUntilParts root_file obj cmap = case res of
res :: Either String ObjectRes
res = evalState (runExceptT (evalScad root_file obj cmap)) emptyScope
extract :: ObjectRes -> [SimplePart]
extract :: ObjectRes -> [ExtrPart]
extract (RUnion children ) = concat $ extract <$> children
extract (RTranslate _ mb_child) = maybe [] extract mb_child
extract (RRotate _ mb_child) = maybe [] extract mb_child
extract (RPart name model _) =
[ Part { part_name = name
, model = model
, part_weight = Nothing
, center_of_mass = Nothing
extract (RPart name model printed) =
[ ExtrPart { ex_name = name
, ex_model = model
, ex_print_file = if printed
then Just $ filename
else Nothing
}
]
where
filename :: String
filename = module_name model ++ "_" ++ (show $ hash name `mod` 9068 )
evalExpr :: LS.Expr -> EvalM ExprRes
evalExpr e = withCallStack ("eval expr: " ++ show e) $ case e of
......@@ -558,7 +570,7 @@ evalScad root_file obj cmap =
pretty_arg x = show x
extractParts
:: Filename -> LS.Ident -> [LS.Argument LS.Expr] -> IO [SimplePart]
:: Filename -> LS.Ident -> [LS.Argument LS.Expr] -> IO [ExtrPart]
extractParts filename mod args = do
abs_path <- canonicalizePath filename
let root_dir = takeDirectory abs_path
......@@ -608,61 +620,70 @@ extractParts filename mod args = do
then new_includes rel_prefix xs cmap
else (full_path, Nothing) : new_includes rel_prefix xs cmap
getWalkerParts :: ExtendedWalker -> PackageConfig -> [(String, [SimplePart])]
getWalkerParts :: ExtendedWalker -> PackageConfig -> [(String, [ExtrPart])]
getWalkerParts Walker {body=ExtendedBody {urdf_name, base_body},legs} PackageConfig {src_dir} =
(urdf_name, (ass_to_parts $ body_ass base_body))
: concatMap
(\Leg { root_joint } -> mapLinks map_link root_joint)
legs
where
ass_to_parts :: ExtendedAssembly -> [SimplePart]
ass_to_parts :: ExtendedAssembly -> [ExtrPart]
ass_to_parts Assembly { amodel = ExtendedSCADModel { smodel } } =
unsafePerformIO $ extractParts (src_dir </> (head $ imports smodel))
(LS.Ident $ module_name smodel)
(args smodel)
map_link :: ExtendedLink -> (String, [SimplePart])
map_link :: ExtendedLink -> (String, [ExtrPart])
map_link ExtendedLink { link = Link { assembly }, urdf_name } =
(urdf_name, maybe [] ass_to_parts assembly)
generatePrint :: ExtendedWalker -> PackageConfig -> IO ()
generatePrint walker pconf = mapM_ part_to_scad walker_parts
generatePrint walker pconf = do
mapM_ part_to_scad walker_parts
abs_render_pairs <- mapM get_render_pair (catMaybes $ ex_print_file <$>walker_parts)
SC.renderSCADFiles $ abs_render_pairs
where
walker_parts :: [SimplePart]
walker_parts :: [ExtrPart]
walker_parts = uniq $ sort $ concatMap snd $ getWalkerParts walker pconf
use_directive :: String -> LS.TopLevel
use_directive file = LS.UseDirective $ src_dir pconf </> file
part_to_scad :: SimplePart -> IO ()
part_to_scad Part{part_name, model} = SC.renderSCAD (filename ++ ".scad") scad
get_render_pair :: Filename -> IO (Filename,Filename)
get_render_pair b = do
a <- makeAbsolute $ "out/print/" ++ b ++ ".scad"
b <- makeAbsolute $ "out/print/" ++ b ++ ".stl"
return (a,b)
part_to_scad :: ExtrPart -> IO ()
part_to_scad ExtrPart{ex_name, ex_model, ex_print_file} = case ex_print_file of
Just filename -> SC.renderSCAD ("out/print/" ++ filename ++ ".scad") scad
Nothing -> return ()
where
filename :: String
filename = "out/print/" ++ module_name model ++ "_" ++ (show $ hash part_name `mod` 9068 )
scad :: [LS.TopLevel]
scad = ( use_directive <$> imports model) ++ [LS.TopLevelScope $ LS.Module (LS.Ident $ module_name model) (args model) Nothing]
scad = ( use_directive <$> imports ex_model) ++ [LS.TopLevelScope $ LS.Module (LS.Ident $ module_name ex_model) (args ex_model) Nothing]
generateBOM :: ExtendedWalker -> PackageConfig -> IO ()
generateBOM walker pconf = do
mapM_ write_f walker_parts
write_sum (concatMap snd walker_parts)
where
walker_parts :: [(String, [SimplePart])]
walker_parts :: [(String, [ExtrPart])]
walker_parts = getWalkerParts walker pconf
write_f :: (String, [SimplePart]) -> IO ()
write_f :: (String, [ExtrPart]) -> IO ()
write_f (filebase, p) = do
let filename = "out/bom/" ++ filebase ++ ".csv"
createDirectoryIfMissing True $ takeDirectory filename
BSL.writeFile filename (CSV.encode $ parts_to_CSV p)
write_sum :: [SimplePart] -> IO ()
write_sum :: [ExtrPart] -> IO ()
write_sum parts = do
let filename = "out/bom/summary.csv"
createDirectoryIfMissing True $ takeDirectory filename
BSL.writeFile filename (CSV.encode $ parts_to_CSV parts)
parts_to_CSV :: [SimplePart] -> [(Int, String)]
parts_to_CSV :: [ExtrPart] -> [(Int, String, Maybe Filename)]
parts_to_CSV iparts =
(\x -> (length x, head x)) <$> (group $ sort (part_name <$> iparts))
(\x -> (length x, ex_name $ head x, (\x -> x ++ ".stl") <$> (ex_print_file $ head x))) <$> (group $ sort iparts)
......@@ -52,7 +52,7 @@ module LX15D_cable_holder_B_screw_pos(off, y_offset) {
}
module LX15D_cable_holder_B_body(part_i, z_offset, h, w, t, off, screw_off,
screw_d, screw_y_offset) part("deeppink")
screw_d, screw_y_offset) part("deeppink", printed=true)
difference() {
s = 3;
r = 2;
......@@ -166,7 +166,7 @@ module LX15D_cable_holder_C_screw_pos(t) {
j * (LX15D_dim[2] - t * 2 - Md(M2L8C)) / 2
]) rotate([ 0, 90, 0 ]) children();
}
module LX15D_cable_holder_C_lock(t, s, w, harness_w) part("deeppink")
module LX15D_cable_holder_C_lock(t, s, w, harness_w) part("deeppink", printed=true)
difference() {
h = s + t * 2;
l = Md(M2L8C) + t * 2;
......@@ -183,7 +183,7 @@ module LX15D_cable_holder_C_lock(t, s, w, harness_w) part("deeppink")
LX15D_cable_holder_C_screw_pos(t = t) translate([ 0, 0, -Ml(M2L8C) ])
Mscrew_hole(M2L8C);
}
module LX15D_cable_holder_C_body(t, s, w, harness_w) part("cyan") difference() {
module LX15D_cable_holder_C_body(t, s, w, harness_w) part("cyan", printed=true) difference() {
l = LX15D_dim[1];
h = s / 2 + t;
union() {
......
......@@ -7,7 +7,7 @@ LX15D_U_offset = [ 40, 0, 0 ];
LX15D_U_screw_y = 16;
module LX15D_U_body(class)
part("blue", part_name = str("SCAD: LX15D_U_body(", Tname(class), ")"))
part("blue", part_name = str("SCAD: LX15D_U_body(", Tname(class), ")"), printed=true)
difference() {
t = 2;
translate([ -LX15D_U_h / 2, 0, 0 ])
......@@ -28,7 +28,7 @@ module LX15D_U_body(class)
}
}
module LX15D_U_plate(class, t = 2)
part("yellow", part_name = str("SCAD: LX15D_U_plate(", Tname(class), ")"))
part("yellow", part_name = str("SCAD: LX15D_U_plate(", Tname(class), ")"), printed=true)
mirror([ 0, 0, 1 ]) difference() {
union() {
translate(LX15D_U_offset - [ LX15D_U_h / 2, 0, LX15D_dim[2] / 2 + t / 2 ])
......@@ -46,14 +46,14 @@ module LX15D_U_plate(class, t = 2)
}
module LX15D_U_plate_cable(class, t, s)
part("yellow", part_name = str("SCAD: LX15D_U_plate_cable(", Tname(class),
")")) difference() {
")"), printed=true) difference() {
LX15D_U_plate(class, t = t + s / 2);
translate(LX15D_U_offset - [ LX15D_U_h / 2, 0, LX15D_dim[2] / 2 + t + s / 2 ])
cable_harness(w = LX15D_U_screw_y, s = s, r = t, l = LX15D_U_h);
}
module LX15D_U_plate_cable_lock(class, t, s)
part("blue", part_name = str("SCAD: LX15D_U_plate_cable_lock(",
Tname(class), ",", t, ",", s, ")")) difference() {
Tname(class), ",", t, ",", s, ")"), printed=true) difference() {
hull() translate(LX15D_U_offset -
[ LX15D_U_h / 2, 0, LX15D_dim[2] / 2 + t + s / 2 ]) {
for (i = [ -0.5, 0.5 ])
......@@ -109,7 +109,7 @@ LX15D_BU_h = 6;
LX15D_BU_t = 3;
LX15D_BU_screw_a = 10;
LX15D_BU_offset = [ -25, 0, 0 ];
module LX15D_BU_plate() part("blue") difference() {
module LX15D_BU_plate() part("blue", printed=true) difference() {
t = LX15D_BU_t;
h = 5;
horn_a = LX15D_horn_screw_d + t;
......@@ -127,7 +127,7 @@ module LX15D_BU_plate() part("blue") difference() {
translate(LX15D_BU_offset + [ LX15D_BU_h / 2, i * LX15D_BU_screw_a, t ])
rotate([ 180, 0, 0 ]) Mscrew_hole(M2L8C);
}
module LX15D_BU_body() part("yellow")
module LX15D_BU_body() part("yellow", printed=true)
translate(LX15D_BU_offset + [ LX15D_BU_h / 2, 0, 0 ]) difference() {
t = LX15D_BU_t;
dim = [ LX15D_BU_h, LX15D_BU_screw_a + t * 2, LX15D_horn_w ];
......
......@@ -25,7 +25,7 @@ module battery() part("red", part_name="18650 battery") {
rotate([ 0, 90, 0 ]) cylinder(d = batt[0], h = batt[1], center = true);
}
module bat_pcb() part("blue") { linear_extrude(height = 2) pack_shape(); }
module bat_pcb() part("blue", part_name="Bat PCB") { linear_extrude(height = 2) pack_shape(); }
bat_holder_h = 5;
......@@ -37,7 +37,7 @@ module bat_set() union() {
rotate([ 0, 0, 90 ]) battery();
}
module bat_holder() part("red") translate([ 0, 0, -bat_holder_h ])
module bat_holder() part("red", printed=true) translate([ 0, 0, -bat_holder_h ])
difference() {
h = bat_holder_h;
......
......@@ -25,7 +25,7 @@ module body_collision(positions) {
cube([ xplate_l, xplate_w, xplate_h * 2 + xplate_tile_h * 2 ], center = true);
}
module spine() part("white") {
module spine() part("white", printed=true) {
for (i = [-2.5:2.5]) translate([ i * Ta(T24), 0, Ta(T24) ]) tile_box(T24);
for (i = [ -2.5, 2.5 ]) translate([ i * Ta(T24), 0, 0 ]) tile_box(T24);
}
......@@ -37,7 +37,7 @@ module servo_pos(coord) {
}
}
module rpi4() part("darkgray", part_name="rpi4") {
module rpi4() part("green", part_name="rpi4"){
translate([ -85 / 2, -56 / 2, 0 ]) import("rpi4.stl");
}
module nucleo() part("white", part_name="nucleo") {
......
......@@ -13,12 +13,12 @@ module femur_collision_a(tibiaOffset) translate([ 0, plate_a / 2 + w / 2, 0 ]) {
hull() {
cube([ Ta(T24), w, Ta(T24) ], center = true);
translate([ 0, 0, tibiaOffset[2] ])
cube([ Ta(T24), w, Ta(T24) ], center = true);
cube([ Ta(T24), w, Ta(T24) ], center = true);
}
translate([ 0, 0, tibiaOffset[2] ]) hull() {
cube([ Ta(T24), w, Ta(T24) ], center = true);
translate([ tibiaOffset[0], 0, 0 ])
cube([ Ta(T24), w, Ta(T24) ], center = true);
cube([ Ta(T24), w, Ta(T24) ], center = true);
}
}
module femur_collision_b(tibiaOffset) {
......@@ -45,7 +45,9 @@ module middle_pos(tibiaOffset) {
module screw_base() { cylinder(d = screw_d + t * 2, h = w); }
module femur_plate(tibiaOffset) part("purple", part_name=str("SCAD: femur_plate(",tibiaOffset,")")) {
module femur_plate(tibiaOffset)
part("purple", part_name = str("SCAD: femur_plate(", tibiaOffset, ")"),
printed = true) {
for (x = [0:Ta(T24):tibiaOffset[0] - 19])
translate([ x, 0, tibiaOffset[2] ]) {
rotate([ -90, 0, 0 ]) tile(T24, w, center = true);
......@@ -54,40 +56,40 @@ module femur_plate(tibiaOffset) part("purple", part_name=str("SCAD: femur_plate(
difference() {
union() {
hull() {
translate([ 0, 0, -Ta(T24) / 2 + tibiaOffset[2] ])
cube([ Ta(T24) * 3 / 4, w, t ], center = true);
rotate([ -90, 45, 0 ]) translate([ 0, 0, -w / 2 ])
LX15D_horn_screw_pos() screw_base();
translate([ 0, 0, -Ta(T24) / 2 + tibiaOffset[2] ])
cube([ Ta(T24) * 3 / 4, w, t ], center = true);
rotate([ -90, 45, 0 ]) translate([ 0, 0, -w / 2 ])
LX15D_horn_screw_pos() screw_base();
}
hull() {
translate(tibiaOffset + [ 0, -w / 2, 0 ]) rotate([ -90, 45, 0 ])
LX15D_horn_screw_pos() screw_base();
translate(tibiaOffset + [ -19 / 2, 0, 0 ])
cube([ t, w, 24 * 3 / 4 ], center = true);
minkowski() {
intersection() {
translate(tibiaOffset + [ 50, 0, 0 ])
cube([ 100, w - 1, 24 / 2 ], center = true);
rotate([ 90, 0, 0 ])
cylinder(r = support_r, h = w - 1, center = true, $fn = 128);
}
rotate([ 90, 0, 0 ]) cylinder(r = support_rr, h = 1, center = true);
}
translate(tibiaOffset + [ 0, -w / 2, 0 ]) rotate([ -90, 45, 0 ])
LX15D_horn_screw_pos() screw_base();
translate(tibiaOffset + [ -19 / 2, 0, 0 ])
cube([ t, w, 24 * 3 / 4 ], center = true);
minkowski() {
intersection() {
translate(tibiaOffset + [ 50, 0, 0 ])
cube([ 100, w - 1, 24 / 2 ], center = true);
rotate([ 90, 0, 0 ])
cylinder(r = support_r, h = w - 1, center = true, $fn = 128);
}
rotate([ 90, 0, 0 ]) cylinder(r = support_rr, h = 1, center = true);
}
}
}
screw_pos(tibiaOffset) cylinder(d = screw_d, h = 100, center = true);
screw_center_pos(tibiaOffset)
cylinder(d = LX15D_horn_clearance_d, h = 100, center = true);
cylinder(d = LX15D_horn_clearance_d, h = 100, center = true);
}
}
module femur(tibiaOffset, expand = 0) {
for (i = [ -0.5, 0.5 ])
translate([ 0, i * (plate_a + w / 2 + 2 * expand), 0 ])
femur_plate(tibiaOffset);
femur_plate(tibiaOffset);
for (i = [ -0.5, 0.5 ])
translate([ 0, i * (plate_a + w + expand * 6), 0 ]) screw_pos(tibiaOffset)
rotate([ i * 180 + 90, 0, 0 ]) Mscrew(M3L8C);
rotate([ i * 180 + 90, 0, 0 ]) Mscrew(M3L8C);
}
module part(part_color="red", part_name=undef) color(part_color) render(){
module part(part_color="red", part_name=undef, printed=false) color(part_color) render(){
// dummy moduel for smart parser :)
children();
}
......@@ -41,7 +41,7 @@ module M3_hole(l) {
cylinder(d = 6, h = 2);
}
module bot_rpi_holder() part("yellow") difference() {
module bot_rpi_holder() part("yellow", part_name = "SCAD: bot_rpi_holder()", printed=true) difference() {
union() {
baseplate();
rpi_screw_pos() cylinder(d = col_d, h = z_off + bot_col_h);
......@@ -55,7 +55,7 @@ module bot_rpi_holder() part("yellow") difference() {
}
}
module top_rpi_holder() part("yellow") difference() {
module top_rpi_holder() part("yellow", part_name = "SCAD: top_rpi_holder()", printed=true) difference() {
union() {
translate([ 0, 0, h ]) rotate([ 180, 0, 0 ]) difference() {
baseplate();
......
......@@ -38,7 +38,7 @@ module tip_cyli() {
tip_h = Ta(T24) / 2;
module tip() part("yellow") difference() {
module tip() part("yellow", printed=true) difference() {
intersection() {
linear_extrude(height = 30) tile_relief(T24);
rotate([ 90, 0, 0 ]) tip_cyli();
......
......@@ -31,7 +31,7 @@ module tile_pos(class, h, center = false)
linear_extrude(height = h, center = center, convexity = 10)
tile_relief(class = class);
module tile_H(class, h, n = 1, center_t = undef) part("purple", part_name=str("SCAD: tile_H(", Tname(class), ",",h,",",h,",",center_t,")")) render()
module tile_H(class, h, n = 1, center_t = undef) part("purple", part_name=str("SCAD: tile_H(", Tname(class), ",",h,",",h,",",center_t,")"), printed=true) render()
difference() {
top_offset = n * Ta(class) + h;
z_center = n * Ta(class) / 2 + h;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment