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