Go to Post yeah, right - like anyone's going to pass up building a robot. - IbleedPink233 [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-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 24-11-2012, 17:09
Skyehawk's Avatar
Skyehawk Skyehawk is offline
Nuts N' Bolts
AKA: Skye Leake
FRC #0876 (Thunder Robotics)
Team Role: Mentor
 
Join Date: Nov 2012
Rookie Year: 2011
Location: Northwood, ND
Posts: 263
Skyehawk is a name known to allSkyehawk is a name known to allSkyehawk is a name known to allSkyehawk is a name known to allSkyehawk is a name known to allSkyehawk is a name known to all
Enhanced I/O through Cypress

Our team is new to the Enhanced I/O through Cypress. I have done everything to spec in setting it up except one thing; when I tried to load the 2012.hex onto the module it said fail in the lower right hand corner (where it says connected) so I used the 2009.hex and it loaded fine. The DS reconized it and I have full suport on the DS of all the functions that are native.

When I loaded my code onto the robot I am using Cypress to get a button value. Here's where I need help:
Initilized:
Code:
    public class RobotClass extends IterativeRobot {
        Relay Feed = new Relay(2);
        DriverStationEnhancedIO Cypress = DriverStation.getInstance().getEnhancedIO();
Teleop:
Code:
if (Cypress.getButton(2) ) {
                Feed.setDirection(Relay.Direction.kForward);
            } else if (Cypress.getButton(3)) {
                Feed.setDirection(Relay.Direction.kReverse);
            } else {
                Feed.set(Relay.Value.kOff);
Netbeans wants me to sorround the teleop portion of code with a try - catch statement:
Code:
        try {
            if(Cypress.getButton(2) ) {
                    Feed.setDirection(Relay.Direction.kForward);
                } else if (Cypress.getButton(3)) {
                    Feed.setDirection(Relay.Direction.kReverse);
                } else {
                    Feed.set(Relay.Value.kOff);
            }
        } catch (EnhancedIOException ex) {
            ex.printStackTrace();
        }
Is the try - catch the correct way to do this? It doesnt seem right. If it isn't, what is the correct way to do this?
Thanks,
Skyehawk
Reply With Quote
  #2   Spotlight this post!  
Unread 24-11-2012, 20:31
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: 8,590
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: Enhanced I/O through Cypress

Most of the ways that EnhancedIOException gets thrown is because the enhanced IO module isn't plugged in to the driver station computer. You should think about what you want the code to do in that case and put that in the catch block. You probably want to turn the relay off, but you may want to do something else like send status back to the driver station.

If you're not familiar with exceptions, there is a java tutorial about them. http://docs.oracle.com/javase/tutori...al/exceptions/

Last edited by Joe Ross : 24-11-2012 at 23:19.
Reply With Quote
  #3   Spotlight this post!  
Unread 25-11-2012, 01:03
Skyehawk's Avatar
Skyehawk Skyehawk is offline
Nuts N' Bolts
AKA: Skye Leake
FRC #0876 (Thunder Robotics)
Team Role: Mentor
 
Join Date: Nov 2012
Rookie Year: 2011
Location: Northwood, ND
Posts: 263
Skyehawk is a name known to allSkyehawk is a name known to allSkyehawk is a name known to allSkyehawk is a name known to allSkyehawk is a name known to allSkyehawk is a name known to all
Re: Enhanced I/O through Cypress

I read that page. Interesting stuff, though a little hard to grasp at parts. The I/O was plugged in and getting readings from the button I had wired in.

This is my new code:
Code:
        try {
            if (Cypress.getButton(2)) {
                Feed.setDirection(Relay.Direction.kForward);
            } else if(Cypress.getButton(3)) {
                Feed.setDirection(Relay.Direction.kReverse);
            }
        } catch (EnhancedIOException ex) {
            ex.printStackTrace();
            Feed.set(Relay.Value.kOff);
        }
I have not tried this code yet so I will update the thread once I do test it. Is this what you were getting at? Also, do I need the "ex.printStackTrace();" line, I know it helps in debuging, but will the program run more efficently without it?

Last edited by Skyehawk : 25-11-2012 at 01:05. Reason: update
Reply With Quote
  #4   Spotlight this post!  
Unread 25-11-2012, 02:51
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Re: Enhanced I/O through Cypress

"ex.printStackTrace();" Does exactly what it says: prints a stack trace to the default console (in your case, netbeans console used to deploy). It would not add anything significant to keep that inside of the catch block. (And it would end up being helpful when debugging)

As for whether what you did will work, it completely depends on what you want your code to do when that exception is thrown, so if that is setting the Feed to Relay.Value.kOff, sure.

Something that bugged me a bit in your code is this:
Code:
DriverStationEnhancedIO Cypress = DriverStation.getInstance().getEnhancedIO();
In Java, camel case is standard (see coding conventions - http://www.oracle.com/technetwork/ja...v-138413.html). This is because accessing static members only requires the class name, which should start with a capital letter. When your fields are named starting with capital letters, it can be hard to distinguish between fields and classes. It's definitely worth starting a habit of camel casing.
__________________
All opinions are my own.
Reply With Quote
  #5   Spotlight this post!  
Unread 25-11-2012, 16:44
Skyehawk's Avatar
Skyehawk Skyehawk is offline
Nuts N' Bolts
AKA: Skye Leake
FRC #0876 (Thunder Robotics)
Team Role: Mentor
 
Join Date: Nov 2012
Rookie Year: 2011
Location: Northwood, ND
Posts: 263
Skyehawk is a name known to allSkyehawk is a name known to allSkyehawk is a name known to allSkyehawk is a name known to allSkyehawk is a name known to allSkyehawk is a name known to all
Re: Enhanced I/O through Cypress

I managed to test the program. I got this in the run box:
Code:
[cRIO] edu.wpi.first.wpilibj.DriverStationEnhancedIO$EnhancedIOException: Enhanced IO Missing
[cRIO]     at edu.wpi.first.wpilibj.DriverStationEnhancedIO.getDigitals(DriverStationEnhancedIO.java:629)
[cRIO]     at edu.wpi.first.wpilibj.DriverStationEnhancedIO.getDigital(DriverStationEnhancedIO.java:619)
[cRIO]     at edu.wpi.first.wpilibj.templates.RobotClass.teleopPeriodic(RobotClass.java:70)
[cRIO]     at edu.wpi.first.wpilibj.IterativeRobot.startCompetition(IterativeRobot.java:145)
[cRIO]     at edu.wpi.first.wpilibj.RobotBase.startApp(RobotBase.java:156)
[cRIO]     in virtual method #10 of javax.microedition.midlet.MIDlet(bci=17)
[cRIO]     at javax.microedition.midlet.MIDletTunnelImpl.callStartApp(64)
[cRIO]     at com.sun.squawk.imp.MIDletMainWrapper.main(110)
[cRIO]     in virtual method #95 of com.sun.squawk.Klass(bci=25)
[cRIO]     at com.sun.squawk.Isolate.run(1506)
[cRIO]     at java.lang.Thread.run(231)
[cRIO]     in virtual method #47 of com.sun.squawk.VMThread(bci=42)
[cRIO]     in static method #3 of com.sun.squawk.VM(bci=6)
[cRIO] Robot Drive... Output not updated often enough.
This is a single loop of the teleop portion of the code. It says near the top that it can not find the Enhanced I/O. Is this what was being refered to previously? I also made a few changes to my code:
Code:
         try {
             if (dseio.getDigital(1)) {
                 feed.setDirection(Relay.Direction.kForward);
             } else if (dseio.getDigital(3)) {
                 feed.setDirection(Relay.Direction.kReverse);
             }
         } catch (EnhancedIOException ex) {
             feed.set(Relay.Value.kOff);
             ex.printStackTrace();
         }
I changed the .getButton to .getDigital based on how things are labeled on the DS.
I reimaged the cRIO (to change IP) and my relay was not responding to my command from the joystick (it worked before I reimaged it). I added it to autonomous and the relay worked. (the joystick was responding in the dionostics tab so I have no Idea what caused it to quit working, I will restore the cRIO to the IP that it had previously) Once I get the relay going again on user command I will have a definate answer on whether or not this code worked, but in the meantime feel free to critique.
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 12:51.

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


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