Skip to content

Commit

Permalink
Merge pull request #27 from Rione:feature/gui-enhancement
Browse files Browse the repository at this point in the history
🎉 change protos and add auto judge color
  • Loading branch information
Tamagoham authored Jun 30, 2024
2 parents 02e1da4 + 93b09e5 commit de41d73
Show file tree
Hide file tree
Showing 23 changed files with 464 additions and 296 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ This is our communication software for [RoboCup Soccer SSL](https://ssl.robocup.

# Usage

## Generate Go Proto files
```bash
protoc --proto_path=proto/pb_src --go_out=proto/pb_gen --go_opt=paths=source_relative proto/pb_src/*.proto
```

## Run

```bash
Expand Down
104 changes: 83 additions & 21 deletions createprotos.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,15 @@ func createGeometryInfo() *pb_gen.Geometry_Info {
return pe
}

func createOtherInfo(goalpos_n int32) *pb_gen.Other_Infos {
func createOtherInfo(goalpos_n int32, ourteam int, match_mode bool, grsim_send_port int, simmode bool, halfswitch int) *pb_gen.Other_Infos {
var numofcameras int32 = int32(maxcameras)
var numofourrobots int32
var numofenemyrobots int32
var teamcolor int
var isYellow bool
var isHalfcourt bool
var grSimSendPort uint32 = uint32(grsim_send_port)
var attackdir int32
for i := 0; i < 16; i++ {
if ourrobot_is_visible[i] {
numofourrobots++
Expand All @@ -202,19 +207,49 @@ func createOtherInfo(goalpos_n int32) *pb_gen.Other_Infos {
}
}

isReal := !simmode

if match_mode {
//マッチモードの場合は、起動フラグのourteamを無視して、Refereeから取得したチームカラーを使う
//また、本番モードはisRealをtrueにする
isReal = true
teamcolor = teamcolor_from_ref
attackdir = int32(attack_direction_from_ref)
} else {
//マッチモードでない場合は、起動フラグのourteamをそのまま使う
teamcolor = ourteam
attackdir = goalpos_n
}

if teamcolor == 1 { //YELLOW
isYellow = true
} else { //BLUE
isYellow = false
}

if halfswitch == 1 || halfswitch == -1 {
isHalfcourt = true
} else {
isHalfcourt = false
}

pe := &pb_gen.Other_Infos{
NumOfCameras: &numofcameras,
NumOfOurRobots: &numofourrobots,
NumOfEnemyRobots: &numofenemyrobots,
Secperframe: &secperframe,
IsVisionRecv: &isvisionrecv,
AttackDirection: &goalpos_n,
IsBallMoving: &is_ball_moving,
NumOfCameras: &numofcameras,
NumOfOurRobots: &numofourrobots,
NumOfEnemyRobots: &numofenemyrobots,
Secperframe: &secperframe,
IsVisionRecv: &isvisionrecv,
AttackDirection: &attackdir,
IsBallMoving: &is_ball_moving,
IsReal: &isReal,
IsTeamYellow: &isYellow,
IsHalfCourt: &isHalfcourt,
GrsimCommandListenPort: &grSimSendPort,
}
return pe
}

func createRefInfo(ourteam int, attackdirection int, ignore_ref_mismatch bool) *pb_gen.Referee_Info {
func createRefInfo(ourteam int, attackdirection int, ignore_ref_mismatch bool, goal_keeper uint, match_mode bool) *pb_gen.Referee_Info {
var yellowcards uint32
var redcards uint32
var command *pb_gen.Referee_Info_Command
Expand All @@ -226,6 +261,8 @@ func createRefInfo(ourteam int, attackdirection int, ignore_ref_mismatch bool) *
var bpY float32
var gameevent []*pb_gen.GameEvent

goal_keeper_id := uint32(goal_keeper)

if ref_command != nil {
command = (*pb_gen.Referee_Info_Command)(ref_command.Command)
stage = (*pb_gen.Referee_Info_Stage)(ref_command.Stage)
Expand All @@ -245,7 +282,7 @@ func createRefInfo(ourteam int, attackdirection int, ignore_ref_mismatch bool) *
teaminfo_their = (*pb_gen.Referee_Info_TeamInfo)(ref_command.Blue)
}

if !ignore_ref_mismatch {
if !ignore_ref_mismatch && !match_mode {
// Check if the team color is correct
if ourteam == 0 && ref_command.GetYellow().GetName() == "Ri-one" {
log.Println("[MW WARNING!!] INCORRECT TEAM COLOR! Referee says (Ri-one == YELLOW)")
Expand All @@ -267,23 +304,48 @@ func createRefInfo(ourteam int, attackdirection int, ignore_ref_mismatch bool) *
}
}

if match_mode {
// Team Color を チーム名 「Ri-one」から取り出す
if ref_command.GetYellow().GetName() == "Ri-one" && ref_command.GetBlue().GetName() == "Ri-one" {
log.Println("[MW WARNING!!] Team Name is Both Ri-one! Referee says (Ri-one == YELLOW) and (Ri-one == BLUE). Forced to set team color to BLUE.")
}
if ref_command.GetBlue().GetName() == "Ri-one" {
teamcolor_from_ref = 0
goal_keeper_id = ref_command.GetBlue().GetGoalkeeper()
if ref_command.GetBlueTeamOnPositiveHalf() == true {
attack_direction_from_ref = -1
} else {
attack_direction_from_ref = 1
}
} else if ref_command.GetYellow().GetName() == "Ri-one" {
teamcolor_from_ref = 1
goal_keeper_id = ref_command.GetYellow().GetGoalkeeper()
if ref_command.GetBlueTeamOnPositiveHalf() == true {
attack_direction_from_ref = 1
} else {
attack_direction_from_ref = -1
}
}
}

} else {
yellowcards = 0
redcards = 0
}

pe := &pb_gen.Referee_Info{
Command: command,
Stage: stage,
TeaminfoOur: teaminfo_our,
TeaminfoTheir: teaminfo_their,
YellowCards: &yellowcards,
RedCards: &redcards,
Event: gameevent,
PreCommand: last_command,
NextCommand: next_command,
BallPlacementX: &bpX,
BallPlacementY: &bpY,
Command: command,
Stage: stage,
TeaminfoOur: teaminfo_our,
TeaminfoTheir: teaminfo_their,
YellowCards: &yellowcards,
RedCards: &redcards,
Event: gameevent,
PreCommand: last_command,
NextCommand: next_command,
BallPlacementX: &bpX,
BallPlacementY: &bpY,
OurGoalkeeperId: &goal_keeper_id,
}
return pe
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/Rione-SSL/RACOON-MW
go 1.17

require (
github.com/golang/protobuf v1.5.0
github.com/rosshemsley/kalman v0.0.0-20190615074247-f4b900823fd1
gonum.org/v1/gonum v0.11.0
google.golang.org/protobuf v1.33.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81/go.mod h1:SX0U8uGpx
github.com/go-pdf/fpdf v0.5.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M=
github.com/go-pdf/fpdf v0.6.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
Expand Down
40 changes: 30 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func CheckVisionRobot(chvisrobot chan bool) {
}
}

func RunServer(chserver chan bool, reportrate uint, ourteam int, goalpose int, debug bool, simmode bool, ignore_ref_mismatch bool) {
func RunServer(chserver chan bool, reportrate uint, ourteam int, goalpose int, debug bool, simmode bool, ignore_ref_mismatch bool, match_mode bool, grsim_send_port int, goal_keeper uint, halfswitch int) {
ipv4 := NW_AI_IPADDR
port := NW_AI_PORT
port_controller := NW_AI_PORT_CONTROLLER
Expand All @@ -130,6 +130,11 @@ func RunServer(chserver chan bool, reportrate uint, ourteam int, goalpose int, d

for {

//チームカラー検査
if teamcolor_from_ref != -1 && match_mode {
ourteam = teamcolor_from_ref
}

var robot_infos [16]*pb_gen.Robot_Infos
var enemy_infos [16]*pb_gen.Robot_Infos
var robotip_infos [16]*pb_gen.RobotIP_Infos
Expand Down Expand Up @@ -171,8 +176,8 @@ func RunServer(chserver chan bool, reportrate uint, ourteam int, goalpose int, d
RobotIpInfo := addRobotIPInfoToRobotIPInfos(robotip_infos)

GeometryInfo := createGeometryInfo()
RefereeInfo := createRefInfo(ourteam, goalpose, ignore_ref_mismatch)
OtherInfo := createOtherInfo(int32(goalpose))
RefereeInfo := createRefInfo(ourteam, goalpose, ignore_ref_mismatch, goal_keeper, match_mode)
OtherInfo := createOtherInfo(int32(goalpose), ourteam, match_mode, grsim_send_port, simmode, halfswitch)

//log.Println(OtherInfo.GetAttackDirection())

Expand Down Expand Up @@ -206,19 +211,22 @@ func RunServer(chserver chan bool, reportrate uint, ourteam int, goalpose int, d
func main() {

var (
visionport = flag.Int("p", 10006, "Vision Multicast Port Number")
ourteam = flag.String("t", "blue", "Our Team (blue or yellow)")
visionport = flag.Int("p", 10006, "Vision Multicast Port Number. Force 10006 when match mode is true")
ourteam = flag.String("t", "blue", "Our Team (blue or yellow). Disable when match mode is true")
goalpos = flag.String("g", "N", "Attack Direction(Enemy goal) Negative or Positive (N or P)")
reportrate = flag.Uint("r", 16, "How often report to RACOON-AI? (milliseconds)")
debug = flag.Bool("d", false, "Show All Send Packet")
simmode = flag.Bool("s", false, "Simulation Mode (Emulate Ball Sensor)")
simmode = flag.Bool("s", false, "Simulation Mode (Emulate Ball Sensor). Disable when match mode is true")
replay = flag.Bool("replay", false, "Replay All Packet")
halfswitch = flag.String("c", "F", "Where to use (N, P, F) F to Full")
halfswitch = flag.String("c", "F", "Where to use (N, P, F) F to Full. Disable when match mode is true")
ballmovethreshold = flag.Float64("b", 1000, "Ball Detect Threshold (Default 1000")
nw_robot = flag.String("rif", "none", "NW Robot Update Interface Name (ex. en0)")
nw_vision = flag.String("vif", "none", "NW Vision and Referee receive Interface Name (ex. en1)")
debug_for_sono = flag.Bool("df", false, "Print ID0 Robot Cordination for Sono")
ignore_ref_mismatch = flag.Bool("igref", false, "Ignore Referee Team Color & Attack Direction Mismatch Errors")
ignore_ref_mismatch = flag.Bool("igref", false, "Ignore Referee Team Color & Attack Direction Mismatch Errors. Disable when match mode is true")
match_mode = flag.Bool("m", false, "Match Mode (Disable Some Options! Most option get from GC)")
grsim_send_port = flag.Int("grsimport", 20011, "grSim Command Listen Port Number")
goal_keeper = flag.Uint("gk", 0, "Goal Keeper ID (0-15) Disable when match mode is true")
)
//OUR TEAM 0 = blue
//OUR TEAM 1 = yellow
Expand All @@ -242,6 +250,13 @@ func main() {
goalpos_n = 1
}

if *match_mode {
*visionport = 10006
*ignore_ref_mismatch = false
*simmode = false
*halfswitch = "F"
}

var halfswitch_n int
if *halfswitch == "N" {
halfswitch_n = -1
Expand All @@ -263,6 +278,11 @@ func main() {
BALL_MOVING_THRESHOULD_SPEED = float32(*ballmovethreshold)
}

if *match_mode {
log.Println("=============================================")
log.Println("[RACOON-MW] Match Mode Enabled! Some Options are Disabled! GOOD LUCK!")
log.Println("=============================================")
}
chupdate := make(chan bool)
chserver := make(chan bool)
chvision := make(chan bool)
Expand All @@ -274,8 +294,8 @@ func main() {
chbattery := make(chan bool)

go Update(chupdate)
go RunServer(chserver, *reportrate, ourteam_n, goalpos_n, *debug, *simmode, *ignore_ref_mismatch)
go VisionReceive(chvision, *visionport, ourteam_n, goalpos_n, *simmode, *replay, halfswitch_n, *debug_for_sono)
go RunServer(chserver, *reportrate, ourteam_n, goalpos_n, *debug, *simmode, *ignore_ref_mismatch, *match_mode, *grsim_send_port, *goal_keeper, halfswitch_n)
go VisionReceive(chvision, *visionport, ourteam_n, goalpos_n, *simmode, *replay, halfswitch_n, *debug_for_sono, *match_mode)
go CheckVisionRobot(chvisrobot)
go FPSCounter(chfps, ourteam_n)
go RefereeClient(chref)
Expand Down
2 changes: 1 addition & 1 deletion proto/pb_gen/grSim_Commands.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/pb_gen/grSim_Packet.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/pb_gen/grSim_Replacement.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/pb_gen/grSim_Robotstatus.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/pb_gen/ssl_gc_common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/pb_gen/ssl_gc_game_event.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/pb_gen/ssl_gc_geometry.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/pb_gen/ssl_gc_referee_message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit de41d73

Please sign in to comment.