Go to Post FIRST is hard. It's supposed to be. We can't keep giving people a check and expecting them to succeed. We need to stop this model. It takes a village to raise a child but it takes a community to build a FIRST team. - Andrew Schreiber [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 20-02-2014, 20:50
miw14 miw14 is offline
Registered User
FRC #4840
 
Join Date: Feb 2014
Location: Michigan
Posts: 19
miw14 is an unknown quantity at this point
Joystick 2/Program issue

Hello! My team is having quite a bit of problems with our 2nd joystick. We are using joystick 1 for driving and joystick 2 for our launcher. Our 2nd joystick doesn't seem to work at all. The driver station recognizes it, but we are unable to do anything with it. I hope it's just a simple code mistake. Could anyone help us out? Any help is greatly appreciated! Here is the code:

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.SimpleRobot; 
import edu.wpi.first.wpilibj.Joystick; 
import edu.wpi.first.wpilibj.RobotDrive; 
import edu.wpi.first.wpilibj.Talon; 
import edu.wpi.first.wpilibj.Timer; 
import edu.wpi.first.wpilibj.Victor; 
/** * 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 Drive extends SimpleRobot { 
private RobotDrive myDrive, Shooter;
 private Joystick driveStick, driveStick2;
 private Talon FrontRight, FrontLeft, BackRight, BackLeft; 
private Victor M1, M2; 
/** * This function is called once each time the robot enters autonomous mode. */
public void robotInit()
 { 
FrontRight = new Talon(1);
 BackLeft = new Talon(2);
 FrontLeft = new Talon(3);
 BackRight = new Talon(4); 
myDrive = new RobotDrive(FrontLeft, BackLeft, FrontRight, BackRight); myDrive.setInvertedMotor(RobotDrive.MotorType.kFrontRight,true);
M1 = new Victor(5); 
M2 = new Victor(6); 
Shooter = new RobotDrive(M1, M2);
 driveStick = new Joystick(1); 
driveStick2 = new Joystick(2); 

} 
public void autonomous() 
{ 
while(isAutonomous() && isEnabled()) 
myDrive.drive(-.5, 0.0); 
Timer.delay(2.0); 
myDrive.drive(0.0,0.0); 

}
 /** * This function is called once each time the robot enters operator control. */

public void operatorControl() 
{ 
while(isOperatorControl() && isEnabled()) 
myDrive.arcadeDrive(driveStick); 
Timer.delay(0.01); 
Shooter.arcadeDrive(driveStick2); 
Timer.delay(0.01); } 

}
Reply With Quote
  #2   Spotlight this post!  
Unread 20-02-2014, 21:03
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: Joystick 2/Program issue

Have you tried using robotbuilder? I know our newer programmers had a lot of success using it. It helps you to avoid programming in a way that wpi doesn't support.

I was first skeptical of generating code that way, but I have since come around, and am now a big fan.

I would also recommend trying to only use one drive, and only have one timer delay. You only need one timer delay per iteration.
__________________
"Never let your schooling interfere with your education" -Mark Twain
Reply With Quote
  #3   Spotlight this post!  
Unread 20-02-2014, 21:36
SousVide SousVide is offline
Registered User
no team
 
Join Date: Jan 2011
Location: CA
Posts: 91
SousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to behold
Re: Joystick 2/Program issue

What is the purpose of M1 and M2 (connected to victor 5 and victor 6) ?

Are they two motors connected to the same gearbox ? If that's the case, then arcade drive would run one of the motors forward and the other backwards - unless if you have one of the motor outputs from one of the victors wired in reverse, the motors will be running against each other in the gear box...

You can also check the output led on victors 5 and 6 also - changes in the led color and flash rate can help debug the motor drive system...

http://wpilib.screenstepslive.com/s/...tem-components
Reply With Quote
  #4   Spotlight this post!  
Unread 20-02-2014, 21:49
miw14 miw14 is offline
Registered User
FRC #4840
 
Join Date: Feb 2014
Location: Michigan
Posts: 19
miw14 is an unknown quantity at this point
Re: Joystick 2/Program issue

We have not tried robotbuilder, but I appreciate the suggestion and will explore it. Thanks!


M1 and M2 are motors connected to the Victor motor controls 5 and 6. The problem is that when we use Joystick 2 to move the motors, nothing happens. We have it wired properly because the lights are are solid orange on the Victor controllers. Could it be an issue with the USB port number? Or anything with the code?
Reply With Quote
  #5   Spotlight this post!  
