Skip to content

Instantly share code, notes, and snippets.

@madhephaestus
Last active June 1, 2016 19:53
Show Gist options
  • Save madhephaestus/0a40ac7d1f17ae15142c25f3818984fd to your computer and use it in GitHub Desktop.
Save madhephaestus/0a40ac7d1f17ae15142c25f3818984fd to your computer and use it in GitHub Desktop.
GCODE devices demonstrated
import com.neuronrobotics.sdk.addons.kinematics.AbstractLink;
import com.neuronrobotics.sdk.addons.kinematics.DHChain;
import com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics;
import com.neuronrobotics.sdk.addons.kinematics.DhInverseSolver;
import com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration;
import com.neuronrobotics.sdk.addons.kinematics.LinkFactory;
import com.neuronrobotics.sdk.addons.kinematics.LinkType;
import com.neuronrobotics.sdk.addons.kinematics.MobileBase;
import com.neuronrobotics.sdk.addons.kinematics.gcodebridge.GCodeHeater;
import com.neuronrobotics.sdk.addons.kinematics.gcodebridge.GcodeDevice;
import com.neuronrobotics.sdk.addons.kinematics.gcodebridge.GcodePrismatic;
import com.neuronrobotics.sdk.addons.kinematics.gcodebridge.GcodeRotory;
import com.neuronrobotics.sdk.addons.kinematics.gcodebridge.IGCodeChannel;
import com.neuronrobotics.sdk.addons.kinematics.math.RotationNR;
import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR;
import com.neuronrobotics.sdk.common.DeviceManager;
import gnu.io.NRSerialPort;
String GCODE = "GCODE";
String portname = "/dev/ttyUSB0";// set your serial port name here
Class<GcodeDevice> GCODECONTOLLER = GcodeDevice.class;
GcodeDevice device;
void fail(String message){
throw new Exception(message)
}
if (DeviceManager.getSpecificDevice(GCODECONTOLLER, GCODE) == null){
hasPort = false;
for (String s : NRSerialPort.getAvailableSerialPorts()) {
if (s.contentEquals(portname))
hasPort = true;
else
println "port: "+s+" is not "+portname
}
if (hasPort) {
NRSerialPort port = new NRSerialPort(portname, 115200);// set your baudrate here
device = new GcodeDevice(port);
device.connect();
DeviceManager.addConnection(device, GCODE);
}else{
println "ERROR serial port "+portname+" not found"
return null;
}
}
device = GCODECONTOLLER.cast(DeviceManager.getSpecificDevice(GCODECONTOLLER, GCODE))
/**
* You can send lines of gcode to the device this way
*/
String response = device.runLine("M105");
if (response.length() > 0)
System.out.println("Gcode line run: " + response);
else {
println("No response");
}
esponse = device.runLine("G90");// Absolute mode
if (response.length() > 0)
System.out.println("Gcode line run: " + response);
else {
fail("No response");
}
response = device.runLine("G1 X100.2 Y100.2 Z0 E10 F6000");
if (response.length() > 0)
System.out.println("Gcode line run: " + response);
else {
fail("No response");
}
response = device.runLine("G1 X0 Y0 Z0 E0 F3000");
if (response.length() > 0)
System.out.println("Gcode line run: " + response);
else {
fail("No response");
}
/**
* You can also wrap the device in a link (this is used inside the creatures)
* this will generate a coordinate motion gcode and send it
*/
LinkFactory lf = new LinkFactory();
LinkConfiguration confp = new LinkConfiguration();
confp.setType(LinkType.GCODE_STEPPER_ROTORY);
confp.setDeviceScriptingName(GCODE);
confp.setHardwareIndex(0);
confp.setScale(1);
AbstractLink link = lf.getLink(confp);
link.setTargetEngineeringUnits(100.5);
link.flush(1);// take 2 seconds to flush
LinkConfiguration confp2 = new LinkConfiguration();
confp2.setType(LinkType.GCODE_STEPPER_ROTORY);
confp2.setDeviceScriptingName(GCODE);
confp2.setHardwareIndex(1);
confp2.setScale(1);
AbstractLink link2 = lf.getLink(confp2);
link2.setTargetEngineeringUnits(100.5);
link2.flush(1);// take 2 seconds to flush
link2.setTargetEngineeringUnits(0);
link.setTargetEngineeringUnits(0);
// coordinated motion flush
lf.flush(1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment