Go to Post ...I've changed my position. I'm fully supportive of Joe's suggestion... - Chris Hibner [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 10-01-2012, 19:21
evilcrouton evilcrouton is offline
Registered User
FRC #2851
 
Join Date: Feb 2011
Location: Behind yOU
Posts: 11
evilcrouton is an unknown quantity at this point
Java Help

Hello I am new to Java for FRC and need help. I want to control two motors connected to jaguars hook up to PWM 1 and 2 to create tank drive. I will control them from one gamepad with two joysticks. This is my code:

Code:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.*;

public class RobotTemplate extends SimpleRobot {

    private Joystick stick1;
    private RobotDrive tank;

    public void autonomous() {
        
    }


    public void operatorControl() {
     
     stick1 = new Joystick(1);
     Jaguar Left = new Jaguar(2);
     Jaguar Right = new Jaguar(1);
     tank = new RobotDrive(Left,Right);
     tank.setExpiration(0.1);
     double leftValue = stick1.getRawAxis(1);
     double rightValue = stick1.getRawAxis(3);
     
        while (true && isOperatorControl() && isEnabled())
        {
          tank.tankDrive(leftValue,rightValue);
           Timer.delay(0.005);
        }
    }
}

The code has no errors or warnings and builds successfully. When I run it, the console shows this:

Code:
init:
init:
Deleting directory C:\Documents and Settings\Robo.CREVO1\My Documents\NetBeansProjects\RobotTemplate2\build
Deleting directory C:\Documents and Settings\Robo.CREVO1\My Documents\NetBeansProjects\RobotTemplate2\suite
Deleting directory C:\Documents and Settings\Robo.CREVO1\My Documents\NetBeansProjects\RobotTemplate2\j2meclasses
clean:
Created dir: C:\Documents and Settings\Robo.CREVO1\My Documents\NetBeansProjects\RobotTemplate2\build
Compiling 1 source file to C:\Documents and Settings\Robo.CREVO1\My Documents\NetBeansProjects\RobotTemplate2\build
compile:
Created dir: C:\Documents and Settings\Robo.CREVO1\My Documents\NetBeansProjects\RobotTemplate2\j2meclasses
preverify:
Created dir: C:\Documents and Settings\Robo.CREVO1\My Documents\NetBeansProjects\RobotTemplate2\suite
Building jar: C:\Documents and Settings\Robo.CREVO1\My Documents\NetBeansProjects\RobotTemplate2\suite\RobotTemplate2_1.0.0.jar
jar-app:
CompilerOracle: exclude com/sun/squawk/Method.getParameterTypes
CompilerOracle: exclude com/sun/squawk/SymbolParser.getSignatureTypeAt
CompilerOracle: exclude com/sun/squawk/SymbolParser.stripMethods
[translating suite image [closed: false, parent: squawk] ...]
### Excluding compile: com.sun.squawk.Method::getParameterTypes
### Excluding compile: com.sun.squawk.SymbolParser::getSignatureTypeAt
[Including resource: META-INF/MANIFEST.MF]
Romizer processed 96 classes and generated 4 files.
Expanding: C:\Documents and Settings\Robo.CREVO1\My Documents\NetBeansProjects\RobotTemplate2\suite\RobotTemplate2_1.0.0.jar into C:\Documents and Settings\Robo.CREVO1\My Documents\NetBeansProjects\RobotTemplate2\suite
Moving 1 file to C:\Documents and Settings\Robo.CREVO1\My Documents\NetBeansProjects\RobotTemplate2\suite
Moving 1 file to C:\Documents and Settings\Robo.CREVO1\My Documents\NetBeansProjects\RobotTemplate2\suite
Moving 1 file to C:\Documents and Settings\Robo.CREVO1\My Documents\NetBeansProjects\RobotTemplate2\suite
Deleting: C:\Documents and Settings\Robo.CREVO1\My Documents\NetBeansProjects\RobotTemplate2\image.suite.api
Host OS: Windows XP 5.1, 5.1
Host JVM: Java HotSpot(TM) Client VM 20.5-b03
Target IP: 10.28.51.2
Network interfaces on host:
    Intel(R) 82566MM Gigabit Network Connection - Packet Scheduler Miniport:  address: 10.28.51.5 netmask: 255.0.0.0 <--- on robot's subnet
