-- $Id: precollimator_02.lua,v 1.1 1999/02/01 21:53:09 gaetz Exp $ -- File : precollimator_02.lua -- Extensively rewritten from precollimator_01.lua (is, 10-17-96) -- Last rev. 1999-01-20 (tjg) -- -------------------------------------------------------------- -- Parameters used for rigid body motion: -- mvx, mvy, mvz, mvazmis, mvelmis, mvclock -- -------------------------------------------------------------- -- PREVIOUS INFO: -- -------------- -- Precollimator model containing all plates for shells 1,3,4,6 -- This module may be used directly, in which case the front of the -- CAP has a z value of 0.0. -- All lengths are in mm; angles are in degrees -- This is the version using 'override()' to select a shell -- (Based on modules from T. Gaetz and on precollimator.lua by D. Jerius) -- ---------------------------------------------------------------------- $debug -- --------------------------------------------------------------------- prog = 'precollimator_02.lua' AXAF_ROOT = getenv('AXAF_ROOT') if ( nil == AXAF_ROOT ) then error ( prog .. ': unable to read environmental variable AXAF_ROOT' ) end dofile( AXAF_ROOT .. '/simul/lib/lua/RDB.lua' ) dofile( AXAF_ROOT .. '/simul/lib/lua/store.lua' ) deg2rad = 3.14159265358979/180.0 inch2mm = 25.4 mm2inch = 1.0/25.4 -- Set up shell (1,3,4,6) first. -- Set some default values: -- shell = 1 -- plate_id = 1 first_plate = 1 last_plate = 0 if ( nil == debug_plate ) then debug_plate = 0 end strut_width = 0.5 * 25.4 -- width of struts in mm -- --------------------------------------------------------------------------- -- translation and rotation parameters mvx = 0.0 mvy = 0.0 mvz = 0.0 mvazmis = 0.0 mvelmis = 0.0 mvclock = 0.0 -- --------------------------------------------------------------------------- -- used to select a shell and set other parameters override() -- tolerance scaling; +1 less vignetting; -1 less ghosting if ( nil == tol_scale ) then tol_scale = 0.0 end if ( nil == precoll_coordsys ) then precoll_coordsys = 'XRCF' end if ( nil == precoll_dir ) then precoll_dir = AXAF_ROOT .. '/simul/databases/apertures/precollimator_data/' end if ( nil == shell ) then error( prog .. ': shell not set' ) end precoll_db = 'precoll_data_01.rdb' precoll = precoll_dir .. precoll_db -- --------------------------------------------------------------------------- -- The functions below set up all the geometric and motion data structures -- ==== 1 ================================================================ function setup_basedata() ------------------------------ -- This function assigns values for annulus radii, for each plate in each shell -- Last rev. 10-17-96 (is) rdb = RDB:new( precoll ) if ( nil == rdb ) then error( prog .. ': unable to open data file: \n' .. precoll ) end -- find the entry which corresponds to this shell match = nil cols = rdb:cols( ) data = rdb:read( ) -- Record: Plates 1-11; z - axial coordinate, ri - inner radius, ro - outer radius -- Dimensions are in mm; in raytrace coordinates. plate_data = {} pid = 0 while ( not match ) do if ( shell == data.shell ) then pid = pid + 1 if ( precoll_coordsys == 'XRCF' ) then plate_data[pid] = { z = -data.X, ri = data.R_i, ro = data.R_o, dri = data.tol_R_i, dro = data.tol_R_o, dz = -data.delta_X, dy = data.delta_Z, dx = -data.delta_Y, azmis = data.theta_Z, elmis = data.theta_Y, clock = data.theta_X } elseif ( precoll_coordsys == 'AXAF' ) then plate_data[pid] = { z = -data.X, ri = data.R_i, ro = data.R_o, dri = data.tol_R_i, dro = data.tol_R_o, dz = -data.delta_X, dy = -data.delta_Z, dx = data.delta_Y, azmis = -data.theta_Z, elmis = -data.theta_Y, clock = data.theta_X } end end data = rdb:read( ) if ( nil == data ) then match = 1 end end last_plate = pid if not match then error( prog .. ": couldn't find shell=" .. shell .. " in " .. precoll ) end -- z of the precollimator center in raytrace coordinates: zpreco_center = (plate_data[first_plate].z + plate_data[last_plate].z)/2.0 pid = first_plate while pid <= last_plate do plate_data[pid].z = plate_data[pid].z - zpreco_center pid = pid + 1 end return last_plate end -- End set_basedata() function -- ==== 2 =============================================================== function set_tolerances() -------------------------------- -- This function assigns machining tolerance values for annulus radii, -- for each plate in each shell -- Last rev. 10-17-96 (is) -- Now add machining tolerances to annulus radii pid = first_plate while pid <= last_plate do plate_data[pid].ri = plate_data[pid].ri + tol_scale * plate_data[pid].dri plate_data[pid].ro = plate_data[pid].ro - tol_scale * plate_data[pid].dro pid = pid + 1 end end -- end of function: 'set_tolerances()' -- ==== 3 =============================================================== function move_body( ) --------------------- -- Last rev. 6-28-96 (is) -- Motion should happen in the Body Centered Coordinate System (OSAC v7 p4-4, BCS) -- NOTE: angles need to be in radians for standard 'Aperture' package routines. -- NOTE: distances are in mm. -- Variable 'motion' : function name performing -- ================ -------- ---- ---------- -- decenter mvx, mvy X, Y translations -- despace mvz Z translation -- tilt mvazmis, mvelims azims, elims rotations -- clock mvclock clock rotation around Z -- Still TB checked : for the right order: OSAC requires : -- 1) Rotate around old OY with azmis -- 2) Rotate around old OX with elmis -- 3) Rotate around new OZ with clock (TG) rotate_y( mvazmis * deg2rad ) -- This rotation should be around 'old' OX axis -- push_ctm() -- (push current transformation matrix) rotate_x( mvelmis * deg2rad ) -- pop_ctm() -- (pop current transformation matrix) -- This rotation should be around 'new' OZ axis (clock) rotate_z(mvclock * deg2rad) -- This translation should be along 'old' OX OY axes (decenter) -- push_ctm() -- (push current transformation matrix) translate( mvx, mvy, 0 ) -- pop_ctm() -- (pop current transformation matrix) -- This translation should be along 'old' OZ axis (despace) -- push_ctm() -- (push current transformation matrix) translate( 0, 0, mvz ) -- pop_ctm() -- (pop current transformation matrix) end -- end of function 'move_body()' -- ==== 4 =============================================================== function move_plate( pid ) -------------------------- -- Apply specified motion tweaks to a specified plate -- Last rev. 6-28-96 (is) local id id = pid -- Decenter, X, Y translations -- Despace, Z translation -- Tilt, azims, elims rotations -- Clock rotation around Z axis mvx = plate_data[id].dx mvy = plate_data[id].dy mvz = plate_data[id].dz mvazmis = plate_data[id].azmis mvelmis = plate_data[id].elmis mvclock = plate_data[id].clock move_body( ) end -- end of function: move_plate( ) -- ==== 5 =============================================================== function do_struts( ) --------------------- -- standard function to do the struts -- Last rev. 6-28-96 (is) local theta = 0 local dtheta = 30 begin_subassembly( ) while theta < 180 do strut( strut_width, 1, 0 ) rotate_z ( dtheta * deg2rad ) theta = theta + dtheta end end_subassembly( ) end -- ==== 6 =============================================================== function do_plate( pid ) ----------------------- -- standard function to do a plate -- Last rev. 10-17-96 (is) begin_subassembly() translate( 0, 0, plate_data[pid].z) if ( pid == debug_plate ) then print_photon( 'raw_project' ) end annulus( plate_data[pid].ri, plate_data[pid].ro, 0, 0 ) do_struts( ) end_subassembly( ) end -- ==== 7 ============================================================== function precollimator() -------------------------------------------- -- Precollimator assembly function -- Last rev. 10-17-96 (is) local id begin_assembly("pass") last_plate = setup_basedata() -- set up shell data set_tolerances() -- add tolerances -- the precollimator is specified in body centered coordinates -- move it to the correct position in raytrace coordinates -- note that zpreco_center is the position of the body -- center in raytrace coordinates. translate(0,0, zpreco_center) --> move_body( ) -- move : for test only ..... -- print_xfrm( ) -- for tests only id = first_plate while id <= last_plate do --> pushctm() move_plate( id ) -- tweak the plate do_plate( id ) --> popctm() id = id + 1 end end_assembly( ) end -- end of precollimator as 'rigid body' -- ==== 8 ================================================================= -- Now run the precollimator for the given shell ------------------------------------------------ -- push_ctm() -- push current transformation matrix -- print_xfrm( ) -- for test only move_body( ) -- Move it as needed; all parameters are applied -- pop_ctm() -- push current transformation matrix -- print_xfrm( ) -- for test only -- translate the precollimator using the offset below -- this is the actual value for the offset from 'datum A' (cap front) precollimator() -- create the precollimator assembly -- print_xfrm( ) -- for test only