Difference between revisions of "FTC:Controller Inputs"

From Project Robotica
Jump to navigation Jump to search
(Created page with "During the 2 minute driver controlled period, the two drivers of the robot have to manipulate the controller to do certain tasks. When a team is programming the controller, th...")
 
(added keywords)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
During the 2 minute driver controlled period, the two drivers of the robot have to manipulate the controller to do certain tasks. When a team is programming the controller, they should first consider which buttons do which actions.  
{{#seo:
|title=FTC Controller Imputs - Project Robotica
|keywords= FTC, FIRST Tech Challenge, Controller Inputs, Gamepad, Controller
|description= Controllers are what allow drivers to control the robot in FTC. There are many different ways to configure them. Learn how to program them here!
|robots=index, follow
}}
In [[FTC:About|FIRST Tech Challenge]] the last two minutes are the driver-controlled period. During this time, the two drivers of the robot have to manipulate the controller to do certain tasks. When a team is programming the controller, they should first consider which inputs do which actions.  


==Java==
In Java programs such as [[Android Studio]] or [[onbot]], teams can program the controllers by using gamepad1.<input type>. Gampad1 could also be replaced by Gamepad2. Joysticks and triggers return floating point numbers ( float), which allow for things such as moving at different speeds based on how far a joystick is moved. Buttons return true or false ( boolean). Here is a table which shows the syntax for each input and the respective input type which corresponds to the image below:


==Java==
[[file:Logitechcontrollerinputs.png|600px]]
In Java programs such as [[Android Studio]] or [[onbot]], teams can program the controllers by using gamepad1.<input type>. Gampad1 could also be replaced by Gamepad2. Joysticks and triggers return floating point numbers ( float), which allow for things such as moving at different speeds based on how far a joystick is moved. Buttons return true or false ( boolean). Here is a table which shows the syntax for each input and the respective input type which corresponds to the image above:


{|class="wikitable"
{|class="wikitable"
Line 95: Line 102:
To use these inputs, teams can simply use if statements to check an input and respond accordingly. Here is an example of code that moves a motor, motor 1, when the button a is pressed and stops moving when a is no longer pressed.
To use these inputs, teams can simply use if statements to check an input and respond accordingly. Here is an example of code that moves a motor, motor 1, when the button a is pressed and stops moving when a is no longer pressed.


if (gamepad1.a) {
<syntaxhighlight lang="Java">
motor1.setpower(1);
if (gamepad1.a) { <br>
}
motor1.setpower(1);<br
else {
}<br>
motor1.setpower(0);
else {<br>
}
motor1.setpower(0);<br>
}<br>
</syntaxhighlight>


Teams can also use float inputs to do things such as control motor speed as shown below:
Teams can also use float inputs to do things such as control motor speed as shown below:


<syntaxhighlight lang="Java">
motor1.setpower(gamepad1.left_stick_x);
motor1.setpower(gamepad1.left_stick_x);
</syntaxhighlight>


==Blocks Programming Tool==
==Blocks Programming Tool==

Latest revision as of 21:51, 9 April 2022

In FIRST Tech Challenge the last two minutes are the driver-controlled period. During this time, the two drivers of the robot have to manipulate the controller to do certain tasks. When a team is programming the controller, they should first consider which inputs do which actions.

Java

In Java programs such as Android Studio or onbot, teams can program the controllers by using gamepad1.<input type>. Gampad1 could also be replaced by Gamepad2. Joysticks and triggers return floating point numbers ( float), which allow for things such as moving at different speeds based on how far a joystick is moved. Buttons return true or false ( boolean). Here is a table which shows the syntax for each input and the respective input type which corresponds to the image below:

Logitechcontrollerinputs.png

Label Input type Syntax
Axis 0 Float gamepad1.left_stick_x
Axis 1 Float (Inverted) gamepad1.left_stick_y
Axis 2 Float gamepad1.right_stick_x
Axis 3 Float (Inverted) gamepad1.right_stick_y
Button 0 Boolean gamepad1.x
Button 1 Boolean gamepad1.a
Button 2 Boolean gamepad1.b
Button 3 Boolean gamepad1.y
Button 4 Boolean gamepad1.left_bumper
Button 5 Boolean gamepad1.right_bumper
Button 6 Float gamepad1.left_trigger
Button 7 Float gamepad1.right_trigger
Button 8 Boolean gamepad1.back
Button 9 Boolean gamepad1.start
Button 10 Boolean gamepad1.left_stick_button
Button 11 Boolean gamepad1.right_stick_button
Hat 1 Boolean gamepad1.dpad_up
Hat 2 Boolean gamepad1.dpad_down
Hat 3 Boolean gamepad1.dpad_left
Hat 4 Boolean gamepad1.dpad_right


To use these inputs, teams can simply use if statements to check an input and respond accordingly. Here is an example of code that moves a motor, motor 1, when the button a is pressed and stops moving when a is no longer pressed.

if (gamepad1.a) { <br>
	motor1.setpower(1);<br
}<br>
else {<br>
	motor1.setpower(0);<br>
}<br>

Teams can also use float inputs to do things such as control motor speed as shown below:

motor1.setpower(gamepad1.left_stick_x);

Blocks Programming Tool

(more info needed)

Additional Resources

References