Unread 21-02-2014, 01:59
SousVide SousVide is offline
Registered User
no team
 
Join Date: Jan 2011
Location: CA
Posts: 91
SousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to behold
Re: Joystick 2/Program issue

More importantly:

1. Are the 2 motors mounted into the same gearbox, or do they sit outside and mounted independent from each other ?

2. When you move joystick 2, do the victors' leds turn off or go to solid green or solid red or do anything besides solid orange ?



Quote:
Originally Posted by miw14 View Post
We have not tried robotbuilder, but I appreciate the suggestion and will explore it. Thanks!


M1 and M2 are motors connected to the Victor motor controls 5 and 6. The problem is that when we use Joystick 2 to move the motors, nothing happens. We have it wired properly because the lights are are solid orange on the Victor controllers. Could it be an issue with the USB port number? Or anything with the code?

Last edited by SousVide : 21-02-2014 at 02:04.
Reply With Quote
  #6   Spotlight this post!  
Unread 21-02-2014, 08:46
miw14 miw14 is offline
Registered User
FRC #4840
 
Join Date: Feb 2014
Location: Michigan
Posts: 19
miw14 is an unknown quantity at this point
Re: Joystick 2/Program issue

1.) The motors are mounted independent of each other.

2.) The Victors stayed orange the whole time.

We switched the ports on the Victor controllers to 1 and 4 to see if it would work on Joystick 1 and it worked fine.
Reply With Quote
  #7   Spotlight this post!  
Unread 21-02-2014, 12:14
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: Joystick 2/Program issue

Does Joystick 2 work if you use Joystick Explorer?

I agree with SousVide, you probably do not want to use Arcade Drive for a shooter. This isn't causing your problem, but will once you start getting joystick 2 data. You should set both Victors individually.
Reply With Quote
  #8   Spotlight this post!  
Unread 21-02-2014, 15:45
SousVide SousVide is offline
Registered User
no team
 
Join Date: Jan 2011
Location: CA
Posts: 91
SousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to behold
Re: Joystick 2/Program issue

try this,

with the DriverStation in Teleop and Enabled... drive a bit with Joystick one.
Now unplug Joystick one from the laptop, does the DriverStation's Joystick light remain lit ?

Also, have you checked the joystick assignments in the DriverStation itself ?
Reply With Quote
  #9   Spotlight this post!  
Unread 22-02-2014, 11:14
miw14 miw14 is offline
Registered User
FRC #4840
 
Join Date: Feb 2014
Location: Michigan
Posts: 19
miw14 is an unknown quantity at this point
Re: Joystick 2/Program issue

Looks like joystick 2 is working again! Played around with the code and the dashboard, and it looks like things are working. Thanks for the help everyone!

As for not using arcade drive for the shooter, what would you recommend?
Reply With Quote
  #10   Spotlight this post!  
Unread 22-02-2014, 18:33
nyaculak nyaculak is offline
Registered User
FRC #0053 (Area 53)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2011
Location: Maryland
Posts: 28
nyaculak will become famous soon enough
Re: Joystick 2/Program issue

Quote:
Originally Posted by miw14 View Post
As for not using arcade drive for the shooter, what would you recommend?
You could use the victor.set(double speed) method. It works similar to the RobotDrive functions, expecting a value in the range of [-1, 1].

Better yet, you could use some object orientation magic to create a class that defines the behavior you want to see in your launcher. You can see team 53's implementation of this here.

For the future, it will help you tremendously to gain a solid working knowledge of Java and other programming languages. You'll have a much better understanding of your own code and the wpilib libraries if you learn object oriented programming.
__________________
2013 MUC DC 3rd Place, FRC DC Regional, FRC Chesapeake Regional
2012 FRC DC Regional, FRC Chesapeake Regional
ERHS Robotics Club
- FRC Team 53 "Area 53"
www.erhsroboticsclub.org
Reply With Quote
  #11   Spotlight this post!  
Unread 22-02-2014, 21:41
miw14 miw14 is offline
Registered User
FRC #4840
 
Join Date: Feb 2014
Location: Michigan
Posts: 19
miw14 is an unknown quantity at this point
Re: Joystick 2/Program issue

I'm taking AP CS online, so I do now a little bit of OOP, but nothing nearly as advanced as what you posted.

For the victor.set(double speed) method, what is the purpose? Is it to set a consistent speed when the joystick is pushed forward?

Thanks for the help! I really appreciate it. Our team has no mentors, so the entire build session has been very stressful.
Reply With Quote
  #12   Spotlight this post!  
