Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Definition and FMS Tool Management Case Study

Similar presentations


Presentation on theme: "Database Definition and FMS Tool Management Case Study"— Presentation transcript:

1 Database Definition and FMS Tool Management Case Study
A Flexible manufacturing system consists of a number of machines or cells each of them capable of handling one tool magazine at a time. The cells use the tools to produce objects according to the instructions in part-programs. The contents of the tool magazines can be changed and they are interchangeable between machines. Answers are required to questions like- Which machine(s), or cell(s), have the appropriate tool mix in their tool magazines to process a given part program? This question could be asked by an FMS production manager, or the FMS scheduling program itself, before finalising the sequence in which the certain part, or parts, will be processed in the system

2 Option 1- An approach to be avoided…..as a warning
First step is to set up some tables (in files) containing the information on about cells, magazines, and workparts. The name of one table is 'machine’ which consists of the following fields machine_id a 16 character long alphanumeric name, containing the machine identifier. Max_power is the maximum machine power in kwatts and is a real number. x_min to z_max describe the motion range limits of the machine in mm. Rot_index stores the size of increment the table is capable of rotating on the X,Y table of the machine. poserr_x_y_z contains the positioning error regarding the relevant axis. controller identifies the type of CNC control used. magazine stores the magazine identifier currently being utilised on the cell. It is assumed that each cell can only have one tool magazine for automated access at any one time.

3 The second file we need must contain information about the tools located in the magazines.
Thus there is a magazine table identifying twelve tool locations. In this example there are only twelve locations in the tool magazines In a real situation machines often have over fifty tools or even more Only one simple code identifying a single tool in the magazine is used.

4 So magazine has the fields-
magazine stores the magazine identifier. T1 to T12 are 8 character fields which hold the tool identifiers of the tools in a particular magazine. i.e. (magazine_Id, T1,T2,T3,T4, T12)

5 The third and last table we set up is called prog_tool.
It contains the tool codes used in different part programs. Again for simplicity we use only six fields describing six tools, although in a real situation a part program could easily require the access of over twenty tools or more. So prog_tool has the fields- Prog_name is a 16 character field containing the part program name T1 to T6 are 8 character fields containing the codes of the tools used in the program. i.e. (prog_name, T1, T2, T3, T4, T5, T6)

6 So, there is- A table telling us which magazine is on which cell A table telling us which tools are in which magazines And a table telling us which tools a part program requires

7 We want the database to find the cell on which there is the appropriate magazine to execute a particular part program. Produce an entity-relationship diagram based on these table definitions. 2. Devise an query to do this based on these table definitions. 3. Assume the database is loaded with data. Write down the steps required to modify the database to accept magazines with twenty tools and part programs that require twenty tools.

8 You should have found that
The data model is a little bizarre-with multiple relationships between the entities That the query is at least very difficult to produce That the tables have to be significantly altered to accommodate the new requirements

9 Option 2 The data has not been modelled correctly-the data model should look like this- Has_mounted Used_on Cell (machine_id, magazine_id etc) Magazine (magazine_id) Mag_Tool (mag_id, tool_id) Tool (tool_id) Prog_Tool (prog_id,tool_id) Program (program_id) Holds Loaded_with Employed_by Requires 0..* 1..1 0..1

10 Create Procedure fmscase
datatype = default value, @parameter2 datatype OUTPUT)*/ As create table magazine (magazine_id varchar(5) not null, constraint magazine_key primary key(magazine_id), constraint mag_check check (magazine_id like 'mag_') );

11 create table machine (machine_id varchar(5), max_power float not null, x_min float, x_max float, y_min float, y_max float, z_min float, z_max float, rotJndex float, poserrx float, poserry float, poserrz float, controller varchar(10), magazine varchar(5), constraint machine_key primary key (machine_id), constraint holds foreign key (magazine ) references magazine(magazine_id) on update no action on delete no action, constraint mc_id_check check (machine_id like 'cell[0-9]'), constraint max_p_check check (max_power>0), constraint x_mincheck check (x_min between and 1500), constraint x_maxcheck check (x_max between and 1500), constraint y_mincheck check (y_min between and 1500), constraint y_maxcheck check (y_max between and 1500), constraint z_mincheck check (z_min between and 1500), constraint z_maxcheck check (z_max between and 1500), constraint rotJndexcheck check (rotJndex between and 1500), constraint poserrxcheck check (poserrx between and 1500), constraint poserrycheck check (poserry between and 1500), constraint poserrzcheck check (poserrz between and 1500), constraint cont_check check (controller in ('cincinnati','hertel','sandvig')));

12 Create table tool ( tool_id varchar(5) not null, constraint tool_key primary key (tool_id), constraint tool_id_check check (tool_id between 't0000' and 't9999') ); create table program (prog_name varchar(6) not null, constraint program_key primary key (prog_name), constraint program_check check (prog_name in ('mill1','bore1','drill1')) Create table mag_tool (magazine_id varchar(5) not null, tool_id varchar(5) not null, constraint mag_tool_key primary key (magazine_id, tool_id), constraint loaded_with foreign key (magazine_id) references magazine(magazine_id) on update cascade on delete cascade, constraint used_on_2 foreign key (tool_id) references tool on update cascade on delete cascade);

13 create table prog_tool
(prog_name varchar(6) not null, tool_id varchar(5) not null, constraint prog_tool_key primary key (prog_name, tool_id), constraint requires foreign key (prog_name) references program on update cascade on delete cascade, constraint employed_with foreign key (tool_id) references tool on update cascade on delete cascade); return

14 Create Procedure fmsinsert
datatype = default value, @parameter2 datatype OUTPUT)*/ As /* set nocount on */ insert into program values ('bore1'); insert into program values ('drill1'); insert into program values ('mill1');

15 insert into tool values('t1002');

16 insert into tool values('t6652');

17 insert into magazine values('mag0');

18 insert into machine values ( 'cell1',15.00, 0,650.0, 0,850.0,
150.0,950.0, 0.1,0.01, 0.01,0.015, 'cincinnati','mag0'); 'cell2',22, 0,800.0, 0,1250.0, 0,1100, 0,0.018, 0.018,0.02, 'cincinnati','mag1'); 'Cell3',15, 0.05,0.005, 0.005,0.01, 'cincinnati','mag2');

19 insert into mag_tool values('mag0','t9001');
/* insert into mag_tool values('mag1','t2626'); removed for query purposes*/

20 insert into mag_tool values('mag1','t1584');
insert into mag_tool values('mag2','tl254'); insert into mag_tool values('mag2', 't8972'); insert into mag_tool values('mag2','t3212'); insert into mag_tool values('mag2','t2341'); insert into mag_tool values('mag2','t2000'); insert into mag_tool values('mag2','t2001'); insert into mag_tool values('mag2','t2002'); insert into mag_tool values('mag2','t9001'); insert into mag_tool values('mag2','t9004');

21 insert into prog_tool values('mill1','t9008');
insert into prog_tool values('bore1','t6800'); insert into prog_tool values('bore1','t2626'); insert into prog_tool values('bore1','t2329'); insert into prog_tool values('bore1','t1002'); insert into prog_tool values('bore1','t5555'); insert into prog_tool values('drill1','t8081'); insert into prog_tool values('drill1','t9102'); insert into prog_tool values('drill1','t7800'); return

22 select * from magazine; A list of all the magazines?'
select * from magazine; A list of all the magazines?' Magazine Mag0 Mag1 Mag2

23 select * from program; A list of all the programs?' prog_name bore1 drill1 mill1

24 select * from mag_tool;
magazine tool_id mag0 t9001 T9004 T9008 T9002 T8081 T9102 T7352 T6739 T3480 T6811 T2329 T1002 Mag1 T8085 T6800 T8087 T8086 T2626 T1584 T5472 T5670 T7800 T4496 T4097 T4797 Mag2 T2109 T3456 T6652 T1254 T8972 T3212 T2341 T2000 T2001 T2002 T9001 select * from mag_tool; 'A list of all the tools on all the magazines?'

25 select * from prog_tool; A list of all the tools used by the programs?
A list of all the tools used by the programs? Prog_name tool_id Mill1 t3480 T9004 T1002 T7352 Bore1 T6800 T2626 T2329 T5555 Drill1 T8081 T9102 T7800

26 select * from tool A list of all the tools?' Tool_id T1002 T1254 T1584
A list of all the tools?'

27 select * from prog_tool; select * from prog_tool order by tool_id
select * from prog_tool order by tool_id prog_name tool_id mill1 t3480 T9004 T1002 T7352 Bore1 T6800 T2626 T2329 T5555 Drill1 T8081 T9102 T7800 prog_name tool_id mill1 T1002 Bore1 T2329 T2626 t3480 T5555 T6800 T7352 Drill1 T7800 T8081 T9004 T9102

28 select machine_id, controller,magazine from machine
What are the controllers and magazines on all the machines? Machine_id controller magazine Cell1 cincinnati Mag0 Cell2 Mag1 Cell3 Mag2

29 machine.magazine=mag_tool.magazine_id and mag_tool.tool_id=’t2626'
select machine_id, controller,magazine from machine where max_power>16.0 What are the controllers and magazines on all the machines that have a maximum power rating greater than 16.0?' Machine_id controller magazine Cell2 cincinnati mag1 select machine_id, mag_too, magazine_id, tool_id from machine,mag_tool where machine.magazine=mag_tool.magazine_id and mag_tool.tool_id=’t2626' Which machines have a magazine with tool ‘t2626’?' Machine_id magazine Tool_id Cell2 Mag1 T2626

30 select prog_name from prog_tool
where not exists (select * from mag_tool where progtool. tool_id=mag_tool.tool_id) Does any program require a tool that is not in a magazine on the machines?' Prog_name Bore1

