Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   How do I upload code to the Robot with Java? (http://www.chiefdelphi.com/forums/showthread.php?t=90338)

mastergamer1231 28-01-2011 14:39

How do I upload code to the Robot with Java?
 
Hi everyone,

Our team has just realised something, we don't know how to upload code with Java! This is our first year with Java and we have Netbeans 6.9.1.

Thanks in advance!

wdell 28-01-2011 15:16

Re: How do I upload code to the Robot with Java?
 
First question: have you reimaged the cRio to accept Java?

Assuming you have sorted that out it's pretty simple. You connect your computer to the cRio with a crossover cable, and then in Netbeans hit "Run". The actual routines to copy it over to the bot are handled by Netbeans.

el-zoroo 28-01-2011 21:57

Re: How do I upload code to the Robot with Java?
 
Hi,

In the ideal world, the steps to download Java are:

1) Reimage the cRIO with the Java specific image.
2) Update Netbeans with the FRC plugins.
3) In Netbeans, in Tools>Options>Misc>FRC Configuration, update the Team Number.
4) Hit Run and cross your fingers :P

I assume all your networking is up and running properly (i.e., you should be able to ping the cRIO).

You can find more detailed information at How to Build and Load Programming in LabVIEW, C++, and Java

Hope that helps! :)

buildmaster5000 31-01-2011 18:02

Re: How do I upload code to the Robot with Java?
 
Quote:

Originally Posted by wdell (Post 1010523)
First question: have you reimaged the cRio to accept Java?

Assuming you have sorted that out it's pretty simple. You connect your computer to the cRio with a crossover cable, and then in Netbeans hit "Run". The actual routines to copy it over to the bot are handled by Netbeans.

It should be noted that while many of the instructional documents that FIRST provides say that the user should use a crossover cable, it is only necessary between the camera and the cRIO. The bridge, classmate, and most other modern devices (computers, routers, etc.) have auto switching ports that will make a non crossover cable into a crossover if needed. This makes it a lot easier to acquire cables since crossovers are hard to find.

Omgsar 31-01-2011 20:04

Re: How do I upload code to the Robot with Java?
 
Our team is having the same issue,
Code:

[cRIO] edu.wpi.first.wpilibj.util.AllocationException: PWM channel 3 on module 4 is already allocated
[cRIO]    at edu.wpi.first.wpilibj.PWM.initPWM(PWM.java:112)
[cRIO]    at edu.wpi.first.wpilibj.PWM.<init>(PWM.java:141)
[cRIO]    at edu.wpi.first.wpilibj.SafePWM.<init>(SafePWM.java:33)
[cRIO]    at edu.wpi.first.wpilibj.Jaguar.<init>(Jaguar.java:41)
[cRIO]    at edu.wpi.first.wpilibj.RobotDrive.<init>(RobotDrive.java:110)
[cRIO]    at edu.wpi.first.wpilibj.templates.Team2745Robot.<init>(Team2745Robot.java:27)
[cRIO]    in virtual method #11 of com.sun.squawk.Klass(bci=53)
[cRIO]    at com.sun.squawk.imp.MIDletMainWrapper.main(99)
[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)


Robototes2412 31-01-2011 20:28

Re: How do I upload code to the Robot with Java?
 
code plz?

Patrick Chiang 31-01-2011 20:31

Re: How do I upload code to the Robot with Java?
 
Quote:

Originally Posted by Omgsar (Post 1012806)
Our team is having the same issue,
Code:

[cRIO] edu.wpi.first.wpilibj.util.AllocationException: PWM channel 3 on module 4 is already allocated
[cRIO]    at edu.wpi.first.wpilibj.PWM.initPWM(PWM.java:112)
[cRIO]    at edu.wpi.first.wpilibj.PWM.<init>(PWM.java:141)
[cRIO]    at edu.wpi.first.wpilibj.SafePWM.<init>(SafePWM.java:33)
[cRIO]    at edu.wpi.first.wpilibj.Jaguar.<init>(Jaguar.java:41)
[cRIO]    at edu.wpi.first.wpilibj.RobotDrive.<init>(RobotDrive.java:110)
[cRIO]    at edu.wpi.first.wpilibj.templates.Team2745Robot.<init>(Team2745Robot.java:27)
[cRIO]    in virtual method #11 of com.sun.squawk.Klass(bci=53)
[cRIO]    at com.sun.squawk.imp.MIDletMainWrapper.main(99)
[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)


You allocated the same PWM twice. Look in your code for the following line:
Code:

new PWM(3);
If you find two of them, delete one of them. If you find one, something else is wrong and I can't help unless I get more code.

Omgsar 31-01-2011 21:10

Re: How do I upload code to the Robot with Java?
 
Here are all of our declarations:
Code:

public Joystick leftStick = new Joystick(1);
    public Joystick rightStick = new Joystick(2);
  public Jaguar jagFrontLeft = new Jaguar(1);
  public Jaguar jagFrontRight = new Jaguar(2);
  public Jaguar jagBackLeft = new Jaguar(3);
    public Jaguar jagBackRight = new Jaguar(4);
    public RobotDrive driveRobot = new RobotDrive(1, 3, 2, 4);
    public Gyro roboGyro = new Gyro(7);
    double leftX =0;
    double leftY =0;
    double rotationRate =0;
    double gyroAngle =0;
    int i = 0;


wdell 31-01-2011 21:37

Re: How do I upload code to the Robot with Java?
 
Quote:

