@@ -5,20 +5,21 @@ import (
5
5
"flag"
6
6
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/ci"
7
7
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/ci/autoref"
8
+ "github.com/RoboCup-SSL/ssl-game-controller/internal/app/geom"
8
9
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/sslconn"
9
10
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/state"
10
11
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/tracker"
11
12
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/vision"
13
+ "github.com/google/uuid"
12
14
"log"
13
15
"net"
14
16
"time"
15
17
)
16
18
17
19
var addressAutoRefCi = flag .String ("addressAutoRef" , "localhost:10013" , "The address of the auto referee CI interface" )
18
20
var addressGcCi = flag .String ("addressGc" , "localhost:10009" , "The address of the ssl-game-controller CI interface" )
21
+ var sendDetectionFrames = flag .Bool ("sendDetectionFrames" , true , "Send detection frames if true, tracker frames else" )
19
22
20
- var detectionFrame = createSSlDetectionFrame ()
21
- var refereeMsg * state.Referee
22
23
var ballSpeed = float32 (0 )
23
24
var ballAcc = float32 (- 0.26 )
24
25
@@ -28,28 +29,67 @@ func main() {
28
29
autoRefConn := connect (* addressAutoRefCi )
29
30
gcConn := connect (* addressGcCi )
30
31
32
+ var detectionFrame * vision.SSL_DetectionFrame
33
+ var trackerFrame * tracker.TrackerWrapperPacket
34
+ var refereeMsg * state.Referee
35
+
36
+ if * sendDetectionFrames {
37
+ detectionFrame = createSSlDetectionFrame ()
38
+ } else {
39
+ trackerFrame = createTrackerFrame ()
40
+ }
41
+
31
42
for {
32
- simulate ()
33
- sendAutoRefCi (autoRefConn , detectionFrame )
34
- trackerFrame := receiveAutoRefCi (autoRefConn )
35
- if trackerFrame == nil {
43
+ if * sendDetectionFrames {
44
+ detectionFrame = simulateDetection (detectionFrame )
45
+ } else {
46
+ trackerFrame .TrackedFrame = simulateTracked (trackerFrame .TrackedFrame )
47
+ }
48
+ sendAutoRefCi (autoRefConn , detectionFrame , trackerFrame , refereeMsg )
49
+ newTrackerFrame := receiveAutoRefCi (autoRefConn )
50
+ if newTrackerFrame == nil {
36
51
return
37
52
}
38
- sendCi (gcConn , trackerFrame )
53
+ sendCi (gcConn , newTrackerFrame )
39
54
refereeMsg = receiveCi (gcConn )
40
55
time .Sleep (10 * time .Millisecond )
41
56
}
42
57
}
43
58
44
- func simulate () {
45
- * detectionFrame .RobotsBlue [0 ].X = 1000
59
+ func simulateDetection (detectionFrame * vision.SSL_DetectionFrame ) * vision.SSL_DetectionFrame {
60
+ timestamp := time .Now ().UnixNano ()
61
+
62
+ * detectionFrame .TSent = float64 (timestamp ) / 1e9
63
+ * detectionFrame .TCapture = float64 (timestamp ) / 1e9
64
+ * detectionFrame .FrameNumber ++
65
+
46
66
ballY := detectionFrame .Balls [0 ].Y
47
67
* ballY += ballSpeed / 100 * 1000
48
68
ballSpeed += ballAcc * 0.01
49
69
if * ballY > 4700 || ballSpeed <= 0 {
50
70
* ballY = 0
51
71
ballSpeed = 3
52
72
}
73
+
74
+ return detectionFrame
75
+ }
76
+
77
+ func simulateTracked (trackedFrame * tracker.TrackedFrame ) * tracker.TrackedFrame {
78
+ timestamp := time .Now ().UnixNano ()
79
+
80
+ * trackedFrame .Timestamp = float64 (timestamp ) / 1e9
81
+ * trackedFrame .FrameNumber ++
82
+
83
+ ballY := trackedFrame .Balls [0 ].Pos .Y
84
+ * ballY += ballSpeed / 100
85
+ ballSpeed += ballAcc * 0.01
86
+ if * ballY > 4.7 || ballSpeed <= 0 {
87
+ * ballY = 0
88
+ ballSpeed = 3
89
+ }
90
+ * trackedFrame .Balls [0 ].Vel .Y = ballSpeed
91
+
92
+ return trackedFrame
53
93
}
54
94
55
95
func connect (addr string ) (conn net.Conn ) {
@@ -82,6 +122,7 @@ func createBot() (robot *vision.SSL_DetectionRobot) {
82
122
robot .Y = new (float32 )
83
123
robot .Orientation = new (float32 )
84
124
* robot .Confidence = 1
125
+ * robot .X = 1000
85
126
return
86
127
}
87
128
@@ -96,10 +137,46 @@ func createSSlDetectionFrame() (p *vision.SSL_DetectionFrame) {
96
137
return
97
138
}
98
139
140
+ func createTrackerFrame () (p * tracker.TrackerWrapperPacket ) {
141
+ p = new (tracker.TrackerWrapperPacket )
142
+ p .Uuid = new (string )
143
+ * p .Uuid = uuid .NewString ()
144
+ p .TrackedFrame = new (tracker.TrackedFrame )
145
+ p .TrackedFrame .FrameNumber = new (uint32 )
146
+ p .TrackedFrame .Timestamp = new (float64 )
147
+ p .TrackedFrame .Balls = append (p .TrackedFrame .Balls ,
148
+ & tracker.TrackedBall {
149
+ Pos : & geom.Vector3 {
150
+ X : new (float32 ),
151
+ Y : new (float32 ),
152
+ Z : new (float32 ),
153
+ },
154
+ Vel : & geom.Vector3 {
155
+ X : new (float32 ),
156
+ Y : new (float32 ),
157
+ Z : new (float32 ),
158
+ },
159
+ })
160
+ p .TrackedFrame .Robots = append (p .TrackedFrame .Robots ,
161
+ & tracker.TrackedRobot {
162
+ RobotId : & state.RobotId {
163
+ Id : new (uint32 ),
164
+ Team : new (state.Team ),
165
+ },
166
+ Pos : & geom.Vector2 {
167
+ X : new (float32 ),
168
+ Y : new (float32 ),
169
+ },
170
+ Orientation : new (float32 ),
171
+ })
172
+
173
+ * p .TrackedFrame .Robots [0 ].RobotId .Team = state .Team_BLUE
174
+ * p .TrackedFrame .Robots [0 ].Pos .X = 1
175
+ return
176
+ }
177
+
99
178
func sendCi (conn net.Conn , trackerPacket * tracker.TrackerWrapperPacket ) {
100
179
timestamp := time .Now ().UnixNano ()
101
- * trackerPacket .TrackedFrame .Timestamp = float64 (timestamp / 1e9 )
102
- * trackerPacket .TrackedFrame .FrameNumber ++
103
180
input := ci.CiInput {Timestamp : & timestamp , TrackerPacket : trackerPacket }
104
181
if err := sslconn .SendMessage (conn , & input ); err != nil {
105
182
log .Println ("Could not send message: " , err )
@@ -115,15 +192,20 @@ func receiveCi(conn net.Conn) *state.Referee {
115
192
return output .RefereeMsg
116
193
}
117
194
118
- func sendAutoRefCi (conn net.Conn , detectionFrame * vision.SSL_DetectionFrame ) {
119
- timestamp := time .Now ().UnixNano ()
120
-
121
- * detectionFrame .TSent = float64 (timestamp ) / 1e9
122
- * detectionFrame .TCapture = float64 (timestamp ) / 1e9
123
- * detectionFrame .FrameNumber ++
195
+ func sendAutoRefCi (
196
+ conn net.Conn ,
197
+ detectionFrame * vision.SSL_DetectionFrame ,
198
+ trackerFrame * tracker.TrackerWrapperPacket ,
199
+ refereeMsg * state.Referee ,
200
+ ) {
201
+ var detections []* vision.SSL_DetectionFrame
202
+ if detectionFrame != nil {
203
+ detections = append (detections , detectionFrame )
204
+ }
124
205
input := autoref.AutoRefCiInput {
125
- Detection : []* vision.SSL_DetectionFrame {detectionFrame },
126
- RefereeMessage : refereeMsg ,
206
+ Detection : detections ,
207
+ TrackerWrapperPacket : trackerFrame ,
208
+ RefereeMessage : refereeMsg ,
127
209
}
128
210
if err := sslconn .SendMessage (conn , & input ); err != nil {
129
211
log .Println ("Could not send message: " , err )
0 commit comments