void UpdateState() { float output = percentOutput * (Inverted ? -1.0f : 1.0f); motor.setInput(output); if (followerMotorController) { followerMotorController.motor.setInput(output); } if (encoder) { int counts = encoder.Counts * (sensorPhase ? -1 : 1); // compute velocity.Position already figured by encoder. encoderPosition = counts; // Compute velocity as change in position. Delta ticks /time in seconds / 10 to get time per 100 mSec encoderVelocity = ((counts - lastEncoderValue)) / (Time.deltaTime) / 10.0f; lastEncoderValue = counts; } supplyCurrent = Mathf.Abs((float)percentOutput) * 30 * Random.Range(0.95f, 1.05f); busVoltage = 12.0 - (percentOutput * percentOutput) * 0.75 * Random.Range(0.95f, 1.05f); }
// Update is called once per frame void FixedUpdate() { motor.setInput(PWMPort.GetSpeed()); }