31 select count( tool_id),prog_name from prog_tool group by prog_name;
*How many tools does each program need ?' COUNT(TOOLID) PROG NAME 5 bore1 3 drill1 4 mill1

32 'Which programs require the use of more than three tools ?'
select count(tool_id),prog_name from prog_tool group by prog_name having count(tool_id)>3 'Which programs require the use of more than three tools ?' count(tool_id) prog_name 5 bore1 4 mill1 Could be written as a stored procedure using parameter thus- create procedure int) as select count(tool_id),prog_name from prog_tool group by prog_name having exec min_no_of_tools 2

33 select count(tool_id),prog_name from prog_tool where prog_name<>’bore1’
group by prog_name having count(tool_id)>3 'Which programs need more than 3 tools except bore1 ?' COUNT(TOOL ID) PROG NAME 4 mill1

34 select avg(maxpower) from machine;
avg(max_power) prog_name bore1 drill1 mill1 select distinct prog_name from prog_tool; select max(max_power) from machine; MAX(MAX POWER) 22 select sum(max_power) from machine; sum(max_power) 52

35 Could be written as a stored procedure using parameter thus-
select magazine_id from magazine where not exists (select * from prog_tool where not exists (select * from mag_tool where progtool.tool_id=mag_tool. tool_id and magazine.magazine_id=mag_tool.magazine_id) and prog_name='mill1’) Which magazine has all the tools for job mill1?' Magazine_id Mag0 Could be written as a stored procedure using parameter thus- create procedure varchar(6)) as select magazine_id from magazine where not exists (select * from prog_tool where not exists (select * from mag_tool where Prog_tool.tool_id=mag_tool. tool_id and magazine.magazine_id=mag_tool.magazine_id) and exec all_tools ‘mill1’

36 select machine_id from machine where magazine in (select magazine_id from magazine
where not exists (select * from prog_tool where not exists (select * from mag_tool where Prog_tool tool_id=mag_tool. tool_id and magazine.magazine_id=mag_tool.magazine_id) and prog_name='mill1’)) Which machine has the magazine to do all of job mill1?' Machine_id cell1

37 ‘Executive’ Commands to Manipulate Schema and Data
exec fmscase /* executes schema */ exec fmsinsert /*insert example data */ exec dropfms /* removes schema */ exec fmsq1 /*example data manipulation */ exec fmsq2 /*example data manipulation */ exec storedprocedure1 'cell5',10,0.0 /*insert with parameters */

38 Extracting Metadata select * from machine select * from information_schema.tables select * from information_schema.columns select * from information_schema.referential_constraints /* lists foreign key constraints */ select * from information_schema.table_constraints

39 exec sp_tables exec sp_stored_procedures /* lists stored procedures */ exec sp_helptext stored_procedure1 /*lists text of stored procedures and other objects */ exec sp_helpconstraint prog_tool /* lists text of constraints inc. foreign and primary key constraints */ exec sp_helptrigger machine /* lists text of trigger */ exec sp_help machine_Trigger3 exec sp_helptext machine_Trigger3 /* lists trigger text */

40 Stored Procedure-insert with parameters
Alter Procedure float) /* datatype = default value, @parameter2 datatype OUTPUT) */ As /* set nocount on */ insert into machine values @m_power, @xmin, 650.0,0,850.0,150.0,950.0,0.05,0.005,0.005,0.01,'cincinnati','mag2'); return exec storedprocedure1 'cell5',10,0.0

41 Insert Trigger-Correlating values in columns
alter trigger power_x_limit on machine for insert as int from inserted begin update machine set x_min=10 where max_power>10 end

42 create trigger x_check
ON machine FOR INSERT, UPDATE AS float float select * from inserted select from inserted if begin RAISERROR (‘x_max must be greater than or equal to x_min', 16, 10) rollback end

43 Consider that some tools cannot be removed from Magazines
create table fixed_tools (magazine_id varchar(5), tool_id varchar(5), constraint ft_key primary key (magazine_id, tool_id)); insert into fixed_tools values('mag0','t1002'); insert into fixed_tools values('mag0','t2329'); insert into fixed_tools values('mag0','t3480'); drop table fixed_tools

44 create trigger tool_prev_del
on mag_tool for delete,update as varchar(5) from deleted in (select tool_id from fixed_tools) begin raiserror(‘This tool cannot be removed from the magazine',16,1) rollback end

45 Create procedure tool_log_create
datatype = default value, @parameter2 datatype OUTPUT)*/ As /* set nocount on */ create table tool_log (tool_replaced varchar(5), new_tool varchar(5), date_replaced datetime, constraint toollogkey primary key (tool_replaced, date_replaced)) return

46 To keep a log of tool changes-
create trigger tool_Trigger1 On tool For Update, Delete As datetime varchar(5) varchar(5) If Update (tool_id) begin from inserted from deleted insert End Else begin insert into end


Download ppt "Database Definition and FMS Tool Management Case Study"

Similar presentations


Ads by Google