|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
UDP Recieving Problems
We are trying to send information from a custom labview dashboard to the robot (runs java). We have a regular java applet that I can upload if you would like to see it, that works perfectly. When we try to enable the robot we get robots don't quit. Here is our code. Do you see any problems. Thanks.
Code:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.*;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.Datagram;
import javax.microedition.io.DatagramConnection;
import javax.microedition.io.UDPDatagramConnection;
public class RobotTemplate extends SimpleRobot {
double targX = 0.0;
double targArea = 0.0;
boolean aHasValue = false;
boolean xHasValue = false;
double distanceFromTarg = 0.0;
static final double distanceConversionFactor = 0;
static final int IMAGE_WIDTH = 320;
int batman = 0;
Datagram data;
DatagramConnection receivePacket;
String rawUdpData;
Jaguar jagL1 = new Jaguar(3);
Jaguar jagL2 = new Jaguar(4);
Jaguar jagR1 = new Jaguar(1);
Jaguar jagR2 = new Jaguar(2);
Joystick stick3 = new Joystick(3);
public void autonomous() {
}
public void operatorControl() {
while (isOperatorControl()) {
udp();
if (stick3.getRawButton(2)) {
tracking();
} else {
jagL1.set(0.0);
jagR1.set(0.0);
jagL2.set(0.0);
jagR2.set(0.0);
}
}
}
public void udp() {
try {
receivePacket = (DatagramConnection)
Connector.open("data://:1130");
// = new DatagramConnection(5021); //put port in here
try{
receivePacket.receive(data);
}finally{
receivePacket.close();
}
//rawUdpData = data.readUTF();
rawUdpData = (String.valueOf(data.getData()));
} catch (IOException ex) {
ex.printStackTrace();
}
// byte[] receiveData = new byte[1024]; //1024 is time out
String udpArea = new String();
String udpX = new String();
//data recieving
//DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
// serverSocket.receive(receivePacket);
//String rawUdpData = new String(receivePacket.getData());
// System.out.println("RECEIVED: " + rawUdpData);
//string analizing
if (rawUdpData.startsWith("Area: ")) { // 1 spaces
//System.out.println("worked");
udpArea = rawUdpData.replace('A', ' ');
udpArea = udpArea.replace('r', ' ');
udpArea = udpArea.replace('e', ' ');
udpArea = udpArea.replace('a', ' ');
udpArea = udpArea.replace(':', ' ');
// udpArea = (rawUdpData.replace("Area: ", ""));
udpArea = udpArea.trim();
}
if (rawUdpData.startsWith("Bounding X: ")) { // 1 spaces
udpX = rawUdpData.replace('B', ' ');
udpX = udpX.replace('o', ' ');
udpX = udpX.replace('u', ' ');
udpX = udpX.replace('n', ' ');
udpX = udpX.replace('d', ' ');
udpX = udpX.replace('i', ' ');
udpX = udpX.replace('n', ' ');
udpX = udpX.replace('g', ' ');
udpX = udpX.replace('X', ' ');
udpX = udpX.replace(':', ' ');
// udpX = (rawUdpData.replace("Bounding X: ", "")); //removes lables
udpX = udpX.trim(); //removes whitespace in string
}
//safty for converting string to double
if (udpArea.length() > 0) {
aHasValue = true;
} else {
aHasValue = false;
targArea = 0.0;
}
if (udpX.length() > 0) {
xHasValue = true;
} else {
xHasValue = false;
targX = 0.0;
}
//converts string to double
if (aHasValue) {
targArea = Double.parseDouble(udpArea);
}
if (xHasValue) {
targX = Double.parseDouble(udpX);
}
System.out.println("Area string: " + udpArea);
System.out.println("X string: " + udpX);
System.out.println("a: " + targArea);
System.out.println("X: " + targX);
}
public void tracking() {
if (xHasValue) {
double distOffCenter = ((IMAGE_WIDTH / 2) - targX);
double ratioOffCenter = distOffCenter / (IMAGE_WIDTH / 2);
double speed = (0.3 * (ratioOffCenter * ratioOffCenter) + (distOffCenter > 0 ? 0.4 : -0.4)); //Left Right
if ((Math.abs(speed)) <= 0.41 && batman <= 15) {
batman++;
}
if (Math.abs(speed) <= 0.41) {
jagL1.set(0.0);
jagL2.set(0.0);
jagR1.set(0.0);
jagR2.set(0.0);
} else {
jagL1.set(speed);
jagL2.set(speed);
jagR1.set(speed);
jagR2.set(speed);
}
} else {
System.out.println("NOIMAGE");//Middle of target // myDrive.tankDrive(0, 0);
jagL1.set(0.0);
jagL2.set(0.0);
jagR1.set(0.0);
jagR2.set(0.0);
}
}
}
//end of class
Last edited by tyandjel94 : 05-18-2012 at 10:54 AM. |
|
#2
|
||||
|
||||
|
Re: UDP Recieving Problems
Quote:
This thread says that it's probably an uncaught exception somewhere. Are you getting any other information printing out? i.e. stack trace, etc.? |
|
#3
|
|||
|
|||
|
Re: UDP Recieving Problems
No. When we press enable it goes straight to robots don't quit. Do you see anything that isn't correctly coded for udp?
|
|
#4
|
|||
|
|||
|
Re: UDP Recieving Problems
Would a possibility be a security exception?
|
|
#5
|
|||
|
|||
|
Re: UDP Recieving Problems
When it says "robots don't quit," it means that you are getting an exception. I believe it prints out the exception as well...
|
|
#6
|
||||
|
||||
|
Re: UDP Recieving Problems
Yes, that message is part of the library, not your code. It is supposed to print a stack trace with the actual error message immediately following the "robots don't quit" message.
|
|
#7
|
|||
|
|||
|
Re: UDP Recieving Problems
We have been getting the IO exception.
|
|
#8
|
|||
|
|||
|
Re: UDP Recieving Problems
We aren't able to open the socket to the labview part can connect to it.
|
|
#9
|
|||
|
|||
|
Re: UDP Recieving Problems
Can you post the complete output of the console where you are getting the "Robots don't quit" message.
To help point you in the right direction in the mean time: That message means there is an uncaught exception and it bubbled up to the system level. If it is an uncaught IO exception it should tell you a line number as well, but it probably has to do with your something within the udp() function. Are you sure the parameter to connector.open is correct? I believe you should be using a "datagram" protocol instead of a "data" protocol. For example A datagram connection for accepting datagrams on port 1234 "datagram://:1234" A datagram connection for sending to a server on port 1234: "datagram://123.456.789.12:1234" And it also looks like you never instantiate the Datagram variable "data", so its null when you call data.readUTF, and null when you use it as a param in receive(data). But that should throw a null point exception, and you should be seeing that in the console. If you don't that's because the program is failing before it gets to that line, which case your problem lies where you open your connection to the datagram (or maybe you do instantiate it somewhere and I just didn't notice it). You mentioned that you have a java applet that works. Is that written using the same version of JavaME that is running on the cRIO? My guess is that you copied your code from the applet to the CRIO, however, if the code was written under different java environments it will not be able to run on the cRIO without modification. Hope that helps. Kevin Last edited by NotInControl : 05-26-2012 at 12:54 AM. |
|
#10
|
|||
|
|||
|
Re: UDP Recieving Problems
We had issues with networking in general. We used TCP for our robot-OI communication. I'd assume it's a bug on the FRC side, as opposed to yours - our code would work 3/4 of the time, and require a robot restart if it failed.
|
|
#11
|
||||||
|
||||||
|
Re: UDP Recieving Problems
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|