Search in sources :

Example 11 with DyIO

use of com.neuronrobotics.sdk.dyio.DyIO in project java-bowler by NeuronRobotics.

the class SafeModeWatchDog method main.

/**
 * @param args
 */
public static void main(String[] args) {
    DyIO dyio = new DyIO();
    if (!ConnectionDialog.getBowlerDevice(dyio)) {
        System.exit(1);
    }
    int heartbeatTime = 3000;
    dyio.startHeartBeat(heartbeatTime);
    int getheartBeat = dyio.getHeartBeatTime();
    System.out.println("Told it to go to " + heartbeatTime + " got " + getheartBeat);
    System.exit(0);
}
Also used : DyIO(com.neuronrobotics.sdk.dyio.DyIO)

Example 12 with DyIO

use of com.neuronrobotics.sdk.dyio.DyIO in project java-bowler by NeuronRobotics.

the class USARTTest method main.

public static void main(String[] args) throws InterruptedException {
    DyIO dyio = new DyIO();
    if (!ConnectionDialog.getBowlerDevice(dyio)) {
        System.exit(0);
    }
    // Instantiate the UARTPassThroughChannel
    UARTChannel uart = new UARTChannel(dyio);
    // Configure the DyIO's output UART to use 115200 baud
    uart.setUARTBaudrate(115200);
    // Create a test string and send it to the serial port
    String s = new String("abcdefghijklmnopqrstuvwxyz");
    ByteList stream = new ByteList(s.getBytes());
    try {
        System.out.println("Sending: " + stream.asString());
        uart.sendBytes(stream);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
    Thread.sleep(1000);
    // Wait for data to arrive
    while (!uart.inStreamDataReady()) {
        Thread.sleep(10);
    }
    // Print out the data we got back
    try {
        System.out.println("Got input: " + new ByteList(uart.getBytes()).asString());
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
    // Cleanup and exit
    dyio.disconnect();
    System.exit(0);
}
Also used : UARTChannel(com.neuronrobotics.sdk.dyio.peripherals.UARTChannel) ByteList(com.neuronrobotics.sdk.common.ByteList) DyIO(com.neuronrobotics.sdk.dyio.DyIO) IOException(java.io.IOException) IOException(java.io.IOException)

Example 13 with DyIO

use of com.neuronrobotics.sdk.dyio.DyIO in project java-bowler by NeuronRobotics.

the class DyIOConversation method onMessage.

@Override
public String onMessage(String input, Chat chat, String from) {
    String[] packet = input.split("\\ ");
    if (packet[0].toLowerCase().contains("ping")) {
        return "ping: \n" + ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).ping();
    } else if (packet[0].toLowerCase().contains("state")) {
        return "state: \n" + ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).toString();
    } else if (packet[0].toLowerCase().contains("setmode")) {
        DyIOChannelMode m = DyIOChannelMode.DIGITAL_IN;
        boolean found = false;
        String options = "";
        for (DyIOChannelMode cm : EnumSet.allOf(DyIOChannelMode.class)) {
            options += cm.toSlug() + "\n";
            if (packet[2].toLowerCase().equals(cm.toSlug())) {
                m = cm;
                found = true;
            }
        }
        try {
            int port = Integer.parseInt(packet[1]);
            if (found && ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).canBeMode(m)) {
                ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).setMode(port, m);
                return "setMode " + port + " " + m.toSlug();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "error: Mode not settible on channel #" + packet[1] + " mode options are:\n" + options;
    } else if (packet[0].toLowerCase().contains("setvalue")) {
        int port = Integer.parseInt(packet[1]);
        int value = Integer.parseInt(packet[2]);
        ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).setValue(value);
        return "setValue " + port + " " + value;
    } else if (packet[0].toLowerCase().contains("getvalue")) {
        int port = Integer.parseInt(packet[1]);
        int value = ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).getValue();
        return "getValue " + port + " " + value;
    } else if (packet[0].toLowerCase().contains("addasync")) {
        int port = Integer.parseInt(packet[1]);
        int rate = 500;
        try {
            rate = Integer.parseInt(packet[2]);
        } catch (Exception ex) {
            rate = 500;
        }
        if (rate < 500)
            rate = 500;
        ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).setAsync(true);
        ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).configAdvancedAsyncNotEqual(rate);
        ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).addChannelEventListener(getListener(chat, from));
        return "async " + port + " " + rate;
    } else if (packet[0].toLowerCase().contains("removeasync")) {
        int port = Integer.parseInt(packet[1]);
        ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).removeChannelEventListener(getListener(chat, from));
        return "async removed " + port + " ";
    } else if (packet[0].toLowerCase().contains("reset")) {
        for (int i = 0; i < 24; i++) {
            ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(i).removeAllChannelEventListeners();
        }
        return "system reset!";
    } else {
        return help();
    }
}
Also used : DyIOChannelMode(com.neuronrobotics.sdk.dyio.DyIOChannelMode) DyIO(com.neuronrobotics.sdk.dyio.DyIO) XMPPException(org.jivesoftware.smack.XMPPException)

Example 14 with DyIO

use of com.neuronrobotics.sdk.dyio.DyIO in project java-bowler by NeuronRobotics.

the class DHKinematicsViewer method main.

public static void main(String[] args) {
    System.setProperty("prism.dirtyopts", "false");
    JFrame frame = new JFrame();
    DyIO.disableFWCheck();
    // Log.enableInfoPrint();
    // Create the references for my known DyIOs
    DyIO master = new DyIO(ConnectionDialog.promptConnection());
    master.connect();
    if (master.isAvailable()) {
        DHParameterKinematics model = new DHParameterKinematics(master, "TrobotMaster.xml");
        frame.setContentPane(new DHKinematicsViewer(model));
        frame.setSize(1024, 1024);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    Log.enableSystemPrint(false);
    while (true) {
        ThreadUtil.wait(1);
        master.getAllChannelValues();
    }
}
Also used : JFrame(javax.swing.JFrame) DyIO(com.neuronrobotics.sdk.dyio.DyIO) DHParameterKinematics(com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics)

Example 15 with DyIO

use of com.neuronrobotics.sdk.dyio.DyIO in project java-bowler by NeuronRobotics.

the class LinkFactory method getLinkLocal.

private AbstractLink getLinkLocal(LinkConfiguration c) {
    if (dyio == null)
        dyio = (DyIO) DeviceManager.getSpecificDevice(DyIO.class, c.getDeviceScriptingName());
    if (pid == null)
        pid = (IPidControlNamespace) DeviceManager.getSpecificDevice(IPidControlNamespace.class, c.getDeviceScriptingName());
    AbstractLink tmp = null;
    Log.info("Loading link: " + c.getName() + " type = " + c.getType() + " device= " + c.getDeviceScriptingName());
    switch(c.getType()) {
        case ANALOG_PRISMATIC:
            if (dyio != null) {
                tmp = new AnalogPrismaticLink(new AnalogInputChannel(dyio.getChannel(c.getHardwareIndex())), c);
                tmp.setUseLimits(false);
            }
            break;
        case ANALOG_ROTORY:
            if (dyio != null) {
                tmp = new AnalogRotoryLink(new AnalogInputChannel(dyio.getChannel(c.getHardwareIndex())), c);
                tmp.setUseLimits(false);
            }
            break;
        case PID_TOOL:
        case PID:
            if (pid != null) {
                tmp = new PidRotoryLink(pid.getPIDChannel(c.getHardwareIndex()), c);
            }
            break;
        case PID_PRISMATIC:
            if (pid != null) {
                tmp = new PidPrismaticLink(pid.getPIDChannel(c.getHardwareIndex()), c);
            }
            break;
        case SERVO_PRISMATIC:
            if (dyio != null) {
                tmp = new ServoPrismaticLink(new ServoChannel(dyio.getChannel(c.getHardwareIndex())), c);
            }
            break;
        case SERVO_ROTORY:
        case SERVO_TOOL:
            if (dyio != null) {
                tmp = new ServoRotoryLink(new ServoChannel(dyio.getChannel(c.getHardwareIndex())), c);
            }
            break;
        case STEPPER_PRISMATIC:
            if (dyio != null) {
                tmp = new StepperPrismaticLink(new CounterOutputChannel(dyio.getChannel(c.getHardwareIndex())), c);
            }
            break;
        case STEPPER_TOOL:
        case STEPPER_ROTORY:
            if (dyio != null) {
                tmp = new StepperRotoryLink(new CounterOutputChannel(dyio.getChannel(c.getHardwareIndex())), c);
            }
            break;
        case DUMMY:
        case VIRTUAL:
            String myVirtualDevName = c.getDeviceScriptingName();
            virtual = (VirtualGenericPIDDevice) DeviceManager.getSpecificDevice(VirtualGenericPIDDevice.class, myVirtualDevName);
            if (virtual == null) {
                virtual = new VirtualGenericPIDDevice();
                DeviceManager.addConnection(virtual, myVirtualDevName);
            }
            tmp = new PidRotoryLink(virtual.getPIDChannel(c.getHardwareIndex()), c);
            break;
    }
    if (tmp == null) {
        String myVirtualDevName = "virtual_" + c.getDeviceScriptingName();
        virtual = (VirtualGenericPIDDevice) DeviceManager.getSpecificDevice(VirtualGenericPIDDevice.class, myVirtualDevName);
        if (virtual == null) {
            virtual = new VirtualGenericPIDDevice();
            DeviceManager.addConnection(virtual, myVirtualDevName);
        }
        if (!c.getType().isPrismatic()) {
            tmp = new PidRotoryLink(virtual.getPIDChannel(c.getHardwareIndex()), c);
        } else {
            tmp = new PidPrismaticLink(virtual.getPIDChannel(c.getHardwareIndex()), c);
        }
    }
    tmp.setLinkConfiguration(c);
    links.add(tmp);
    if (!getLinkConfigurations().contains(c))
        getLinkConfigurations().add(c);
    return tmp;
}
Also used : CounterOutputChannel(com.neuronrobotics.sdk.dyio.peripherals.CounterOutputChannel) IPidControlNamespace(com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace) AnalogInputChannel(com.neuronrobotics.sdk.dyio.peripherals.AnalogInputChannel) ServoChannel(com.neuronrobotics.sdk.dyio.peripherals.ServoChannel) DyIO(com.neuronrobotics.sdk.dyio.DyIO) VirtualGenericPIDDevice(com.neuronrobotics.sdk.pid.VirtualGenericPIDDevice)

Aggregations

DyIO (com.neuronrobotics.sdk.dyio.DyIO)25 ServoChannel (com.neuronrobotics.sdk.dyio.peripherals.ServoChannel)5 AnalogInputChannel (com.neuronrobotics.sdk.dyio.peripherals.AnalogInputChannel)3 CounterOutputChannel (com.neuronrobotics.sdk.dyio.peripherals.CounterOutputChannel)3 DigitalInputChannel (com.neuronrobotics.sdk.dyio.peripherals.DigitalInputChannel)3 ByteList (com.neuronrobotics.sdk.common.ByteList)2 DyIOChannelMode (com.neuronrobotics.sdk.dyio.DyIOChannelMode)2 BowlerBoardDevice (com.neuronrobotics.replicator.driver.BowlerBoardDevice)1 NRPrinter (com.neuronrobotics.replicator.driver.NRPrinter)1 DHParameterKinematics (com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics)1 LinkConfiguration (com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration)1 ServoRotoryLink (com.neuronrobotics.sdk.addons.kinematics.ServoRotoryLink)1 NRBootLoader (com.neuronrobotics.sdk.bootloader.NRBootLoader)1 BowlerCamDevice (com.neuronrobotics.sdk.bowlercam.device.BowlerCamDevice)1 BowlerAbstractConnection (com.neuronrobotics.sdk.common.BowlerAbstractConnection)1 DyPIDConfiguration (com.neuronrobotics.sdk.dyio.dypid.DyPIDConfiguration)1 CounterInputChannel (com.neuronrobotics.sdk.dyio.peripherals.CounterInputChannel)1 DCMotorOutputChannel (com.neuronrobotics.sdk.dyio.peripherals.DCMotorOutputChannel)1 DigitalOutputChannel (com.neuronrobotics.sdk.dyio.peripherals.DigitalOutputChannel)1 PWMOutputChannel (com.neuronrobotics.sdk.dyio.peripherals.PWMOutputChannel)1