001/*----------------------------------------------------------------------------*/
002/* Copyright (c) FIRST 2008-2012. All Rights Reserved.                        */
003/* Open Source Software - may be modified and shared by FRC teams. The code   */
004/* must be accompanied by the FIRST BSD license file in the root directory of */
005/* the project.                                                               */
006/*----------------------------------------------------------------------------*/
007
008package edu.wpi.first.wpilibj;
009
010import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
011import edu.wpi.first.wpilibj.communication.UsageReporting;
012import edu.wpi.first.wpilibj.livewindow.LiveWindow;
013
014/**
015 * VEX Robotics Victor 888 Speed Controller
016 * 
017 * The Vex Robotics Victor 884 Speed Controller can also be used with this
018 * class but may need to be calibrated per the Victor 884 user manual.
019 */
020public class Victor extends SafePWM implements SpeedController {
021
022    /**
023     * Common initialization code called by all constructors.
024     *
025     * Note that the Victor uses the following bounds for PWM values.  These values were determined
026     * empirically and optimized for the Victor 888. These values should work reasonably well for
027     * Victor 884 controllers also but if users experience issues such as asymmetric behaviour around
028     * the deadband or inability to saturate the controller in either direction, calibration is recommended.
029     * The calibration procedure can be found in the Victor 884 User Manual available from VEX Robotics:
030     * http://content.vexrobotics.com/docs/ifi-v884-users-manual-9-25-06.pdf
031     *
032     *   - 2.027ms = full "forward"
033     *   - 1.525ms = the "high end" of the deadband range
034     *   - 1.507ms = center of the deadband range (off)
035     *   - 1.49ms = the "low end" of the deadband range
036     *   - 1.026ms = full "reverse"
037     */
038    private void initVictor() {
039        setBounds(2.027, 1.525, 1.507, 1.49, 1.026);
040        setPeriodMultiplier(PeriodMultiplier.k2X);
041        setRaw(m_centerPwm);
042                setZeroLatch();
043
044        LiveWindow.addActuator("Victor", getChannel(), this);
045        UsageReporting.report(tResourceType.kResourceType_Victor, getChannel());
046    }
047
048    /**
049     * Constructor.
050     *
051     * @param channel The PWM channel that the Victor is attached to. 0-9 are on-board, 10-19 are on the MXP port
052     */
053    public Victor(final int channel) {
054        super(channel);
055        initVictor();
056    }
057
058    /**
059     * Set the PWM value.
060     *
061     * @deprecated For compatibility with CANJaguar
062     *
063     * The PWM value is set using a range of -1.0 to 1.0, appropriately
064     * scaling the value for the FPGA.
065     *
066     * @param speed The speed to set.  Value should be between -1.0 and 1.0.
067     * @param syncGroup The update group to add this Set() to, pending UpdateSyncGroup().  If 0, update immediately.
068     */
069    public void set(double speed, byte syncGroup) {
070        setSpeed(speed);
071        Feed();
072    }
073
074    /**
075     * Set the PWM value.
076     *
077     * The PWM value is set using a range of -1.0 to 1.0, appropriately
078     * scaling the value for the FPGA.
079     *
080     * @param speed The speed value between -1.0 and 1.0 to set.
081     */
082    public void set(double speed) {
083        setSpeed(speed);
084        Feed();
085    }
086
087    /**
088     * Get the recently set value of the PWM.
089     *
090     * @return The most recently set value for the PWM between -1.0 and 1.0.
091     */
092    public double get() {
093        return getSpeed();
094    }
095
096    /**
097     * Write out the PID value as seen in the PIDOutput base object.
098     *
099     * @param output Write out the PWM value as was found in the PIDController
100     */
101    public void pidWrite(double output) {
102        set(output);
103    }
104}