-
Notifications
You must be signed in to change notification settings - Fork 19
/
launch.groovy
78 lines (70 loc) · 2.18 KB
/
launch.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
def cat =ScriptingEngine.gitScriptRun( "https://github.com/OperationSmallKat/SmallKat_V2.git",
"loadRobot.groovy",
["https://github.com/OperationSmallKat/greycat.git",
"MediumKat.xml","GameController_22","kevkat"]);
println "Cat loaded, searching for game controller"
def gameController =null
try{
gameController = ScriptingEngine.gitScriptRun(
"https://gist.github.com/e26c0d8ef7d5283ef44fb22441a603b8.git", // git location of the library
"LoadGameController.groovy" , // file to load
// Parameters passed to the function
["GameController_22"]
);
// This is in development again once more
}catch (Exception ex){
//ex.printStackTrace()
return
}
if(gameController==null){
println "Exiting script"
return
}
int [] data = gameController.getData()
double toSeconds=0.02//100 ms for each increment
println "Starting controller loop..."
while (!Thread.interrupted() ){
Thread.sleep((long)(toSeconds*1000))
data = gameController.getData()
//println data
double xdata = data[3]
double rzdata = data[2]
double rxdata = data[0]
double rydata = data[1]
/*
if(xdata<0)
xdata+=256
if(rzdata<0)
rzdata+=256
if(rxdata<0)
rxdata+=256
if(rydata<0)7
rydata+=256
*/
double scale = 0.15
double displacement = 40*(scale*xdata/255.0-scale/2)
double displacementY =-10*(scale*rxdata/255.0-scale/2)
double rot =((scale*2.0*rzdata/255.0)-scale)*-2.5
double rotx =((rxdata/255.0)-scale/2)*5
double roty =((rydata/255.0)-scale/2)*-5
if(Math.abs(displacement)<0.1 ){
displacement=0
}
if( Math.abs(rot)<0.1){
rot=0
}
try{
if(Math.abs(displacement)>0.16 || Math.abs(rot)>0.16 ||Math.abs(displacementY)>0.16 ){
println "displacement "+displacement+" rot "+rot+" straif = "+displacementY
TransformNR move = new TransformNR(displacement,displacementY,0,new RotationNR(rotx,rot,roty))
cat.DriveArc(move, toSeconds);
}
if(Math.abs(rotx)>2 || Math.abs(roty)>2){
//println "tilt "+rotx+" rot "+roty
TransformNR move = new TransformNR(displacement,displacementY,0,new RotationNR(rotx,0,roty))
//cat.getWalkingDriveEngine().pose(move)
}
}catch(Throwable t){
BowlerStudio.printStackTrace(t)
}
}