![]() |
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; |
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. |
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 |
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? |
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:
|
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. |
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. |
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 ? |
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? |
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. |
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. |
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
Hope that helps. |
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! |
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() {
|
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! |
Re: Joystick 2/Program issue
The axis numbers are different than the button numbers. The axis numbers refer to the analog inputs (things that can be moved or twisted to different positions) on the input device where as the button numbers refer to the digital buttons (things that can only be pressed on/off).
So, if you are using a gamepad as your controller. It will typically have two "sticks" on it that you can move up/down and left/right to many different positions. This corresponds to 4 axis values (left stick right/left axis, left stick up/down axis, right stick right/left axis and right stick up/down axis). If you are using a non-gamepad joystick. You will have one axis for the left/right direction, another for the up/down direction and possibly others for twisting motions or throttle dials. When you write your software, part of the challenge will be determining which axis you want to read in order to set your shooter speed. For example, axis 2 might be the up/down axis on a gamepad's left stick. However, if 2 is not the correct number, you may need to experiment and try other values (1, 2, 3, 4, or 5). For autonomous, you would need to set specific motor powers (you would not want to read them from the joystick/gamepad). It may also turn out that you don't need to vary the speed with a joystick while under operator control (in which case you would not need to use the joystick either). I'm still not entirely clear on what your use cases are. From your last message, it sounded like you were more interested in being able to turn the shooter motors (Victors) on and off for the entire autonomous and operator control periods. Here is an example of setting your shooter motors to a specific power level and leaving them set to that level during all of autonomous and all of teleop (and also turning them off at the end). This example assumes you don't need/want to vary the speed of the shooter motors using a joystick/gamepad: Code:
public void autonomous() { |
Re: Joystick 2/Program issue
For our use, in auto we would like to drive, stop driving, fire, and then stop completely.
For teleop, we would like to drive and have the ability to launch our launcher forward and reset it. I'm getting closer to understanding what's going on, but I am still uncertain with a few things. How would we declare the launcher in the constructor? How do we control it in the autonomous period? I know with the drive we can select the power and put on a delay. But with the shooter, how would we control when it fires, if the shooter is running the entire time? Lastly, in the telop period, if the power is set at .5 at all times, would our launcher only be able to go forward or backwards? How could we reset our launcher each time? Sorry for the plethora of questions, I just want to make sure that we have no issues. Thank you again! |
Re: Joystick 2/Program issue
oh. hope it's not flaky joystick cable or usb port...
Quote:
|
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)? |
Re: Joystick 2/Program issue
Our launcher uses the two Victor controllers to control two CIM motors. The motors are used to operate our belt system, which can lift the launcher and also return the launcher to rest position if put in reverse. Sorry for any confusion. If you need me to clear anything else up, let me know.
|
Re: Joystick 2/Program issue
That helps to know that the two Victors are used to operate a belt and that running them in one direction will lift the launcher and that running them in the other direction will cause them to lower the launcher.
However, I don't understand how you know when to stop? If you keep running the Victors to lift the launcher, how will you know when you are at the launch point? If the Victors run too long, will it damage your robot? From what I know so far, it sounds like your only option is to run your Victors at certain power levels for a specific time period and hope for the best. Here's an example which has a autonomous routine that drives for a bit, then raises your launcher for a period of time and then stops (I don't know what you need to do to actually fire). The operator control has been adjusted slightly so that it uses two buttons on the joystick so the operator should be able to raise or lower the launcher depending which button they hold down (when they release both buttons it should stop). There are several comments flagged with TODO indicating that there are values that will need to be determined/adjusted. Code:
package edu.wpi.first.wpilibj.templates;Let me mention again that it is typically desirable to add limit switches so you can tell when the launcher has reached a certain point and should not be raised or lowered any more. The is especially important if moving the lift too far could damage the robot. |
Re: Joystick 2/Program issue
Thank you so much! I truly appreciate all of your help. You have been a godsend. As for the stopping mechanism, I'm not sure how that's going to work. I think our build team is coming up with ideas on it, so hopefully we'll have something figured out. I, too, am worried about potential damages. We will be sure to keep that in mind. Once again, thank you! I can not express my gratitude. You have been a mentor to a team lacking any mentors. Thank you!
|
Re: Joystick 2/Program issue
No worries - I'm glad my input was useful.
I'm really impressed that a new team without any mentors could produce a robot. I am a mentor who joined an established team and I was pretty lost for the first season. Your team should be proud to have gotten through a build season on its own. Good luck and have fun at your regionals. |
Re: Joystick 2/Program issue
Just a heads up, in the autonomous example, I had an error in the code that was suppose to drive for three seconds. The original code would start driving, wait for 3 seconds, but fail to stop driving afterwards. This would have resulted in your robot to continue driving for the next 1.5 seconds as it raised its launcher (until stopAll() was reached).
I've corrected the example in the previous post. Here is the fragment of code that was corrected with the addition of myDrive.stopMotor() (it will stop driving before raising the launcher): Code:
// Example of driving at half power for 3 seconds (not sure if this |
| All times are GMT -5. The time now is 12:17. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi