Skip to content

Commit

Permalink
Merge pull request #10 from robocup-logistics/dominik_wip
Browse files Browse the repository at this point in the history
Updates for the CI and fixing of bugs in the frontend and in the zones manager
  • Loading branch information
TarikViehmann authored Jun 27, 2023
2 parents 283f8bb + e2ee165 commit c110473
Show file tree
Hide file tree
Showing 59 changed files with 1,287 additions and 2,123 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ name: .NET build and test

on:
push:
branches: [ "master", "WIP" ]
branches: [ "master", "dominik_wip" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Checkout the code
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ bld/

# Visual Studio 2015/2017 cache/options directory
.vs/
.idea/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

Expand Down Expand Up @@ -517,3 +518,6 @@ MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder

# End of https://www.toptal.com/developers/gitignore/api/csharp,visualstudio

# Remove the class diagramms
*.cd
41 changes: 26 additions & 15 deletions Simulator/Configurations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public class Configurations
public uint WebguiPort { get; private set;}
public bool BarcodeScanner { get; private set; }

//Constructor of my Singleton variable
private Configurations()

public Configurations()
{
MpsConfigs = new List<MpsConfig>();
RobotConfigs = new List<RobotConfig>();
Expand All @@ -71,17 +71,7 @@ private Configurations()
RobotConnectionType = "tcp";
RobotDirectBeaconSignals = false;
BarcodeScanner = false;
}

//private member and getter for my singleton configurations class
private static Configurations? Instance;
/// <returns>
/// Returns the instance of the Configurations Singleton
/// </returns>
///
public static Configurations GetInstance()
{
return Instance ??= new Configurations();
WebguiPrefix = "http";
}

public void LoadConfig(string path)
Expand Down Expand Up @@ -284,6 +274,7 @@ public void LoadConfig(string path)
var jersey = 0;
var color = Team.Cyan;
var (yamlNode, yamlNode1) = child;
var connection = "tcp";
var allNodes = ((YamlMappingNode)yamlNode1).Children;
foreach (var (key, value) in allNodes)
{
Expand All @@ -302,9 +293,12 @@ public void LoadConfig(string path)
case "team":
color = Team.Cyan;
break;
case "connection":
connection = value.ToString().ToLower();
break;
}
}
var config = new RobotConfig(yamlNode.ToString(), jersey, color);
var config = new RobotConfig(yamlNode.ToString(), jersey, color, connection);
return config;
}

Expand Down Expand Up @@ -467,6 +461,20 @@ public void AddConfig(TeamConfig conf)
{
Teams.Add(conf);
}

public void AddConfig(RefboxConfig refbox)
{
Refbox = refbox;
}
public void SetConnectionType(string connectionType)
{
RobotConnectionType = connectionType;
}

public void ToggleMockUp()
{
MockUp = !MockUp;
}
}

public class MpsConfig
Expand Down Expand Up @@ -560,18 +568,21 @@ public class RobotConfig
public string Name;
public int Jersey;
public Team TeamColor;
public RobotConfig(string name, int jersey, Team color)
public string Connection;
public RobotConfig(string name, int jersey, Team color, string connection)
{
Name = name;
Jersey = jersey;
TeamColor = color;
Connection = connection;
}
public void PrintConfig()
{
Console.WriteLine("---------------------------");
Console.WriteLine("Name = [" + Name + "]");
Console.WriteLine("Jersey = [" + Jersey + "]");
Console.WriteLine("Team = [" + TeamColor + "]");
Console.WriteLine("Connection = [" + Connection + "]");
}
}
}
4 changes: 2 additions & 2 deletions Simulator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ RUN apt-get update && apt-get -y install xterm libncurses5-dev locales locales-a
COPY /MPS/ /simulator/MPS
COPY /protobuff/ /simulator/protobuff
COPY /RobotEssentials/ /simulator/RobotEssentials
COPY /TerminalGui/ /simulator/TerminalGui/
#COPY /TerminalGui/ /simulator/TerminalGui/
COPY /Utility/ /simulator/Utility
COPY /Configurations.cs /simulator/
COPY /MainClass.cs /simulator/
Expand All @@ -13,4 +13,4 @@ COPY /WebGui/ /simulator/WebGui/
WORKDIR /simulator
RUN dotnet restore
RUN dotnet build
RUN mkdir logs
RUN mkdir logs
8 changes: 5 additions & 3 deletions Simulator/MPS/Belt.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Threading;

