Search in sources :

Example 1 with LinkConfiguration

use of com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration in project java-bowler by NeuronRobotics.

the class DrivingTest method setupRealRobot.

private void setupRealRobot(DyIO dyio) {
    DyPIDConfiguration dypid = new // PID group 0
    DyPIDConfiguration(// PID group 0
    0, // Input channel number
    23, // Input mode
    DyIOChannelMode.COUNT_IN_INT, // Output Channel
    11, // Output mode
    DyIOChannelMode.SERVO_OUT);
    PIDConfiguration pid = new // PID group
    PIDConfiguration(// PID group
    0, // enabled
    true, // inverted
    false, // Async
    true, // Kp
    1, // Ki
    1, // Kd
    .5, // Value to latch on index pulse
    0, // Use the latch system
    false, // Stop PID controller on index latch event
    false);
    dyio.ConfigureDynamicPIDChannels(dypid);
    dyio.ConfigurePIDController(pid);
    PIDChannel drive = dyio.getPIDChannel(0);
    ServoChannel srv = new ServoChannel(dyio.getChannel(10));
    AckermanBot a = new AckermanBot(new ServoRotoryLink(srv, new LinkConfiguration(98, 51, 143, 1)), drive);
    ServoChannel sweeper = new ServoChannel(dyio.getChannel(9));
    range = new LaserRangeSensor(new NRSerialPort("/dev/ttyACM0", 115200));
    // range = new LinearRangeSensor(	sweeper,
    // new AnalogInputChannel(dyio.getChannel(12)));
    line = new LineSensor(new AnalogInputChannel(dyio.getChannel(13)), null, new AnalogInputChannel(dyio.getChannel(14)));
    // This flame sensor uses the same servo as the rangefinder
    flame = new LinearRangeSensor(sweeper, new AnalogInputChannel(dyio.getChannel(15)));
    mainRobot = a;
}
Also used : PIDChannel(com.neuronrobotics.sdk.pid.PIDChannel) ServoChannel(com.neuronrobotics.sdk.dyio.peripherals.ServoChannel) LinkConfiguration(com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration) VirtualLineSensor(com.neuronrobotics.addons.driving.virtual.VirtualLineSensor) AnalogInputChannel(com.neuronrobotics.sdk.dyio.peripherals.AnalogInputChannel) PIDConfiguration(com.neuronrobotics.sdk.pid.PIDConfiguration) DyPIDConfiguration(com.neuronrobotics.sdk.dyio.dypid.DyPIDConfiguration) VirtualAckermanBot(com.neuronrobotics.addons.driving.virtual.VirtualAckermanBot) NRSerialPort(gnu.io.NRSerialPort) DyPIDConfiguration(com.neuronrobotics.sdk.dyio.dypid.DyPIDConfiguration) ServoRotoryLink(com.neuronrobotics.sdk.addons.kinematics.ServoRotoryLink)

Example 2 with LinkConfiguration

use of com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration in project java-bowler by NeuronRobotics.

the class RealLineTrack method main.

/**
 * @param args
 */
public static void main(String[] args) {
    final DyIO d = new DyIO();
    ConnectionDialog.getBowlerDevice(d);
    if (d.isAvailable()) {
        new Thread() {

            public void run() {
                DyPIDConfiguration dypid = new // PID group 0
                DyPIDConfiguration(// PID group 0
                0, // Input channel number
                23, // Input mode
                DyIOChannelMode.COUNT_IN_INT, // Output Channel
                11, // Output mode
                DyIOChannelMode.SERVO_OUT);
                PIDConfiguration pid = new // PID group
                PIDConfiguration(// PID group
                0, // enabled
                true, // inverted
                false, // Async
                true, // Kp
                1, // Ki
                1, .5, 0, false, // Kd
                false);
                d.ConfigureDynamicPIDChannels(dypid);
                d.ConfigurePIDController(pid);
                PIDChannel drive = d.getPIDChannel(0);
                ServoChannel srv = new ServoChannel(d.getChannel(10));
                AbstractRobotDrive mainRobot = new AckermanBot(new ServoRotoryLink(srv, new LinkConfiguration(98, 51, 143, 1)), drive);
                AbstractSensor line = new LineSensor(new AnalogInputChannel(d.getChannel(14), true), null, new AnalogInputChannel(d.getChannel(13), true));
            // new LineTrack().runTrack(mainRobot,line);
            }
        }.start();
    } else {
        System.out.println("Failed");
        d.disconnect();
    }
}
Also used : AnalogInputChannel(com.neuronrobotics.sdk.dyio.peripherals.AnalogInputChannel) PIDConfiguration(com.neuronrobotics.sdk.pid.PIDConfiguration) DyPIDConfiguration(com.neuronrobotics.sdk.dyio.dypid.DyPIDConfiguration) DyPIDConfiguration(com.neuronrobotics.sdk.dyio.dypid.DyPIDConfiguration) PIDChannel(com.neuronrobotics.sdk.pid.PIDChannel) ServoChannel(com.neuronrobotics.sdk.dyio.peripherals.ServoChannel) LinkConfiguration(com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration) DyIO(com.neuronrobotics.sdk.dyio.DyIO) ServoRotoryLink(com.neuronrobotics.sdk.addons.kinematics.ServoRotoryLink)

Example 3 with LinkConfiguration

use of com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration in project bowler-script-kernel by CommonWealthRobotics.

the class MobileBaseCadManager method _generateStls.

private ArrayList<File> _generateStls(MobileBase base, File baseDirForFiles, boolean kinematic) throws IOException {
    ArrayList<File> allCadStl = new ArrayList<>();
    ArrayList<DHParameterKinematics> limbs = base.getAllDHChains();
    double numLimbs = limbs.size();
    int i;
    // Start by generating the legs using the DH link based generator
    ArrayList<CSG> totalAssembly = new ArrayList<>();
    double offset = 0;
    for (i = 0; i < limbs.size(); i += 1) {
        double progress = (1.0 - ((numLimbs - i) / numLimbs)) / 2;
        getProcesIndictor().set(progress);
        DHParameterKinematics l = limbs.get(i);
        ArrayList<CSG> parts = getDHtoCadMap().get(l);
        for (int j = 0; j < parts.size(); j++) {
            CSG csg = parts.get(j);
            String name = csg.getName();
            try {
                CSG tmp;
                if (!kinematic)
                    csg = csg.prepForManufacturing();
                if (csg != null) {
                    if (!kinematic) {
                        tmp = csg.toXMax().toYMax();
                    } else {
                        tmp = csg;
                    }
                    if (totalAssembly.size() > 0 && !kinematic)
                        totalAssembly.add(tmp.movey(.5 + totalAssembly.get(totalAssembly.size() - 1).getMaxY() + Math.abs(csg.getMinY())));
                    else
                        totalAssembly.add(tmp);
                    LinkConfiguration conf = getLinkConfiguration(parts.get(j));
                    String linkNum = conf.getLinkIndex() + "_Link_";
                    File dir = new File(baseDirForFiles.getAbsolutePath() + "/" + base.getScriptingName() + "/" + l.getScriptingName());
                    if (!dir.exists())
                        dir.mkdirs();
                    System.out.println("Making STL for " + name);
                    File stl = new File(dir.getAbsolutePath() + "/" + linkNum + name + "_limb_" + i + "_Part_" + j + ".stl");
                    FileUtil.write(Paths.get(stl.getAbsolutePath()), tmp.toStlString());
                    allCadStl.add(stl);
                    // totalAssembly.add(tmp);
                    getUi().setAllCSG(totalAssembly, getCadScript());
                    set(base, i, j);
                }
            } catch (Exception ex) {
                getUi().highlightException(getCadScript(), ex);
            }
        // legAssembly.setManufactuing(new PrepForManufacturing() {
        // public CSG prep(CSG arg0) {
        // return null;
        // }
        // });
        }
    // offset =
    // -2-((legAssembly.get(legAssembly.size()-1).getMaxX()+legAssembly.get(legAssembly.size()-1).getMinX())*i);
    // legAssembly=legAssembly.movex(offset);
    }
    int link = 0;
    // now we genrate the base pieces
    for (CSG csg : getBasetoCadMap().get(base)) {
        String name = csg.getName();
        try {
            if (!kinematic)
                csg = csg.prepForManufacturing();
            if (csg != null) {
                if (!kinematic) {
                    csg = csg.toYMin().movex(-2 - csg.getMaxX() + offset);
                }
                File dir = new File(baseDirForFiles.getAbsolutePath() + "/" + base.getScriptingName() + "/");
                if (!dir.exists())
                    dir.mkdirs();
                File stl = new File(dir.getAbsolutePath() + "/" + name + "_Body_part_" + link + ".stl");
                FileUtil.write(Paths.get(stl.getAbsolutePath()), csg.toStlString());
                allCadStl.add(stl);
                totalAssembly.add(csg);
                getUi().setAllCSG(totalAssembly, getCadScript());
                link++;
            }
        } catch (Exception ex) {
            getUi().highlightException(getCadScript(), ex);
        }
    }
    // ui.setCsg(BasetoCadMap.get(base),getCadScript());
    // for(CSG c: DHtoCadMap.get(base.getAllDHChains().get(0))){
    // ui.addCsg(c,getCadScript());
    // }
    showingStl = true;
    getProcesIndictor().set(1);
    return allCadStl;
}
Also used : LinkConfiguration(com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration) CSG(eu.mihosoft.vrl.v3d.CSG) ArrayList(java.util.ArrayList) DHParameterKinematics(com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics) File(java.io.File) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) TransportException(org.eclipse.jgit.api.errors.TransportException) InvalidRemoteException(org.eclipse.jgit.api.errors.InvalidRemoteException)

