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

made progress on units in config

parent bdc5db07
// rendered by script, do not edit manually!
leg_holder_h = 1.0381;
leg_holder_h = 39.425;
mount_screw_d = 0.003;
mount_screw_d = 3.0;
t = 0.004;
t = 4.0;
strip_t = 0.002;
strip_t = 2.0;
plate_t = 0.002;
plate_t = 2.0;
strip_w = 0.02;
strip_w = 20.0;
// rendered by script, do not edit manually!
rpi_screw_d = 0.0025;
rpi_holes_y = 0.049;
rpi_holes_x = 0.058;
rpi_offset = [-0.02,0,0];
rpi_screw_d = 2.5;
rpi_holes_y = 49.0;
rpi_holes_x = 58.0;
rpi_offset = [-20.0,0,0];
battery_dim = [0.08,0.012,0.035];
battery_offset = [-0.005,0,0];
battery_dim = [80.0,12.0,35.0];
battery_offset = [-5.0,0,0];
// rendered by script, do not edit manually!
clearance = 0.01;
clearance = 10.0;
camera_holder_t = 0.003;
camera_holder_t = 3.0;
yaw_rot = [0,0,180];
yaw_pos = [0.009,0.0,0.0391];
yaw_pos = [9.0,0,39.1];
horn_angle = -0.174532925199;
horn_holes_step = 0.002;
horn_holes_first = 0.0045;
horn_holes_n = 6.0;
horn_d = 0.0071;
horn_d2 = 0.001;
horn_angle = -10.0;
horn_holes_step = 2.0;
horn_holes_first = 4.5;
horn_holes_n = 6;
horn_d = 7.1;
horn_d2 = 1.0;
camera_offset = [0.025,0.0055,-0.0215];
camera_offset = [25.0,5.5,-21.5];
pitch_offset = [-0.0125,-0.00585,0.01705];
pitch_offset = [-12.5,-5.85,17.05];
t = 0.003;
t = 3.0;
cam_screw_h = 0.004;
cam_screw_d = 0.002;
cam_screw_pos = [0.00935,0.02185];
cam_base_pos = [0.009,0,0.025];
cam_screw_h = 4.0;
cam_screw_d = 2.0;
cam_screw_pos = [9.35,21.85];
cam_base_pos = [9.0,0,25.0];
pi_screw_d = 0.0025;
pi_screw_distance = 0.049;
pi_y_offset = -0.002;
pi_screw_d = 2.5;
pi_screw_distance = 49.0;
pi_y_offset = -2.0;
......@@ -14,18 +14,18 @@ module holder_hole()
}
// use as tibia in entire system
module tibia() {
translate([-mg90s_turret_diameter/2, 0, 0])
rotate([90, 0, -90])
rotate([0, 0, 90]){
mg90s();
color("DarkGray")
translate([0, 11, -4.5])
rotate([0, 0, 90])
import("leg.stl");
mg90s();
}
}
module femur(length){
translate([-mg90s_turret_diameter/2 - servo_horn_h - mg90s_turret_height, 0, 0])
......@@ -64,4 +64,4 @@ module coxa(){
mg90s();
}
}
}
\ No newline at end of file
}
include <leg_modules.scad>;
module fr_beta_joint_pos() translate([0, 0.0125, -1.02105]) rotate([0, 0, 0]){
femur(0.045);
module fr_beta_joint_pos() translate([0, 12.5, -22.375]) rotate([0.0, 0, 0]){
femur(45.0);
children();
}
......@@ -9,16 +9,16 @@ module fr_alfa_joint_pos() translate([0, 0, 0]) rotate([0, 0, 0]){
children();
}
module fr_gama_joint_pos() translate([0, 0.045, 0]) rotate([-1.5707963267948966, 0, 0]){
module fr_gama_joint_pos() translate([0, 45.0, 0]) rotate([-90.0, 0, 0]){
tibia();
children();
}
module fr_leg()translate([0.055, -0.025, 0])rotate([0, 0, -2.6179938779914944])mirror([0, 0, 0]){
module fr_leg()translate([55.0, -25.0, 0])rotate([0, 0, -150.0])mirror([0, 0, 0]){
fr_alfa_joint_pos() fr_beta_joint_pos() fr_gama_joint_pos();
}
module rr_beta_joint_pos() translate([0, 0.0125, -1.02105]) rotate([0, 0, 0]){
femur(0.045);
module rr_beta_joint_pos() translate([0, 12.5, -22.375]) rotate([0.0, 0, 0]){
femur(45.0);
children();
}
......@@ -27,16 +27,16 @@ module rr_alfa_joint_pos() translate([0, 0, 0]) rotate([0, 0, 0]){
children();
}
module rr_gama_joint_pos() translate([0, 0.045, 0]) rotate([-1.5707963267948966, 0, 0]){
module rr_gama_joint_pos() translate([0, 45.0, 0]) rotate([-90.0, 0, 0]){
tibia();
children();
}
module rr_leg()translate([-0.055, -0.025, 0])rotate([0, 0, 2.6179938779914944])mirror([1, 0, 0]){
module rr_leg()translate([-55.0, -25.0, 0])rotate([0, 0, 150.0])mirror([1, 0, 0]){
rr_alfa_joint_pos() rr_beta_joint_pos() rr_gama_joint_pos();
}
module mr_beta_joint_pos() translate([0, 0.0125, -1.02105]) rotate([0, 0, 0]){
femur(0.045);
module mr_beta_joint_pos() translate([0, 12.5, -22.375]) rotate([0.0, 0, 0]){
femur(45.0);
children();
}
......@@ -45,16 +45,16 @@ module mr_alfa_joint_pos() translate([0, 0, 0]) rotate([0, 0, 0]){
children();
}
module mr_gama_joint_pos() translate([0, 0.045, 0]) rotate([-1.5707963267948966, 0, 0]){
module mr_gama_joint_pos() translate([0, 45.0, 0]) rotate([-90.0, 0, 0]){
tibia();
children();
}
module mr_leg()translate([0, -0.03, 0])rotate([0, 0, 3.141592653589793])mirror([1, 0, 0]){
module mr_leg()translate([0, -30.0, 0])rotate([0, 0, 180.0])mirror([1, 0, 0]){
mr_alfa_joint_pos() mr_beta_joint_pos() mr_gama_joint_pos();
}
module rl_beta_joint_pos() translate([0, 0.0125, -1.02105]) rotate([0, 0, 0]){
femur(0.045);
module rl_beta_joint_pos() translate([0, 12.5, -22.375]) rotate([0.0, 0, 0]){
femur(45.0);
children();
}
......@@ -63,16 +63,16 @@ module rl_alfa_joint_pos() translate([0, 0, 0]) rotate([0, 0, 0]){
children();
}
module rl_gama_joint_pos() translate([0, 0.045, 0]) rotate([-1.5707963267948966, 0, 0]){
module rl_gama_joint_pos() translate([0, 45.0, 0]) rotate([-90.0, 0, 0]){
tibia();
children();
}
module rl_leg()translate([-0.055, 0.025, 0])rotate([0, 0, 0.5235987755982988])mirror([0, 0, 0]){
module rl_leg()translate([-55.0, 25.0, 0])rotate([0, 0, 29.999999999999996])mirror([0, 0, 0]){
rl_alfa_joint_pos() rl_beta_joint_pos() rl_gama_joint_pos();
}
module ml_beta_joint_pos() translate([0, 0.0125, -1.02105]) rotate([0, 0, 0]){
femur(0.045);
module ml_beta_joint_pos() translate([0, 12.5, -22.375]) rotate([0.0, 0, 0]){
femur(45.0);
children();
}
......@@ -81,16 +81,16 @@ module ml_alfa_joint_pos() translate([0, 0, 0]) rotate([0, 0, 0]){
children();
}
module ml_gama_joint_pos() translate([0, 0.045, 0]) rotate([-1.5707963267948966, 0, 0]){
module ml_gama_joint_pos() translate([0, 45.0, 0]) rotate([-90.0, 0, 0]){
tibia();
children();
}
module ml_leg()translate([0, 0.03, 0])rotate([0, 0, 0])mirror([0, 0, 0]){
module ml_leg()translate([0, 30.0, 0])rotate([0, 0, 0])mirror([0, 0, 0]){
ml_alfa_joint_pos() ml_beta_joint_pos() ml_gama_joint_pos();
}
module fl_beta_joint_pos() translate([0, 0.0125, -1.02105]) rotate([0, 0, 0]){
femur(0.045);
module fl_beta_joint_pos() translate([0, 12.5, -22.375]) rotate([0.0, 0, 0]){
femur(45.0);
children();
}
......@@ -99,12 +99,12 @@ module fl_alfa_joint_pos() translate([0, 0, 0]) rotate([0, 0, 0]){
children();
}
module fl_gama_joint_pos() translate([0, 0.045, 0]) rotate([-1.5707963267948966, 0, 0]){
module fl_gama_joint_pos() translate([0, 45.0, 0]) rotate([-90.0, 0, 0]){
tibia();
children();
}
module fl_leg()translate([0.055, 0.025, 0])rotate([0, 0, -0.5235987755982988])mirror([1, 0, 0]){
module fl_leg()translate([55.0, 25.0, 0])rotate([0, 0, -29.999999999999996])mirror([1, 0, 0]){
fl_alfa_joint_pos() fl_beta_joint_pos() fl_gama_joint_pos();
}
module legs(){
......@@ -116,10 +116,10 @@ module legs(){
fl_leg();
}
module leg_pos(){
translate([0.055, -0.025, 0])rotate([0, 0, -2.6179938779914944])mirror([0, 0, 0])children();
translate([-0.055, -0.025, 0])rotate([0, 0, 2.6179938779914944])mirror([1, 0, 0])children();
translate([0, -0.03, 0])rotate([0, 0, 3.141592653589793])mirror([1, 0, 0])children();
translate([-0.055, 0.025, 0])rotate([0, 0, 0.5235987755982988])mirror([0, 0, 0])children();
translate([0, 0.03, 0])rotate([0, 0, 0])mirror([0, 0, 0])children();
translate([0.055, 0.025, 0])rotate([0, 0, -0.5235987755982988])mirror([1, 0, 0])children();
translate([55.0, -25.0, 0])rotate([0, 0, -150.0])mirror([0, 0, 0])children();
translate([-55.0, -25.0, 0])rotate([0, 0, 150.0])mirror([1, 0, 0])children();
translate([0, -30.0, 0])rotate([0, 0, 180.0])mirror([1, 0, 0])children();
translate([-55.0, 25.0, 0])rotate([0, 0, 29.999999999999996])mirror([0, 0, 0])children();
translate([0, 30.0, 0])rotate([0, 0, 0])mirror([0, 0, 0])children();
translate([55.0, 25.0, 0])rotate([0, 0, -29.999999999999996])mirror([1, 0, 0])children();
}
// rendered by script, do not edit manually!
servo_horn_d = 0.0071;
servo_horn_h = 0.006;
servo_horn_d2 = 0.001;
servo_horn_t = 0.002;
servo_horn_holes_step = 0.002;
servo_horn_holes_first = 0.0045;
servo_horn_d = 7.1;
servo_horn_h = 6.0;
servo_horn_d2 = 1.0;
servo_horn_t = 2.0;
servo_horn_holes_step = 2.0;
servo_horn_holes_first = 4.5;
servo_horn_holes_n = 6;
mg90s_horn_offset = 0.0111;
mg90s_gimbal_vector = [-0.00585,0.0125,-0.01705];
mg90s_servo_width = 0.0125;
mg90s_servo_length = 0.0229;
mg90s_servo_height = 0.0229;
mg90s_turret_diameter = 0.0117;
mg90s_turret_margin_y = 0.0112;
mg90s_turret_margin_x = 0.0004;
mg90s_turret_height = 0.0052;
mg90s_frame_length = 0.0322;
mg90s_frame_v_offset = 0.016;
mg90s_frame_thickness = 0.00245;
mg90s_axle_diameter = 0.00482;
mg90s_axle_screw_diameter = 0.002;
mg90s_axle_height = 0.0039;
mg90s_horn_offset = 11.1;
mg90s_gimbal_vector = [-5.85,12.5,-17.05];
mg90s_servo_width = 12.5;
mg90s_servo_length = 22.9;
mg90s_servo_height = 22.9;
mg90s_turret_diameter = 11.7;
mg90s_turret_margin_y = 11.2;
mg90s_turret_margin_x = 0.4;
mg90s_turret_height = 5.2;
mg90s_frame_length = 32.2;
mg90s_frame_v_offset = 16.0;
mg90s_frame_thickness = 2.45;
mg90s_axle_diameter = 4.82;
mg90s_axle_screw_diameter = 2.0;
mg90s_axle_height = 3.9;
mg90s_mounting_hole_slot = 1;
mg90s_mounting_hole_diameter = 0.002;
mg90s_mounting_hole_center_offset_y = 1.001;
mg90s_mounting_hole_center_offset_x = 0.00625;
mg90s_mounting_hole_diameter = 2.0;
mg90s_mounting_hole_center_offset_y = 2.325;
mg90s_mounting_hole_center_offset_x = 6.25;
// rendered by script, do not edit manually!
t = 0.003;
t = 3.0;
mount_h = 1.004;
mount_h = 5.325;
h = 0.01;
h = 10.0;
k = 0.0001;
k = 0.1;
spacing = 0.001;
spacing = 1.0;
screw_d = 0.003;
screw_d = 3.0;
screw_offset = -1.0239;
screw_offset = -25.225;
use <../servo/sg9.scad>;
include <../base.scad>;
include <../config.scad>;
include <config.scad>;
include <../servo/config.scad>;
use <../servo/sg9.scad>;
module servo_strengthen()
difference(){
......@@ -43,5 +44,4 @@ difference(){
translate([-mg90s_servo_width/2, -50, -mg90s_servo_height])
cube([mg90s_servo_width*2 + spacing, 100, 100]);
}
\ No newline at end of file
......@@ -13,7 +13,7 @@ mg90s:
slot: 1
center_offset:
x: "% mg90s.servo.width/2 %"
y: "% mg90s.mounting_hole.slot + mg90s.mounting_hole.diameter / 2 %"
y: "% (mg90s.frame.length - mg90s.servo.length)/4 %"
axle:
height: 3.9mm
diameter: 4.82mm
......@@ -109,7 +109,7 @@ default_leg:
- 0
- "% mg90s.servo.width %"
- "% -( mg90s.servo.length - mg90s.turret.diameter / 2 + strengthen.mount_h ) %"
rot: [0, 0, 0]
rot: [0°, 0, 0]
axis: [1, 0, 0]
min: -75°
max: 75°
......
import yaml
import re
import copy
import os
import math
from lxml import etree
def _recur_scad_config(fd, base, variables):
if isinstance(variables, dict):
for key, item in variables.items():
if base == "":
newbase = key
else:
newbase = base + "_" + key
_recur_scad_config(fd, newbase, item)
if base == "":
fd.write("\n")
elif isinstance(variables, (list, tuple)):
fd.write(
"{} = [{}];\n".format(base, ",".join(str(x) for x in variables)))
elif isinstance(variables, (int, float)):
fd.write("{} = {};\n".format(base, variables))
else:
raise Exception("unknown data", variables)
def generate_scad_config(filename, variables):
print("generating scad file: " + filename)
with open(filename, "w") as fd:
fd.write("// rendered by script, do not edit manually!\n")
_recur_scad_config(fd, "", variables)
def generate_scad_joint_pos(fd, key, joint):
fd.write("module " + key + "_joint_pos()")
fd.write(" translate({})".format(joint['pos']))
fd.write(" rotate({})".format(joint['rot']))
fd.write("{\n")
module_args = joint['scad']['args']
module_args = ",".join([str(i) for i in module_args])
fd.write(" {}({});\n".format(joint['scad']['module'], module_args))
fd.write(" children();")
fd.write("\n}\n")
fd.write("\n")
from lib.config import *
from lxml import etree
def generate_scad_leg_pos(filename, legs):
with open(filename, "w") as fd:
fd.write("include <leg_modules.scad>;\n")
for leg_key, leg in legs.items():
for joint_key, joint in leg['joints'].items():
generate_scad_joint_pos(fd, leg_key + "_" + joint_key, joint)
fd.write("module {}_leg()".format(leg_key))
fd.write("translate({})".format(leg['pos']))
fd.write("rotate({})".format(leg['rot']))
fd.write("mirror({})".format(leg['mirror']))
fd.write("{\n")
for key in leg['joint_chain']:
fd.write(" {}_{}_joint_pos()".format(leg_key, key))
fd.write(";\n}\n")
fd.write("module legs(){\n")
for leg_key in legs.keys():
fd.write(" {}_leg();\n".format(leg_key))
fd.write("}\n")
fd.write("module leg_pos(){\n")
for leg_key, leg in legs.items():
fd.write("translate({})".format(leg['pos']))
fd.write("rotate({})".format(leg['rot']))
fd.write("mirror({})".format(leg['mirror']))
fd.write("children();\n")
fd.write("}\n")
def check_stl(filename, module):
......@@ -169,176 +92,3 @@ def generate_urdf_joint(robot,
" return number of replaced items, unreplaced items, new value "
def _parse_val(val, top_cfg):
res = re.match("^\s*%(.*)%\s*$", val)
if res is None:
return 0, 0, val
expr = res.group(1)
base_expr = expr
#print expr
vars = re.findall("[a-zA-Z][a-zA-Z0-9\._]+", expr)
replaced_count = 0
unreplaced_count = 0
for var in vars:
if var in ["max", "min", "abs"]:
continue
keys = var.split('.')
value = top_cfg
while len(keys) > 0:
if isinstance(value, list):
value = value[int(keys[0])]
elif isinstance(value, dict):
try:
value = value[keys[0]]
except KeyError:
raise Exception(
"Using key for variable that does not exist ", keys[0],
" in expression: ", base_expr)
keys = keys[1:]
if isinstance(value, str):
unreplaced_count += 1
continue
#print var, "->", value
expr = expr.replace(var, str(value))
replaced_count += 1
try:
expr = eval(expr)
expr = float(expr)
except:
expr = "%" + expr + "%"
#print val, "=>", expr
#print
return replaced_count, unreplaced_count, expr
# returns number of replaced values
def _parse_config_rec(cfg, top_cfg):
keys = list()
if isinstance(cfg, list):
keys = range(len(cfg))
elif isinstance(cfg, dict):
keys = cfg.keys()
replaced_big_count = 0
unreplaced_big_count = 0
for key in keys:
if isinstance(cfg[key], (float, int, bool)):
continue
elif isinstance(cfg[key], str):
replaced_count, unreplaced_count, res = _parse_val(
cfg[key], top_cfg)
replaced_big_count += replaced_count
unreplaced_big_count += unreplaced_count
cfg[key] = res
else:
replaced_count, unreplaced_count = _parse_config_rec(
cfg[key], top_cfg)
replaced_big_count += replaced_count
unreplaced_big_count += unreplaced_count
return replaced_big_count, unreplaced_big_count
# overlay 'a' over 'b' and return result
def overlay(a, b):
if isinstance(a, list):
assert isinstance(b, list)
keys = range(len(a))
elif isinstance(a, dict):
assert isinstance(b, dict)
keys = a.keys()
res = copy.copy(b)
for key in keys:
if isinstance(a[key], (float, int, bool)):
res[key] = a[key]
elif isinstance(a[key], dict):
try:
res[key] = overlay(a[key], b[key])
except KeyError:
res[key] = a[key]
elif isinstance(a[key], list):
try:
res[key] = overlay(a[key], b[key])
except KeyError:
res[key] = a[key]
return res
class Distance(float):
@classmethod
def from_mm(cls, val):
return cls( val/1000 )
distance_re = re.compile("^\s*([-\d.]+)(mm|m)\s*$")
def distance_constructor(loader, node):
value = loader.construct_scalar(node)
res = re.match(distance_re, value)
val, unit = res.group(1), res.group(2)
val = float(val)
if unit == 'mm':
return Distance.from_mm(val)
elif unit == 'm':
return Distance(val)
yaml.add_constructor(u'!distance', distance_constructor)
yaml.add_implicit_resolver(u'!distance', distance_re)
class Angle(float):
@classmethod
def from_degree(cls, val):
return cls( math.radians(val))
angle_re = re.compile(u"^\s*([-\d.]+)(\xb0*)\s*$")
def angle_constructor(loader, node):
value = loader.construct_scalar(node)
res = re.match(angle_re, value)
val, unit = res.group(1), res.group(2)
val = float(val)
if unit == u'\xb0':
return Angle.from_degree(val)
elif unit == '':
return Angle(val)
yaml.add_constructor(u'!angle', angle_constructor)
yaml.add_implicit_resolver(u'!angle', angle_r