/// <summary> /// Constructor for RobotDrive with 4 motors specified as <see cref="ISpeedController"/> objects. /// </summary> /// <remarks>The <see cref="ISpeedController"/> version of the constructor enables programs to use /// RobotDrive classes with subclasses of the <see cref="ISpeedController"/> objects.</remarks> /// <param name="frontLeftMotor">The <see cref="ISpeedController"/> controlling the Front Left Motor</param> /// <param name="rearLeftMotor">The <see cref="ISpeedController"/> controlling the Rear Left Motor</param> /// <param name="frontRightMotor">The <see cref="ISpeedController"/> controlling the Front Right Motor</param> /// <param name="rearRightMotor">The <see cref="ISpeedController"/> controlling the Rear Right Motor</param> public RobotDrive(ISpeedController frontLeftMotor, ISpeedController rearLeftMotor, ISpeedController frontRightMotor, ISpeedController rearRightMotor) { if (frontLeftMotor == null) { throw new ArgumentNullException(nameof(frontLeftMotor), "Null Motor Controller Provided"); } if (frontRightMotor == null) { throw new ArgumentNullException(nameof(frontRightMotor), "Null Motor Controller Provided"); } if (rearLeftMotor == null) { throw new ArgumentNullException(nameof(rearLeftMotor), "Null Motor Controller Provided"); } if (rearRightMotor == null) { throw new ArgumentNullException(nameof(rearRightMotor), "Null Motor Controller Provided"); } FrontLeftMotor = frontLeftMotor; RearLeftMotor = rearLeftMotor; FrontRightMotor = frontRightMotor; RearRightMotor = rearRightMotor; Sensitivity = DefaultSensitivity; MaxOutput = DefaultMaxOutput; AllocatedSpeedControllers = false; SetupMotorSafety(); Drive(0, 0); }
public static void SetVoltage(this ISpeedController @this, ElectricPotential potential) { if (@this == null) { throw new ArgumentNullException(nameof(@this)); } @this.Set(potential / RobotController.BatteryVoltage); }
/// <summary> /// Constructor for RobotDrive with 2 motors specified with channel numbers. /// </summary> /// <remarks>Sets up parameters for a two motor drive system where the left /// and right motor channels are specified in the call. This call assumes Talons /// for controlling the motors.</remarks> /// <param name="leftMotorChannel">The PWM channel number that drives the left motor</param> /// <param name="rightMotorChannel">The PWM channel number that drives the right motor</param> public RobotDrive(int leftMotorChannel, int rightMotorChannel) { Sensitivity = DefaultSensitivity; MaxOutput = DefaultMaxOutput; FrontLeftMotor = null; RearLeftMotor = new Talon(leftMotorChannel); FrontRightMotor = null; RearRightMotor = new Talon(rightMotorChannel); AllocatedSpeedControllers = true; SetupMotorSafety(); Drive(0, 0); }
/// <summary> /// Constructor for RobotDrive with 2 motors specified with channel numbers. /// </summary> /// <remarks>Sets up parameters for a two motor drive system where the left /// and right motor channels are specified in the call. This call assumes Talons /// for controlling the motors.</remarks> /// <param name="leftMotorChannel">The PWM channel number that drives the left motor</param> /// <param name="rightMotorChannel">The PWM channel number that drives the right motor</param> public RobotDrive(int leftMotorChannel, int rightMotorChannel) { m_sensitivity = DefaultSensitivity; m_maxOutput = DefaultMaxOutput; m_frontLeftMotor = null; m_rearLeftMotor = new Talon(leftMotorChannel); m_frontRightMotor = null; m_rearRightMotor = new Talon(rightMotorChannel); m_allocatedSpeedControllers = true; SetupMotorSafety(); Drive(0, 0); }
/// <summary> /// Constructor for RobotDrive with 4 motors specified with channel numbers. /// </summary> /// <remarks>Sets up parameters for a two motor drive system where the left /// and right motor channels are specified in the call. This call assumes Talons /// for controlling the motors.</remarks> /// <param name="frontLeftMotor">The PWM Channel that drives the Front Left Motor</param> /// <param name="rearLeftMotor">The PWM Channel that drives the Rear Left Motor</param> /// <param name="frontRightMotor">The PWM Channel that drives the Front Right Motor</param> /// <param name="rearRightMotor">The PWM Channel that drives the Rear Right Motor</param> public RobotDrive(int frontLeftMotor, int rearLeftMotor, int frontRightMotor, int rearRightMotor) { Sensitivity = DefaultSensitivity; MaxOutput = DefaultMaxOutput; RearLeftMotor = new Talon(rearLeftMotor); RearRightMotor = new Talon(rearRightMotor); FrontLeftMotor = new Talon(frontLeftMotor); FrontRightMotor = new Talon(frontRightMotor); AllocatedSpeedControllers = true; SetupMotorSafety(); Drive(0, 0); }
/// <summary> /// Creates a new instance of EncoderPID with the supplied speed controller and PIDF values. /// </summary> /// <param name="speedController">Speed controller to use, such as <c>CANTalon</c> or <c>Spark</c></param> /// <param name="encoder">Encoder for measuring positional data.</param> /// <param name="kP">Proportional gain.</param> /// <param name="kI">Integral gain.</param> /// <param name="kD">Derivative gain.</param> /// <param name="kF">Filter gain.</param> public EncoderPID(ISpeedController speedController, Encoder encoder, double kP, double kI, double kD, double kF) { // Set the speed controller equal to something. _SpeedController = speedController; // Create a new instance of the PID controller. Controller = new PIDController(kP, kI, kD, kF, encoder, this); // Set the inputs for the encoder. Limits the range it can go. Controller.SetInputRange(0, 100); // Sets the output range of the motor. Controller.SetOutputRange(-0.5, 0.5); }
private void Initialize() { lock (this) { if (!initialized) { initialized = true; aSource = GiveDigitalInputA(); bSource = GiveDigitalInputB(); encoder = new Encoder(aSource, bSource); counters[0] = new Counter(aSource); counters[1] = new Counter(bSource); motor = GiveSpeedController(); } } }
private void Initialize() { lock (this) { if (!m_initialized) { m_initialized = true; m_aSource = GiveDigitalInputA(); m_bSource = GiveDigitalInputB(); m_encoder = new Encoder(m_aSource, m_bSource); m_counters[0] = new Counter(m_aSource); m_counters[1] = new Counter(m_bSource); m_motor = GiveSpeedController(); } } }
public bool Teardown() { var type = motor != null ? GetCustomType() : "null"; if (!tornDown) { bool wasNull = false; var pwm = motor as PWM; if (pwm != null && motor != null) { pwm.Dispose(); motor = null; } else if (motor == null) wasNull = true; if (encoder != null) { encoder.Dispose(); encoder = null; } else wasNull = true; if (counters[0] != null) { counters[0].Dispose(); counters[0] = null; } else wasNull = true; if (counters[1] != null) { counters[1].Dispose(); counters[1] = null; } else wasNull = true; if (aSource != null) { aSource.Dispose(); aSource = null; } else wasNull = true; if (bSource != null) { bSource.Dispose(); bSource = null; } else wasNull = true; tornDown = true; if (wasNull) { throw new NullReferenceException("MotorEncoderFixture had null params at teardown"); } } else { throw new SystemException(type + " Motor Encoder torn down multiple times"); } return true; }
public virtual bool Teardown() { var type = m_motor != null?GetCustomType() : "null"; if (!m_tornDown) { bool wasNull = false; var pwm = m_motor as PWM; if (pwm != null && m_motor != null) { pwm.Dispose(); m_motor = null; } else if (m_motor == null) { wasNull = true; } if (m_encoder != null) { m_encoder.Dispose(); m_encoder = null; } else { wasNull = true; } if (m_counters[0] != null) { m_counters[0].Dispose(); m_counters[0] = null; } else { wasNull = true; } if (m_counters[1] != null) { m_counters[1].Dispose(); m_counters[1] = null; } else { wasNull = true; } if (m_aSource != null) { m_aSource.Dispose(); m_aSource = null; } else { wasNull = true; } if (m_bSource != null) { m_bSource.Dispose(); m_bSource = null; } else { wasNull = true; } m_tornDown = true; if (wasNull) { throw new NullReferenceException("MotorEncoderFixture had null params at teardown"); } } else { throw new SystemException(type + " Motor Encoder torn down multiple times"); } return(true); }
/// <summary> /// Creates a new instance of EncoderPID with the supplied speed controller and PIDF values. /// </summary> /// <param name="speedController">Speed controller to use, such as <c>CANTalon</c> or <c>Spark</c></param> /// <param name="encoder">Encoder for measuring positional data.</param> /// <param name="values">The PIDF values to use.</param> public EncoderPID(ISpeedController speedController, Encoder encoder, PIDF values) : this(speedController, encoder, values.kP, values.kI, values.kD, values.kF) { }
/// <summary> /// Constructor for RobotDrive with 2 motors specified as <see cref="ISpeedController"/> objects. /// </summary> /// <remarks>The <see cref="ISpeedController"/> version of the constructor enables programs to use /// RobotDrive classes with subclasses of the <see cref="ISpeedController"/> objects.</remarks> /// <param name="leftMotor">The <see cref="ISpeedController"/> controlling the Left Motor</param> /// <param name="rightMotor">The <see cref="ISpeedController"/> controlling the Right Motor</param> public RobotDrive(ISpeedController leftMotor, ISpeedController rightMotor) { if (leftMotor == null) { throw new ArgumentNullException(nameof(leftMotor), "Null Motor Controller Provided"); } if (rightMotor == null) { throw new ArgumentNullException(nameof(rightMotor), "Null Motor Controller Provided"); } m_frontLeftMotor = null; m_rearLeftMotor = leftMotor; m_frontRightMotor = null; m_rearRightMotor = rightMotor; m_sensitivity = DefaultSensitivity; m_maxOutput = DefaultMaxOutput; m_allocatedSpeedControllers = false; SetupMotorSafety(); Drive(0, 0); }
public DriveTrainObject(ISpeedController frontLeftMotor, ISpeedController rearLeftMotor, ISpeedController frontRightMotor, ISpeedController rearRightMotor) : base(frontLeftMotor, rearLeftMotor, frontRightMotor, rearRightMotor) { }
public Quadcopter(ISpeedController controller) { controller = _controller; }
/// <summary> /// Wraps an existing <see cref="ISpeedController"/> with <see cref="RampMotor{T}"/> /// </summary> /// <param name="motorController">existing Motor Controller</param> public RampMotor(ISpeedController motorController) { m_controller = motorController; MaxChange = 1; m_power = 0; }