CSharpRoboticsLib.WPIExtensions.RampMotor.Set C# (CSharp) Method

Set() public method

Sets the value to the motor, within the change limitations
public Set ( double value ) : void
value double value to set to or approach
return void
        public void Set(double value)
        {
            //The motor is DECELLERATING if |value| < |power| OR value and power are not both positive or both negative
            //Likewise, the motor is ACCELERATING if |value| > |power| AND value and power are both negative or both positive
            //If power is zero, the motor is accelerating.
            //if the motor is ACCELERATING, use MaxAccel. If the robot is DECELLERATING, use MaxDecel.
            bool accel = (Math.Sign(value) == Math.Sign(m_power) && Math.Abs(value) > Math.Abs(m_power)) ||
                         Math.Abs(m_power) < MaxAccel;
            double delta = accel ? MaxAccel : MaxDecel;

            if (value > m_power + delta) //If the motor wants to change power faster than it is allowed, change it by the max power change allowed
                m_power += delta;
            else if (value < m_power - delta)
                m_power -= delta;
            else //If the motor wants to go to a power within the change limitations, set the power to the value.
                m_power = value;

            m_controller.Set(m_power);
        }

Same methods

RampMotor::Set ( double value, byte syncGroup ) : void

Usage Example

 public void RampAccelPositiveTest()
 {
     using (RampMotor motor = new RampMotor(typeof(Talon), 0))
     {
         motor.MaxAccel = 0.2;
         for (int i = 0; motor.Get() < 1; i++)
         {
             motor.Set(1);
             Assert.AreEqual(0.2 * (i + 1), motor.Get(), 0.001);
         }
     }
 }
All Usage Examples Of CSharpRoboticsLib.WPIExtensions.RampMotor::Set