|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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); }
}
|
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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? |
|
#5
|
|||
|
|||
|
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:
Last edited by SousVide : 21-02-2014 at 02:04. |
|
#6
|
|||
|
|||
|
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. |
|
#7
|
||||||
|
||||||
|
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. |
|
#8
|
|||
|
|||
|
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 ? |
|
#9
|
|||
|
|||
|
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? |
|
#10
|
|||
|
|||
|
Re: Joystick 2/Program issue
Quote:
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. |
|
#11
|
|||
|
|||
|
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. |
|
#12
|
|||
|
|||
|
Re: Joystick 2/Program issue
oh. hope it's not flaky joystick cable or usb port...
|
|
#13
|
|||
|
|||
|
Re: Joystick 2/Program issue
Can you describe your shooting mechanism?
How are the two motors controlled by the Victors used (are they just spinning wheels that the ball drops into and shoots out of, or are they used to crank down a catapult, etc)? Are there any other sensors or mechanisms required to shoot the ball (you mentioned a laucher of some type but did not describe how the launcher is controlled)? |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|