Skip to content

Commit 9490787

Browse files
committed
debug mode
1 parent b04c56b commit 9490787

5 files changed

Lines changed: 52 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
RACOON-Pi
22
ssl-RACOON-Pi2
33
.env
4+
.DS_Store

main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"flag"
45
"fmt"
56
"log"
67
"net"
@@ -45,6 +46,17 @@ func kickCheck(chkicker chan bool) {
4546
}
4647

4748
func main() {
49+
// デバッグモードのフラグを解析
50+
flag.BoolVar(&debugSerial, "ds", false, "シリアル送受信のモニタリングを有効化")
51+
flag.BoolVar(&debugReceive, "dr", false, "AIからの受信結果表示を有効化")
52+
flag.Parse()
53+
54+
if debugSerial {
55+
log.Println("Debug Mode: Serial monitoring enabled (-ds)")
56+
}
57+
if debugReceive {
58+
log.Println("Debug Mode: AI receive monitoring enabled (-dr)")
59+
}
4860

4961
err := rpio.Open()
5062
if err != nil {

receive.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"encoding/binary"
66
"encoding/json"
7+
"fmt"
78
"log"
89
"net"
910
"time"
@@ -41,10 +42,25 @@ func RunClient(chclient chan bool, MyID uint32, ip string) {
4142

4243
robotcmd := packet.Commands.GetRobotCommands()
4344

45+
// デバッグモード: AI受信パケットの表示
46+
if debugReceive {
47+
log.Printf("[AI RX] Received packet with %d robot commands", len(robotcmd))
48+
}
49+
4450
for _, v := range robotcmd {
4551
// log.Printf("%d\n", int(v.GetId()))
4652
//ロボットIDが自分のIDと一致したら、受信した情報を反映する
4753
if v.GetId() == MyID {
54+
// デバッグモード: AI受信データの詳細表示
55+
if debugReceive {
56+
log.Printf("[AI RX] === Robot ID: %d (Match) ===", v.GetId())
57+
log.Printf("[AI RX] VelTangent: %.3f m/s, VelNormal: %.3f m/s, VelAngular: %.3f rad/s",
58+
v.GetVeltangent(), v.GetVelnormal(), v.GetVelangular())
59+
log.Printf("[AI RX] KickSpeedX: %.1f, KickSpeedZ: %.1f, Spinner: %t, Wheel1(DribblePower): %.1f",
60+
v.GetKickspeedx(), v.GetKickspeedz(), v.GetSpinner(), v.GetWheel1())
61+
fmt.Println("---")
62+
}
63+
4864
Id := v.GetId()
4965
Kickspeedx := v.GetKickspeedx()
5066
if Kickspeedx >= 100 {

serial.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"bytes"
55
"encoding/binary"
6+
"fmt"
67
"log"
78
"time"
89

@@ -73,6 +74,12 @@ func RunSerial(chclient chan bool, MyID uint32) {
7374
err = binary.Read(bytes.NewReader(recvbuf), binary.BigEndian, &recvdata)
7475
CheckError(err)
7576

77+
// デバッグモード: シリアル受信データの表示
78+
if debugSerial {
79+
log.Printf("[Serial RX] Volt: %d (%.1fV), SensorInfo: 0b%08b, CapPower: %d",
80+
recvdata.Volt, float32(recvdata.Volt)*0.1, recvdata.SensorInformation, recvdata.CapPower)
81+
}
82+
7683
//////////////////////////////////
7784
///
7885
/// エラーチェック部分
@@ -198,6 +205,18 @@ func RunSerial(chclient chan bool, MyID uint32) {
198205
//それぞれのデータを表示
199206
// log.Printf("VOLT: %f, BALLSENS: %t, IMUDEG: %d\n", float32(recvdata.Volt)*0.1, recvdata.IsHoldBall, recvdata.ImuDir)
200207

208+
// デバッグモード: シリアル送信データの表示
209+
if debugSerial {
210+
velx := int16(sendbytes[1]) | int16(sendbytes[2])<<8
211+
vely := int16(sendbytes[3]) | int16(sendbytes[4])<<8
212+
velang := int16(sendbytes[5]) | int16(sendbytes[6])<<8
213+
log.Printf("[Serial TX] VelX: %d, VelY: %d, VelAng: %d, Dribble: %d, Kick: %d, Chip: %d, Info: 0b%08b",
214+
velx, vely, velang, sendbytes[7], sendbytes[8], sendbytes[9], sendbytes[18])
215+
log.Printf("[Serial TX] CamBallX: %d, CamBallY: %d, Raw: %v",
216+
sendbytes[16], sendbytes[17], sendbytes)
217+
fmt.Println("---")
218+
}
219+
201220
port.Write(sendbytes) //書き込み
202221

203222
pre_isReceived = isReceived

variables.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ type ImageResponse struct {
9797

9898
var imageResponse ImageResponse
9999

100+
// デバッグモードフラグ
101+
var debugSerial bool = false // -ds: シリアル送受信のモニタリング
102+
var debugReceive bool = false // -dr: AIからの受信結果表示
103+
100104
type Adjustment struct {
101105
Min_Threshold string `json:"minThreshold"`
102106
Max_Threshold string `json:"maxThreshold"`

0 commit comments

Comments
 (0)