Skip to content

Instantly share code, notes, and snippets.

@javatechs
Forked from madhephaestus/.gitignore
Created November 30, 2020 22:46
Show Gist options
  • Save javatechs/3b3164067d463d39b8f87a3148504aba to your computer and use it in GitHub Desktop.
Save javatechs/3b3164067d463d39b8f87a3148504aba to your computer and use it in GitHub Desktop.
Bowler Studio Game Controllers
/.classpath
/.project
import com.neuronrobotics.sdk.addons.gamepad.IJInputEventListener;
import com.neuronrobotics.sdk.addons.kinematics.MobileBase
import com.neuronrobotics.sdk.addons.kinematics.math.RotationNR
import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR
import com.neuronrobotics.sdk.common.DeviceManager
import com.neuronrobotics.sdk.util.ThreadUtil
import com.neuronrobotics.bowlerstudio.BowlerStudio
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine
import com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice;
import net.java.games.input.Component;
import net.java.games.input.Event;
import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;
BowlerJInputDevice g=null;// Create a variable to store the device
MobileBase cat =ScriptingEngine.gitScriptRun( "https://github.com/OperationSmallKat/SmallKat_V2.git",
"loadRobot.groovy",
["https://github.com/OperationSmallKat/greycat.git",
"MediumKat.xml","GameController_22","kevkat"]);
//Check if the device already exists in the device Manager
if(DeviceManager.getSpecificDevice(BowlerJInputDevice.class, "gamepad")==null){
//If the device does not exist, prompt for the connection
g = new BowlerJInputDevice(ControllerEnvironment.getDefaultEnvironment().getControllers()[0]); // This is the DyIO to talk to.
g.connect(); // Connect to it.
// add the device to the maager
DeviceManager.addConnection(g,"gamepad");
}else{
//the device is already present on the system, load the one that exists.
g=(BowlerJInputDevice)DeviceManager.getSpecificDevice(BowlerJInputDevice.class, "gamepad")
}
//Set the DyIO into cached mode
//dyio.setCachedMode(true);
//ServoChannel pan = new ServoChannel(dyio.getChannel(11))
//ServoChannel tilt = new ServoChannel(dyio.getChannel(10))
def x =0;
def straif=0;
def rz=0;
IJInputEventListener listener = new IJInputEventListener() {
@Override public void onEvent(Component comp, Event event1,float value, String eventString) {
if(comp.getName().contentEquals("x")){
straif=-value;System.out.println(comp.getName()+" is value= "+value);
}
else if(comp.getName().contentEquals("y")){
x=-value;System.out.println(comp.getName()+" is value= "+value);
}
else if(comp.getName().contentEquals("rz")){
//ignore
}
else if(comp.getName().contentEquals("rx")){
rz=value;System.out.println(comp.getName()+" is value= "+value);
}
else
System.out.println(comp.getName()+" is value= "+value);
}
}
g.clearListeners()
// gamepad is a BowlerJInputDevice
g.addListeners(listener);
// wait while the application is not stopped
while(!Thread.interrupted() ){
ThreadUtil.wait(20)
if(Math.abs(x)>0.01 || Math.abs(straif)>0.01 || Math.abs(rz)>0.01) {
def newPose = new TransformNR(x*0.2,straif*0.5,0,new RotationNR(0, rz*0.1, 0))
//println newPose
cat.DriveArc(newPose, 0.0020);
}
}
//remove listener and exit
g.removeListeners(listener);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment