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    
008    package edu.wpi.first.wpilibj;
009    
010    import edu.wpi.first.wpilibj.communication.UsageReporting;
011    import edu.wpi.first.wpilibj.livewindow.LiveWindow;
012    import edu.wpi.first.wpilibj.parsing.IDeviceController;
013    
014    /**
015     * VEX Robotics Victor Speed Controller
016     */
017    public class Victor extends SafePWM implements SpeedController, IDeviceController {
018    
019        /**
020         * Common initialization code called by all constructors.
021         *
022         * Note that the Victor uses the following bounds for PWM values.  These values were determined
023         * empirically and optimized for the Victor 888. These values should work reasonably well for
024         * Victor 884 controllers also but if users experience issues such as asymmetric behavior around
025         * the deadband or inability to saturate the controller in either direction, calibration is recommended.
026         * The calibration procedure can be found in the Victor 884 User Manual available from VEX Robotics:
027         * http://content.vexrobotics.com/docs/ifi-v884-users-manual-9-25-06.pdf
028         * 
029         *   - 2.027ms = full "forward"
030         *   - 1.525ms = the "high end" of the deadband range
031         *   - 1.507ms = center of the deadband range (off)
032         *   - 1.49ms = the "low end" of the deadband range
033         *   - 1.026ms = full "reverse"
034         */
035        private void initVictor() {
036            setBounds(2.027, 1.525, 1.507, 1.49, 1.026);
037            setPeriodMultiplier(PeriodMultiplier.k2X);
038            setRaw(m_centerPwm);
039    
040            LiveWindow.addActuator("Victor", getModuleNumber(), getChannel(), this);
041            UsageReporting.report(UsageReporting.kResourceType_Victor, getChannel(), getModuleNumber()-1);
042        }
043    
044        /**
045         * Constructor that assumes the default digital module.
046         *
047         * @param channel The PWM channel on the digital module that the Victor is attached to.
048         */
049        public Victor(final int channel) {
050            super(channel);
051            initVictor();
052        }
053    
054        /**
055         * Constructor that specifies the digital module.
056         *
057         * @param slot The slot in the chassis that the digital module is plugged into.
058         * @param channel The PWM channel on the digital module that the Victor is attached to.
059         */
060        public Victor(final int slot, final int channel) {
061            super(slot, channel);
062            initVictor();
063        }
064    
065        /**
066         * Set the PWM value.
067         *
068         * @deprecated For compatibility with CANJaguar
069         *
070         * The PWM value is set using a range of -1.0 to 1.0, appropriately
071         * scaling the value for the FPGA.
072         *
073         * @param speed The speed to set.  Value should be between -1.0 and 1.0.
074         * @param syncGroup The update group to add this Set() to, pending UpdateSyncGroup().  If 0, update immediately.
075         */
076        public void set(double speed, byte syncGroup) {
077            setSpeed(speed);
078                    Feed();
079        }
080    
081        /**
082         * Set the PWM value.
083         *
084         * The PWM value is set using a range of -1.0 to 1.0, appropriately
085         * scaling the value for the FPGA.
086         *
087         * @param speed The speed value between -1.0 and 1.0 to set.
088         */
089        public void set(double speed) {
090            setSpeed(speed);
091                    Feed();
092        }
093    
094        /**
095         * Get the recently set value of the PWM.
096         *
097         * @return The most recently set value for the PWM between -1.0 and 1.0.
098         */
099        public double get() {
100            return getSpeed();
101        }
102    
103        /**
104         * Write out the PID value as seen in the PIDOutput base object.
105         *
106         * @param output Write out the PWM value as was found in the PIDController
107         */
108        public void pidWrite(double output) {
109            set(output);
110        }
111    }