forked from OperationSmallKat/SmallKat_V2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
launch.groovy
69 lines (61 loc) · 2.02 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
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine
import com.neuronrobotics.sdk.addons.kinematics.MobileBase
import com.neuronrobotics.sdk.addons.kinematics.math.RotationNR
import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR
MobileBase cat =ScriptingEngine.gitScriptRun( "https://github.com/OperationSmallKat/SmallKat_V2.git",
"loadRobot.groovy",
["https://github.com/OperationSmallKat/SmallKat_V2.git",
"Bowler/MediumKat.xml"]);
def gameController = ScriptingEngine.gitScriptRun(
"https://gist.github.com/e26c0d8ef7d5283ef44fb22441a603b8.git", // git location of the library
"LoadGameController.groovy" , // file to load
// Parameters passed to the function
["KatControl"]
)
if(gameController==null){
return
}
byte [] data = gameController.getData()
double toSeconds=0.03//100 ms for each increment
while (!Thread.interrupted()){
Thread.sleep(30)
gameController.getData(data)
//println gameController
double xdata = data[4]
double rzdata = data[3]
double rxdata = data[1]
double rydata = data[2]
if(xdata<0)
xdata+=256
if(rzdata<0)
rzdata+=256
if(rxdata<0)
rxdata+=256
if(rydata<0)
rydata+=256
double scale = 1.0
double displacement = 15*(scale*xdata/255.0-scale/2)
double rot =((scale*rzdata/255.0)-scale/2)*-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(rotx)>0.1 || Math.abs(roty)>0.1){
TransformNR move = new TransformNR(displacement,0,0,new RotationNR(rotx,0,roty))
cat.getWalkingDriveEngine().pose(move)
}
if(Math.abs(displacement)>0.1 || Math.abs(rot)>0.1){
print "\r\ndisplacement "+displacement+" rot "+rot
print " tilt "+rotx+" rot "+roty
print " rawX "+xdata+" rawZ "+rzdata+" data "+data+"\r\n"
TransformNR move = new TransformNR(displacement,0,0,new RotationNR(rotx,rot,roty))
cat.DriveArc(move, toSeconds);
}
}
catch(Throwable t){}
}