Skip to content

Commit

Permalink
Add ball placement pos to visualizer
Browse files Browse the repository at this point in the history
  • Loading branch information
g3force committed Jul 7, 2024
1 parent 2631fc9 commit 50270b4
Show file tree
Hide file tree
Showing 8 changed files with 7,490 additions and 6 deletions.
20 changes: 14 additions & 6 deletions cmd/ssl-vision-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"github.com/RoboCup-SSL/ssl-vision-client/frontend"
"github.com/RoboCup-SSL/ssl-vision-client/pkg/client"
"github.com/RoboCup-SSL/ssl-vision-client/pkg/referee"
"github.com/RoboCup-SSL/ssl-vision-client/pkg/tracked"
"github.com/RoboCup-SSL/ssl-vision-client/pkg/vision"
"github.com/RoboCup-SSL/ssl-vision-client/pkg/visualization"
Expand All @@ -16,6 +17,7 @@ var address = flag.String("address", ":8082", "The address on which the UI and A
var visionAddress = flag.String("visionAddress", "224.5.23.2:10006", "The multicast address of ssl-vision, default: 224.5.23.2:10006")
var trackedAddress = flag.String("trackedAddress", "224.5.23.2:10010", "The multicast address of trackers, default: 224.5.23.2:10010")
var visualizationAddress = flag.String("visualizationAddress", "224.5.23.2:10012", "The multicast address of visualization frames, default: 224.5.23.2:10012")
var refereeAddress = flag.String("refereeAddress", "224.5.23.1:10003", "The multicast address of the game controller, default: 224.5.23.1:10003")
var skipInterfaces = flag.String("skipInterfaces", "", "Comma separated list of interface names to ignore when receiving multicast packets")
var verbose = flag.Bool("verbose", false, "Verbose output")

Expand All @@ -34,28 +36,34 @@ func main() {
}

func setupVisionClient() {
receiver := vision.NewReceiver()
visionReceiver := vision.NewReceiver()
visualizationReceiver := visualization.NewReceiver()
trackedReceiver := tracked.NewReceiver()
refereeReceiver := referee.NewReceiver()

publisher := client.NewPublisher()
publisher.DetectionProvider = receiver.CombinedDetectionFrames
publisher.DetectionProvider = visionReceiver.CombinedDetectionFrames
publisher.TrackerProvider = trackedReceiver.TrackedFrames
publisher.GeometryProvider = geometryProvider(receiver)
publisher.GeometryProvider = geometryProvider(visionReceiver)
publisher.RefereeProvider = refereeReceiver.RefereeMsg
publisher.LineSegmentProvider = visualizationReceiver.GetLineSegments
publisher.CircleProvider = visualizationReceiver.GetCircles
http.HandleFunc("/api/vision", publisher.Handler)

skipIfis := parseSkipInterfaces()
receiver.MulticastServer.SkipInterfaces = skipIfis
receiver.MulticastServer.Verbose = *verbose
visionReceiver.MulticastServer.SkipInterfaces = skipIfis
visionReceiver.MulticastServer.Verbose = *verbose
visualizationReceiver.MulticastServer.SkipInterfaces = skipIfis
visualizationReceiver.MulticastServer.Verbose = *verbose
trackedReceiver.MulticastServer.SkipInterfaces = skipIfis
trackedReceiver.MulticastServer.Verbose = *verbose
refereeReceiver.MulticastServer.SkipInterfaces = skipIfis
refereeReceiver.MulticastServer.Verbose = *verbose

receiver.Start(*visionAddress)
visionReceiver.Start(*visionAddress)
visualizationReceiver.Start(*visualizationAddress)
trackedReceiver.Start(*trackedAddress)
refereeReceiver.Start(*refereeAddress)
}

func geometryProvider(receiver *vision.Receiver) func() *vision.SSL_GeometryData {
Expand Down
27 changes: 27 additions & 0 deletions pkg/client/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,33 @@ func (p *Package) AddCircle(sourceId string, circle *visualization.Circle) {
})
}

func (p *Package) AddBallPlacementPos(pos *Point) {
p.Shapes = append(p.Shapes, Shape{OrderNumber: 3, Circle: &Circle{
Center: Point{
X: pos.X,
Y: -pos.Y,
},
Radius: 150,
Style: Style{
Stroke: &black,
StrokeWidth: &lineWidth,
FillOpacity: &noFill,
},
}})
p.Shapes = append(p.Shapes, Shape{OrderNumber: 3, Circle: &Circle{
Center: Point{
X: pos.X,
Y: -pos.Y,
},
Radius: ballRadius,
Style: Style{
Stroke: &black,
StrokeWidth: &lineWidth,
Fill: &black,
},
}})
}

func rgb(rgb *visualization.RgbColor) *string {
if rgb == nil {
return nil
Expand Down
12 changes: 12 additions & 0 deletions pkg/client/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"encoding/json"
"github.com/RoboCup-SSL/ssl-vision-client/pkg/referee"
"github.com/RoboCup-SSL/ssl-vision-client/pkg/tracked"
"github.com/RoboCup-SSL/ssl-vision-client/pkg/vision"
"github.com/RoboCup-SSL/ssl-vision-client/pkg/visualization"
Expand All @@ -22,6 +23,7 @@ type Publisher struct {
DetectionProvider func() *vision.SSL_DetectionFrame
TrackerProvider func() map[string]*tracked.TrackerWrapperPacket
GeometryProvider func() *vision.SSL_GeometryData
RefereeProvider func() *referee.Referee
LineSegmentProvider func() map[string][]*visualization.LineSegment
CircleProvider func() map[string][]*visualization.Circle
}
Expand Down Expand Up @@ -155,5 +157,15 @@ func (p *Publisher) addVisualization(pack *Package) {
}
}

refereeMsg := p.RefereeProvider()
if refereeMsg != nil && refereeMsg.DesignatedPosition != nil {
pack.AddBallPlacementPos(
&Point{
X: refereeMsg.DesignatedPosition.GetX(),
Y: refereeMsg.DesignatedPosition.GetY(),
},
)
}

pack.SortShapes()
}
43 changes: 43 additions & 0 deletions pkg/referee/receiver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package referee

import (
"github.com/RoboCup-SSL/ssl-vision-client/pkg/sslnet"
"google.golang.org/protobuf/proto"
"log"
"sync"
)

type Receiver struct {
lastRefereeMsg *Referee
mutex sync.Mutex
MulticastServer *sslnet.MulticastServer
ConsumeRefereeMsg func(msg *Referee)
}

func NewReceiver() (r *Receiver) {
r = new(Receiver)
r.MulticastServer = sslnet.NewMulticastServer(r.consumeMessage)
r.ConsumeRefereeMsg = func(referee *Referee) {}
return
}

func (r *Receiver) Start(multicastAddress string) {
r.MulticastServer.Start(multicastAddress)
}

func (r *Receiver) RefereeMsg() (msg *Referee) {
r.mutex.Lock()
defer r.mutex.Unlock()
return r.lastRefereeMsg
}

func (r *Receiver) consumeMessage(data []byte) {
msg := new(Referee)
if err := proto.Unmarshal(data, msg); err != nil {
log.Print("Could not parse message: ", err)
return
}
r.mutex.Lock()
r.lastRefereeMsg = msg
r.mutex.Unlock()
}
Loading

0 comments on commit 50270b4

Please sign in to comment.