View Single Post
  #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: 103
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