using Simulator.Utility;

namespace Simulator.MPS
Expand Down Expand Up @@ -26,7 +26,8 @@ public class Belt
private readonly Mps Machine;
private Products? ProductOnBelt;
private bool Work;
public Belt(Mps machine, ManualResetEvent mre)
private Configurations Config;
public Belt(Configurations config, Mps machine, ManualResetEvent mre)
{
Position = Positions.In;
Direction = Direction.FromInToOut;
Expand All @@ -35,6 +36,7 @@ public Belt(Mps machine, ManualResetEvent mre)
On = false;
Work = true;
Machine = machine;
Config = config;
var beltThread = new Thread(StateMachine);
beltThread.Start();
}
Expand Down Expand Up @@ -87,7 +89,7 @@ private void StateMachine()
}


Thread.Sleep(Configurations.GetInstance().BeltActionDuration);
Thread.Sleep(Config.BeltActionDuration);
switch (Direction)
{
case Direction.FromInToOut:
Expand Down
2 changes: 2 additions & 0 deletions Simulator/MPS/Light.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public Light(LightColor color, ManualResetEvent mre)
Event = mre;
LightOn = false;
var lightThread = new Thread(StateMachine);
lightThread.Name = "Light_" + color.ToString() + "_Thread";
lightThread.Start();

}

public void SetLight(LightState update)
Expand Down
143 changes: 82 additions & 61 deletions Simulator/MPS/MPSNodeManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.Generic;
using Opc.Ua;
using Opc.UaFx;
using Opc.UaFx.Client;
using Opc.UaFx.Server;
using Simulator.Utility;

Expand Down Expand Up @@ -48,38 +50,40 @@ public MPSNodeManager(string defaultnamespace, string[] namespaces, MyLogger Log
protected override IEnumerable<IOpcNode> CreateNodes(OpcNodeReferenceCollection references)
{
var objectsNode = OpcObjectTypes.ObjectsFolder;

var ns = DefaultNamespaceIndex;
// Creating the basic structure of the OPC UA communication with the refbox
var deviceNode = new OpcFolderNode(new OpcName("DeviceSet", ns));
var nodeId = new OpcNodeId(5001, ns);
var deviceNode = new OpcObjectNode(new OpcName("DeviceSet",this.DefaultNamespace),nodeId);
references.Add(deviceNode, objectsNode);
ns = Namespaces[2].Index;
var CPXNode = new OpcFolderNode(deviceNode, new OpcName("CPX-E-CEC-C1-PN", ns)); //changed between "CPX-E-CEC-C1-PN" and "CODESYS Control Win V3" "CODESYS Control Win V3 x64"
var resNode = new OpcFolderNode(CPXNode, new OpcName("Resources", ns));
var AppNode = new OpcFolderNode(resNode, new OpcName("Application", ns));
nodeId = new OpcNodeId("|var|CPX-E-CEC-C1-PN", ns);
var CPXNode = new OpcObjectNode(deviceNode, new OpcName("CPX-E-CEC-C1-PN", ns), nodeId); //changed between "CPX-E-CEC-C1-PN" and "CODESYS Control Win V3" "CODESYS Control Win V3 x64"
nodeId = new OpcNodeId(1001, ns);
var resNode = new OpcObjectNode(CPXNode, new OpcName("Resources", ns),nodeId);

nodeId = new OpcNodeId("|var|CPX-E-CEC-C1-PN.Application", ns);
var AppNode = new OpcObjectNode(resNode, new OpcName("Application", ns),nodeId);

ns = Namespaces[1].Index;
var GlobNode = new OpcFolderNode(AppNode, new OpcName("GlobalVars", ns));
nodeId = new OpcNodeId("|appo|CPX-E-CEC-C1-PN.Application.GlobalVars", ns);
var GlobNode = new OpcObjectNode(AppNode, new OpcName("GlobalVars", ns), nodeId);

ns = Namespaces[2].Index;
var GNode = new OpcFolderNode(GlobNode, new OpcName("G", ns));
var In = new OpcFolderNode(GNode, new OpcName("In", ns));
var Basic = new OpcFolderNode(GNode, new OpcName("Basic", ns));
nodeId = new OpcNodeId("|var|CPX-E-CEC-C1-PN.Application.G", ns);
var GNode = new OpcFolderNode(GlobNode, new OpcName("G", ns),nodeId);

//Adding the references to correct the naming convention
references.Add(CPXNode, deviceNode.Id);
references.Add(resNode, CPXNode.Id);
references.Add(AppNode, resNode.Id);
references.Add(GlobNode, AppNode.Id);
references.Add(GNode, GlobNode.Id);
references.Add(In, GNode.Id);
references.Add(Basic, GNode.Id);
nodeId = new OpcNodeId("|var|CPX-E-CEC-C1-PN.Application.G.In", ns);
var In = new OpcObjectNode(GNode, new OpcName("In", ns), nodeId);
nodeId = new OpcNodeId("|var|CPX-E-CEC-C1-PN.Application.G.Basic", ns);
var Basic = new OpcObjectNode(GNode, new OpcName("Basic", ns), nodeId);

//create the local variables for the communication
var In_p = new OpcFolderNode(In, new OpcName("p", ns));
var Ba_p = new OpcFolderNode(Basic, new OpcName("p", ns));
references.Add(In_p, In.Id);
references.Add(Ba_p, Basic.Id);
BasicNodes = new NodeCollection(Ba_p, ns, references);
InNodes = new NodeCollection(In_p, ns, references);
nodeId = new OpcNodeId("|var|CPX-E-CEC-C1-PN.Application.G.In.p", ns);
var In_p = new OpcFolderNode(In, new OpcName("p", ns), nodeId);
nodeId = new OpcNodeId("|var|CPX-E-CEC-C1-PN.Application.G.Basic.p", ns);
var Ba_p = new OpcFolderNode(Basic, new OpcName("p", ns), nodeId);
BasicNodes = new NodeCollection(Ba_p, ns, "Basic", references);
InNodes = new NodeCollection(In_p, ns, "In", references);

// Yielding of the nodes
yield return GlobNode;
Expand Down Expand Up @@ -143,32 +147,39 @@ public class NodeCollection
public OpcFolderNode ParentNode;
public OpcFolderNode Status;
public Status StatusNodes;
public NodeCollection(OpcFolderNode Parent, int ns, OpcNodeReferenceCollection reference)
public NodeCollection(OpcFolderNode Parent, int ns, string prefix, OpcNodeReferenceCollection reference)
{
//ActionId = new OpcNode();
ParentNode = Parent;
ActionId = new OpcDataVariableNode<ushort>(Parent, new OpcName("ActionId", ns), 0);

var path = "|var|CPX-E-CEC-C1-PN.Application.G." + prefix + ".p.";
var name = "ActionId";
var nodeId = new OpcNodeId(path + name, ns);
ActionId = new OpcDataVariableNode<ushort>(ParentNode,new OpcName(name, ns), nodeId ,0);
//reference.Add(ActionId, ParentNode.Id);
//ActionId
//OpcText()
BarCode = new OpcDataVariableNode<uint>(Parent, new OpcName("BarCode", ns), (uint)0);
Data = new OpcDataVariableNode<ushort>(Parent, new OpcName("Data", ns), 0);
Data0 = new OpcDataVariableNode<ushort>(Data, new OpcName("Data[0]", ns), 0);
Data1 = new OpcDataVariableNode<ushort>(Data, new OpcName("Data[1]", ns), 0);

SlideCnt = new OpcDataVariableNode<ushort>(Parent, new OpcName("SlideCnt", ns), 0);
ByteError = new OpcDataVariableNode<byte>(Parent, new OpcName("Error", ns), 0);
Status = new OpcFolderNode(Parent, new OpcName("Status", ns));
// todo add Dimensions with value 1 (uint32); add IndexMax with value 1 (uint32) and IndexMin with value 0 (uint32)
reference.Add(ActionId, Parent.Id);
reference.Add(BarCode, Parent.Id);
reference.Add(Data, Parent.Id);
reference.Add(Data0, Data.Id);
reference.Add(Data1, Data.Id);
reference.Add(SlideCnt, Parent.Id);
reference.Add(ByteError, Parent.Id);
reference.Add(Status, Parent.Id);
StatusNodes = new Status(Status, ns, reference);
name = "BarCode";
nodeId = new OpcNodeId(path + name, ns);
BarCode = new OpcDataVariableNode<uint>(ParentNode, new OpcName(name, ns), nodeId, (uint)0);
name = "Data";
nodeId = new OpcNodeId(path + name, ns);
Data = new OpcDataVariableNode<ushort>(ParentNode, new OpcName(name, ns), nodeId, 0);
name = "Data[0]";
nodeId = new OpcNodeId(path + name, ns);
Data0 = new OpcDataVariableNode<ushort>(Data, new OpcName(name, ns), nodeId, 0);
name = "Data[1]";
nodeId = new OpcNodeId(path + name, ns);
Data1 = new OpcDataVariableNode<ushort>(Data, new OpcName(name, ns), nodeId,0);
name = "SlideCnt";
nodeId = new OpcNodeId(path + name, ns);
SlideCnt = new OpcDataVariableNode<ushort>(ParentNode, new OpcName(name, ns), nodeId, 0);
name = "Error";
nodeId = new OpcNodeId(path + name, ns);
ByteError = new OpcDataVariableNode<byte>(ParentNode, new OpcName(name, ns), nodeId, 0);
name = "Status";
nodeId = new OpcNodeId(path + name, ns);
Status = new OpcFolderNode(ParentNode, new OpcName(name, ns), nodeId);
StatusNodes = new Status(Status, ns, prefix, reference);
}
}
public class Status
Expand All @@ -182,24 +193,34 @@ public class Status
public OpcDataVariableNode<bool> inSensor;
public OpcDataVariableNode<bool> outSensor;

public Status(OpcFolderNode Parent, int ns, OpcNodeReferenceCollection reference)
public Status(OpcFolderNode Parent, int ns, string prefix, OpcNodeReferenceCollection reference)
{
busy = new OpcDataVariableNode<bool>(Parent, new OpcName("Busy", ns), false);
ready = new OpcDataVariableNode<bool>(Parent, new OpcName("Ready", ns), false);
error = new OpcDataVariableNode<bool>(Parent, new OpcName("Error", ns), false);
enable = new OpcDataVariableNode<bool>(Parent, new OpcName("Enable", ns), false);
unused0 = new OpcDataVariableNode<bool>(Parent, new OpcName("unused0", ns), false);
unused1 = new OpcDataVariableNode<bool>(Parent, new OpcName("unused1", ns), false);
inSensor = new OpcDataVariableNode<bool>(Parent, new OpcName("inSensor", ns), false);
outSensor = new OpcDataVariableNode<bool>(Parent, new OpcName("outSensor", ns), false);
reference.Add(busy, Parent.Id);
reference.Add(ready, Parent.Id);
reference.Add(error, Parent.Id);
reference.Add(enable, Parent.Id);
reference.Add(unused0, Parent.Id);
reference.Add(unused1, Parent.Id);
reference.Add(inSensor, Parent.Id);
reference.Add(outSensor, Parent.Id);
var path = "|var|CPX-E-CEC-C1-PN.Application.G." + prefix + ".p.Status.";
var name = "Busy";
var nodeId = new OpcNodeId(path + name, ns);
busy = new OpcDataVariableNode<bool>(Parent, new OpcName(name, ns), nodeId, false);
name = "Ready";
nodeId = new OpcNodeId(path + name, ns);
ready = new OpcDataVariableNode<bool>(Parent, new OpcName(name, ns), nodeId, false);
name = "Error";
nodeId = new OpcNodeId(path + name, ns);
error = new OpcDataVariableNode<bool>(Parent, new OpcName(name, ns),nodeId, false);
name = "Enable";
nodeId = new OpcNodeId(path + name, ns);
enable = new OpcDataVariableNode<bool>(Parent, new OpcName(name, ns),nodeId, false);
name = "unused0";
nodeId = new OpcNodeId(path + name, ns);
unused0 = new OpcDataVariableNode<bool>(Parent, new OpcName(name, ns),nodeId, false);
name = "unused1";
nodeId = new OpcNodeId(path + name, ns);
unused1 = new OpcDataVariableNode<bool>(Parent, new OpcName(name, ns),nodeId, false);
name = "inSensor";
nodeId = new OpcNodeId(path + name, ns);
inSensor = new OpcDataVariableNode<bool>(Parent, new OpcName(name, ns),nodeId, false);
name = "outSensor";
nodeId = new OpcNodeId(path + name, ns);
outSensor = new OpcDataVariableNode<bool>(Parent, new OpcName(name, ns),nodeId, false);

}
}
}
Loading

0 comments on commit c110473

Please sign in to comment.