Update README
parent
65c9585687
commit
4ad1b9f450
59
README.md
59
README.md
|
@ -27,6 +27,42 @@ ser.write(data_to_send)
|
||||||
ser.close()
|
ser.close()
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Testing Game
|
||||||
|
|
||||||
|
```python
|
||||||
|
import numpy as np
|
||||||
|
import serial
|
||||||
|
import struct
|
||||||
|
|
||||||
|
# Tạo mảng NumPy
|
||||||
|
n = 2
|
||||||
|
# Kích thước của mảng
|
||||||
|
|
||||||
|
num_rows = 1
|
||||||
|
num_cols = 0
|
||||||
|
|
||||||
|
data = np.array([[60, 120,1]]).astype(np.float32)
|
||||||
|
num_rows = data.shape[0]
|
||||||
|
num_cols = data.shape[1]
|
||||||
|
|
||||||
|
# Chuyển mảng thành chuỗi byte
|
||||||
|
data_bytes = data.tobytes()
|
||||||
|
# Đóng gói kích thước và dữ liệu
|
||||||
|
header = struct.pack('<II', num_rows, num_cols) # <II cho hai số nguyên không dấu 32-bit
|
||||||
|
data_to_send = header + data_bytes
|
||||||
|
# Mở cổng serial
|
||||||
|
ser = serial.Serial('/dev/ttyACM0', 115200*2) # Thay 'COM3' bằng cổng serial của bạn
|
||||||
|
print(data)
|
||||||
|
# Gửi dữ liệu
|
||||||
|
ser.write(data_to_send)
|
||||||
|
|
||||||
|
# Đóng cổng serial
|
||||||
|
ser.close()
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Receive Data
|
### Receive Data
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
|
@ -69,4 +105,27 @@ void loop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
# Data frame format
|
||||||
|
```python
|
||||||
|
# Game Hung Vat
|
||||||
|
x = 60 # X coordinate
|
||||||
|
y = 120 # Y coordinate (no action)
|
||||||
|
z = 1 # action (no action)
|
||||||
|
data = np.array([[60, 120,1]]).astype(np.float32)
|
||||||
|
|
||||||
|
# Game Stick Man
|
||||||
|
x = 60 # X coordinate
|
||||||
|
y = 120 # Y coordinate (no action)
|
||||||
|
z = 1 # 1: right shield; 2 left shield; 0 none sheild
|
||||||
|
data = np.array([[60, 120,1]]).astype(np.float32)
|
||||||
|
|
||||||
|
#Game Space Craft
|
||||||
|
|
||||||
|
x = 60 # X coordinate
|
||||||
|
y = 120 # Y coordinate (no action)
|
||||||
|
z = 1 # 1: fire bullet; 0 none fire
|
||||||
|
data = np.array([[60, 120,1]]).astype(np.float32)
|
||||||
|
|
||||||
```
|
```
|
Loading…
Reference in New Issue