Skip to content

Instantly share code, notes, and snippets.

@madhephaestus
Last active December 18, 2019 17:30
Show Gist options
  • Save madhephaestus/e54cfebe4f55fb0549dd to your computer and use it in GitHub Desktop.
Save madhephaestus/e54cfebe4f55fb0549dd to your computer and use it in GitHub Desktop.
import com.neuronrobotics.bowlerstudio.creature.ICadGenerator;
import com.neuronrobotics.bowlerstudio.creature.CreatureLab;
import org.apache.commons.io.IOUtils;
def base;
//Check if the device already exists in the device Manager
if(args==null){
base=DeviceManager.getSpecificDevice( "CarlTheWalkingRobot",{
//If the device does not exist, prompt for the connection
MobileBase m = MobileBaseLoader.fromGit(
"https://github.com/madhephaestus/carl-the-hexapod.git",
"CarlTheRobot.xml"
)
if(m==null)
throw new RuntimeException("Arm failed to assemble itself")
println "Connecting new device robot arm "+m
return m
})
}else
base=args.get(0)
def script = ["https://gist.github.com/e54cfebe4f55fb0549dd.git","ExampleCadGenerator.groovy"]as String[]
base.setGitCadEngine(script)
for(DHParameterKinematics appendge: base.getAllDHChains()){
appendge.setGitCadEngine(script)
}
return null;
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.*;
import javafx.scene.transform.Affine;
println "Loading STL file"
// Load an STL file from a git repo
// Loading a local file also works here
CSG reverseDHValues(CSG incoming,DHLink dh ){
println "Reversing "+dh
TransformNR step = new TransformNR(dh.DhStep(0))
Transform move = com.neuronrobotics.bowlerstudio.physics.TransformFactory.nrToCSG(step)
return incoming.transformed(move)
}
CSG moveDHValues(CSG incoming,DHLink dh ){
TransformNR step = new TransformNR(dh.DhStep(0)).inverse()
Transform move = com.neuronrobotics.bowlerstudio.physics.TransformFactory.nrToCSG(step)
return incoming.transformed(move)
}
return new ICadGenerator(){
@Override
public ArrayList<CSG> generateCad(DHParameterKinematics d, int linkIndex) {
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
Affine manipulator = dh.getListener();
// loading the vitamins referenced in the configuration
CSG servo= Vitamins.get(conf.getElectroMechanicalType(),conf.getElectroMechanicalSize())
CSG tmpSrv = moveDHValues(servo,dh)
//Compute the location of the base of this limb to place objects at the root of the limb
TransformNR step = d.getRobotToFiducialTransform()
Transform locationOfBaseOfLimb = com.neuronrobotics.bowlerstudio.physics.TransformFactory.nrToCSG(step)
tmpSrv.setManipulator(manipulator)
allCad.add(tmpSrv)
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