Search in sources :

Example 1 with PIDChannel

use of com.neuronrobotics.sdk.pid.PIDChannel 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 PIDChannel

use of com.neuronrobotics.sdk.pid.PIDChannel 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 PIDChannel

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

the class AbstractPidNamespaceImp method getPIDChannel.

/* (non-Javadoc)
	 * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#getPIDChannel
	 */
@Override
public PIDChannel getPIDChannel(int group) {
    if (getNumberOfChannels() == 0) {
        getChannels();
    }
    while (!(group < getNumberOfChannels())) {
        PIDChannel c = new PIDChannel(this, group);
        getChannels().add(c);
    }
    return getChannels().get(group);
}
Also used : PIDChannel(com.neuronrobotics.sdk.pid.PIDChannel)

Example 4 with PIDChannel

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

the class LegacyPidNamespaceImp method GetAllPIDPosition.

@Override
public int[] GetAllPIDPosition() {
    Log.debug("Getting All PID Positions");
    BowlerDatagram b = getDevice().send(new ControlAllPIDCommand());
    ByteList data = b.getData();
    int[] back = new int[data.size() / 4];
    for (int i = 0; i < back.length; i++) {
        int start = i * 4;
        byte[] tmp = data.getBytes(start, 4);
        back[i] = ByteList.convertToInt(tmp, true);
    }
    if (back.length != getNumberOfChannels()) {
        lastPacketTime = new long[back.length];
        for (int i = 0; i < back.length; i++) {
            PIDChannel c = new PIDChannel(this, i);
            c.setCachedTargetValue(back[i]);
            getChannels().add(c);
        }
    }
    return back;
}
Also used : ByteList(com.neuronrobotics.sdk.common.ByteList) PIDChannel(com.neuronrobotics.sdk.pid.PIDChannel) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) ControlAllPIDCommand(com.neuronrobotics.sdk.commands.bcs.pid.ControlAllPIDCommand)

Example 5 with PIDChannel

use of com.neuronrobotics.sdk.pid.PIDChannel 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)

Aggregations

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