Example 4 with LinkConfiguration

use of com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration in project bowler-script-kernel by CommonWealthRobotics.

the class MobileBaseCadManager method generateCad.

/**
 * This function iterates through the links generating them
 *
 * @param dh
 * @return
 */
public ArrayList<CSG> generateCad(DHParameterKinematics dh) {
    ArrayList<CSG> dhLinks = new ArrayList<>();
    if (cadEngine == null) {
        try {
            setDefaultLinkLevelCadEngine();
        } catch (Exception e) {
            getUi().highlightException(getCadScript(), e);
        }
    }
    try {
        IgenerateCad generatorToUse = getIgenerateCad();
        if (dhCadGen.get(dh) != null) {
            Object object = dhCadGen.get(dh);
            if (IgenerateCad.class.isInstance(object))
                generatorToUse = (IgenerateCad) object;
        }
        int j = 0;
        for (DHParameterKinematics dhtest : getMobileBase().getAllDHChains()) {
            if (dhtest == dh)
                break;
            j++;
        }
        for (int i = 0; i < dh.getNumberOfLinks(); i++) {
            set(base, (int) j, (int) i);
            if (!bail) {
                ArrayList<CSG> tmp = generatorToUse.generateCad(dh, i);
                getUi().addCSG(tmp, getCadScript());
                LinkConfiguration configuration = dh.getLinkConfiguration(i);
                if (getLinktoCadMap().get(configuration) == null) {
                    getLinktoCadMap().put(configuration, new ArrayList<>());
                } else
                    getLinktoCadMap().get(configuration).clear();
                for (CSG c : tmp) {
                    dhLinks.add(c);
                    // add to
                    getLinktoCadMap().get(configuration).add(c);
                // the
                // regestration
                // storage
                }
                AbstractLink link = dh.getFactory().getLink(configuration);
                link.addLinkListener(new ILinkListener() {

                    @Override
                    public void onLinkPositionUpdate(AbstractLink arg0, double arg1) {
                    // TODO Auto-generated method stub
                    }

                    @Override
                    public void onLinkLimit(AbstractLink arg0, PIDLimitEvent arg1) {
                        if (getAutoRegen())
                            selectCsgByLink(base, configuration);
                    }
                });
            }
        }
        return dhLinks;
    } catch (Exception e) {
        getUi().highlightException(getCadScript(), e);
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) TransportException(org.eclipse.jgit.api.errors.TransportException) InvalidRemoteException(org.eclipse.jgit.api.errors.InvalidRemoteException) ILinkListener(com.neuronrobotics.sdk.addons.kinematics.ILinkListener) LinkConfiguration(com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration) CSG(eu.mihosoft.vrl.v3d.CSG) PIDLimitEvent(com.neuronrobotics.sdk.pid.PIDLimitEvent) DHParameterKinematics(com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics) AbstractLink(com.neuronrobotics.sdk.addons.kinematics.AbstractLink)

Example 5 with LinkConfiguration

use of com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration in project java-bowler by NeuronRobotics.

the class BasicWalker method parse.

private void parse(InputStream is) {
    /**
     * sample code from
     * http://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/
     */
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder;
    Document doc = null;
    try {
        dBuilder = dbFactory.newDocumentBuilder();
        doc = dBuilder.parse(is);
        doc.getDocumentElement().normalize();
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    } catch (SAXException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    // System.out.println("Parsing File...");
    NodeList nList = doc.getElementsByTagName("leg");
    for (int temp = 0; temp < nList.getLength(); temp++) {
        // System.out.println("Leg # "+temp);
        Node nNode = nList.item(temp);
        ArrayList<WalkerServoLink> legLinks = new ArrayList<WalkerServoLink>();
        if (nNode.getNodeType() == Node.ELEMENT_NODE) {
            Element eElement = (Element) nNode;
            x = Double.parseDouble(getTagValue("x", eElement));
            y = Double.parseDouble(getTagValue("y", eElement));
            theta = Double.parseDouble(getTagValue("theta", eElement));
            // Leg tmpLeg = new Leg(x,y,theta);
            NodeList links = eElement.getElementsByTagName("link");
            for (int i = 0; i < links.getLength(); i++) {
                // System.out.println("\tLink # "+i);
                Node lNode = links.item(i);
                if (lNode.getNodeType() == Node.ELEMENT_NODE) {
                    Element lElement = (Element) lNode;
                    llimit = Integer.parseInt(getTagValue("llimit", lElement));
                    ulimit = Integer.parseInt(getTagValue("ulimit", lElement));
                    home = Integer.parseInt(getTagValue("home", lElement));
                    channel = Integer.parseInt(getTagValue("channel", lElement));
                    inverse = Double.parseDouble(getTagValue("inverse", lElement));
                    scale = Double.parseDouble(getTagValue("scale", lElement));
                    linkLen = Double.parseDouble(getTagValue("linkLen", lElement));
                    String type = getTagValue("type", lElement);
                    if (useHardware) {
                        ServoChannel srv = new ServoChannel(getDyio().getChannel(channel));
                        WalkerServoLink tmpLink = new WalkerServoLink(srv, new LinkConfiguration(home, llimit, ulimit, (scale * inverse)), linkLen, type);
                        legLinks.add(tmpLink);
                    }
                }
            }
            addLeg(x, y, theta, legLinks);
        } else {
        // System.out.println("Not Element Node");
        }
    }
    System.out.println("Populated Hexapod.");
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) ServoChannel(com.neuronrobotics.sdk.dyio.peripherals.ServoChannel) LinkConfiguration(com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

LinkConfiguration (com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration)6 DHParameterKinematics (com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics)3 ServoChannel (com.neuronrobotics.sdk.dyio.peripherals.ServoChannel)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ServoRotoryLink (com.neuronrobotics.sdk.addons.kinematics.ServoRotoryLink)2 DyPIDConfiguration (com.neuronrobotics.sdk.dyio.dypid.DyPIDConfiguration)2 AnalogInputChannel (com.neuronrobotics.sdk.dyio.peripherals.AnalogInputChannel)2 PIDChannel (com.neuronrobotics.sdk.pid.PIDChannel)2 PIDConfiguration (com.neuronrobotics.sdk.pid.PIDConfiguration)2 CSG (eu.mihosoft.vrl.v3d.CSG)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 InvalidRemoteException (org.eclipse.jgit.api.errors.InvalidRemoteException)2 TransportException (org.eclipse.jgit.api.errors.TransportException)2 VirtualAckermanBot (com.neuronrobotics.addons.driving.virtual.VirtualAckermanBot)1 VirtualLineSensor (com.neuronrobotics.addons.driving.virtual.VirtualLineSensor)1 LinkConfigurationWidget (com.neuronrobotics.bowlerstudio.creature.LinkConfigurationWidget)1 LinkSliderWidget (com.neuronrobotics.bowlerstudio.creature.LinkSliderWidget)1 AbstractLink (com.neuronrobotics.sdk.addons.kinematics.AbstractLink)1 ILinkListener (com.neuronrobotics.sdk.addons.kinematics.ILinkListener)1