/
StateConfiguration.cs
161 lines (136 loc) · 5.39 KB
/
StateConfiguration.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Newtonsoft.Json;
using System.ComponentModel;
using Newtonsoft.Json.Converters;
using RoboNui.Core;
namespace RoboNui.Management
{
/**
* <summary>
* Configuration structure for RoboNui.
*
* Contains all necessary paramters to be read on Startup for the operation of the StateManager's control of the system.
* </summary>
*
* <remarks>Author: Jon Eisen (jon.m.eisen@gmail.com) </remarks>
*/
public class StateConfiguration
{
/**
* <summary>
* Configuration sub-struct for the RobotAdapter Assembly.
* </summary>
*/
public struct _RobotAdapterConfig
{
public int UseArm;
/**
* <summary>
* Configuration sub-struct for the Robotic Arm component(s).
* </summary>
*/
public struct _Arm
{
/// <summary>Serial Port name of the Robotic Arm's Servo Controller</summary>
public string Port;
/// <summary>Robotic Angle to Channel Number list</summary>
public Dictionary<RoboticAngle, uint> Channels;
/// <summary>Speed of motions for the Robotic Arm (in microseconds per second)</summary>
public ulong Speed;
}
/**
* <summary>
* Configuration sub-struct for the Robotic Marionette component(s).
* </summary>
*/
public struct _Marionette
{
/// <summary>Serial Port name of the Robotic Arm's Servo Controller</summary>
public string Port;
/// <summary>Robotic Angle to Channel Number list</summary>
public Dictionary<RoboticAngle, uint> Channels;
}
/**
* <summary>Accessible Field for the Robotic Arm configuration sub-struct</summary>
*/
public _Arm Arm;
/**
* <summary>Accessible Field for the Robotic Marionette configuration sub-struct</summary>
*/
public _Marionette Marionette;
}
/**
* <summary>
* Configuration sub-struct for the Kinect Adapter Assembly.
* </summary>
*/
public struct _KinectAdapter
{
/// <summary>Period to update the system</summary>
/// <remarks>In milliseconds</remarks>
public long Period;
}
/**
* <summary>
* Configuration sub-struct for the Core RoboNui Assembly.
* </summary>
*/
public struct _Core
{
}
/**
* <summary>Accessible Field for the Robot Adapter Assembly configuration sub-struct</summary>
*/
public _RobotAdapterConfig RobotAdapter;
/**
* <summary>Accessible Field for the Kinect Adapter Assembly configuration sub-struct</summary>
*/
public _KinectAdapter KinectAdapter;
/**
* <summary>Accessible Field for the Core RoboNui Assembly configuration sub-struct</summary>
*/
public _Core Core;
/**
* <summary>Construct the Configuration with default values.</summary>
*/
public StateConfiguration()
{
RobotAdapter.Arm.Port = "";
RobotAdapter.Arm.Channels = new Dictionary<RoboticAngle, uint>();
RobotAdapter.Arm.Speed = 0;
RobotAdapter.Arm.Channels[RoboticAngle.ArmBaseRotate] = 0;
RobotAdapter.Arm.Channels[RoboticAngle.ArmShoulderLift] = 1;
RobotAdapter.Arm.Channels[RoboticAngle.ArmElbowBend] = 2;
RobotAdapter.Arm.Channels[RoboticAngle.ArmWristTilt] = 3;
RobotAdapter.Arm.Channels[RoboticAngle.ArmWristRotate] = 4;
RobotAdapter.Arm.Channels[RoboticAngle.ArmHandGrasp] = 5;
RobotAdapter.Marionette.Channels = new Dictionary<RoboticAngle, uint>();
RobotAdapter.Marionette.Port = "";
RobotAdapter.Marionette.Channels[RoboticAngle.CurtainOpen] = 6;
RobotAdapter.Marionette.Channels[RoboticAngle.RightArmLift] = 1;
RobotAdapter.Marionette.Channels[RoboticAngle.LeftArmLift] = 7;
RobotAdapter.Marionette.Channels[RoboticAngle.RearLift] = 3;
RobotAdapter.Marionette.Channels[RoboticAngle.HeadLift] = 5;
}
/**
* <summary>Construct the Configuration with a configuration file to load in custom configuration.</summary>
*/
public static StateConfiguration ReadConfigFile(string fn)
{
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.NullValueHandling = NullValueHandling.Ignore;
settings.MissingMemberHandling = MissingMemberHandling.Error;
JsonSerializer serializer = JsonSerializer.Create(settings);
JsonReader reader = new JsonTextReader(new StreamReader(fn));
StateConfiguration sc = serializer.Deserialize<StateConfiguration>(reader);
StateConfiguration realSc = new StateConfiguration();
sc.RobotAdapter.Arm.Channels = realSc.RobotAdapter.Arm.Channels;
sc.RobotAdapter.Marionette.Channels = realSc.RobotAdapter.Marionette.Channels;
return sc;
}
}
}