private void setSpeedCommon(MotorInstance inst, float percent) { try { // Direction is a bitmask and can only be set for both motors. byte dir = 0x02; if (percent < 0) { dir = 0x01; percent = Math.Abs(percent); } /* * if (inst == MotorInstance.A) * { * dir <<= 2; * direction = (byte)((direction & 0x3) | dir); * } * else * { * direction = (byte)((direction & 0xC) | dir); * } * * byte[] dirBuffer = new byte[] { DirectionSet, direction, Nothing }; * * motorController.Write(dirBuffer); */ byte speed = (byte)Math.Floor(percent * 255); byte[] setSpeedBuffer = new byte[] { (inst == MotorInstance.A)?MotorSetA : MotorSetB, dir, speed }; motorController.Write(setSpeedBuffer); } catch (Exception e) { Debug.WriteLine("Exception: " + e.Message + "\n" + e.StackTrace); throw; } }
private void setSpeedCommon(MotorInstance inst, float percent) { try { // Direction is a bitmask and can only be set for both motors at once (though you can set different directions for each) byte dir = 0x02; if (percent < 0) { dir = 0x01; percent = Math.Abs(percent); } byte speed = (byte)Math.Floor(percent * 255); byte[] setSpeedBuffer = new byte[] { (inst == MotorInstance.A) ? MotorSetA : MotorSetB, dir, speed }; motorController.Write(setSpeedBuffer); } catch (Exception e) { Debug.WriteLine("Exception: " + e.Message + "\n" + e.StackTrace); throw; } }