Forked from madhephaestus/CreatureCadGenerator.groovy
Last active
February 1, 2017 03:59
-
-
Save acamilo/f6cc6325b6da918feeb46d2586248e88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.neuronrobotics.bowlerstudio.creature.ICadGenerator; | |
import com.neuronrobotics.bowlerstudio.creature.CreatureLab; | |
import org.apache.commons.io.IOUtils; | |
//Create the kinematics model from the xml file describing the D-H compliant parameters. | |
String xmlContent = ScriptingEngine.codeFromGistID("bcb4760a449190206170","CarlTheRobot.xml")[0]; | |
println "Loading the robot" | |
MobileBase base=null; | |
if(DeviceManager.getSpecificDevice(MobileBase.class, "CarlTheWalkingRobot")==null){ | |
BowlerStudio.speak("Connecting CarlTheWalkingRobot."); | |
base = new MobileBase(IOUtils.toInputStream(xmlContent, "UTF-8")); | |
DeviceManager.addConnection(base,"CarlTheWalkingRobot"); | |
}else{ | |
base = (MobileBase)DeviceManager.getSpecificDevice(MobileBase.class, "CarlTheWalkingRobot"); | |
} | |
def script = ["https://gist.github.com/f6cc6325b6da918feeb46d2586248e88.git","ExampleCadGenerator.groovy"]as String[] | |
base.setGitCadEngine(script) | |
for(DHParameterKinematics appendge: base.getAllDHChains()){ | |
appendge.setGitCadEngine(script) | |
} | |
return null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.neuronrobotics.bowlerstudio.creature.ICadGenerator; | |
import com.neuronrobotics.bowlerstudio.creature.CreatureLab; | |
import org.apache.commons.io.IOUtils; | |
import com.neuronrobotics.bowlerstudio.vitamins.*; | |
import java.nio.file.Paths; | |
import eu.mihosoft.vrl.v3d.FileUtil; | |
import com.neuronrobotics.bowlerstudio.vitamins.*; | |
println "Loading STL file" | |
// Load an STL file from a git repo | |
// Loading a local file also works here | |
return new ICadGenerator(){ | |
@Override | |
public ArrayList<CSG> generateCad(DHParameterKinematics d, int linkIndex) { | |
//create a sphere | |
int sphereRadius = 250; | |
int flapRadius = 130; | |
CSG body = new Sphere(250,40,40)// Spheres radius | |
.toCSG()// convert to CSG to display | |
CSG diskcylmask = new Cylinder(flapRadius, // Radius at the bottom | |
flapRadius, // Radius at the top | |
40, // Height | |
(int)30 //resolution | |
).toCSG().movez(210)//convert to CSG to display | |
CSG diskcylcut = new Cylinder(flapRadius+4, // Radius at the bottom | |
flapRadius+4, // Radius at the top | |
50, // Height | |
(int)30 //resolution | |
).toCSG().movez(200)//convert to CSG to display | |
CSG flap = diskcylmask.intersect(body); | |
CSG TopRightFlap = flap.roty(45).setColor(javafx.scene.paint.Color.CYAN); | |
CSG TopLeftFlap = flap.roty(-45).setColor(javafx.scene.paint.Color.CYAN);; | |
CSG BotRightFlap = flap.roty(-225).setColor(javafx.scene.paint.Color.CYAN);; | |
CSG BotLeftFlap = flap.roty(225).setColor(javafx.scene.paint.Color.CYAN);; | |
CSG Chassis = body.difference([diskcylcut.roty(45),diskcylcut.roty(225),diskcylcut.roty(-45),diskcylcut.roty(-225)]); | |
//return [Chassis,TopLeftFlap,BotRightFlap,BotLeftFlap]; | |
ArrayList<DHLink> dhLinks = d.getChain().getLinks() | |
ArrayList<CSG> allCad=new ArrayList<>() | |
int i=linkIndex; | |
DHLink dh = dhLinks.get(linkIndex) | |
// Hardware to engineering units configuration | |
LinkConfiguration conf = d.getLinkConfiguration(i); | |
// Engineering units to kinematics link (limits and hardware type abstraction) | |
AbstractLink abstractLink = d.getAbstractLink(i);// Transform used by the UI to render the location of the object | |
// Transform used by the UI to render the location of the object | |
Affine manipulator = dh.getListener(); | |
// loading the vitamins referenced in the configuration | |
CSG servo= Vitamins.get(conf.getElectroMechanicalType(),conf.getElectroMechanicalSize()) | |
CSG tmpSrv = servo | |
.rotx(-Math.toDegrees(dh.getAlpha())) | |
.rotz(-Math.toDegrees(dh.getTheta())) | |
.movex(-dh.getR()) | |
.movez(-dh.getD()) | |
flap .setManipulator(manipulator) | |
allCad.add(flap ) | |
println "Generating link: "+linkIndex | |
if(i==0){ | |
// more at https://github.com/NeuronRobotics/java-bowler/blob/development/src/main/java/com/neuronrobotics/sdk/addons/kinematics/DHLink.java | |
println dh | |
println "D = "+dh.getD()// this is the height of the link | |
println "R = "+dh.getR()// this is the radius of rotation of the link | |
println "Alpha = "+Math.toDegrees(dh.getAlpha())// this is the alpha rotation | |
println "Theta = "+Math.toDegrees(dh.getTheta())// this is the rotation about hte final like orentation | |
println conf // gets the link hardware map from https://github.com/NeuronRobotics/java-bowler/blob/development/src/main/java/com/neuronrobotics/sdk/addons/kinematics/LinkConfiguration.java | |
println conf.getHardwareIndex() // gets the link hardware index | |
println conf.getScale() // gets the link hardware scale to degrees from link units | |
// more from https://github.com/NeuronRobotics/java-bowler/blob/development/src/main/java/com/neuronrobotics/sdk/addons/kinematics/AbstractLink.java | |
println "Max engineering units for link = " + abstractLink.getMaxEngineeringUnits() | |
println "Min engineering units for link = " + abstractLink.getMinEngineeringUnits() | |
println "Position "+abstractLink.getCurrentEngineeringUnits() | |
println manipulator | |
} | |
return allCad; | |
} | |
@Override | |
public ArrayList<CSG> generateBody(MobileBase b ) { | |
ArrayList<CSG> allCad=new ArrayList<>(); | |
double size =40; | |
File servoFile = ScriptingEngine.fileFromGit( | |
"https://github.com/NeuronRobotics/NASACurisoity.git", | |
"STL/body.STL"); | |
// Load the .CSG from the disk and cache it in memory | |
CSG body = Vitamins.get(servoFile) | |
body.setManipulator(b.getRootListener()); | |
return [body]; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment