Skip to content

Commit

Permalink
⚠️ optimise and add flag to ignore error
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamagoham committed Jun 29, 2024
1 parent 1954037 commit 7baaa1d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 68 deletions.
2 changes: 2 additions & 0 deletions controllerfeedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ func controllerFeedback(chctrlfb chan bool) {

mutex.Unlock()
}

chctrlfb <- true
}
52 changes: 21 additions & 31 deletions createprotos.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,6 @@ func createRobotInfo(i int, ourteam int, simmode bool) *pb_gen.Robot_Infos {
return pe
}

func addRobotIpToRobotIps(robotip [16]*pb_gen.RobotIP_Infos) []*pb_gen.RobotIP_Infos {
RobotIps := []*pb_gen.RobotIP_Infos{}

for _, robot := range robotip {
if robot != nil {
RobotIps = append(RobotIps, robot)
}
}

return RobotIps
}

func addRobotInfoToRobotInfos(robotinfo [16]*pb_gen.Robot_Infos) []*pb_gen.Robot_Infos {
RobotInfos := []*pb_gen.Robot_Infos{}

Expand Down Expand Up @@ -226,7 +214,7 @@ func createOtherInfo(goalpos_n int32) *pb_gen.Other_Infos {
return pe
}

func createRefInfo(ourteam int, attackdirection int) *pb_gen.Referee_Info {
func createRefInfo(ourteam int, attackdirection int, ignore_ref_mismatch bool) *pb_gen.Referee_Info {
var yellowcards uint32
var redcards uint32
var command *pb_gen.Referee_Info_Command
Expand Down Expand Up @@ -257,24 +245,26 @@ func createRefInfo(ourteam int, attackdirection int) *pb_gen.Referee_Info {
teaminfo_their = (*pb_gen.Referee_Info_TeamInfo)(ref_command.Blue)
}

// 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)")
} else if ourteam == 1 && ref_command.GetBlue().GetName() == "Ri-one" {
log.Println("[MW WARNING!!] INCORRECT TEAM COLOR! Referee says (Ri-one == Blue)")
}

// Check if the attack direction is correct
if ourteam == 0 && *ref_command.BlueTeamOnPositiveHalf && attackdirection == 1 {
log.Println("[MW WARNING!!] INCORRECT ATTACK DIRECTION! Referee says (BlueTeamOnPositiveHalf == true)")
} else if ourteam == 1 && !*ref_command.BlueTeamOnPositiveHalf && attackdirection == 1 {
log.Println("[MW WARNING!!] INCORRECT ATTACK DIRECTION! Referee says (BlueTeamOnPositiveHalf == false)")
}

if ourteam == 0 && !*ref_command.BlueTeamOnPositiveHalf && attackdirection == -1 {
log.Println("[MW WARNING!!] INCORRECT ATTACK DIRECTION! Referee says (BlueTeamOnPositiveHalf == true)")
} else if ourteam == 1 && *ref_command.BlueTeamOnPositiveHalf && attackdirection == -1 {
log.Println("[MW WARNING!!] INCORRECT ATTACK DIRECTION! Referee says (BlueTeamOnPositiveHalf == false)")
if !ignore_ref_mismatch {
// 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)")
} else if ourteam == 1 && ref_command.GetBlue().GetName() == "Ri-one" {
log.Println("[MW WARNING!!] INCORRECT TEAM COLOR! Referee says (Ri-one == Blue)")
}

// Check if the attack direction is correct
if ourteam == 0 && *ref_command.BlueTeamOnPositiveHalf && attackdirection == 1 {
log.Println("[MW WARNING!!] INCORRECT ATTACK DIRECTION! Referee says (BlueTeamOnPositiveHalf == true)")
} else if ourteam == 1 && !*ref_command.BlueTeamOnPositiveHalf && attackdirection == 1 {
log.Println("[MW WARNING!!] INCORRECT ATTACK DIRECTION! Referee says (BlueTeamOnPositiveHalf == false)")
}

if ourteam == 0 && !*ref_command.BlueTeamOnPositiveHalf && attackdirection == -1 {
log.Println("[MW WARNING!!] INCORRECT ATTACK DIRECTION! Referee says (BlueTeamOnPositiveHalf == true)")
} else if ourteam == 1 && *ref_command.BlueTeamOnPositiveHalf && attackdirection == -1 {
log.Println("[MW WARNING!!] INCORRECT ATTACK DIRECTION! Referee says (BlueTeamOnPositiveHalf == false)")
}
}

} else {
Expand Down
31 changes: 16 additions & 15 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) {
func RunServer(chserver chan bool, reportrate uint, ourteam int, goalpose int, debug bool, simmode bool, ignore_ref_mismatch bool) {
ipv4 := NW_AI_IPADDR
port := NW_AI_PORT
port_controller := NW_AI_PORT_CONTROLLER
Expand Down Expand Up @@ -171,7 +171,7 @@ func RunServer(chserver chan bool, reportrate uint, ourteam int, goalpose int, d
RobotIpInfo := addRobotIPInfoToRobotIPInfos(robotip_infos)

GeometryInfo := createGeometryInfo()
RefereeInfo := createRefInfo(ourteam, goalpose)
RefereeInfo := createRefInfo(ourteam, goalpose, ignore_ref_mismatch)
OtherInfo := createOtherInfo(int32(goalpose))

//log.Println(OtherInfo.GetAttackDirection())
Expand Down Expand Up @@ -206,18 +206,19 @@ 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)")
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)")
replay = flag.Bool("replay", false, "Replay All Packet")
halfswitch = flag.String("c", "F", "Where to use (N, P, F) F to Full")
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")
visionport = flag.Int("p", 10006, "Vision Multicast Port Number")
ourteam = flag.String("t", "blue", "Our Team (blue or yellow)")
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)")
replay = flag.Bool("replay", false, "Replay All Packet")
halfswitch = flag.String("c", "F", "Where to use (N, P, F) F to Full")
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")
)
//OUR TEAM 0 = blue
//OUR TEAM 1 = yellow
Expand Down Expand Up @@ -273,7 +274,7 @@ func main() {
chbattery := make(chan bool)

go Update(chupdate)
go RunServer(chserver, *reportrate, ourteam_n, goalpos_n, *debug, *simmode)
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 CheckVisionRobot(chvisrobot)
go FPSCounter(chfps, ourteam_n)
Expand Down
13 changes: 0 additions & 13 deletions variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,16 @@ var balldetect [16]bool
var visionwrapper [16]*pb_gen.SSL_WrapperPacket
var visiondetection [16]*pb_gen.SSL_DetectionFrame

var trackerwrapper [16]*pb_gen.TrackerWrapperPacket
var trackerdetection [16]*pb_gen.TrackedFrame

var geometrydata *pb_gen.SSL_GeometryData
var left_geo_goal_x float32
var left_geo_goal_y float32

var num_bluerobots int
var num_yellowrobots int

var bluerobots [16]*pb_gen.SSL_DetectionRobot
var yellowrobots [16]*pb_gen.SSL_DetectionRobot

var trackedblue [16]*pb_gen.TrackedRobot
var trackedyellow [16]*pb_gen.TrackedRobot

var ref_command *pb_gen.Referee
var ball *pb_gen.SSL_DetectionBall

var trackedball *pb_gen.TrackedBall

var only_use_tracker bool = false

var maxcameras int

var filtered_ball_x float32
Expand Down
9 changes: 0 additions & 9 deletions visionreceive.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,27 +238,21 @@ func VisionReceive(chvision chan bool, port int, ourteam int, goalpos int, simmo
}
}