Originally Posted by buildmaster5000 (Post 1012686)
It should be noted that while many of the instructional documents that FIRST provides say that the user should use a crossover cable, it is only necessary between the camera and the cRIO. The bridge, classmate, and most other modern devices (computers, routers, etc.) have auto switching ports that will make a non crossover cable into a crossover if needed. This makes it a lot easier to acquire cables since crossovers are hard to find.

Thank you! I've been using a crossover cable that for some reason needs one particular end plugged into the cRio, and it's driving me nuts. I do it all wireless now so I don't have to keep track of that $@#$@#$@#$@# cable!

wdell 31-01-2011 21:40

Re: How do I upload code to the Robot with Java?
 
Quote:

Originally Posted by Omgsar (Post 1012806)
Our team is having the same issue,
Code:

(Team2745Robot.java:27)

If I'm reading that right look at line 27 in Team2745.java. Or post the first 27 lines of that class so we can take a look at it.

wdell 31-01-2011 21:49

Re: How do I upload code to the Robot with Java?
 
kk, in your declarations most of that doesn't need to be public. Try:

Code:

Joystick leftStick = new Joystick(1);
Joystick rightStick = new Joystick(2);
Jaguar jagFrontLeft = new Jaguar(1);
Jaguar jagFrontRight = new Jaguar(2);
Jaguar jagBackLeft = new Jaguar(3);
Jaguar jagBackRight = new Jaguar(4);
RobotDrive driveRobot = new RobotDrive(1, 3, 2, 4);
Gyro roboGyro = new Gyro(7);
double leftX =0;
double leftY =0;
double rotationRate =0;
double gyroAngle =0;
int i = 0;

Here's the first chunk of mine:

Code:

package edu.wpi.first.wpilibj.templates;

/**
 * @author  William Dell
 * @author  Team 647
 * @version  v7, January 29, 2011
 * @version  FRC Java version 2011.4
 */

import edu.wpi.first.wpilibj.SimpleRobot;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Timer;

import edu.wpi.first.wpilibj.Gyro;

import edu.wpi.first.wpilibj.Victor;
// import edu.wpi.first.wpilibj.Jaguar;  // for change to production bot
import edu.wpi.first.wpilibj.RobotDrive;

public class Main extends SimpleRobot {

    DStation station; // consolidated, simplified dash and driver station
    Joystick controllerOne = new Joystick(1);
    Timer timer = new Timer(); // one timer to rule them all....
    Gyro spinGyro = new Gyro(1);
    Kamera cam;  // consolidated web cam controller
   
    //------------Drive System-----------------//
    Victor leftFrontVictor = new Victor(1);
    Victor rightFrontVictor = new Victor(2);
    RobotDrive drive = new RobotDrive(leftFrontVictor, rightFrontVictor);

    /*  4 motor drive for production bot commented out here
    Jaguar leftFrontJaguar = new Jaguar(1);
    Jaguar leftRearJaguar = new Jaguar(2);
    Jaguar rightFrontJaguar = new Jaguar(3);
    Jaguar rightRearJaguar = new Jaguar(4);
    RobotDrive drive = new RobotDrive(leftFrontJaguar, leftRearJaguar,
    rightFrontJaguar, rightRearJaguar);
    */
    AutoDrive autodrive; // simple autonomous routines

    /**
    * This method is called once when the robot boots up.
    */
    public void robotInit() {

AND I just found your problem. You're declaring your robot drive wrong. You have
Code:

RobotDrive driveRobot = new RobotDrive(1, 3, 2, 4);
when you should have
Code:

RobotDrive driveRobot = new RobotDrive(jagFrontLeft,jagBackLeft,jagFrontRight,jagBackRight);
What was happening is it would hit the Jaguar declaration and assign the PWM port to the jag. Then you're RobotDrive declaration would try to assign the PWM ports directly instead of going through the jaguars.

Patrick Chiang 31-01-2011 23:27

Re: How do I upload code to the Robot with Java?
 
Code:

public Joystick leftStick = new Joystick(1);
public Joystick rightStick = new Joystick(2);
/* Here, the cRIO allocates slot 1-4 of the PWM.
Which means if you try to allocate them again in
another part of the code, you'll get errors. */

public Jaguar jagFrontLeft = new Jaguar(1);
public Jaguar jagFrontRight = new Jaguar(2);
public Jaguar jagBackLeft = new Jaguar(3);
public Jaguar jagBackRight = new Jaguar(4);
/* See? Here, you're allocating the EXACT SAME
PWM slots AGAIN. Which creates problems and are
 most likely the cause of your problem. */

public RobotDrive driveRobot = new RobotDrive(1, 3, 2, 4);

Comments in navy blue. Here's the solution:
Code:

Joystick leftStick = new Joystick(1);
Joystick rightStick = new Joystick(2);
/* Code removed because it creates problems */
// Jaguar jagFrontLeft = new Jaguar(1);
// Jaguar jagFrontRight = new Jaguar(2);
// Jaguar jagBackLeft = new Jaguar(3);
// Jaguar jagBackRight = new Jaguar(4);

RobotDrive driveRobot = new RobotDrive(1, 3, 2, 4);
Gyro roboGyro = new Gyro(7);
double leftX =0;
double leftY =0;
double rotationRate =0;
double gyroAngle =0;
int i = 0;

Edit: Darn. Someone beat me to it. :)

Omgsar 31-01-2011 23:50

Re: How do I upload code to the Robot with Java?
 
Ahh, noob mistake. Haven't touched java in forevers. Thanks All.


All times are GMT -5. The time now is 09:45.

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