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 Jaguar Speed Control
016     */
017    public class Jaguar extends SafePWM implements SpeedController, IDeviceController {
018    
019        /**
020         * Common initialization code called by all constructors.
021         */
022        private void initJaguar() {
023            /*
024             * Input profile defined by Luminary Micro.
025             *
026             * Full reverse ranges from 0.671325ms to 0.6972211ms
027             * Proportional reverse ranges from 0.6972211ms to 1.4482078ms
028             * Neutral ranges from 1.4482078ms to 1.5517922ms
029             * Proportional forward ranges from 1.5517922ms to 2.3027789ms
030             * Full forward ranges from 2.3027789ms to 2.328675ms
031             */
032            setBounds(2.31, 1.55, 1.507, 1.454, .697);
033            setPeriodMultiplier(PeriodMultiplier.k1X);
034            setRaw(m_centerPwm);
035    
036            UsageReporting.report(UsageReporting.kResourceType_Jaguar, getChannel(), getModuleNumber()-1);
037            LiveWindow.addActuator("Jaguar", getModuleNumber(), getChannel(), this);
038        }
039    
040        /**
041         * Constructor that assumes the default digital module.
042         *
043         * @param channel The PWM channel on the digital module that the Jaguar is attached to.
044         */
045        public Jaguar(final int channel) {
046            super(channel);
047            initJaguar();
048        }
049    
050        /**
051         * Constructor that specifies the digital module.
052         *
053         * @param slot The slot in the chassis that the digital module is plugged into.
054         * @param channel The PWM channel on the digital module that the Jaguar is attached to.
055         */
056        public Jaguar(final int slot, final int channel) {
057            super(slot, channel);
058            initJaguar();
059        }
060    
061        /**
062         * Set the PWM value.
063         *
064         * @deprecated For compatibility with CANJaguar
065         *
066         * The PWM value is set using a range of -1.0 to 1.0, appropriately
067         * scaling the value for the FPGA.
068         *
069         * @param speed The speed to set.  Value should be between -1.0 and 1.0.
070         * @param syncGroup The update group to add this Set() to, pending UpdateSyncGroup().  If 0, update immediately.
071         */
072        public void set(double speed, byte syncGroup) {
073            setSpeed(speed);
074                    Feed();
075        }
076    
077        /**
078         * Set the PWM value.
079         *
080         * The PWM value is set using a range of -1.0 to 1.0, appropriately
081         * scaling the value for the FPGA.
082         *
083         * @param speed The speed value between -1.0 and 1.0 to set.
084         */
085        public void set(double speed) {
086            setSpeed(speed);
087                    Feed();
088        }
089    
090        /**
091         * Get the recently set value of the PWM.
092         *
093         * @return The most recently set value for the PWM between -1.0 and 1.0.
094         */
095        public double get() {
096            return getSpeed();
097        }
098    
099        /**
100         * Write out the PID value as seen in the PIDOutput base object.
101         *
102         * @param output Write out the PWM value as was found in the PIDController
103         */
104        public void pidWrite(double output) {
105            set(output);
106        }
107    }