Skip to content

Commit ee8dd21

Browse files
committed
Read robot specs from config and send it to simulator
1 parent 3b99ac9 commit ee8dd21

19 files changed

+282
-140
lines changed

cmd/ssl-simulation-controller/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ var visionAddress = flag.String("visionAddress", "224.5.23.2:10006", "The addres
1212
var trackerAddress = flag.String("trackerAddress", "224.5.23.2:10010", "The address (ip+port) from which tracker packages are received")
1313
var refereeAddress = flag.String("refereeAddress", "224.5.23.1:10003", "The address (ip+port) from which referee packages are received")
1414
var simControlPort = flag.String("simControlPort", "10300", "The port to which simulation control packets are send")
15+
var robotSpecConfig = flag.String("robotSpecConfig", "config/robot-specs.yaml", "The robot specs config file")
1516

1617
func main() {
1718
flag.Parse()
18-
ctl := simctl.NewSimulationController(*visionAddress, *refereeAddress, *trackerAddress, *simControlPort)
19+
ctl := simctl.NewSimulationController(*visionAddress, *refereeAddress, *trackerAddress, *simControlPort, *robotSpecConfig)
1920
ctl.Start()
2021

2122
signals := make(chan os.Signal, 1)

config/robot-specs.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
robot-specs:
2+
"TIGERs Mannheim":
3+
radius: 0.09
4+
height: 0.15
5+
mass: 2
6+
max_linear_kick_speed: 8
7+
max_chip_kick_speed: 8
8+
center_to_dribbler: 0.073
9+
limits:
10+
acc_speedup_absolute_max: 3
11+
acc_speedup_angular_max: 50
12+
acc_brake_absolute_max: 6
13+
acc_brake_angular_max: 50
14+
vel_absolute_max: 3
15+
vel_angular_max: 20
16+
"ER-Force":
17+
radius: 0.09
18+
height: 0.15
19+
mass: 2
20+
max_linear_kick_speed: 8
21+
max_chip_kick_speed: 8
22+
center_to_dribbler: 0.073
23+
limits:
24+
acc_speedup_absolute_max: 3
25+
acc_speedup_angular_max: 50
26+
acc_brake_absolute_max: 6
27+
acc_brake_angular_max: 50
28+
vel_absolute_max: 3
29+
vel_angular_max: 20

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ go 1.15
55
require (
66
github.com/golang/protobuf v1.4.3
77
google.golang.org/protobuf v1.25.0
8+
gopkg.in/yaml.v2 v2.4.0
89
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,9 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
6363
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
6464
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
6565
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
66+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
67+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
68+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
69+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
6670
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
6771
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

internal/geom/ssl_gc_geometry.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/referee/ssl_gc_common.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/referee/ssl_gc_game_event.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/referee/ssl_gc_referee_message.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/simctl/robot_specs.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package simctl
2+
3+
import (
4+
"github.com/RoboCup-SSL/ssl-simulation-controller/internal/referee"
5+
"github.com/golang/protobuf/proto"
6+
"gopkg.in/yaml.v2"
7+
"io/ioutil"
8+
"log"
9+
)
10+
11+
type TeamRobotSpecs struct {
12+
Teams map[string]RobotSpec `yaml:"robot-specs"`
13+
}
14+
15+
type RobotSpec struct {
16+
Radius float32 `yaml:"radius"`
17+
Height float32 `yaml:"height"`
18+
Mass float32 `yaml:"mass"`
19+
MaxLinearKickSpeed float32 `yaml:"max_linear_kick_speed"`
20+
MaxChipKickSpeed float32 `yaml:"max_chip_kick_speed"`
21+
CenterToDribbler float32 `yaml:"center_to_dribbler"`
22+
Limits Limits `yaml:"limits"`
23+
}
24+
25+
type Limits struct {
26+
AccSpeedupAbsoluteMax float32 `yaml:"acc_speedup_absolute_max,omitempty"`
27+
AccSpeedupAngularMax float32 `yaml:"acc_speedup_angular_max,omitempty"`
28+
AccBrakeAbsoluteMax float32 `yaml:"acc_brake_absolute_max,omitempty"`
29+
AccBrakeAngularMax float32 `yaml:"acc_brake_angular_max,omitempty"`
30+
VelAbsoluteMax float32 `yaml:"vel_absolute_max,omitempty"`
31+
VelAngularMax float32 `yaml:"vel_angular_max,omitempty"`
32+
}
33+
34+
type RobotSpecSetter struct {
35+
c *SimulationController
36+
37+
teamRobotSpecs TeamRobotSpecs
38+
appliedTeams map[referee.Team]string
39+
}
40+
41+
func (r *RobotSpecSetter) LoadRobotSpecs(configFile string) {
42+
data, err := ioutil.ReadFile(configFile)
43+
if err != nil {
44+
log.Println("Could not read robot spec file: ", err)
45+
}
46+
if err := yaml.Unmarshal(data, &r.teamRobotSpecs); err != nil {
47+
log.Println("Could not unmarshal robot spec file: ", err)
48+
}
49+
r.appliedTeams = map[referee.Team]string{}
50+
}
51+
52+
func (r *RobotSpecSetter) handleRobotSpecs() {
53+
if *r.c.lastRefereeMsg.Command != referee.Referee_HALT {
54+
// Only during HALT
55+
return
56+
}
57+
58+
r.updateTeam(referee.Team_BLUE, *r.c.lastRefereeMsg.Blue.Name)
59+
r.updateTeam(referee.Team_YELLOW, *r.c.lastRefereeMsg.Yellow.Name)
60+
}
61+
62+
func (r *RobotSpecSetter) updateTeam(team referee.Team, teamName string) {
63+
if r.appliedTeams[team] != teamName {
64+
if spec, ok := r.teamRobotSpecs.Teams[teamName]; ok {
65+
protoSpec := mapRobotSpec(spec)
66+
protoSpec.Id = new(referee.RobotId)
67+
protoSpec.Id.Id = new(uint32)
68+
protoSpec.Id.Team = new(referee.Team)
69+
*protoSpec.Id.Id = 0
70+
*protoSpec.Id.Team = team
71+
r.sendConfig(protoSpec)
72+
r.appliedTeams[team] = teamName
73+
}
74+
}
75+
}
76+
77+
func (r *RobotSpecSetter) sendConfig(robotSpec *RobotSpecs) {
78+
log.Printf("Sending robot spec %v", robotSpec)
79+
80+
command := SimulatorCommand{
81+
Config: &SimulatorConfig{
82+
RobotSpecs: []*RobotSpecs{
83+
robotSpec,
84+
}},
85+
}
86+
87+
if data, err := proto.Marshal(&command); err != nil {
88+
log.Println("Could not marshal command: ", err)
89+
} else {
90+
r.c.simControlClient.Send(data)
91+
}
92+
}
93+
94+
func mapRobotSpec(spec RobotSpec) (protoSpec *RobotSpecs) {
95+
protoSpec = new(RobotSpecs)
96+
protoSpec.Radius = &spec.Radius
97+
protoSpec.Height = &spec.Height
98+
protoSpec.Mass = &spec.Mass
99+
protoSpec.MaxLinearKickSpeed = &spec.MaxLinearKickSpeed
100+
protoSpec.MaxChipKickSpeed = &spec.MaxChipKickSpeed
101+
protoSpec.CenterToDribbler = &spec.CenterToDribbler
102+
protoSpec.Limits = mapRobotLimits(spec.Limits)
103+
return
104+
}
105+
106+
func mapRobotLimits(limits Limits) (protoLimits *RobotLimits) {
107+
protoLimits = new(RobotLimits)
108+
protoLimits.AccSpeedupAbsoluteMax = &limits.AccSpeedupAbsoluteMax
109+
protoLimits.AccSpeedupAngularMax = &limits.AccSpeedupAngularMax
110+
protoLimits.AccBrakeAbsoluteMax = &limits.AccBrakeAbsoluteMax
111+
protoLimits.AccBrakeAngularMax = &limits.AccBrakeAngularMax
112+
protoLimits.VelAbsoluteMax = &limits.VelAbsoluteMax
113+
protoLimits.VelAngularMax = &limits.VelAngularMax
114+
return
115+
}

internal/simctl/simctl.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ type SimulationController struct {
2424

2525
ballReplacer BallReplacer
2626
robotCountMaintainer RobotCountMaintainer
27+
robotSpecsSetter RobotSpecSetter
2728
}
2829

29-
func NewSimulationController(visionAddress, refereeAddress, trackerAddress string, simControlPort string) (c *SimulationController) {
30+
func NewSimulationController(visionAddress, refereeAddress, trackerAddress, simControlPort, robotSpecConfig string) (c *SimulationController) {
3031
c = new(SimulationController)
3132
c.visionServer = sslnet.NewMulticastServer(visionAddress, c.onNewVisionData)
3233
c.refereeServer = sslnet.NewMulticastServer(refereeAddress, c.onNewRefereeData)
3334
c.trackerServer = sslnet.NewMulticastServer(trackerAddress, c.onNewTrackerData)
3435
c.simControlPort = simControlPort
3536
c.ballReplacer.c = c
3637
c.robotCountMaintainer.c = c
38+
c.robotSpecsSetter.c = c
39+
c.robotSpecsSetter.LoadRobotSpecs(robotSpecConfig)
3740
return
3841
}
3942

@@ -101,6 +104,7 @@ func (c *SimulationController) handle() {
101104

102105
c.ballReplacer.handleReplaceBall()
103106
c.robotCountMaintainer.handleRobotCount()
107+
c.robotSpecsSetter.handleRobotSpecs()
104108
}
105109

106110
func (c *SimulationController) Start() {

0 commit comments

Comments
 (0)