OCCRA
Go to Post I include these trivial facts for the sole purpose of confusing people. :p - KarenH [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Events   CD-Media   CD-Spy   FRC-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 05-17-2012, 03:18 PM
tyandjel94 tyandjel94 is offline
Registered User
FRC #1647 (Iron Devils)
Team Role: Programmer
 
Join Date: Apr 2012
Rookie Year: 2009
Location: New Jersey
Posts: 14
tyandjel94 is an unknown quantity at this point
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
__________________
-Tyler
Team 1647 Iron Devils

Last edited by tyandjel94 : 05-18-2012 at 09:54 AM.
Reply With Quote
  #2   Spotlight this post!  
Unread 05-19-2012, 11:33 PM
Fletch1373's Avatar
Happy Birthday! Fletch1373 Fletch1373 is offline
Registered User
AKA: Fletch
FRC #3555 (Aluminati)
Team Role: College Student
 
Join Date: Jan 2008
Rookie Year: 2004
Location: Connecticut
Posts: 228
Fletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud of
Send a message via AIM to Fletch1373 Send a message via MSN to Fletch1373 Send a message via Skype™ to Fletch1373
Re: UDP Recieving Problems

Quote:
Originally Posted by tyandjel94 View Post
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.

This thread says that it's probably an uncaught exception somewhere. Are you getting any other information printing out? i.e. stack trace, etc.?
__________________
<04: 213 - BAE> <05-08: 1373 - CT>
<09: 809 - PA> <09: CT - Inspector>
<10: 809 - VA> <10: WPI, BOS, CT, CMP - Inspector>
<11: CMP - Official Scorer> <11-12: 3555 - CT> <11-12: WPI - FTAA> <11-12: CT - Inspector>
<12: 73 - Mentor> <12: CMP - CSA>

Reply With Quote
  #3   Spotlight this post!  
Unread 05-20-2012, 12:18 AM
tyandjel94 tyandjel94 is offline
Registered User
FRC #1647 (Iron Devils)
Team Role: Programmer
 
Join Date: Apr 2012
Rookie Year: 2009
Location: New Jersey
Posts: 14
tyandjel94 is an unknown quantity at this point
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?
__________________
-Tyler
Team 1647 Iron Devils
Reply With Quote
  #4   Spotlight this post!  
Unread 05-20-2012, 12:48 AM
tyandjel94 tyandjel94 is offline
Registered User
FRC #1647 (Iron Devils)
Team Role: Programmer
 
Join Date: Apr 2012
Rookie Year: 2009
Location: New Jersey
Posts: 14
tyandjel94 is an unknown quantity at this point
Re: UDP Recieving Problems

Would a possibility be a security exception?
__________________
-Tyler
Team 1647 Iron Devils
Reply With Quote
  #5   Spotlight this post!  
Unread 05-20-2012, 02:16 PM
Sunstroke Sunstroke is offline
Programmer
AKA: Joe Grinstead
FRC #3504 (Girls of Steel)
Team Role: Mentor
 
Join Date: Apr 2009
Rookie Year: 2009
Location: New England
Posts: 49
Sunstroke is an unknown quantity at this point
Re: UDP Recieving Problems

Quote:
Originally Posted by tyandjel94 View Post
No. When we press enable it goes straight to robots don't quit. Do you see anything that isn't correctly coded for udp?
When it says "robots don't quit," it means that you are getting an exception. I believe it prints out the exception as well...
Reply With Quote
  #6   Spotlight this post!  
Unread 05-21-2012, 12:09 AM
Fletch1373's Avatar
Happy Birthday! Fletch1373 Fletch1373 is offline
Registered User
AKA: Fletch
FRC #3555 (Aluminati)
Team Role: College Student
 
Join Date: Jan 2008
Rookie Year: 2004
Location: Connecticut
Posts: 228
Fletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud of
Send a message via AIM to Fletch1373 Send a message via MSN to Fletch1373 Send a message via Skype™ to Fletch1373
Re: UDP Recieving Problems

Quote:
Originally Posted by Sunstroke View Post
When it says "robots don't quit," it means that you are getting an exception. I believe it prints out the exception as well...
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.
__________________
<04: 213 - BAE> <05-08: 1373 - CT>
<09: 809 - PA> <09: CT - Inspector>
<10: 809 - VA> <10: WPI, BOS, CT, CMP - Inspector>
<11: CMP - Official Scorer> <11-12: 3555 - CT> <11-12: WPI - FTAA> <11-12: CT - Inspector>
<12: 73 - Mentor> <12: CMP - CSA>

Reply With Quote
  #7   Spotlight this post!  
Unread 05-21-2012, 08:38 PM
tyandjel94 tyandjel94 is offline
Registered User
FRC #1647 (Iron Devils)
Team Role: Programmer
 
Join Date: Apr 2012
Rookie Year: 2009
Location: New Jersey
Posts: 14
tyandjel94 is an unknown quantity at this point
Re: UDP Recieving Problems

We have been getting the IO exception.
__________________
-Tyler
Team 1647 Iron Devils
Reply With Quote
  #8   Spotlight this post!  
Unread 05-22-2012, 10:00 PM
tyandjel94 tyandjel94 is offline
Registered User
FRC #1647 (Iron Devils)
Team Role: Programmer
 
Join Date: Apr 2012
Rookie Year: 2009
Location: New Jersey
Posts: 14
tyandjel94 is an unknown quantity at this point
Re: UDP Recieving Problems

We aren't able to open the socket to the labview part can connect to it.
__________________
-Tyler
Team 1647 Iron Devils
Reply With Quote
  #9   Spotlight this post!  
Unread 05-25-2012, 11:38 PM
NotInControl NotInControl is offline
Controls Engineer
AKA: Kevin
FRC #2168 (Aluminum Falcons)
Team Role: Engineer
 
Join Date: Oct 2011
Rookie Year: 2004
Location: Groton, CT
Posts: 195
NotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond repute
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
__________________
Controls Engineer, Team 2168 - The Aluminum Falcons
[2014 Season] - NE Championship Controls Award & Semi-finalists, District Controls Award, Creativity Award, & Finalists
-NE Championship- #36 seed in Quals, SemiFinalist(228,2168,3525), NE Championship Innovation in Controls Award
-RI District Event- #7 seed in Quals, Finalist(1519,2168,5163), Innovation in Controls Award
-Groton District Event- #9 seed in Quals, QuarterFinalist(2168, 125, 5112), Creativity Award
[2013 Season] - Won Our First Blue Banner
-Curie Divison- #38 seed in Quals, Quarterfinalist(2168, 103, 4564)
-WPI Regional - #10 seed in Quals, #8 Alliance Capt., Winners(2168, 3280, 3044)
-NE Utilities First CT Regional - #9 seed in Quals, Quarterfinalist(2168, 228, 263)
[2012 Season] - Controls Award
-NYC Regional, #1 seed in Quals, SemiFinalists(2168,1676,329), Innovation in Controls Award
-NE Utilities First CT Regional - #1 seed in Quals, SemiFinalist(2168, 118, 2791)

Last edited by NotInControl : 05-25-2012 at 11:54 PM.
Reply With Quote
  #10   Spotlight this post!  
Unread 05-28-2012, 07:00 PM
ItzWarty ItzWarty is offline
Registered User
FRC #1072 (Harker Robotics)
Team Role: Leadership
 
Join Date: Jan 2012
Rookie Year: 2010
Location: California
Posts: 15
ItzWarty is an unknown quantity at this point
Send a message via Skype™ to ItzWarty
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.
__________________
Leader of Team 1072. Software developer of RAF Manager.
Follow me on Twitter: Twitter.com/ItzWarty/
Reply With Quote
  #11   Spotlight this post!  
Unread 09-24-2012, 08:58 PM
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 7,895
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: UDP Recieving Problems

Quote:
Originally Posted by NotInControl View Post
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"
Were you able to use the datagram protocol on the cRIO? I get the following exception: "javax.microedition.io.ConnectionNotFoundException : The 'datagram' protocol does not exist". The following thread says that datagram wasn't supported as of 2011: http://www.chiefdelphi.com/forums/sh...61&postcount=5
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 04:14 PM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi