-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrcControl.groovy
165 lines (139 loc) · 4.55 KB
/
rcControl.groovy
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
import com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice
import com.neuronrobotics.sdk.addons.gamepad.IGameControlEvent
import com.neuronrobotics.sdk.addons.kinematics.MobileBase
import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR
import com.neuronrobotics.sdk.addons.kinematics.parallel.ParallelGroup
import com.neuronrobotics.sdk.common.DeviceManager
import com.neuronrobotics.sdk.common.Log
import com.neuronrobotics.bowlerstudio.BowlerStudioController
import com.neuronrobotics.bowlerstudio.assets.ConfigurationDatabase
import com.neuronrobotics.bowlerstudio.creature.MobileBaseCadManager
import com.neuronrobotics.bowlerstudio.creature.MobileBaseLoader
import com.neuronrobotics.bowlerstudio.threed.BowlerStudio3dEngine
MobileBase base=DeviceManager.getSpecificDevice( "JackSkellington",{
//If the device does not exist, prompt for the connection
MobileBase m = MobileBaseLoader.fromGit(
"https://github.com/Halloween2022RodPuppet/RodPuppetKinematics.git",
"rodpuppet.xml"
)
return m
})
MobileBase left=DeviceManager.getSpecificDevice( "JackSkellingtonLeftHand",{
//If the device does not exist, prompt for the connection
MobileBase m = MobileBaseLoader.fromGit(
"https://github.com/Halloween2022RodPuppet/RodPuppetKinematics.git",
"rodpuppet2.xml"
)
return m
})
MobileBase right=DeviceManager.getSpecificDevice( "JackSkellingtonRightHand",{
//If the device does not exist, prompt for the connection
MobileBase m = MobileBaseLoader.fromGit(
"https://github.com/Halloween2022RodPuppet/RodPuppetKinematics.git",
"rodpuppet3.xml"
)
return m
})
ParallelGroup pg = base.getParallelGroup("delta")
ParallelGroup l = left.getParallelGroup("delta")
ParallelGroup r = right.getParallelGroup("delta")
println " base name "+base.getScriptingName()+" paraalell "+pg.getScriptingName()
if (pg==null)
throw new NullPointerException("Paralel group is null!")
List<String> gameControllerNames = ConfigurationDatabase.getObject("katapult", "gameControllerNames", [
"Dragon",
"X-Box",
"Game",
"Switch"
])
//Check if the device already exists in the device Manager
BowlerJInputDevice g=DeviceManager.getSpecificDevice("gamepad",{
def t = new BowlerJInputDevice(gameControllerNames); //
t.connect(); // Connect to it.
return t
})
if (g==null)
return
float x =0;
float straif=0;
float rz=0;
float ljud =0;
float trigButton=0;
float trigAnalog=0;
float tilt=1;
float rTilt=1
long timeOfLastCommand = System.currentTimeMillis()
IGameControlEvent listener = new IGameControlEvent() {
@Override public void onEvent(String name,float value) {
timeOfLastCommand = System.currentTimeMillis()
if(name.contentEquals("l-joy-left-right")){
straif=value;
}
else if(name.contentEquals("r-joy-up-down")){
x=-value;
}
else if(name.contentEquals("l-joy-up-down")){
ljud=value;
}
else if(name.contentEquals("r-joy-left-right")){
rz=value;
}else if(name.contentEquals("analog-trig")){
trigAnalog=value;
}else if(name.contentEquals("z")){
trigButton=value/2.0+0.5;
}
else if(name.contentEquals("x-mode")){
if(value>0) {
}
}else if(name.contentEquals("r-trig-button")){
if(value>0) {
rTilt=-1;
}else
rTilt=1;
}
else if(name.contentEquals("l-trig-button")){
if(value>0) {
tilt=-1;
}else
tilt=1;
}
else if(name.contentEquals("y-mode")){
if(value>0) {
}
}
//System.out.println(name+" is value= "+value);
}
}
g.clearListeners()
Log.enableSystemPrint(true)
g.addListeners(listener);
BowlerStudioController.setCsg(MobileBaseCadManager.get(base).getAllCad())
BowlerStudioController.addObject(MobileBaseCadManager.get(left).getAllCad(), null)
BowlerStudioController.addObject(MobileBaseCadManager.get(right).getAllCad(), null)
try{
def lasttrig=0;
while(!Thread.interrupted() ){
Thread.sleep(10)
if(System.currentTimeMillis()-timeOfLastCommand<1000) {
TransformNR changed=pg.calcHome()
changed.translateX(rz*20)
changed.translateY(x*-15)
TransformNR changedr=r.calcHome()
changedr.translateY(ljud*20)
changedr.translateX(straif*15*tilt)
changedr.translateZ(trigAnalog*tilt*5)
TransformNR changedl=l.calcHome()
changedl.translateY(ljud*20)
changedl.translateX(straif*-15*rTilt)
changedl.translateZ(trigAnalog*5)
pg.setDesiredTaskSpaceTransform(changed, 0);
l.setDesiredTaskSpaceTransform(changedl, 0);
r.setDesiredTaskSpaceTransform(changedr, 0);
}
}
}catch(java.lang.InterruptedException ex) {
//exit sig
}catch(Throwable t){
t.printStackTrace(System.out)
}
g.removeListeners(listener);