public void ArcadeDrive(double x, double y, bool isInverted = false) { double left; double right; if (isInverted) { left = (y - x) * MaxOutput; right = (y + x) * MaxOutput; } else { left = (y + x) * MaxOutput; right = (y - x) * MaxOutput; } if (right <= .2 && right >= -.2) { right = 0; } if (left <= .2 && left >= -.2) { left = 0; } RightPrimary.Set(right); RightSecondary.Set(right); LeftPrimary.Set(left); LeftSecondary.Set(left); }
private void Init() { LeftDrive = new CANTalon((int)TalonIDs.LeftDrive); LeftSlave = new CANTalon((int)TalonIDs.LeftSlave) { MotorControlMode = WPILib.Interfaces.ControlMode.Follower }; LeftSlave.Set(LeftDrive.DeviceId); RightDrive = new CANTalon((int)TalonIDs.RightDrive); RightSlave = new CANTalon((int)TalonIDs.RightSlave) { MotorControlMode = WPILib.Interfaces.ControlMode.Follower }; RightSlave.Set(RightDrive.DeviceId); }
public Drive() { LeftM = new CANTalon(Config.DriveLeftM); Left1 = new CANTalon(Config.DriveLeft1); Left1.MotorControlMode = WPILib.Interfaces.ControlMode.Follower; Left1.Set(Config.DriveLeft1); Left2 = new CANTalon(Config.DriveLeft2); Left2.MotorControlMode = WPILib.Interfaces.ControlMode.Follower; Left2.Set(Config.DriveLeft2); LeftFollowers = new SpeedControllerGroup(Left1, Left2); RightM = new CANTalon(Config.DriveRightM); Right1 = new CANTalon(Config.DriveRight1); Right1.MotorControlMode = WPILib.Interfaces.ControlMode.Follower; Right1.Set(Config.DriveRight1); Right2 = new CANTalon(Config.DriveRight2); Right2.MotorControlMode = WPILib.Interfaces.ControlMode.Follower; Right2.Set(Config.DriveRight2); RightFollowers = new SpeedControllerGroup(Right1, Right2); }//end Drive
}//end Drive public void driver(double left, double right) { LeftM.Set(left); RightM.Set(-right); }
/// <summary> /// Sets the talon to run at the given rpm. /// </summary> /// <param name="rpm">Amount of RPMs to run the motor at.</param> /// <param name="talon">Which talon to run.</param> public static void SetVelocity(double rpm, CANTalon talon) { talon.Set(rpm); }
/// <summary> /// Sets a value to the talon /// </summary> /// <param name="val">value to set the controller to</param> /// <param name="sender">the caller of this method</param> public override void Set(double val, object sender) { Sender = sender; SetAllowC(upperLimit?.GetBool() ?? true); SetAllowCc(lowerLimit?.GetBool() ?? true); if (BrownOut && !Critical) { val *= Constants.BROWNOUT_MULT; } if (Slave) { Report.Warning( $"Someone is trying to set {Name}, but {Name} is a slave, it can only be set by its master {master}."); return; } if (!Master) #if USE_LOCKING { lock (talon) #endif { talon.ControlEnabled = true; if ((val < -Constants.MINUMUM_JOYSTICK_RETURN) && AllowCc) { InUse = true; if (IsReversed) { talon.Set(-val); onValueChanged(new VirtualControlEventArgs(-val, InUse)); } else { talon.Set(val); onValueChanged(new VirtualControlEventArgs(val, InUse)); } } else if ((val > Constants.MINUMUM_JOYSTICK_RETURN) && AllowC) { InUse = true; if (IsReversed) { talon.Set(-val); onValueChanged(new VirtualControlEventArgs(-val, InUse)); } else { talon.Set(val); onValueChanged(new VirtualControlEventArgs(val, InUse)); } } else { talon.Set(0); talon.ControlEnabled = false; InUse = false; onValueChanged(new VirtualControlEventArgs(val, InUse)); } } if (!Master) { return; } if ((val < Constants.MINUMUM_JOYSTICK_RETURN) && AllowCc) { if (IsReversed) { #if USE_LOCKING lock (talon) #endif { talon.ControlEnabled = true; InUse = true; talon.Set(-val); onValueChanged(new VirtualControlEventArgs(-val, InUse)); } foreach (var slave in slaves) #if USE_LOCKING lock (slave) #endif { ((CANTalon)slave.GetRawComponent()).ControlEnabled = true; ((CANTalon)slave.GetRawComponent()).Set(talon.DeviceId); } } else { #if USE_LOCKING lock (talon) #endif { talon.ControlEnabled = true; InUse = true; talon.Set(val); onValueChanged(new VirtualControlEventArgs(val, InUse)); } foreach (var slave in slaves) #if USE_LOCKING lock (slave) #endif { ((CANTalon)slave.GetRawComponent()).ControlEnabled = true; ((CANTalon)slave.GetRawComponent()).Set(talon.DeviceId); } } } else if ((val > Constants.MINUMUM_JOYSTICK_RETURN) && AllowC) { if (IsReversed) { #if USE_LOCKING lock (talon) #endif { talon.ControlEnabled = true; InUse = true; talon.Set(-val); onValueChanged(new VirtualControlEventArgs(-val, InUse)); } foreach (var slave in slaves) #if USE_LOCKING lock (slave) #endif { ((CANTalon)slave.GetRawComponent()).ControlEnabled = true; ((CANTalon)slave.GetRawComponent()).Set(talon.DeviceId); } } else { #if USE_LOCKING lock (talon) #endif { talon.ControlEnabled = true; InUse = true; talon.Set(val); onValueChanged(new VirtualControlEventArgs(val, InUse)); } foreach (var slave in slaves) #if USE_LOCKING lock (slave) #endif { ((CANTalon)slave.GetRawComponent()).ControlEnabled = true; ((CANTalon)slave.GetRawComponent()).Set(talon.DeviceId); } } } else { #if USE_LOCKING lock (talon) #endif { talon.Set(0); talon.ControlEnabled = false; InUse = false; onValueChanged(new VirtualControlEventArgs(-val, InUse)); } foreach (var slave in slaves) #if USE_LOCKING lock (slave) #endif { ((CANTalon)slave.GetRawComponent()).ControlEnabled = false; } } }