# 邁入正式寫程式
:::success
template --->
java --->
timed robot
:::
## select a project type
1. template:+1: : 一個模板,讓我們可以從頭打程式,但是會提供一些基本架構,主要是選擇這個。
2. example : 若是選擇 example,到後面會提供如下圖多種機器程式範例,有時若是有疑問時可以到這邊看看範例是怎麼做的。

## select a language
1. cpp : 不要理他
2. java:+1: :基本上大部分的隊伍都是使用爪哇,極少部分是用西屁屁。據前面的學長所說,第一屆使用西批批,第二屆的程式組組長個人偏好爪哇,才導致之後都使用爪哇的。
> There are two versions of WPILib, one for each of the two officially-supported text-based languages: WPILibJ for java, and WPILibC for C++. A considerable effort is made to maintain feature-parity between these two languages - library features are not added unless they can be reasonably supported for both Java and C++, and when possible the class and method names are kept identical or highly-similar. While unofficial community-built support is available for some other languages, notably python, this documentation will only cover Java and C++. Java and C++ were chosen for the officially-supported languages due to their appropriate level-of-abstraction and ubiquity in both industry and high-school computer science classes.
> In general, C++ offers better high-end performance, at the cost of increased user effort (memory must be handled manually, and the C++ compiler does not do much to ensure user code will not crash at runtime). Java offers lesser performance, but much greater convenience. New/inexperienced users are strongly encouraged to use Java.
## select a project base
基本上如果都有按照前面的步驟進來,這裡因該會看到五個選擇。

1. timed robot:+1: : 我們會先從這個開始講起,這是最基本、最直觀的程式寫法。
> TimedRobot is the same as IterativeRobot except that it uses a timer (Notifier) to guarantee that the periodic methods are called at a predictable time interval. When getting driver station data such as joystick values the most recent value will be provided since the time interval may not line up with the 20 millisecond delivery of data. This is the recommended base class for most robot programs.
Just as with IterativeRobot, it is very important to not have long running code or loops in the periodic methods or the timing may slip.
2. timed skeleton : 我不認識
3. robotbase skeleton : 我不認識
4. command robot : 較難的寫機器人程式的方式,之後會再教。
> While based on the TimedRobot base class, the command based robot programming style is recommended for most teams. It makes it easy to break up the program into Commands which each implement some robot behavior such as raising an arm to some position, driving for some distance, etc. It also makes the program easily extensible and testable. The RobotBuilder utility (included with the eclipse plugins) provides an easy way of organizing the program. The dashboards (SmartDashboard and Shuffleboard) allow you to easily debug and test command based programs.
:::success
command-based 是讓code更有可讀性,也讓程式更好的修改,是一種design pattern,也是declarative programming的實做。
以上來自:[昱翔的工作筆記](https://hackmd.io/@frc7130-futureshock/Bys8Ngd_w)
:::
5. old command robot : 似乎是 command robot 的前身,我們也沒在用他。
## 基本架構
:::info
```cpp=
Init --> 一開始、初始
Periodic --> 持續
---------------------------------------------------
autonomous --> 自動模式 //比賽的前15秒為自動模式
teleop --> 手動操控模式、遙控模式 //最主要且最常使用的
disabled --> 殘障、停止 //基本上是不會用到的
test --> 測試 //基本上是不會用到的
```
:::
```java=
package frc.robot;
@Override
public void robotInit() {
}
@Override
public void robotPeriodic() {
}
@Override
public void autonomousInit() {
}
@Override
public void autonomousPeriodic() {
}
@Override
public void teleopInit() {
}
@Override
public void teleopPeriodic() {
}
@Override
public void disabledInit() {
}
@Override
public void disabledPeriodic() {
}
@Override
public void testInit() {
}
@Override
public void testPeriodic() {
}
}
```
## 機器間的連結
看到這張圖講得很好所以就放上來了

###### tags: `程式組教程`