public static InterRangeDoubleConverter converterFromNormalTo(double toLimit1, double toLimit2) {
	return converterFromNormalTo(range(toLimit1, toLimit2));
}
 public static PololuMaestroServoController pololuMaestroServoController(PololuMaestroServoCard card) {
	return new PololuMaestroServoController(card);
}
 public static PololuMaestroServoCard defaultUsbPololuMaestroServoCard() {
	return usbPololuMaestroServoCard(Usb.device(isAMaestroUsbDevice()));
}
 public static <C> DefaultingServoSourceCalibration<C> servoSourceCalibration(ServoCalibration calibration) {
	return new DefaultingServoSourceCalibration<C>(calibration);
}
 public interface AnalogIOSource<C> extends PerChannelSource<C, AnalogIO> {
	
	/**
	 * Returns a AnalogIOSource that has new channel ids, as defined by the given function.
	 */
	default <NewChannelId> AnalogIOSource<NewChannelId> remapped(Function<NewChannelId, C> remapping) {
		return new RemappedAnalogIOSource<NewChannelId, C>(this, remapping);
	}

	/**
	 * Returns a proxy AnalogIO that is two-way calibrated representation of this instance.
	 */
	default AnalogIOSource<C> calibrated(AnalogIOSourceCalibration<C> calibration) {
		return new CalibratedAnalogIOSource<C>(this, calibration);
	}

	public static <C> AnalogIOSource<C> rawAnalogIOSource(final AnalogIOController<C> controller) {
		return new AnalogIOSource<C>() {
			@Override
			public AnalogIO forChannel(C channelId) {
				return new RawAnalogIO<C>(controller, channelId);
			}
		};
	}
}
 public interface Servo extends AnalogIO, ServoFeatures<MutableDouble> {

	/**
	 * Returns a proxy {@link Servo} that is two-way calibrated representation of this instance.
	 */
	default Servo calibrated(ServoCalibration calibration) {
		return new CalibratedServo(this, calibration);
	}
}
 public interface ServoCalibration extends AnalogIOCalibration, ServoFeatures<DoubleConverter> {
	static ServoCalibration IDENTITY = new ImmutableServoCalibration(DoubleConverter.IDENTITY);
}
 public interface ServoController<C> extends AnalogIOController<C> {
	MutableDouble speed(C channelId);
	MutableDouble acceleration(C channelId);
} public interface ServoSource<C> extends PerChannelSource<C, Servo> {

	/**
	 * Returns a ServoSource that has new channel ids, as defined by the given function.
	 */
	default <NewServoId> ServoSource<NewServoId> remapped(Function<NewServoId, C> remapping) {
		return new RemappedServoSource<NewServoId, C>(this, remapping);
	}

	/**
	 * Returns a ServoSource that returns calibrated proxies of the {@link Servo}s from another (target) {@link ServoSource}.
	 */
	default ServoSource<C> calibrated(ServoSourceCalibration<C> calibration) {
		return new CalibratedServoSource<C>(this, calibration);
	}

	/**
	 * Returns a ServoSource that returns calibrated proxies of the {@link Servo}s from another (target) {@link ServoSource}.
	 */
	default ServoSource<C> calibrated(ServoCalibration calibration) {
		return calibrated(servoSourceCalibration(calibration));
	}

	/**
	 * @return A {@link ServoSource} of {@link RawServo}s for the given {@link ServoController}.
	 */
	public static <C> ServoSource<C> rawServoSource(final ServoController<C> controller) {
		return new ServoSource<C>() {
			@Override
			public Servo forChannel(C channel) {
				return new RawServo<C>(controller, channel);
			}
		};
	}

}
 public interface ServoSourceCalibration<C> extends PerChannelSource<C, ServoCalibration> {


	public static <C> DefaultingServoSourceCalibration<C> servoSourceCalibration(ServoCalibration calibration) {
		return new DefaultingServoSourceCalibration<C>(calibration);
	}

	public static <C> DefaultingServoSourceCalibration<C> servoSourceCalibration() {
		return servoSourceCalibration(ServoCalibration.IDENTITY);
	}
}
 public class ImmutableServoCalibration implements ServoCalibration {

	private final DoubleConverter value, speed, acceleration;

	public static final ServoCalibration REVERSE_NORMAL_SERVO_CALIBRATION = new ImmutableServoCalibration(REVERSE_NORMAL_CONVERTER);

	public ImmutableServoCalibration(DoubleConverter value, DoubleConverter speed, DoubleConverter acceleration) {
		this.value = value;
		this.speed = speed;
		this.acceleration = acceleration;
	}

	public ImmutableServoCalibration(DoubleConverter value, DoubleConverter speed) {
		this(value, speed, DoubleConverter.IDENTITY);
	}

	public ImmutableServoCalibration(DoubleConverter value) {
		this(value, DoubleConverter.IDENTITY);
	}

	@Override
	public DoubleConverter value() {
		return value;
	}

	@Override
	public DoubleConverter speed() {
		return speed;
	}

	@Override
	public DoubleConverter acceleration() {
		return acceleration;
	}

	public static ImmutableServoCalibration calibrateValueFromNormalTo(double limit1, double limit2) {
		return new ImmutableServoCalibration(InterRangeDoubleConverter.converterFromNormalTo(limit1, limit2));
	}
}
import com.iamcontent.device.servo.impl.ImmutableServoCalibration;
import static com.iamcontent.core.math.InterRangeDoubleConverter.converterFromNormalTo;
import static com.iamcontent.device.controller.pololu.maestro.PololuMaestroServoController.pololuMaestroServoController;
import static com.iamcontent.device.controller.pololu.maestro.usb.UsbPololuMaestroServoCards.defaultUsbPololuMaestroServoCard;
import static com.iamcontent.device.servo.ServoSourceCalibration.servoSourceCalibration;
import javax.usb.UsbDevice;
import com.iamcontent.device.io.analog.AnalogIOSource;
import com.iamcontent.device.servo.Servo;
import com.iamcontent.device.servo.ServoCalibration;
import com.iamcontent.device.servo.ServoController;
import com.iamcontent.device.servo.ServoSource;
import com.iamcontent.device.servo.ServoSourceCalibration;

/**
  IAmContent Public Libraries.
  Copyright (C) 2015-2021 Greg Elderfield
  @author Greg Elderfield, support@jarchitect.co.uk
 
  This program is free software; you can redistribute it and/or modify it under the terms of the
  GNU General Public License as published by the Free Software Foundation; either version 2 of 
  the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along with this program;
  if not, write to the Free Software Foundation, Inc., 
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
package com.iamcontent.device.controller.pololu.maestro;




/**
 * A helper for creating a default configuration of {@link Servo}s of the {@link PololuMaestroServoController},
 * calibrated to the normal (0..1) range. Uses the first Pololu Maestro {@link UsbDevice} that is found.
 * @author Greg Elderfield
 */
public class DefaultPololuServoConfig {

	public static ServoSource<Integer> normalServos() {
		return rawServoSource().calibrated(servoSourceNormalization());
	}
	
	public static ServoSource<Integer> rawServoSource() {
		return ServoSource.rawServoSource(servoController());
	}

	public static AnalogIOSource<Integer> rawAnalogIOSource() {
		return AnalogIOSource.rawAnalogIOSource(servoController());
	}

	public static ServoController<Integer> servoController() {
		return pololuMaestroServoController(defaultUsbPololuMaestroServoCard());
	}
	
	public static ServoSourceCalibration<Integer> servoSourceNormalization() {

		return servoSourceCalibration(pololuMaestroServoNormalization());