Connecting FTP @10.28.51.2
upgrade:
Sending local file image.suite
flashapp:
deploy:
init:
[cRIO] [OTA Server] ********* REBOOTING cRIO *********
[cRIO] 
   Waiting for cRIO to reboot (1s)
   Waiting for cRIO to reboot (2s)
   Waiting for cRIO to reboot (3s)
   Waiting for cRIO to reboot (4s)
   Waiting for cRIO to reboot (5s)
   Waiting for cRIO to reboot (6s)
   Waiting for cRIO to reboot (7s)
   Waiting for cRIO to reboot (8s)
   Waiting for cRIO to reboot (9s)
   Waiting for cRIO to reboot (10s)
[cRIO] 
[cRIO] -> * Loading debug.o: debug
[cRIO] Debugging is up, target server mounted at /tsfs
[cRIO] 
[cRIO] 
[cRIO]                 VxWorks
[cRIO] 
[cRIO] Copyright 1984-2006  Wind River Systems, Inc.
[cRIO] 
[cRIO]              CPU: MPC5200 -- Wind River Lite5200 BSP.
[cRIO]     Runtime Name: VxWorks
[cRIO]  Runtime Version: 6.3
[cRIO]      BSP version: 2.0/10
[cRIO]          Created: May 27 2011, 11:02:24
[cRIO] ED&R Policy Mode: Deployed
[cRIO]    WDB Comm Type: WDB_COMM_END
[cRIO]              WDB: Ready.
[cRIO] 
[cRIO] * Loading nisysrpc.out: nisysrpc
[cRIO] * Loading NiRioRpc.out: NiRioRpc
[cRIO] * Loading nivissvc.out: nivissvc
[cRIO] * Loading nivision.out: nivision
[cRIO] NI-RIO Server 4.0.0b8 started successfully.
[cRIO] task 0xe2f8d8 (NiRioRpc) deleted: errno=0 (0) status=0 (0)
[cRIO] * Loading visa32.out: visa32
[cRIO] * Loading niserial.out: niserial
[cRIO] * Loading NiFpgaLv.out: NiFpgaLv
[cRIO] * Loading FRC_FPGA.out: FRC_FPGA
[cRIO] * Loading FRC_NetworkCommunication.out: FRC_NetworkCommunication
[cRIO] FRC_NetworkCommunication was compiled from SVN revision 2923
[cRIO] FPGA Hardware GUID: 0xA14C11BDE4BB64AEF6A86FC52A294CD9
[cRIO] FPGA Software GUID: 0xA14C11BDE4BB64AEF6A86FC52A294CD9
[cRIO] FPGA Hardware Version: 2012
[cRIO] FPGA Software Version: 2012
[cRIO] FPGA Hardware Revision: 1.6.4
[cRIO] FPGA Software Revision: 1.6.4
[cRIO] * Loading FRC_JavaVM.out: FRC_JavaVM
[cRIO] 
[cRIO] 
[cRIO] [OTA Server] Version: 2012 FRC, Jan  5 2012, 17:20:48
[cRIO] 
[cRIO] 
[cRIO] Welcome to LabVIEW Real-Time 11.0rc14
[cRIO] task 0xddbd60 (sysapi-rpc) deleted: errno=0 (0) status=0 (0)
[cRIO] 
[cRIO] [Squawk VM] Version: 2011 FRC, Nov  5 2011, 14:34:13
[cRIO] FPGA Hardware GUID: 0xa14c11bde4bb64aef6a86fc52a294cd9
[cRIO] FPGA Software GUID: 0xa14c11bde4bb64aef6a86fc52a294cd9
[cRIO] Default robotInit() method running, consider providing your own
[cRIO] Default disabled() method running, consider providing your own
[cRIO] Digital module 1 is not present.
[cRIO] Digital module 1 is not present.
[cRIO] DIO LoopTiming: 260, expecting: 261
[cRIO] Digital module 1 is not present.
[cRIO] Digital module 1 is not present.
[cRIO] Default disabled() method running, consider providing your own
I have two questions.
Does my code do what I intend for it to do?
Is the code being sent to the robot?
Thanks in advance!
Reply With Quote
  #2   Spotlight this post!  
