Robot will not drive when using UDP in autonomous


I’ve wrote UDP code to communicate with a beaglebone from the roboRIO, however when the I put on autonomous mode and the UDP is used none of the motors work, and when I change back to teleop I still can’t control anything.

Here is the code:

public class Robot extends IterativeRobot {
	//Beaglebone Communications
    DatagramSocket serverSocket;
    byte] receiveData;
    byte] sendData;

Code for robot init

try {
			serverSocket = new DatagramSocket(9876);
		} catch (SocketException e) {
			// TODO Auto-generated catch block
    	receiveData = new byte[1024];
        sendData = new byte[1024];	

public void autonomousPeriodic() {
    	//Receive Data
        DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
        try {
		} catch (IOException e) {
			// TODO Auto-generated catch block
        String sentence = new String( receivePacket.getData());
        System.out.println("RECEIVED: " + sentence);
        InetAddress IPAddress = receivePacket.getAddress();
        int port = receivePacket.getPort();

        //Return data
        String capitalizedSentence = sentence.toUpperCase();
        sendData = capitalizedSentence.getBytes();
        DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port);
        try {
		} catch (IOException e) {
			// TODO Auto-generated catch block
        switch (sentence) {
        	case "a":
        		myRobot.tankDrive(0.5, 0.5);
        	case "b":



Thanks for any help!

You may be running into a Java subtlety here.

boolean eq = ("abc" == "abc");
System.out.println(eq); // false!

I’m not entirely sure, but it may be the same problem in your switch statement. Try using String.equals in an if-else instead.

Otherwise, use the debugger to verify that sentence contains the “a” or “b” you need.

From the documentation for DatagramSocket.receive():

This method blocks until a datagram is received.

This means it will wait for information from the beaglebone before continuing with your user program. This waiting causes the motors to not be updated fast enough. I see two options to solve this:

We have a NetworkTables build for the beaglebone on the WPILib maven server (armhf):

Take a look at this document for more information:

That looks ok to me. Take a look at this Oracle document:

As it turns out, the string being sent was not just a single letter, It was a single letter with another 1023 filler characters. When I made it split up the string based on spaces the switch function worked.

Also thank you for the networking table content, I will look into setting up a seperate thread because the robot “jitters” and moves a tiny bit every time a udp packet is received!

The beauty of NetworkTables is that they’ve dealt with the threading issues for you already. If you aren’t familiar with/comfortable with multithreaded programming in Java, tread carefully on the UDP route!