Go to Post ... the real mark of integrity is doing the right thing even when nobody is watching. - DonRotolo [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-02-2011, 18:52
Sotha Sotha is offline
Registered User
FRC #2501
 
Join Date: Feb 2011
Location: Minnesota
Posts: 3
Sotha is an unknown quantity at this point
First Year with Java, Help Requested

This is our first year using Java, our team does not have any programming mentors so I have pretty much been hung out to dry. I've been banging my head against the wall because I can not get this code to work.

Here is our code: (Some things are commented out due to me trying to debug.

Code:
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.                             */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/

package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Watchdog;



/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the SimpleRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class Team2501Robot extends SimpleRobot {
   RobotDrive drive = new RobotDrive(1, 2, 3, 4);

  /* Jaguar frontLeft = new Jaguar(1);    // Front Left Motor
    Jaguar frontRight = new Jaguar(2);   // Front Right Motor
   Jaguar backLeft = new Jaguar(3);     // Back Left Mottr
   Jaguar backRight = new Jaguar(4);    // Back Right Motor
   Jaguar armLower = new Jaguar(5);     // Motor for Arm
   Jaguar armUpper = new Jaguar(6);     // Upper Motor for Arm
   Compressor c = new Compressor(6,7);
*/


   Joystick leftStick = new Joystick(1);                    // Drive Stick
   Joystick rightStick = new Joystick(2);                   // Arm stick
   double magnitude = leftStick.getMagnitude();             // Magnitude
   double direction = leftStick.getDirectionDegrees();      // Direction
   double rotation = leftStick.getX();                      // Rotation
   double rmagnitude = rightStick.getY();


    public void autonomous() {
        for (int i = 0; i < 14; i++){        // Autonomius Mode
  //          c.start();
            drive.drive(0.5, 0.0);          // Drive forward at half speed
            Timer.delay(2.0);               // Wait two seconds

            
        }
        drive.drive(0.0, 0.0);              // Stop
    }

    public void operatorControl() {
        getWatchdog().setEnabled(true);
        while (isOperatorControl() && isEnabled()){         //loop during telop
    //        c.start();
            drive.mecanumDrive_Polar(leftStick.getDirectionDegrees(),leftStick.getMagnitude(), rightStick.getY());
           if(rmagnitude > 0.0)
            {
                /*armLower.set(rmagnitude);
                armUpper.set(-rmagnitude);*/
            }
            else if (rmagnitude < 0.0)
            {
                /*armLower.set(-rmagnitude);
                armUpper.set(rmagnitude);*/

            }
            
            else if(leftStick.getRawButton(4)){     // For Strafe Left
                    /*frontLeft.set(0.5);
                    backRight.set(0.5);
                    frontRight.set(-0.5);
                    backLeft.set(-0.5); */
                }
            
            else if(leftStick.getRawButton(5)){     // For Strafe Right
      /*              frontLeft.set(-0.5);
                    backRight.set(-0.5);
                    frontRight.set(0.5);
                    backLeft.set(0.5); */
                }
            
           }
            Timer.delay(0.005);
            // c.stop();
        
    }
}
Reply With Quote
  #2   Spotlight this post!  
Unread 10-02-2011, 19:09
mwtidd's Avatar
mwtidd mwtidd is offline
Registered User
AKA: mike
FRC #0319 (Big Bad Bob)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 2003
Location: Boston, MA
Posts: 714
mwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond repute
Re: First Year with Java, Help Requested

If its your first year with Java. Maybe start by using arcadeDrive, and then once you get that running, upgrade to mecanum

also your polar code is wrong
first param is magnitude, second direction, third rotation
also you could try cartesian

having your jags and drive mapped to the same ports may cause problems later
__________________
"Never let your schooling interfere with your education" -Mark Twain

Last edited by mwtidd : 10-02-2011 at 19:15.
Reply With Quote
  #3   Spotlight this post!  
Unread 10-02-2011, 20:43
Aaron V Aaron V is offline
Registered User
FRC #1325 (Inverse Paradox)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2009
Location: Ontario, Canada
Posts: 13
Aaron V is an unknown quantity at this point
Re: First Year with Java, Help Requested

I agree with lineskier on all points; it would be simpler to start with arcade drive, then upgrade to mecanum later. On the other hand I can imagine your team wants this to work soon, so here's my interpretation.

First of all, you don't need the while loop. It doesn't hurt, but the system already calls the operatorControl method in a loop - getting rid of it cleans things up.

Secondly, I strongly recommend you use Cartesian drive. It's just much simpler, and I find it's more intuitive to drive (it's a lot like an FPS). Even if you don't plan on directly mapping controls in this way, it's way easier to conceptualize - x and y directions and rotation (just put 0 for the gyro until you understand it).

The other thing is that for simplicity reasons, you should only use the drive method to control the drive system. None of this manual Jaguar control for the drive system - it could conflict with the drive method. (Don't worry about the arm control, that should be fine.)

When I write semi-complex drive code, I like to set variables at the beginning as my drive values. So in this example, I'd set three variables as: xMagnitude, yMagnitude and rotation. Then I'd manipulate these values and after that call the drive method.

By setting variables I can start with a controller input, then adjust them as I see fit. It also makes the code way simpler.

One final thing that is probably a fundamental misconception is that you need to set values that you want to change (ie. rmagnitude) in the operatorControl method. Otherwise it sets the value to whatever the joystick was at when you start the robot and doesn't change. Values that won't change during the runtime can stay above the method (ie. RobotDrive) (There's a lot of complexities as to why, but that's not important now - let me know if you want more info later.)

So, unless I missed something, here is working code for you:

Code:
 public void operatorControl() {
           getWatchdog().setEnabled(true);
		
 	   double xMagnitude = 0; // unless you have a spare axis for this.
	   double yMagnitude = leftStick.getY();
	   double rotation = leftStick.getX();	
           double rmagnitude = rightStick.getY();


           if(rmagnitude > 0.0)
            {
                armLower.set(rmagnitude);
                armUpper.set(-rmagnitude);
            }
            else if (rmagnitude < 0.0)
            {
                armLower.set(-rmagnitude);
                armUpper.set(rmagnitude);

            }
            
            else if(leftStick.getRawButton(4)){     // For Strafe Left
                    xMagnitude = -0.5;
		    // If you want, you could set yMagnitude or rotation to zero here.
                }
            
            else if(leftStick.getRawButton(5)){     // For Strafe Right
           	    xMagnitude = 0.5;        
		    // If you want, you could set yMagnitude or rotation to zero here.
                }
            
           }
            Timer.delay(0.005); // I don't know why this is here - you don't really 
			        // need to slow anything down
	    
	    drive.mecanumDrive_Cartesian(xMagnitude, yMagnitude, rotation, 0);
I did make a few assumptions and didn't explain everything, but I hope I communicated most of it to you. Let me know if you have questions.

EDIT: I just realized I didn't do anything about your compressor. Just start it in the autonomous or even the initializer (if you know what that is) and leave it. I don't see a reason to turn it off as the power of the robot should just turn it off.

Last edited by Aaron V : 11-02-2011 at 13:06. Reason: Clarification
Reply With Quote
  #4   Spotlight this post!  
Unread 27-06-2014, 14:05
ccresta1386's Avatar
ccresta1386 ccresta1386 is offline
Registered User
AKA: Collin Cresta
FRC #4954 (Palindrome Robotics)
Team Role: Driver
 
Join Date: Feb 2014
Rookie Year: 2014
Location: Middletown, DE
Posts: 24
ccresta1386 is an unknown quantity at this point
Re: First Year with Java, Help Requested

We are also in our first year and need help with programming. Our forward/backward and rotation works but strafing does not work.
Code:
 
    drive = new RobotDrive(1, 3, 2, 4); 
    driverStick = new Joystick(1);
    shooterStick = new Joystick(2);
    robotHeadingGyro = new Gyro(1);


double rotation = driverStick.getZ()*-1 / 2;                                                if (driverStick.getRawButton(3)){
rotation += .4;
 }else if(driverStick.getRawButton(4)){
rotation += -.4;
      }
               
drive.mecanumDrive_Cartesian(driverStick.getX(),
rotation,
driverStick.getY()*-1,
0);// we plan on putting a gyro in when the strafe works
Reply With Quote
  #5   Spotlight this post!  
Unread 27-06-2014, 14:08
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,729
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: First Year with Java, Help Requested

Quote:
Originally Posted by ccresta1386 View Post
We are also in our first year and need help with programming. Our forward/backward and rotation works but strafing does not work.
Code:
 
    drive = new RobotDrive(1, 3, 2, 4); 
    driverStick = new Joystick(1);
    shooterStick = new Joystick(2);
    robotHeadingGyro = new Gyro(1);


double rotation = driverStick.getZ()*-1 / 2;                                                if (driverStick.getRawButton(3)){
rotation += .4;
 }else if(driverStick.getRawButton(4)){
rotation += -.4;
      }
               
drive.mecanumDrive_Cartesian(driverStick.getX(),
rotation,
driverStick.getY()*-1,
0);// we plan on putting a gyro in when the strafe works
Are you positive that your wheels are oriented correctly?
Reply With Quote
  #6   Spotlight this post!  
Unread 27-06-2014, 14:11
ccresta1386's Avatar
ccresta1386 ccresta1386 is offline
Registered User
AKA: Collin Cresta
FRC #4954 (Palindrome Robotics)
Team Role: Driver
 
Join Date: Feb 2014
Rookie Year: 2014
Location: Middletown, DE
Posts: 24
ccresta1386 is an unknown quantity at this point
Re: First Year with Java, Help Requested

Quote:
Originally Posted by notmattlythgoe View Post
Are you positive that your wheels are oriented correctly?
Yes because we recently switched from labview and strafing worked then but doesn't now.
Reply With Quote
  #7   Spotlight this post!  
Unread 27-06-2014, 14:16
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,729
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: First Year with Java, Help Requested

Quote:
Originally Posted by ccresta1386 View Post
Yes because we recently switched from labview and strafing worked then but doesn't now.
It looks like you have your parameters out of order when you call the drive method. Try this:
Code:
drive.mecanumDrive_Cartesian(driverStick.getX(), driverStick.getY()*-1, rotation, 0);
Reply With Quote
  #8   Spotlight this post!  
Unread 27-06-2014, 14:21
ccresta1386's Avatar
ccresta1386 ccresta1386 is offline
Registered User
AKA: Collin Cresta
FRC #4954 (Palindrome Robotics)
Team Role: Driver
 
Join Date: Feb 2014
Rookie Year: 2014
Location: Middletown, DE
Posts: 24
ccresta1386 is an unknown quantity at this point
Re: First Year with Java, Help Requested

Also when we strafe right the wheels spin like:

^ ^
\ /

/ \
v v
and left:

\ /
v v

^ ^
/ \
Reply With Quote
  #9   Spotlight this post!  
Unread 27-06-2014, 14:25
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,729
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: First Year with Java, Help Requested

Quote:
Originally Posted by ccresta1386 View Post
Also when we strafe right the wheels spin like:

^ ^
\ /

/ \
v v
and left:

\ /
v v

^ ^
/ \
How are your motors numbered?

Ours are always :
1 2
3 4
Reply With Quote
  #10   Spotlight this post!  
Unread 27-06-2014, 14:53
ccresta1386's Avatar
ccresta1386 ccresta1386 is offline
Registered User
AKA: Collin Cresta
FRC #4954 (Palindrome Robotics)
Team Role: Driver
 
Join Date: Feb 2014
Rookie Year: 2014
Location: Middletown, DE
Posts: 24
ccresta1386 is an unknown quantity at this point
Re: First Year with Java, Help Requested

Quote:
Originally Posted by notmattlythgoe View Post
How are your motors numbered?

Ours are always :
1 2
3 4
I believe
1 2
3 4
but i will check them at the meeting tonight.
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 00:39.

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