icub-basic-demos
generate_shape_model.py
1 # Copyright: (C) 2019 iCub Tech Facility - Istituto Italiano di Tecnologia
2 # Authors: Ugo Pattacini <ugo.pattacini@iit.it>
3 # CopyPolicy: Released under the terms of the GNU GPL v3.0.
4 
5 # This script generates the ball shape model
6 # composed of initial estimates of its radius
7 
8 import argparse
9 import math
10 
11 parser = argparse.ArgumentParser()
12 parser.add_argument("-r", "--radius", type=float,
13  help="ball radius in millimeters (default: 30)", default=30)
14 parser.add_argument("-p", "--percentage", type=float,
15  help="percentage in [0, 100] for inner and outer radii (default: 20)", default=20)
16 parser.add_argument("-n", "--points", type=int,
17  help="number of points generated (default: 50)", default=50)
18 parser.add_argument("-f", "--file", type=str,
19  help="name of the generated file (default: shape_model.csv)", default='shape_model.csv')
20 args = parser.parse_args()
21 
22 print('using:')
23 print('radius = {} [mm]'.format(args.radius))
24 print('percentage = {} [%]'.format(args.percentage))
25 print('points = {}'.format(args.points))
26 print('file = "{}"'.format(args.file))
27 
28 R_i = (1.0 - (args.percentage / 100.0)) * args.radius
29 R_o = (1.0 + (args.percentage / 100.0)) * args.radius
30 
31 x = []
32 y = []
33 z = []
34 t = 0.0
35 t_delta = (2.0 * math.pi) / args.points
36 for i in range(args.points):
37  x.append(0.0)
38  y.append(math.sin(t))
39  z.append(math.cos(t))
40  t += t_delta
41 
42 fout = open(args.file, "w")
43 for i in range(args.points):
44  fout.write('{0:.3f}\n'.format(x[i]))
45 for i in range(args.points):
46  fout.write('{0:.3f}\n'.format(x[i]))
47 for i in range(args.points):
48  fout.write('{0:.3f}\n'.format(R_i * y[i]))
49 for i in range(args.points):
50  fout.write('{0:.3f}\n'.format(R_o * y[i]))
51 for i in range(args.points):
52  fout.write('{0:.3f}\n'.format(R_i * z[i]))
53 for i in range(args.points):
54  fout.write('{0:.3f}\n'.format(R_o * z[i]))
55 fout.close()