forked from RoboCup-SSL/grSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configwidget.cpp
201 lines (173 loc) · 9.76 KB
/
configwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
grSim - RoboCup Small Size Soccer Robots Simulator
Copyright (C) 2011, Parsian Robotic Center (eew.aut.ac.ir/~parsian/grsim)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "configwidget.h"
#define ADD_ENUM(type,name,Defaultvalue,namestring) \
v_##name = shared_ptr<Var##type>(new Var##type(namestring,Defaultvalue));
#define END_ENUM(parents, name) \
parents->addChild(v_##name);
#define ADD_TO_ENUM(name,str) \
v_##name->addItem(str);
#define ADD_VALUE(parent,type,name,defaultvalue,namestring) \
v_##name = shared_ptr<Var##type>(new Var##type(namestring,defaultvalue)); \
parent->addChild(v_##name);
#include<QDir>
ConfigWidget::ConfigWidget()
{
tmodel=new VarTreeModel();
this->setModel(tmodel);
geo_vars = VarListPtr(new VarList("Geometry"));
world.push_back(geo_vars);
robot_settings = new QSettings;
VarListPtr field_vars(new VarList("Field"));
geo_vars->addChild(field_vars);
ADD_VALUE(field_vars,Double,Field_Length,6.05,"Length")
ADD_VALUE(field_vars,Double,Field_Width,4.05,"Width")
ADD_VALUE(field_vars,Double,Field_Rad,0.5,"Radius")
ADD_VALUE(field_vars,Double,Field_Penalty_Rad,0.50,"Penalty radius")
ADD_VALUE(field_vars,Double,Field_Penalty_Line,0.350,"Penalty line length")
ADD_VALUE(field_vars,Double,Field_Penalty_Point,0.450,"Penalty point")
ADD_VALUE(field_vars,Double,Field_Margin,1.0,"Margin")
ADD_VALUE(field_vars,Double,Field_Referee_Margin,0.7,"Referee margin")
ADD_VALUE(field_vars,Double,Wall_Thickness,0.100,"Wall thickness")
ADD_VALUE(field_vars,Double,Goal_Thickness,0.020,"Goal thickness")
ADD_VALUE(field_vars,Double,Goal_Depth,0.20,"Goal depth")
ADD_VALUE(field_vars,Double,Goal_Width,0.70,"Goal width")
ADD_VALUE(field_vars,Double,Goal_Height,0.40,"Goal height")
ADD_ENUM(StringEnum,YellowTeam,"Parsian","Yellow Team");
END_ENUM(geo_vars,YellowTeam)
ADD_ENUM(StringEnum,BlueTeam,"Parsian","Blue Team");
END_ENUM(geo_vars,BlueTeam)
VarListPtr ballg_vars(new VarList("Ball"));
geo_vars->addChild(ballg_vars);
ADD_VALUE(ballg_vars,Double,BallRadius,0.0215,"Radius")
VarListPtr phys_vars(new VarList("Physics"));
world.push_back(phys_vars);
VarListPtr worldp_vars(new VarList("World"));
phys_vars->addChild(worldp_vars);
ADD_VALUE(worldp_vars,Double,DesiredFPS,65,"Desired FPS")
ADD_VALUE(worldp_vars,Bool,SyncWithGL,false,"Synchronize ODE with OpenGL")
ADD_VALUE(worldp_vars,Double,DeltaTime,0.015,"ODE time step")
ADD_VALUE(worldp_vars,Double,Gravity,9.8,"Gravity")
VarListPtr ballp_vars(new VarList("Ball"));
phys_vars->addChild(ballp_vars);
ADD_VALUE(ballp_vars,Double,BallMass,0.043,"Ball mass");
ADD_VALUE(ballp_vars,Double,BallFriction,0.05,"Ball-ground friction")
ADD_VALUE(ballp_vars,Double,BallSlip,1,"Ball-ground slip")
ADD_VALUE(ballp_vars,Double,BallBounce,0.5,"Ball-ground bounce factor")
ADD_VALUE(ballp_vars,Double,BallBounceVel,0.1,"Ball-ground bounce min velocity")
ADD_VALUE(ballp_vars,Double,BallLinearDamp,0.004,"Ball linear damping")
ADD_VALUE(ballp_vars,Double,BallAngularDamp,0.004,"Ball angular damping")
VarListPtr comm_vars(new VarList("Communication"));
world.push_back(comm_vars);
ADD_VALUE(comm_vars,String,VisionMulticastAddr,"224.5.23.2","Vision multicast address") //SSL Vision: "224.5.23.2"
ADD_VALUE(comm_vars,Int,VisionMulticastPort,10020,"Vision multicast port")
ADD_VALUE(comm_vars,Int,CommandListenPort,20011,"Command listen port")
ADD_VALUE(comm_vars,Int,BlueStatusSendPort,30011,"Blue Team status send port")
ADD_VALUE(comm_vars,Int,YellowStatusSendPort,30012,"Yellow Team status send port")
ADD_VALUE(comm_vars,Int,sendDelay,0,"Sending delay (milliseconds)")
VarListPtr gauss_vars(new VarList("Gaussian noise"));
comm_vars->addChild(gauss_vars);
ADD_VALUE(gauss_vars,Bool,noise,false,"Noise")
ADD_VALUE(gauss_vars,Double,noiseDeviation_x,3,"Deviation for x values")
ADD_VALUE(gauss_vars,Double,noiseDeviation_y,3,"Deviation for y values")
ADD_VALUE(gauss_vars,Double,noiseDeviation_angle,2,"Deviation for angle values")
VarListPtr vanishing_vars(new VarList("Vanishing probability"));
comm_vars->addChild(vanishing_vars);
ADD_VALUE(gauss_vars,Bool,vanishing,false,"Vanishing")
ADD_VALUE(vanishing_vars,Double,blue_team_vanishing,0,"Blue team")
ADD_VALUE(vanishing_vars,Double,yellow_team_vanishing,0,"Yellow team")
ADD_VALUE(vanishing_vars,Double,ball_vanishing,0,"Ball")
world=VarXML::read(world,(qApp->applicationDirPath() + QString("/settings.xml")).toStdString());
QDir dir;
std::string blueteam = v_BlueTeam->getString();
geo_vars->removeChild(v_BlueTeam);
std::string yellowteam = v_YellowTeam->getString();
geo_vars->removeChild(v_YellowTeam);
ADD_ENUM(StringEnum,BlueTeam,blueteam.c_str(),"Blue Team");
ADD_ENUM(StringEnum,YellowTeam,yellowteam.c_str(),"Yellow Team");
dir.setCurrent(qApp->applicationDirPath()+"/../config/");
dir.setNameFilters(QStringList() << "*.ini");
dir.setSorting(QDir::Size | QDir::Reversed);
QFileInfoList list = dir.entryInfoList();
for (int i = 0; i < list.size(); ++i) {
QFileInfo fileInfo = list.at(i);
QStringList s = fileInfo.fileName().split(".");
QString str;
if (s.count() > 0) str = s[0];
ADD_TO_ENUM(BlueTeam,str.toStdString())
ADD_TO_ENUM(YellowTeam,str.toStdString())
}
END_ENUM(geo_vars,BlueTeam)
END_ENUM(geo_vars,YellowTeam)
v_BlueTeam->setString(blueteam);
v_YellowTeam->setString(yellowteam);
tmodel->setRootItems(world);
this->expandAndFocus(geo_vars);
this->expandAndFocus(phys_vars);
this->expandAndFocus(comm_vars);
this->fitColumns();
resize(320,400);
connect(v_BlueTeam.get(), SIGNAL(wasEdited(VarPtr)), this, SLOT(loadRobotsSettings()));
connect(v_YellowTeam.get(), SIGNAL(wasEdited(VarPtr)), this, SLOT(loadRobotsSettings()));
loadRobotsSettings();
}
ConfigWidget::~ConfigWidget() {
VarXML::write(world,(qApp->applicationDirPath() + QString("/settings.xml")).toStdString());
}
ConfigDockWidget::ConfigDockWidget(QWidget* _parent,ConfigWidget* _conf){
parent=_parent;conf=_conf;
setWidget(conf);
conf->move(0,20);
}
void ConfigDockWidget::closeEvent(QCloseEvent* event)
{
emit closeSignal(false);
}
void ConfigWidget::loadRobotsSettings()
{
loadRobotSettings(YellowTeam().c_str());
yellowSettings = robotSettings;
loadRobotSettings(BlueTeam().c_str());
blueSettings = robotSettings;
}
void ConfigWidget::loadRobotSettings(QString team)
{
QString ss = qApp->applicationDirPath()+QString("/../config/")+QString("%1.ini").arg(team);
robot_settings = new QSettings(ss, QSettings::IniFormat);
robotSettings.RobotCenterFromKicker = robot_settings->value("Geometery/CenterFromKicker", 0.073).toDouble();
robotSettings.RobotRadius = robot_settings->value("Geometery/Radius", 0.09).toDouble();
robotSettings.RobotHeight = robot_settings->value("Geometery/Height", 0.13).toDouble();
robotSettings.BottomHeight = robot_settings->value("Geometery/RobotBottomZValue", 0.02).toDouble();
robotSettings.KickerZ = robot_settings->value("Geometery/KickerZValue", 0.005).toDouble();
robotSettings.KickerThickness = robot_settings->value("Geometery/KickerThickness", 0.005).toDouble();
robotSettings.KickerWidth = robot_settings->value("Geometery/KickerWidth", 0.08).toDouble();
robotSettings.KickerHeight = robot_settings->value("Geometery/KickerHeight", 0.04).toDouble();
robotSettings.WheelRadius = robot_settings->value("Geometery/WheelRadius", 0.0325).toDouble();
robotSettings.WheelThickness = robot_settings->value("Geometery/WheelThickness", 0.005).toDouble();
robotSettings.Wheel1Angle = robot_settings->value("Geometery/Wheel1Angle", 60).toDouble();
robotSettings.Wheel2Angle = robot_settings->value("Geometery/Wheel2Angle", 135).toDouble();
robotSettings.Wheel3Angle = robot_settings->value("Geometery/Wheel3Angle", 225).toDouble();
robotSettings.Wheel4Angle = robot_settings->value("Geometery/Wheel4Angle", 300).toDouble();
robotSettings.BodyMass = robot_settings->value("Physics/BodyMass", 2).toDouble();
robotSettings.WheelMass = robot_settings->value("Physics/WheelMass", 0.2).toDouble();
robotSettings.KickerMass= robot_settings->value("Physics/KickerMass",0.02).toDouble();
robotSettings.KickerDampFactor = robot_settings->value("Physics/KickerDampFactor", 0.2f).toDouble();
robotSettings.RollerTorqueFactor = robot_settings->value("Physics/RollerTorqueFactor", 0.06f).toDouble();
robotSettings.RollerPerpendicularTorqueFactor = robot_settings->value("Physics/RollerPerpendicularTorqueFactor", 0.005f).toDouble();
robotSettings.Kicker_Friction = robot_settings->value("Physics/KickerFriction", 0.8f).toDouble();
robotSettings.WheelTangentFriction = robot_settings->value("Physics/WheelTangentFriction", 0.8f).toDouble();
robotSettings.WheelPerpendicularFriction = robot_settings->value("Physics/WheelPerpendicularFriction", 0.05f).toDouble();
robotSettings.Wheel_Motor_FMax = robot_settings->value("Physics/WheelMotorMaximumApplyingTorque", 0.2f).toDouble();
}