/
new_serial.shsds
178 lines (178 loc) · 6.87 KB
/
new_serial.shsds
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
{
"AutomaticReconnect": true,
"SerialPortName": "COM5",
"IsConnecting": false,
"IsEnabled": true,
"LogIncomingData": false,
"IsConnected": true,
"BaudRate": 115200,
"UpdateMessages": [
{
"Message": {
"Interpreter": 1,
"Expression": "// adjust range of servo movements\r\nvar l = [$prop('Settings.LeftOffset')];\r\nvar r = [$prop('Settings.RightOffset')];\r\nconst zero = [0];\t// offset adjust control codes\r\nconst one = [1];\r\nvar two = [2];\t\t// most slack control values\r\nvar three = [3];\r\nif ($prop('Settings.max_test')) {\r\n two = 126 & $prop('Settings.tmax'); // most tense control values\r\n three = 1 + two;\r\n} \r\nconst right = String.fromCharCode(one);\r\nconst left = String.fromCharCode(zero);\r\nvar s2 = String.fromCharCode(two); // send tension control characters after setting new offsets\r\nvar s3 = String.fromCharCode(three);\r\nvar sl = String.fromCharCode.apply(String, l);\r\nvar sr = String.fromCharCode.apply(String, r);\r\n// send updated offsets, then servo positions\r\nreturn left.concat(sl,right,sr,s2,s3);"
},
"IsEnabled": true,
"MaximumFrequency": 0
},
{
"Message": {
"Interpreter": 1,
"Expression": "// G-forces from SimHub properties\r\nvar Gy = - $prop('GameRawData.Physics.AccG01');\t// lateral (yaw) acceleration\r\nvar Gs = - $prop('GameRawData.Physics.AccG03');\t// deceleration\r\nGy *= $prop('Settings.yaw_gain');\r\nGs *= $prop('Settings.decel_gain');\r\nif (0 > Gs)\r\n Gs = 0;\t\t\t\t// non-negative deceleration\r\n\r\n// convert speed and yaw changes to left and right tension values\r\n// turning right should increase right harness tension (body pushed left)\r\nvar r = Math.sqrt(Gs*Gs + Gy*Gy);\r\nvar l = Gs + Gs - r;\r\nif (0 > Gy) {\r\n var t = r;\t// negative Gy increases left tension\r\n r = l;\r\n l = t;\r\n}\r\n\r\n// Low-pass IIR filtering of left and right tension values\r\nif (null == root[\"lb4\"]) {\r\n root[\"rb4\"] = r; root[\"lb4\"] = l;\t// initialize\r\n}\r\nvar rb4 = root[\"rb4\"];\r\nvar lb4 = root[\"lb4\"]; // previously filtered values\r\nvar tc = 1 + $prop('Settings.smooth');\r\nrb4 += (r - rb4) / tc;\r\nlb4 += (l - lb4) / tc;\r\nroot[\"lb4\"] = lb4;\r\nroot[\"rb4\"] = rb4;\r\n\r\nl = lb4; r = rb4; // filtered tensions; comment out for unfiltered (or set Settings.smooth = 1)\r\nvar tmax = $prop('Settings.tmax') & 126;\r\nif (l > tmax)\r\n l = tmax;\r\nelse if (l < 2)\r\n l = 2;\r\nl &= 0x7E; // left lsb is 0\r\ntmax |= 1;\r\nif (r > tmax)\r\n r = tmax;\r\nelse if (r < 3)\r\n r = 3;\r\nr |= 1; // right lsb is 1\r\n\r\nif ($prop('Settings.max_test') || $prop('Settings.TestOffsets')) {\r\n // disable normal message output\r\n // slider changes will provoke first message outputs\r\n root[\"Gsb4\"] = root[\"Gyb4\"] = 0;\r\n} else {\r\n/* servo control output\r\nvar ls = String.fromCharCode(l); // tension control characters\r\nvar rs = String.fromCharCode(r);\r\n*/\r\n\r\n//* gnuplot output **************************************\r\nvar s = $prop('SpeedMph');\r\nvar ls = l.toString();\r\nvar rs = r.toString();\r\nvar ss = s.toString();\r\nvar Gys = Gy.toString();\r\nvar Gss = Gs.toString();\r\nrs = ls.concat('\\t',rs,'\\r\\n'); // gnuplot columns\r\nls = ss.concat('\\t'); \r\n//*/\r\nreturn ls.concat(rs);\r\n}"
},
"IsEnabled": true,
"MaximumFrequency": 0
}
],
"OnConnectMessage": {
"Expression": "' !'"
},
"OnDisconnectMessage": {
"Expression": "' !'"
},
"DtrEnable": true,
"RtsEnable": false,
"EditorExpanded": true,
"Name": "Custom Serial device",
"Description": "Blue Pill belt servos",
"LastErrorDate": "2021-03-28T13:09:03.2826259-04:00",
"LastErrorMessage": null,
"IsFreezed": false,
"SettingsBuilder": {
"Settings": [
{
"Maximum": 65,
"Minimum": 0,
"PropertyName": "LeftOffset",
"CurrentValue": 62,
"Name": null,
"TypeName": "SliderEntry",
"IsEnabled": true,
"IsEnabledFormula": {
"Expression": ""
},
"IsVisible": true,
"Label": "Left untensioned",
"IsVisibleFormula": {
"Expression": ""
}
},
{
"Maximum": 65,
"Minimum": 0,
"PropertyName": "RightOffset",
"CurrentValue": 65,
"Name": null,
"TypeName": "SliderEntry",
"IsEnabled": true,
"IsEnabledFormula": {
"Expression": ""
},
"IsVisible": true,
"Label": "Right untensioned",
"IsVisibleFormula": {
"Expression": ""
}
},
{
"PropertyName": "TestOffsets",
"CurrentValue": false,
"Name": null,
"TypeName": "BoolEntry",
"IsEnabled": true,
"IsEnabledFormula": {
"Expression": ""
},
"IsVisible": true,
"Label": "Test untensioned positions",
"IsVisibleFormula": {
"Expression": ""
}
},
{
"Maximum": 100,
"Minimum": 0,
"PropertyName": "decel_gain",
"CurrentValue": 69,
"Name": null,
"TypeName": "SliderEntry",
"IsEnabled": true,
"IsEnabledFormula": {
"Expression": ""
},
"IsVisible": true,
"Label": "decel gain",
"IsVisibleFormula": {
"Expression": ""
}
},
{
"Maximum": 80,
"Minimum": 0,
"PropertyName": "yaw_gain",
"CurrentValue": 56,
"Name": null,
"TypeName": "SliderEntry",
"IsEnabled": true,
"IsEnabledFormula": {
"Expression": ""
},
"IsVisible": true,
"Label": "delta yaw gain",
"IsVisibleFormula": {
"Expression": ""
}
},
{
"Maximum": 4,
"Minimum": 0,
"PropertyName": "smooth",
"CurrentValue": 2,
"Name": null,
"TypeName": "SliderEntry",
"IsEnabled": true,
"IsEnabledFormula": {
"Expression": ""
},
"IsVisible": true,
"Label": "smoothing",
"IsVisibleFormula": {
"Expression": ""
}
},
{
"Maximum": 127,
"Minimum": 20,
"PropertyName": "tmax",
"CurrentValue": 90,
"Name": null,
"TypeName": "SliderEntry",
"IsEnabled": true,
"IsEnabledFormula": {
"Expression": ""
},
"IsVisible": true,
"Label": "max tension",
"IsVisibleFormula": {
"Expression": ""
}
},
{
"PropertyName": "max_test",
"CurrentValue": false,
"Name": null,
"TypeName": "BoolEntry",
"IsEnabled": true,
"IsEnabledFormula": {
"Expression": ""
},
"IsVisible": true,
"Label": "test max tension",
"IsVisibleFormula": {
"Expression": ""
}
}
],
"IsEditMode": false
}
}