Search in sources :

Example 6 with PIDConfiguration

use of com.neuronrobotics.sdk.pid.PIDConfiguration in project java-bowler by NeuronRobotics.

the class AbstractKinematicsNR method setDevice.

protected void setDevice(LinkFactory f, ArrayList<LinkConfiguration> linkConfigs) {
    Log.info("Loading device: " + f.getClass() + " " + f);
    setFactory(f);
    // Log.enableDebugPrint(true);
    for (int i = 0; i < linkConfigs.size(); i++) {
        LinkConfiguration c = linkConfigs.get(i);
        c.setLinkIndex(i);
        getFactory().getLink(c);
        Log.info("\nAxis #" + i + " Configuration:\n" + c);
        if (c.getType() == LinkType.PID) {
            IPidControlNamespace device = getFactory().getPid();
            try {
                PIDConfiguration tmpConf = device.getPIDConfiguration(c.getHardwareIndex());
                tmpConf.setGroup(c.getHardwareIndex());
                tmpConf.setKP(c.getKP());
                tmpConf.setKI(c.getKI());
                tmpConf.setKD(c.getKD());
                tmpConf.setEnabled(true);
                tmpConf.setInverted(c.isInverted());
                tmpConf.setAsync(false);
                tmpConf.setUseLatch(false);
                tmpConf.setIndexLatch(c.getIndexLatch());
                tmpConf.setStopOnIndex(false);
                Log.info("\nAxis #" + i + " " + tmpConf);
                getAxisPidConfiguration().add(tmpConf);
                setLinkCurrentConfiguration(i, tmpConf);
                // Send configuration for ONE axis
                device.ConfigurePIDController(tmpConf);
            } catch (Exception ex) {
                Log.error("Configuration #" + i + " failed!!");
                ex.printStackTrace();
            }
            device.addPIDEventListener(this);
        }
    }
    getCurrentTaskSpaceTransform();
    getFactory().addLinkListener(this);
    getDhParametersChain().setFactory(getFactory());
    // filling up the d-h parameters so the chain sizes match
    while (getDhParametersChain().getLinks().size() < linkConfigs.size()) {
        getDhParametersChain().addLink(new DHLink(0, 0, 0, 0));
    }
}
Also used : IPidControlNamespace(com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace) PIDConfiguration(com.neuronrobotics.sdk.pid.PIDConfiguration) InvalidConnectionException(com.neuronrobotics.sdk.common.InvalidConnectionException) RuntimeErrorException(javax.management.RuntimeErrorException)

Example 7 with PIDConfiguration

use of com.neuronrobotics.sdk.pid.PIDConfiguration in project java-bowler by NeuronRobotics.

the class AbstractKinematicsNR method homeLink.

public void homeLink(int link) {
    if (link < 0 || link >= getNumberOfLinks()) {
        throw new IndexOutOfBoundsException("There are only " + getNumberOfLinks() + " known links, requested:" + link);
    }
    LinkConfiguration conf = getLinkConfiguration(link);
    if (conf.getType() == LinkType.PID) {
        getFactory().getPid().removePIDEventListener(this);
        // Range is in encoder units
        double range = Math.abs(conf.getUpperLimit() - conf.getLowerLimit()) * 2;
        Log.info("Homing link:" + link + " to latch value: " + conf.getIndexLatch());
        PIDConfiguration pidConf = getLinkCurrentConfiguration(link);
        PIDChannel joint = getFactory().getPid().getPIDChannel(conf.getHardwareIndex());
        // Clear the index
        pidConf.setStopOnIndex(false);
        pidConf.setUseLatch(false);
        pidConf.setIndexLatch(conf.getIndexLatch());
        // Sets up the latch
        joint.ConfigurePIDController(pidConf);
        // Move forward to stop
        runHome(joint, (int) (range));
        // Enable index
        pidConf.setStopOnIndex(true);
        pidConf.setUseLatch(true);
        pidConf.setIndexLatch(conf.getIndexLatch());
        // Sets up the latch
        joint.ConfigurePIDController(pidConf);
        // Move negative to the index
        runHome(joint, (int) (range * -1));
        pidConf.setStopOnIndex(false);
        pidConf.setUseLatch(false);
        pidConf.setIndexLatch(conf.getIndexLatch());
        // Shuts down the latch
        joint.ConfigurePIDController(pidConf);
        try {
            // go to zero instead of to the index itself
            setDesiredJointAxisValue(link, 0, 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
        getFactory().getPid().addPIDEventListener(this);
    } else {
        getFactory().getLink(getLinkConfiguration(link)).Home();
        getFactory().flush(1000);
    }
}
Also used : PIDChannel(com.neuronrobotics.sdk.pid.PIDChannel) PIDConfiguration(com.neuronrobotics.sdk.pid.PIDConfiguration) InvalidConnectionException(com.neuronrobotics.sdk.common.InvalidConnectionException) RuntimeErrorException(javax.management.RuntimeErrorException)

Example 8 with PIDConfiguration

use of com.neuronrobotics.sdk.pid.PIDConfiguration in project java-bowler by NeuronRobotics.

the class LinkConfiguration method getPidConfiguration.

public PIDConfiguration getPidConfiguration() {
    PIDConfiguration pid = new PIDConfiguration();
    pid.setKD(getKD());
    pid.setGroup(getHardwareIndex());
    pid.setStopOnIndex(isStopOnLatch());
    pid.setKI(getKI());
    pid.setKP(getKP());
    pid.setIndexLatch(getIndexLatch());
    pid.setInverted(isInverted());
    return pid;
}
Also used : PIDConfiguration(com.neuronrobotics.sdk.pid.PIDConfiguration)

Aggregations

PIDConfiguration (com.neuronrobotics.sdk.pid.PIDConfiguration)8 DyPIDConfiguration (com.neuronrobotics.sdk.dyio.dypid.DyPIDConfiguration)3 PIDChannel (com.neuronrobotics.sdk.pid.PIDChannel)3 LinkConfiguration (com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration)2 ServoRotoryLink (com.neuronrobotics.sdk.addons.kinematics.ServoRotoryLink)2 InvalidConnectionException (com.neuronrobotics.sdk.common.InvalidConnectionException)2 AnalogInputChannel (com.neuronrobotics.sdk.dyio.peripherals.AnalogInputChannel)2 ServoChannel (com.neuronrobotics.sdk.dyio.peripherals.ServoChannel)2 RuntimeErrorException (javax.management.RuntimeErrorException)2 VirtualAckermanBot (com.neuronrobotics.addons.driving.virtual.VirtualAckermanBot)1 VirtualLineSensor (com.neuronrobotics.addons.driving.virtual.VirtualLineSensor)1 DHParameterKinematics (com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics)1 ConfigurePIDCommand (com.neuronrobotics.sdk.commands.bcs.pid.ConfigurePIDCommand)1 BowlerDatagram (com.neuronrobotics.sdk.common.BowlerDatagram)1 DyIO (com.neuronrobotics.sdk.dyio.DyIO)1 IPidControlNamespace (com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace)1 NRSerialPort (gnu.io.NRSerialPort)1