-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMachines.cs
142 lines (125 loc) · 4.39 KB
/
Machines.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ExceptionServices;
using UnityEngine;
public class Machines : MonoBehaviour
{
//Instantiate machine transforms
public Transform Target1;
public Transform Target2;
public Transform Target3;
public Transform Target4;
public Transform Target5;
public Transform Target6;
public Transform Target7;
//Access to robot agents to end their training episode when jobs at all machines are completed
public MobileRobotAgent robot;
public MobileRobotAgent robot2;
public MobileRobotAgent robot3;
//Machine states, 0 = 'Completed processing' state, 1 = 'Processing' state
public int[] Flags = {0, 0, 0, 0, 0, 0, 0};
//Store time when processing starts, uncomment for repeated cycle testing
//public int[] Temp = {100, 100, 100, 100, 100, 100, 100};
//Processing time, uncomment when testing repeated cycles
//public int[] Process = {0, 0, 0, 0, 0, 0, 0};
//Color for completed processing state
public Color Green = new Color(0f, 1f, 0f, 1f);
//Color for processing state
public Color Red = new Color(1f, 0f, 0f, 1f);
//Called on episode beginning to reset all machines
public void Start()
{
Flags[0] = 0;
Flags[1] = 0;
Flags[2] = 0;
Flags[3] = 0;
Flags[4] = 0;
Flags[5] = 0;
Flags[6] = 0;
Target1.GetComponent<MeshRenderer>().material.color = Green;
Target1.tag = "Machine A";
Target2.GetComponent<MeshRenderer>().material.color = Green;
Target2.tag = "Machine B";
Target3.GetComponent<MeshRenderer>().material.color = Green;
Target3.tag = "Machine C";
Target4.GetComponent<MeshRenderer>().material.color = Green;
Target4.tag = "Machine D";
Target5.GetComponent<MeshRenderer>().material.color = Green;
Target5.tag = "Machine E";
Target6.GetComponent<MeshRenderer>().material.color = Green;
Target6.tag = "Machine F";
Target7.GetComponent<MeshRenderer>().material.color = Green;
Target7.tag = "Machine G";
}
public void Check()
{
if (Flags[0] == 1 && Flags[1] == 1 && Flags[2] == 1 && Flags[3] == 1 && Flags[4] == 1 && Flags[5] == 1 && Flags[6] == 1) //If all jobs are assigned,
{
UnityEngine.Debug.Log("All Targets Met");
EndAll();//End episodes
}
}
//Uncomment for repeated cycle testing
/*void Update()
{
if ((int)Time.time == Temp[0] + Process[0]) //If processing time is over, switch state
{
Flags[0] = 0;
Target1.GetComponent<MeshRenderer>().material.color = Green;
Target1.tag = "Machine A";
}
if ((int)Time.time == Temp[1] + Process[1])
{
Flags[1] = 0;
Target2.GetComponent<MeshRenderer>().material.color = Green;
Target2.tag = "Machine B";
}
if ((int)Time.time == Temp[2] + Process[2])
{
Flags[2] = 0;
Target3.GetComponent<MeshRenderer>().material.color = Green;
Target3.tag = "Machine C";
}
if ((int)Time.time == Temp[3] + Process[3])
{
Flags[3] = 0;
Target4.GetComponent<MeshRenderer>().material.color = Green;
Target4.tag = "Machine D";
}
if ((int)Time.time == Temp[4] + Process[4])
{
Flags[4] = 0;
Target5.GetComponent<MeshRenderer>().material.color = Green;
Target5.tag = "Machine E";
}
if ((int)Time.time == Temp[5] + Process[5])
{
Flags[5] = 0;
Target6.GetComponent<MeshRenderer>().material.color = Green;
Target6.tag = "Machine F";
}
if ((int)Time.time == Temp[6] + Process[6])
{
Flags[6] = 0;
Target7.GetComponent<MeshRenderer>().material.color = Green;
Target7.tag = "Machine G";
}
//Machine stuck in processing state
if ((int)Time.time > 48)
{
Flags[4] = 1;
Target5.GetComponent<MeshRenderer>().material.color = Red;
Target5.tag = "Null";
}
}*/
//End episodes for all agents
public void EndAll()
{
robot.End();
robot2.End();
robot3.End();
}
}