001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005// THIS FILE WAS AUTO-GENERATED BY ./commandsv3/generate_files.py. DO NOT MODIFY 006 007package org.wpilib.commands3.button; 008 009import edu.wpi.first.wpilibj.XboxController; 010import edu.wpi.first.wpilibj.event.EventLoop; 011import org.wpilib.commands3.Scheduler; 012import org.wpilib.commands3.Trigger; 013 014/** 015 * A version of {@link XboxController} with {@link Trigger} factories for command-based. 016 * 017 * @see XboxController 018 */ 019@SuppressWarnings("MethodName") 020public class CommandXboxController extends CommandGenericHID { 021 private final XboxController m_hid; 022 023 /** 024 * Construct an instance of a controller. Commands bound to buttons on the controller will be 025 * scheduled on the {@link Scheduler#getDefault() default scheduler} using its default event loop. 026 * 027 * @param port The port index on the Driver Station that the controller is plugged into. 028 */ 029 public CommandXboxController(int port) { 030 super(port); 031 m_hid = new XboxController(port); 032 } 033 034 /** 035 * Construct an instance of a controller. Commands bound to buttons on the controller will be 036 * scheduled on the given scheduler using its default event loop. 037 * 038 * @param scheduler The scheduler that should execute the triggered commands. 039 * @param port The port index on the Driver Station that the controller is plugged into. 040 */ 041 public CommandXboxController(Scheduler scheduler, int port) { 042 super(scheduler, port); 043 m_hid = new XboxController(port); 044 } 045 046 /** 047 * Get the underlying GenericHID object. 048 * 049 * @return the wrapped GenericHID object 050 */ 051 @Override 052 public XboxController getHID() { 053 return m_hid; 054 } 055 056 /** 057 * Constructs a Trigger instance around the A button's digital signal. 058 * 059 * @return a Trigger instance representing the A button's digital signal attached 060 * to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the 061 * scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault 062 * default scheduler} if a scheduler was not explicitly provided. 063 * @see #a(EventLoop) 064 */ 065 public Trigger a() { 066 return a(getScheduler().getDefaultEventLoop()); 067 } 068 069 /** 070 * Constructs a Trigger instance around the A button's digital signal. 071 * 072 * @param loop the event loop instance to attach the event to. 073 * @return a Trigger instance representing the A button's digital signal attached 074 * to the given loop. 075 */ 076 public Trigger a(EventLoop loop) { 077 return button(XboxController.Button.kA.value, loop); 078 } 079 080 /** 081 * Constructs a Trigger instance around the B button's digital signal. 082 * 083 * @return a Trigger instance representing the B button's digital signal attached 084 * to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the 085 * scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault 086 * default scheduler} if a scheduler was not explicitly provided. 087 * @see #b(EventLoop) 088 */ 089 public Trigger b() { 090 return b(getScheduler().getDefaultEventLoop()); 091 } 092 093 /** 094 * Constructs a Trigger instance around the B button's digital signal. 095 * 096 * @param loop the event loop instance to attach the event to. 097 * @return a Trigger instance representing the B button's digital signal attached 098 * to the given loop. 099 */ 100 public Trigger b(EventLoop loop) { 101 return button(XboxController.Button.kB.value, loop); 102 } 103 104 /** 105 * Constructs a Trigger instance around the X button's digital signal. 106 * 107 * @return a Trigger instance representing the X button's digital signal attached 108 * to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the 109 * scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault 110 * default scheduler} if a scheduler was not explicitly provided. 111 * @see #x(EventLoop) 112 */ 113 public Trigger x() { 114 return x(getScheduler().getDefaultEventLoop()); 115 } 116 117 /** 118 * Constructs a Trigger instance around the X button's digital signal. 119 * 120 * @param loop the event loop instance to attach the event to. 121 * @return a Trigger instance representing the X button's digital signal attached 122 * to the given loop. 123 */ 124 public Trigger x(EventLoop loop) { 125 return button(XboxController.Button.kX.value, loop); 126 } 127 128 /** 129 * Constructs a Trigger instance around the Y button's digital signal. 130 * 131 * @return a Trigger instance representing the Y button's digital signal attached 132 * to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the 133 * scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault 134 * default scheduler} if a scheduler was not explicitly provided. 135 * @see #y(EventLoop) 136 */ 137 public Trigger y() { 138 return y(getScheduler().getDefaultEventLoop()); 139 } 140 141 /** 142 * Constructs a Trigger instance around the Y button's digital signal. 143 * 144 * @param loop the event loop instance to attach the event to. 145 * @return a Trigger instance representing the Y button's digital signal attached 146 * to the given loop. 147 */ 148 public Trigger y(EventLoop loop) { 149 return button(XboxController.Button.kY.value, loop); 150 } 151 152 /** 153 * Constructs a Trigger instance around the left bumper button's digital signal. 154 * 155 * @return a Trigger instance representing the left bumper button's digital signal attached 156 * to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the 157 * scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault 158 * default scheduler} if a scheduler was not explicitly provided. 159 * @see #leftBumper(EventLoop) 160 */ 161 public Trigger leftBumper() { 162 return leftBumper(getScheduler().getDefaultEventLoop()); 163 } 164 165 /** 166 * Constructs a Trigger instance around the left bumper button's digital signal. 167 * 168 * @param loop the event loop instance to attach the event to. 169 * @return a Trigger instance representing the left bumper button's digital signal attached 170 * to the given loop. 171 */ 172 public Trigger leftBumper(EventLoop loop) { 173 return button(XboxController.Button.kLeftBumper.value, loop); 174 } 175 176 /** 177 * Constructs a Trigger instance around the right bumper button's digital signal. 178 * 179 * @return a Trigger instance representing the right bumper button's digital signal attached 180 * to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the 181 * scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault 182 * default scheduler} if a scheduler was not explicitly provided. 183 * @see #rightBumper(EventLoop) 184 */ 185 public Trigger rightBumper() { 186 return rightBumper(getScheduler().getDefaultEventLoop()); 187 } 188 189 /** 190 * Constructs a Trigger instance around the right bumper button's digital signal. 191 * 192 * @param loop the event loop instance to attach the event to. 193 * @return a Trigger instance representing the right bumper button's digital signal attached 194 * to the given loop. 195 */ 196 public Trigger rightBumper(EventLoop loop) { 197 return button(XboxController.Button.kRightBumper.value, loop); 198 } 199 200 /** 201 * Constructs a Trigger instance around the back button's digital signal. 202 * 203 * @return a Trigger instance representing the back button's digital signal attached 204 * to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the 205 * scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault 206 * default scheduler} if a scheduler was not explicitly provided. 207 * @see #back(EventLoop) 208 */ 209 public Trigger back() { 210 return back(getScheduler().getDefaultEventLoop()); 211 } 212 213 /** 214 * Constructs a Trigger instance around the back button's digital signal. 215 * 216 * @param loop the event loop instance to attach the event to. 217 * @return a Trigger instance representing the back button's digital signal attached 218 * to the given loop. 219 */ 220 public Trigger back(EventLoop loop) { 221 return button(XboxController.Button.kBack.value, loop); 222 } 223 224 /** 225 * Constructs a Trigger instance around the start button's digital signal. 226 * 227 * @return a Trigger instance representing the start button's digital signal attached 228 * to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the 229 * scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault 230 * default scheduler} if a scheduler was not explicitly provided. 231 * @see #start(EventLoop) 232 */ 233 public Trigger start() { 234 return start(getScheduler().getDefaultEventLoop()); 235 } 236 237 /** 238 * Constructs a Trigger instance around the start button's digital signal. 239 * 240 * @param loop the event loop instance to attach the event to. 241 * @return a Trigger instance representing the start button's digital signal attached 242 * to the given loop. 243 */ 244 public Trigger start(EventLoop loop) { 245 return button(XboxController.Button.kStart.value, loop); 246 } 247 248 /** 249 * Constructs a Trigger instance around the left stick button's digital signal. 250 * 251 * @return a Trigger instance representing the left stick button's digital signal attached 252 * to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the 253 * scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault 254 * default scheduler} if a scheduler was not explicitly provided. 255 * @see #leftStick(EventLoop) 256 */ 257 public Trigger leftStick() { 258 return leftStick(getScheduler().getDefaultEventLoop()); 259 } 260 261 /** 262 * Constructs a Trigger instance around the left stick button's digital signal. 263 * 264 * @param loop the event loop instance to attach the event to. 265 * @return a Trigger instance representing the left stick button's digital signal attached 266 * to the given loop. 267 */ 268 public Trigger leftStick(EventLoop loop) { 269 return button(XboxController.Button.kLeftStick.value, loop); 270 } 271 272 /** 273 * Constructs a Trigger instance around the right stick button's digital signal. 274 * 275 * @return a Trigger instance representing the right stick button's digital signal attached 276 * to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the 277 * scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault 278 * default scheduler} if a scheduler was not explicitly provided. 279 * @see #rightStick(EventLoop) 280 */ 281 public Trigger rightStick() { 282 return rightStick(getScheduler().getDefaultEventLoop()); 283 } 284 285 /** 286 * Constructs a Trigger instance around the right stick button's digital signal. 287 * 288 * @param loop the event loop instance to attach the event to. 289 * @return a Trigger instance representing the right stick button's digital signal attached 290 * to the given loop. 291 */ 292 public Trigger rightStick(EventLoop loop) { 293 return button(XboxController.Button.kRightStick.value, loop); 294 } 295 296 /** 297 * Constructs a Trigger instance around the axis value of the left trigger. The returned 298 * trigger will be true when the axis value is greater than {@code threshold}. 299 * 300 * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value 301 * should be in the range [0, 1] where 0 is the unpressed state of the axis. 302 * @param loop the event loop instance to attach the Trigger to. 303 * @return a Trigger instance that is true when the left trigger's axis exceeds the provided 304 * threshold, attached to the given event loop 305 */ 306 public Trigger leftTrigger(double threshold, EventLoop loop) { 307 return axisGreaterThan(XboxController.Axis.kLeftTrigger.value, threshold, loop); 308 } 309 310 /** 311 * Constructs a Trigger instance around the axis value of the left trigger. The returned 312 * trigger will be true when the axis value is greater than {@code threshold}. 313 * 314 * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value 315 * should be in the range [0, 1] where 0 is the unpressed state of the axis. 316 * @return a Trigger instance that is true when the left trigger's axis exceeds the provided 317 * threshold, attached to the {@link Scheduler#getDefaultEventLoop() default scheduler event 318 * loop} on the scheduler passed to the controller's constructor, or the {@link 319 * Scheduler#getDefault default scheduler} if a scheduler was not explicitly provided. 320 */ 321 public Trigger leftTrigger(double threshold) { 322 return leftTrigger(threshold, getScheduler().getDefaultEventLoop()); 323 } 324 325 /** 326 * Constructs a Trigger instance around the axis value of the left trigger. The returned trigger 327 * will be true when the axis value is greater than 0.5. 328 * 329 * @return a Trigger instance that is true when the left trigger's axis exceeds 0.5, attached to 330 * the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the 331 * scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault 332 * default scheduler} if a scheduler was not explicitly provided. 333 */ 334 public Trigger leftTrigger() { 335 return leftTrigger(0.5); 336 } 337 338 /** 339 * Constructs a Trigger instance around the axis value of the right trigger. The returned 340 * trigger will be true when the axis value is greater than {@code threshold}. 341 * 342 * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value 343 * should be in the range [0, 1] where 0 is the unpressed state of the axis. 344 * @param loop the event loop instance to attach the Trigger to. 345 * @return a Trigger instance that is true when the right trigger's axis exceeds the provided 346 * threshold, attached to the given event loop 347 */ 348 public Trigger rightTrigger(double threshold, EventLoop loop) { 349 return axisGreaterThan(XboxController.Axis.kRightTrigger.value, threshold, loop); 350 } 351 352 /** 353 * Constructs a Trigger instance around the axis value of the right trigger. The returned 354 * trigger will be true when the axis value is greater than {@code threshold}. 355 * 356 * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value 357 * should be in the range [0, 1] where 0 is the unpressed state of the axis. 358 * @return a Trigger instance that is true when the right trigger's axis exceeds the provided 359 * threshold, attached to the {@link Scheduler#getDefaultEventLoop() default scheduler event 360 * loop} on the scheduler passed to the controller's constructor, or the {@link 361 * Scheduler#getDefault default scheduler} if a scheduler was not explicitly provided. 362 */ 363 public Trigger rightTrigger(double threshold) { 364 return rightTrigger(threshold, getScheduler().getDefaultEventLoop()); 365 } 366 367 /** 368 * Constructs a Trigger instance around the axis value of the right trigger. The returned trigger 369 * will be true when the axis value is greater than 0.5. 370 * 371 * @return a Trigger instance that is true when the right trigger's axis exceeds 0.5, attached to 372 * the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the 373 * scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault 374 * default scheduler} if a scheduler was not explicitly provided. 375 */ 376 public Trigger rightTrigger() { 377 return rightTrigger(0.5); 378 } 379 380 /** 381 * Get the X axis value of left side of the controller. Right is positive. 382 * 383 * @return The axis value. 384 */ 385 public double getLeftX() { 386 return m_hid.getLeftX(); 387 } 388 389 /** 390 * Get the X axis value of right side of the controller. Right is positive. 391 * 392 * @return The axis value. 393 */ 394 public double getRightX() { 395 return m_hid.getRightX(); 396 } 397 398 /** 399 * Get the Y axis value of left side of the controller. Back is positive. 400 * 401 * @return The axis value. 402 */ 403 public double getLeftY() { 404 return m_hid.getLeftY(); 405 } 406 407 /** 408 * Get the Y axis value of right side of the controller. Back is positive. 409 * 410 * @return The axis value. 411 */ 412 public double getRightY() { 413 return m_hid.getRightY(); 414 } 415 416 /** 417 * Get the left trigger axis value of the controller. Note that this axis is bound to the 418 * range of [0, 1] as opposed to the usual [-1, 1]. 419 * 420 * @return The axis value. 421 */ 422 public double getLeftTriggerAxis() { 423 return m_hid.getLeftTriggerAxis(); 424 } 425 426 /** 427 * Get the right trigger axis value of the controller. Note that this axis is bound to the 428 * range of [0, 1] as opposed to the usual [-1, 1]. 429 * 430 * @return The axis value. 431 */ 432 public double getRightTriggerAxis() { 433 return m_hid.getRightTriggerAxis(); 434 } 435}