You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/basics/java_basics.md
+36-29Lines changed: 36 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,24 +8,26 @@ Learning What's What
8
8
9
9
- Objects, variables, and classes (in Java) make up our programs. We define, modify, and use these variables and objects to make our programs run.
10
10
- Programs use key words to define characteristics of variables or objects. Basic keywords:
11
-
-`#!java public` - an object accessible by other classes (files)
12
-
-`#!java private` - an object only accessible by its containing class (file).
13
-
-`#!java protected` - like private but can be seen by subclasses
14
-
-`#!java return` - value to return or give back after method execution (run).
15
-
-`#!java void` - a method that returns no value
16
-
-`#!java null` - a value that means empty or nothing
17
-
18
-
!!! Warning "IMPORTANT NOTE"
11
+
-`public` - an object accessible by other classes (files)
12
+
-`private` - an object only accessible by its containing class (file).
13
+
-`protected` - like private but can be seen by subclasses
14
+
-`return` - value to return or give back after method execution (run).
15
+
-`void` - a method that returns no value
16
+
-`null` - a value that means empty or nothing
17
+
18
+
!!! warning "IMPORTANT NOTE"
19
19
Java is case sensitive, meaning capitalization matters!
20
20
***
21
21
22
22
## Classes
23
23
24
24
- Classes are the files that contain our programming
25
25
- A program can be made up of one class but can also be made up of many classes
26
-
- All programs run a main class that can optionally load additional classes either directly or indirectly
27
-
- !!! example
28
-
main loads class1, class1 loads class2
26
+
- All programs run a main class that can optionally load additional classes either directly or indirectly
27
+
28
+
!!! example
29
+
main loads class1, class1 loads class2
30
+
29
31
- Classes are made up of variables and methods and are often used to separate and organize your code.
30
32
- Classes can also **call** (use) variables or methods of other classes if those have been set to public.
31
33
@@ -37,8 +39,9 @@ Learning What's What
37
39
- They can be called again if the class is programmed to be unloaded (destroyed) and reloaded.
38
40
- Calls to methods, and assignment of values, within the constructor will run as soon as the class is called (loaded) in the code.
39
41
- The **new** operator creates an object of a type of class using a constructor
40
-
- !!! example
41
-
classObject = new className();
42
+
43
+
!!! example
44
+
classObject = new className();
42
45
43
46
***
44
47
@@ -82,25 +85,28 @@ Learning What's What
82
85
- Variables are assigned names and data types on creation
83
86
- Names can be anything with the exception of pre-existing keywords such as `public` or `int`
84
87
- Data types define what type of data is being stored in the variables:
85
-
-`#!java int` - integers (whole numbers)
86
-
-`#!java double` - double precision floating point (fractional/decimal values)
87
-
-`#!java boolean` - true or false (true = 1 or false = 0) values.
88
-
-`#!java string` - text values contained in parentheses
89
-
- !!! Example "Example: `#!java int sum;`"
90
-
A variable that can hold whole number values
91
-
- !!! Example "Example: `#!java boolean isFull = true;`"
92
-
A variable can either hold a true or false value and is being assigned a true value
88
+
-`int` - integers (whole numbers)
89
+
-`double` - double precision floating point (fractional/decimal values)
90
+
-`boolean` - true or false (true = 1 or false = 0) values.
91
+
-`string` - text values contained in parentheses
92
+
93
+
!!! example "Example: `int sum;`"
94
+
A variable that can hold whole number values
95
+
96
+
!!! example "Example: `boolean isFull = true;`"
97
+
A variable can either hold a true or false value and is being assigned a true value
93
98
94
99
### Constants
95
100
96
101
Most variables can have their values assigned or reassigned at any point elsewhere in your program. To avoid having a variable change its value during runtime you can make it a **constant**
97
102
98
-
- In Java you can create constants using the `#!java static final` keywords together in front of the data type of the variable
99
-
- The static modifier causes the variable to be available without loading the class where it is defined.
103
+
- In Java you can create constants using the `static final` keywords together in front of the data type of the variable
104
+
- The static modifier causes the variable to be available without loading the class where it is defined.
100
105
- The final modifier causes the variable to be unchangeable.
101
106
- Java constants are normally declared in ALL CAPS. Words in Java constants are normally separated by underscores.
102
-
- !!! Example "Example: `#!java public static final double PI_VALUE = 3.14159;`"
103
-
A variable that cannot be modified during code run time.
107
+
108
+
!!! example "Example: `public static final double PI_VALUE = 3.14159;`"
109
+
A variable that cannot be modified during code run time.
104
110
105
111
### Scope
106
112
@@ -171,9 +177,10 @@ Most variables can have their values assigned or reassigned at any point elsewhe
171
177
- There are also many different conventions when programming, this ensures that programs are readable between different people.
172
178
- A common naming convention:
173
179
- Programming is often done in CamelCase or lowerCamelCase
174
-
- Instead of adding spaces, capitalize the first letter of each word
175
-
- !!! example
176
-
ThreeMotorDrive, driveForward, setSpeed
180
+
- Instead of adding spaces, capitalize the first letter of each word
181
+
182
+
!!! example
183
+
ThreeMotorDrive, driveForward, setSpeed
177
184
178
-
!!! info
185
+
!!! info
179
186
There are other naming conventions, but for this tutorial we will use the camel cases
Copy file name to clipboardExpand all lines: docs/basics/wpilib.md
+43-34Lines changed: 43 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,10 +9,10 @@ Making FRC Programming Easy
9
9
- The WPI Robotics library (WPILib) is a set of software classes that interfaces with the hardware and software in your FRC RoboRIO.
10
10
- There are classes to handle sensors, motor speed controllers, the driver station, and a number of other utility functions.
11
11
- Documentation is available at <http://first.wpi.edu/FRC/roborio/release/docs/java>
12
-
- WPILib adds those sensors and controllers as additional data types (like `#!java int` or `#!java double`) and classes.
12
+
- WPILib adds those sensors and controllers as additional data types (like `int` or `double`) and classes.
13
13
14
-
/// details | Examples
15
-
`Talon`, `Solenoid`, `Encoder`...
14
+
??? example "Examples"
15
+
`Talon`, `Solenoid`, `Encoder`...
16
16
17
17
***
18
18
@@ -41,13 +41,14 @@ Making FRC Programming Easy
41
41
- Some variables (parts) would be: **leftEye**, **rightEye**, **nose**, **leftEar**, **rightEar**.
42
42
- Some example methods would be **closeEyes** or **openEyes** since these are things the dog are capable of.
43
43
- These methods would use both the **leftEye** and **rightEye** and close them.
44
-
- /// details | example
45
-
```java
46
-
//This method closes the dog eyes
44
+
45
+
??? example
46
+
```java
47
+
//This method closes the dog eyes
47
48
public void closeEyes(){
48
-
leftEye.close();
49
-
rightEye.close();
50
-
```
49
+
leftEye.close();
50
+
rightEye.close();
51
+
```
51
52
- A robot example of a **Drivetrain** subsystem would have **leftMotor**, and **rightMotor** as variables and **setSpeed** as a method telling it how to set the speed of those motor controllers.
52
53
- Having the **setSpeed** method tells our program that our **Drivetrain** subsystem can set its speed.
53
54
- ??? example
@@ -68,48 +69,56 @@ Making FRC Programming Easy
68
69
- A **command** is an action a **subsystem(s)** performs.
69
70
- For example you may want your robot to drive full speed forward so you make a command class called **DriveForward**.
70
71
- Since a robot uses a **Drivetrain** subsystem to control its motors, this command would call our previously created **setSpeed** method from that subsystem.
71
-
- !!! Tip
72
-
**Subsystems** define what the robot is made of and what it can do while **commands** actually tell the robot to do those things
72
+
73
+
!!! tip
74
+
**Subsystems** define what the robot is made of and what it can do while **commands** actually tell the robot to do those things
75
+
73
76
- Using a dog as an example we can tell the dog to blink by creating a **BlinkEyes** command
74
77
- The command would call the method, **closeEyes()** then the method **openEyes()**
75
-
- ??? example "BlinkEyes Command"
76
-
```java
78
+
79
+
??? example "BlinkEyes Command"
80
+
```java
77
81
//This command will continuously run the two methods in execute
78
82
protected void execute() {
79
-
dog.head.closeEyes();
80
-
dog.head.openEyes();
83
+
dog.head.closeEyes();
84
+
dog.head.openEyes();
81
85
}
82
-
```
86
+
```
87
+
83
88
- A robot example of a **DriveForward** command would call (use) the **setSpeed** methods that we created in the **Drivetrain** subsystem
84
89
-**DriveForward**, when executed, will tell our robot to drive forward using the **Drivetrain** subsystem
85
-
- ??? example "DriveForward Command"
86
-
```java
90
+
91
+
??? example "DriveForward Command"
92
+
```java
87
93
//This command tells the robot to drive forward full speed
88
-
protected void initialize(){
89
-
robot.drivetrain.setSpeed(1.0);
90
-
}
91
-
```
94
+
protected void initialize(){
95
+
robot.drivetrain.setSpeed(1.0);
96
+
}
97
+
```
92
98
93
99
#### Default Command Structure
94
100
95
101
- The template for FRC commands actually come with some pre-defined methods that have special properties for FRC robots, they are:
96
-
-`#!java void initialize()` - Methods in here are called just before this Command runs the first time.
97
-
-`#!java void execute()` - Methods in here are called repeatedly when this Command is scheduled to run
98
-
-`#!java boolean isFinished()` - When this returns true, the Command stops running execute()
99
-
-`#!java void end()` - Methods in here are called once after isFinished returns true
100
-
-`#!java void interrupted()` - Methods in here are called when another command which requires one or more of the same subsystems is scheduled to run
101
-
- !!! Tip
102
-
It is good practice to call `end()` in `interrupted()`
102
+
-`void initialize()` - Methods in here are called just before this Command runs the first time.
103
+
-`void execute()` - Methods in here are called repeatedly when this Command is scheduled to run
104
+
-`boolean isFinished()` - When this returns true, the Command stops running execute()
105
+
-`void end()` - Methods in here are called once after isFinished returns true
106
+
-`void interrupted()` - Methods in here are called when another command which requires one or more of the same subsystems is scheduled to run
107
+
108
+
!!! tip
109
+
It is good practice to call `end()` in `interrupted()`
103
110
104
111
***
105
112
106
113
### Overview of execution
107
114
108
-
- In FRC programming our main class is **Robot.java** and all other classes (command files and subsystem files) must be loaded from **Robot.java** either directly or indirectly
- In FRC programming our main class is **Robot.java** and all other classes (command files and subsystem files) must be loaded from **Robot.java** either directly or indirectly
- All **subsystem** files must be added to **RobotContainer.java**.
112
-
- This loads our **subsystems** into the code and allow its public methods to be useable by other files such as commands later by typing `#!java RobotContainer.nameOfSubsystem.desiredMethod();`
121
+
- This loads our **subsystems** into the code and allow its public methods to be useable by other files such as commands later by typing `RobotContainer.nameOfSubsystem.desiredMethod();`
113
122
114
123
***
115
124
@@ -125,5 +134,5 @@ See [Default Project Contents](../programming/new_project.md#default-project-con
125
134
-**Subsystems** define what the robot is made of and what it can do while **commands** actually tell the robot to do those things
126
135
- All classes must directly or indirectly connect to **Robot.java**.
127
136
- All **Subsystems** must be added to **RobotContainer.java**
128
-
-**RobotMap.java** holds port numbers and IDs accessible throughout the program by typing: `#!java RobotMap.NameOfMotor()`
137
+
-**RobotMap.java** holds port numbers and IDs accessible throughout the program by typing: `RobotMap.NameOfMotor()`
129
138
-**RobotContainer.java** contains our publicly accessible instances of our subsystems. It also connects our commands to physical controllers.
0 commit comments