Go to Post I'm really impressed with how much effort we'll go to, to avoid buying a $25 servo tester. - MrForbes [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
  #16   Spotlight this post!  
Unread 23-02-2014, 13:05
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

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() { 
  // Turn on shooters for all of autonomous period
  startShooters();

  // Turn off drive safety so we can use long timer delays before
  // changing drive power (if you don't do this, your program
  // may get interrupted and killed during autonomous)
  myDrive.setSafetyEnabled(false);

  // Example of driving at half power for 3 seconds (not sure if this
  // will be forward or backwards on your robot)
  myDrive.drive(-.5, 0.0); 
  Timer.delay(3.0);

  // Stop everything
  stopAll();
}

public void operatorControl() {
  // Turns shooter motors on for all of operator control period
  startShooters();

  // You can enable the drive safety check here (optional) as you
  // should be calling the arcadeDrive() method very frequently)
  myDrive.setSafetyEnabled(true);

  while(isOperatorControl() && isEnabled()) {
    // Let driver control robot
    myDrive.arcadeDrive(driveStick);
    Timer.delay(0.01);
  }

  // Stop everything
  stopAll();
}

private void stopAll() {
  // Stop drive motors and shooter
  myDrive.stopMotor();
  stopShooters();
}

private void stopShooters() {
  // Set output power to 0 to both shooter motors
  setShooterPower(0);
}

private void startShooters() {
  // Determine a reasonable power level for your shooter motors
  // (you will need to experiment)
  setShooterPower(0.5);
}

private void setShooterPower(double shooterPower) {
  // Apply power to shooter motors
  M1.set(shooterPower);
  M2.set(shooterPower);

  // IMPORTANT: If one or both of the 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:
  // (this would replace the set methods above)
  //M1.set(-shooterPower);
  //M2.set(-shooterPower);
}
Reply With Quote
  #17   Spotlight this post!  
Unread 23-02-2014, 13:45
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

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!

Last edited by miw14 : 23-02-2014 at 13:49.
Reply With Quote
  #18   Spotlight this post!  
Unread 23-02-2014, 14:14
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

oh. hope it's not flaky joystick cable or usb port...

Quote:
Originally Posted by miw14 View Post
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
  #19   Spotlight this post!  
Unread 23-02-2014, 15:10
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

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)?
Reply With Quote
  #20   Spotlight this post!  
Unread 23-02-2014, 15:40
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

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.

Last edited by miw14 : 23-02-2014 at 16:01.
Reply With Quote
  #21   Spotlight this post!  
Unread 23-02-2014, 17:15
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

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;

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() {

        // Turn off drive safety so we can use long timer delays before
        // changing drive power (if you don't do this, your program
        // may get interrupted and killed during autonomous)
        myDrive.setSafetyEnabled(false);

        // Example of driving at half power for 3 seconds (not sure if this
        // will be forward or backwards on your robot)
        myDrive.drive(-.5, 0.0);
        Timer.delay(3.0);
        // Stop drive motors
        myDrive.stopMotor();
        
        // Raise the launcher for one and a half seconds
        // TODO: Determine time value or better yet add a switch so you
        // know when launcher is in position
        startRaisingLauncher();
        Timer.delay(1.5);
        stopMovingLauncher();

        // TODO: INSERT FIRE OPERATION HERE
        
        // Stop everything
        stopAll();
    }

    public void operatorControl() {
        // You can enable the drive safety check here (optional) as you
        // should be calling the arcadeDrive() method very frequently)
        myDrive.setSafetyEnabled(true);

        while (isOperatorControl() && isEnabled()) {
            // Let driver control robot
            myDrive.arcadeDrive(driveStick);

            // Check to see if operator is raising or lowering the launcher
            checkLauncherControl();
            
            Timer.delay(0.01);
        }

        // Stop everything
        stopAll();
    }
    
    /**
     * Allow operator to raise/lower launcher using two buttons (stops if neither pressed).
     */
    private void checkLauncherControl() {
        int RAISE_BUTTON = 1;
        int LOWER_BUTTON = 2;
        
        if (driveStick2.getRawButton(RAISE_BUTTON) == true) {
            startRaisingLauncher();
        } else if (driveStick2.getRawButton(LOWER_BUTTON) == true) {
            startLoweringLauncher();
        } else {
            stopMovingLauncher();
        }
    }
    

    /**
     * Helper method to stop all motors on the robot.
     */
    private void stopAll() {
        myDrive.stopMotor();
        stopMovingLauncher();
    }

    /**
     * Set output power to 0 to both launcher motors that move the lift.
     */
    private void stopMovingLauncher() {
        setLiftPower(0);
    }

    /**
     * Turn launcher motors on so launcher starts going up.
     */
    private void startRaisingLauncher() {
        // TODO: Determine a reasonable power level for your shooter motors
        // (you will need to experiment)
        setLiftPower(0.5);
    }

    /**
     * Turn launcher motors on so launcher starts going down.
     */
    private void startLoweringLauncher() {
        // TODO: Determine a reasonable power level for your shooter motors
        // (you will need to experiment)
        setLiftPower(-0.5);
    }

    /**
     * Set the power on the motors that raise and lower the launcher.
     * 
     * @param power The power level in the range of [-1.0, +1.0] where
     * negative values will lower the launcher and positive values will
     * lift it.
     */
    private void setLiftPower(double power) {
        // Apply power to shooter motors
        // TODO: Determine if one or both power values need to be inverted
        // (see comment block below)
        M1.set(power);
        M2.set(power);

        // IMPORTANT: If one or both of the 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:
        // (this would replace the set methods above)
        //M1.set(-power);
        //M2.set(-power);
    }
}
The above code does not actually fire the ball (unless your ball automatically fires once the launcher has been lifted to a certain height).

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.

Last edited by pblankenbaker : 24-02-2014 at 04:41. Reason: Forgot to stop drive motors in autonomous
Reply With Quote
  #22   Spotlight this post!  
Unread 23-02-2014, 17:57
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

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!
Reply With Quote
  #23   Spotlight this post!  
Unread 23-02-2014, 20:35
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

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.
Reply With Quote
  #24   Spotlight this post!  
Unread 24-02-2014, 04:47
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

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
        // will be forward or backwards on your robot)
        myDrive.drive(-.5, 0.0);
        Timer.delay(3.0);
        // Stop drive motors
        myDrive.stopMotor();
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