Unread 10-01-2012, 20:10
gerberduffy gerberduffy is offline
Registered User
FRC #0192
 
Join Date: Jun 2011
Location: California
Posts: 8
gerberduffy is an unknown quantity at this point
Re: Java Help

Same error. Does anybody know why the the digital module is not being detected?
Reply With Quote
  #3   Spotlight this post!  
Unread 10-01-2012, 20:12
kinganu123 kinganu123 is offline
Registered User
FRC #1747
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Piscataway, NJ
Posts: 243
kinganu123 is on a distinguished road
Re: Java Help

Ok, so I wrote a simpler version of your code to reduce redundancy.
Only problem you had was that u stored your left and right values before the loop. so once it had a value, that loop would continuously give the motors that value.

Code:
public void operatorControl() {
     stick1 = new Joystick(1);
     tank = new RobotDrive(2,1);//Left, Right. PWM values instead of passing jaguars
     tank.setExpiration(0.1);//Not sure if you need this. Probably not.     
        while (true && isOperatorControl() && isEnabled())
        {
          tank.tankDrive(stick1.getRawAxis(1),stick1.getRawAxis(3));
           Timer.delay(0.005);//Probably don't need this either
        }
    }
__________________
Reply With Quote
  #4   Spotlight this post!  
Unread 10-01-2012, 20:15
BradenWatling BradenWatling is offline
Registered User
no team
 
Join Date: Mar 2011
Rookie Year: 2009
Location: Toronto, ON
Posts: 8
BradenWatling is an unknown quantity at this point
Re: Java Help

We are having a similar issue: we are unable to get inputs or set outputs through the cRIO. However, we are not getting the "Digital module 1 is not present" error message. You can use code like the following to detect module presence:

Code:
            for(int i = 0; i < 2; ++i) {
                System.out.println("digital module " + i + ": " + ModulePresence.getModulePresence(ModulePresence.ModuleType.kDigital, i));
                System.out.println("analog module " + i + ": " + ModulePresence.getModulePresence(ModulePresence.ModuleType.kAnalog, i));
                System.out.println("solenoid module " + i + ": " + ModulePresence.getModulePresence(ModulePresence.ModuleType.kSolenoid, i));
            }
We *are* seeing this error message as well:
[cRIO] DIO LoopTiming: 260, expecting: 261
[cRIO] DIO LoopTiming: 260, expecting: 261
Reply With Quote
  #5   Spotlight this post!  
Unread 10-01-2012, 20:47
BradenWatling BradenWatling is offline
Registered User
no team
 
Join Date: Mar 2011
Rookie Year: 2009
Location: Toronto, ON
Posts: 8
BradenWatling is an unknown quantity at this point
Re: Java Help

So it turns out, we unplugged and re-plugged in our modules, and it magically started working.

You guys should make sure your modules are in the following slots:
Analog - Slot 1
Digital - Slot 2
Solenoid - Slot 3
Reply With Quote
  #6   Spotlight this post!  
Unread 10-01-2012, 20:54
evilcrouton evilcrouton is offline
Registered User
FRC #2851
 
Join Date: Feb 2011
Location: Behind yOU
Posts: 11
evilcrouton is an unknown quantity at this point
Re: Java Help

So it seems like it isn't a coding issue. I'll check the connections in the robot tomorrow and see if this works.
Reply With Quote
  #7   Spotlight this post!  
Unread 10-01-2012, 21:43
TimSchley's Avatar
TimSchley TimSchley is offline
Registered User
AKA: Tim Schley
FRC #0997 (Spartan Robotics)
Team Role: Mentor
 
Join Date: Aug 2011
Rookie Year: 2011
Location: United States
Posts: 24
TimSchley is an unknown quantity at this point
Re: Java Help

We are having this same issue. We have the same problem with both the cRIO and the cRIO II. Are there any updates on why this is happening? Could there be an issue with the Digital IO Sidecar?
Reply With Quote
  #8   Spotlight this post!  
Unread 11-01-2012, 00:21
frasnow's Avatar
frasnow frasnow is offline
Software
no team
Team Role: Mentor
 
Join Date: Jun 2010
Rookie Year: 2010
Location: Oregon
Posts: 83
frasnow is a splendid one to beholdfrasnow is a splendid one to beholdfrasnow is a splendid one to beholdfrasnow is a splendid one to beholdfrasnow is a splendid one to beholdfrasnow is a splendid one to beholdfrasnow is a splendid one to behold
Re: Java Help

I compared the source code for WPILib 2011 & 2012 and the developers changed the constructors for all the I/O to use
Code:
ConstructorName(int moduleNumber, int channel)
instead of the old
Code:
ConstructorName(int slot, int Channel)
The module number is not the same as the slot (OK it is for the first Analog module). The first digital I/O module located in slot 2 of the cRIO is actually module 1. In an 8 slot cRIO digital I/O module 2 should be placed in slot 6. Considering that the signatures of the old constructors and the new ones are the same, I can see lots of veteran teams making this mistake. Even if it is documented somewhere (I haven’t checked). The exceptions being thrown by WPILib don’t have the most helpful error messages in this regard.

Team 997 was also seeing the exception “Solenoid channel 1 on module 3 is already allocated", which makes it sound like our code had allocated solenoid channel 1 twice. We made it work by using the simple constructor where only the channel is specified. A better error message could have saved us time. The error really should say something about 3 being an invalid module number and suggest using 1 or 2 (The solenoid module in slot 3 is module 1). In fact the incorrect exception message actually appears to be masking an only slightly more useful exception CheckedAllocationException("Index " + index + " out of range");. Hiding an exception with one that gives false information is a bad programming practice.

Another way to fix this problem in WPILib would be to deprecate the old constructor and add a new one with a different signature. You can only have one of each module type, so a Boolean value would work for the module number.
Code:
ConstructorName(boolean isModuleOne, int Channel)
Reply With Quote
  #9   Spotlight this post!  
Unread 07-02-2012, 21:37
tmccalister tmccalister is offline
Registered User
FRC #2985
 
Join Date: Jan 2011
Location: TEXAS YEEEHAWWWWW
Posts: 18
tmccalister is an unknown quantity at this point
Re: Java Help

Quote:
Originally Posted by frasnow View Post
I compared the source code for WPILib 2011 & 2012 and the developers changed the constructors for all the I/O to use
Code:
ConstructorName(int moduleNumber, int channel)
instead of the old
Code:
ConstructorName(int slot, int Channel)
The module number is not the same as the slot (OK it is for the first Analog module). The first digital I/O module located in slot 2 of the cRIO is actually module 1. In an 8 slot cRIO digital I/O module 2 should be placed in slot 6. Considering that the signatures of the old constructors and the new ones are the same, I can see lots of veteran teams making this mistake. Even if it is documented somewhere (I haven’t checked). The exceptions being thrown by WPILib don’t have the most helpful error messages in this regard.

Team 997 was also seeing the exception “Solenoid channel 1 on module 3 is already allocated", which makes it sound like our code had allocated solenoid channel 1 twice. We made it work by using the simple constructor where only the channel is specified. A better error message could have saved us time. The error really should say something about 3 being an invalid module number and suggest using 1 or 2 (The solenoid module in slot 3 is module 1). In fact the incorrect exception message actually appears to be masking an only slightly more useful exception CheckedAllocationException("Index " + index + " out of range");. Hiding an exception with one that gives false information is a bad programming practice.

Another way to fix this problem in WPILib would be to deprecate the old constructor and add a new one with a different signature. You can only have one of each module type, so a Boolean value would work for the module number.
Code:
ConstructorName(boolean isModuleOne, int Channel)
Can you just post your actual library? Since you fixed it already and its actually very difficult to find it would be much easier for us if you posted a copy of the revised library.
Reply With Quote
  #10   Spotlight this post!  
Unread 08-02-2012, 19:34
tmccalister tmccalister is offline
Registered User
FRC #2985
 
Join Date: Jan 2011
Location: TEXAS YEEEHAWWWWW
Posts: 18
tmccalister is an unknown quantity at this point
Re: Java Help

I havent fixed that error but my codes running fine. Lol... our electronic team forgot to connect the sidecar to the crio. Thats why i was recieving code but i wasnt able to move the robot
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:50.

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