num_yellowrobots = 0
num_bluerobots = 0

// Get Blue Robots
for _, robot := range packet.Detection.GetRobotsBlue() {
switch halfswitch_n {
case 0:
num_bluerobots++
bluerobots[robot.GetRobotId()] = robot
visible_in_vision_b[robot.GetRobotId()] = true

case 1:
if robot.GetX() > 0 {
num_bluerobots++
bluerobots[robot.GetRobotId()] = robot
visible_in_vision_b[robot.GetRobotId()] = true
}

case -1:
if robot.GetX() <= 0 {
num_bluerobots++
bluerobots[robot.GetRobotId()] = robot
visible_in_vision_b[robot.GetRobotId()] = true
}
Expand All @@ -269,20 +263,17 @@ func VisionReceive(chvision chan bool, port int, ourteam int, goalpos int, simmo
for _, robot := range packet.Detection.GetRobotsYellow() {
switch halfswitch_n {
case 0:
num_yellowrobots++
yellowrobots[robot.GetRobotId()] = robot
visible_in_vision_y[robot.GetRobotId()] = true

case 1:
if robot.GetX() > 0 {
num_yellowrobots++
yellowrobots[robot.GetRobotId()] = robot
visible_in_vision_y[robot.GetRobotId()] = true
}

case -1:
if robot.GetX() <= 0 {
num_yellowrobots++
yellowrobots[robot.GetRobotId()] = robot
visible_in_vision_y[robot.GetRobotId()] = true
}
Expand Down

0 comments on commit 7baaa1d

Please sign in to comment.