Unread 23-02-2014, 08:00
pblankenbaker pblankenbaker is offline
Registered User
FRC #0868
 
Join Date: Feb 2012
Location: Carmel, IN, USA
Posts: 108
pblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of light
Re: Joystick 2/Program issue

I like to think of the set(power) methods on the SpeedController classes (like Victor, Talon and Jaguar) as the way to control how much power the speed controller lets through.

The power value can range from -1.0 (full reverse) to +1.0 (full foward).

For example:

Code:
victor.set(1.0); // Run motor "forwards" at full power
victor.set(0.5); // Run motor "forwards" at half power
victor.set(0.0); // Turn motor off (if Victor is calibrated)
victor.set(-0.25); // Run motor "backwards" at quarter power
victor.set(-1.0); // Run motor "backwards" at full power
  • The term "forwards" and "backwards" are virtual directions. Depending on how your motors are wired and mechanically connected, you may need to invert your power levels (use negative values for "forwards" and positive for "backwards") to get your physical device to move/rotate in the actual desired direction.
  • If your speed controller has not been calibrated, then setting a value of 0.0 may not fully stop the motor. See: http://content.vexrobotics.com/docs/...UserManual.pdf for directions on calibrating a Victor.

Hope that helps.
Reply With Quote
  #13   Spotlight this post!  
Unread 23-02-2014, 09:36
miw14 miw14 is offline
Registered User
FRC #4840
 
Join Date: Feb 2014
Location: Michigan
Posts: 19
miw14 is an unknown quantity at this point
Re: Joystick 2/Program issue

I kinda understand what you're saying. So the set method allows for a constant speed to be received to the motors? How would the program drive with the set method? Would I still use arcade drive? or would I use something else?

Thanks for help!
Reply With Quote
  #14   Spotlight this post!  
Unread 23-02-2014, 11:01
pblankenbaker pblankenbaker is offline
Registered User
FRC #0868
 
Join Date: Feb 2012
Location: Carmel, IN, USA
Posts: 108
pblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of light
Re: Joystick 2/Program issue

For your shooter, I would not use the RobotDrive class but recommend that your read values from your joysticks and then apply the current values to your shooter motors. Here's an example of a slight refactoring of some of your code:

Code:
public void operatorControl() { 
  while(isOperatorControl() && isEnabled()) {
    myDrive.arcadeDrive(driveStick);
    updateShooterPower();
    Timer.delay(0.01);
  }

  // Stop motors
  myDrive.stopMotor();
  M1.set(0);
  M2.set(0);
}

private void updateShooterPower() {
  // Read in joystick values from second game pad
  // (returns values in range of -1.0 to +1.0)
  double m1Power = driveStick2.getRawAxis(2);
  double m2Power = driveStick2.getRawAxis(4);

  // You might need/want to adjust power values here, the following example
  // treats values close to 0 as being zero

  if (Math.abs(m1Power) < 0.05) {
    m1Power = 0;
  }

  if (Math.abs(m2Power) < 0.05) {
    m2Power = 0;
  }

  // Apply power to shooter motors
  M1.set(m1Power);
  M2.set(m2Power);

  // If the joystick values or motor connections end up being the opposite of
  // what you expect, you may need to invert the power applied to one or
  // both of the motors.
  // Commented example of how to invert the power applied to both motors:
  //M1.set(-m1Power);
  //M2.set(-m2Power);

}
NOTE:
  • You will need to experiment with the Joystick axis values (I showed 2 and 4 above, 1, 3 and 5 are also available).
  • If you want to apply the same power to both shooter motors you will only need to read one joystick axis.
  • You may need to negate (invert) the power applied to one or both of your motors in order to get them to spin in the proper direction.
  • The Y-axis on gamepads tends to return -1.0 when pushed all the way up and +1.0 when pulled all the way down.
Reply With Quote
  #15   Spotlight this post!  
Unread 23-02-2014, 11:36
miw14 miw14 is offline
Registered User
FRC #4840
 
Join Date: Feb 2014
Location: Michigan
Posts: 19
miw14 is an unknown quantity at this point
Re: Joystick 2/Program issue

I really appreciate your time and effort, thank you very much. I still have a few more questions.

What do the axis numbers represent? Are they button numbers? I thought that there are only 2 axes on the joystick.
We do want the motors running at the same power, so we would only need one axis.

Also for the code you posted, how would we shoot in autonomous?

Lastly, where would we set the Victor power? And if we set them once, would they be set for the same in both autonomous and teleoperated?

Thank you once again!
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